You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2015/10/31 23:22:19 UTC

[04/14] lucy git commit: Rework OpenOut for multi-value return.

Rework OpenOut for multi-value return.

The Go binding for Folder's OpenOut method should return a tuple of the
OutStream and an error.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/c8950d00
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/c8950d00
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/c8950d00

Branch: refs/heads/master
Commit: c8950d0069a2714b3476f58026da9995624cf4b5
Parents: c7e9636
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Oct 20 19:04:43 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Fri Oct 23 16:40:05 2015 -0700

----------------------------------------------------------------------
 go/build.go            |  4 ++++
 go/lucy/search_test.go |  8 ++++----
 go/lucy/store.go       | 16 ++++++++++++++++
 go/lucy/store_test.go  |  8 ++++----
 4 files changed, 28 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/c8950d00/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 0a03d90..96f01ed 100644
--- a/go/build.go
+++ b/go/build.go
@@ -252,6 +252,10 @@ func specClasses(parcel *cfc.Parcel) {
 	outStreamBinding.SpecMethod("Write_F64", "WriteF64(float64) error")
 	outStreamBinding.SpecMethod("Absorb", "Absorb(InStream) error")
 	outStreamBinding.Register()
+
+	folderBinding := cfc.NewGoClass(parcel, "Lucy::Store::Folder")
+	folderBinding.SpecMethod("Open_Out", "OpenOut(string) (OutStream, error)")
+	folderBinding.Register()
 }
 
 func build() {

http://git-wip-us.apache.org/repos/asf/lucy/blob/c8950d00/go/lucy/search_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/search_test.go b/go/lucy/search_test.go
index ae4c352..c4cd282 100644
--- a/go/lucy/search_test.go
+++ b/go/lucy/search_test.go
@@ -23,7 +23,7 @@ import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
 
 func checkQuerySerialize(t *testing.T, query Query) {
 	folder := NewRAMFolder("")
-	outStream := folder.OpenOut("foo")
+	outStream, _ := folder.OpenOut("foo")
 	query.Serialize(outStream)
 	outStream.Close()
 	inStream := folder.OpenIn("foo")
@@ -401,7 +401,7 @@ func TestTopDocsBasics(t *testing.T) {
 	}
 
 	folder := NewRAMFolder("")
-	outstream := folder.OpenOut("foo")
+	outstream, _ := folder.OpenOut("foo")
 	td.Serialize(outstream)
 	outstream.Close()
 	inStream := folder.OpenIn("foo")
@@ -490,7 +490,7 @@ func TestSortSpecBasics(t *testing.T) {
 		t.Error("Sort by field value")
 	}
 
-	outstream := folder.OpenOut("foo")
+	outstream, _ := folder.OpenOut("foo")
 	sortSpec.Serialize(outstream)
 	outstream.Close()
 	inStream := folder.OpenIn("foo")
@@ -698,7 +698,7 @@ func TestMatchDocSerialization(t *testing.T) {
 	values := []interface{}{"foo", int64(42)}
 	matchDoc := NewMatchDoc(100, 1.5, values)
 	folder := NewRAMFolder("")
-	outstream := folder.OpenOut("foo")
+	outstream, _ := folder.OpenOut("foo")
 	matchDoc.Serialize(outstream)
 	outstream.Close()
 	inStream := folder.OpenIn("foo")

http://git-wip-us.apache.org/repos/asf/lucy/blob/c8950d00/go/lucy/store.go
----------------------------------------------------------------------
diff --git a/go/lucy/store.go b/go/lucy/store.go
index 503327e..f23241e 100644
--- a/go/lucy/store.go
+++ b/go/lucy/store.go
@@ -20,6 +20,7 @@ package lucy
 #include <stdlib.h>
 
 #include "Lucy/Store/Lock.h"
+#include "Lucy/Store/Folder.h"
 #include "Lucy/Store/InStream.h"
 #include "Lucy/Store/OutStream.h"
 
@@ -329,3 +330,18 @@ func (out *OutStreamIMP) Absorb(in InStream) error {
 		C.LUCY_OutStream_Absorb(self, inStreamC)
 	})
 }
+
+func (f *FolderIMP) OpenOut(path string) (retval OutStream, err error) {
+	err = clownfish.TrapErr(func() {
+		self := (*C.lucy_Folder)(clownfish.Unwrap(f, "f"))
+		pathC := (*C.cfish_String)(clownfish.GoToClownfish(path, unsafe.Pointer(C.CFISH_STRING), false))
+		defer C.cfish_decref(unsafe.Pointer(pathC))
+		retvalC := C.LUCY_Folder_Open_Out(self, pathC)
+		if retvalC == nil {
+			cfErr := C.cfish_Err_get_error();
+			panic(clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(cfErr)))).(error))
+		}
+		retval = WRAPOutStream(unsafe.Pointer(retvalC))
+	})
+	return retval, err
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/c8950d00/go/lucy/store_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/store_test.go b/go/lucy/store_test.go
index 5c73693..d75dbf0 100644
--- a/go/lucy/store_test.go
+++ b/go/lucy/store_test.go
@@ -280,7 +280,7 @@ func TestIOStreamReadWrite(t *testing.T) {
 
 func TestIOStreamMisc(t *testing.T) {
 	folder := NewRAMFolder("mydir")
-	outStream := folder.OpenOut("file.dat")
+	outStream, _ := folder.OpenOut("file.dat")
 	if got := outStream.GetPath(); got != "mydir/file.dat" {
 		t.Errorf("GetPath: %s", got)
 	}
@@ -301,9 +301,9 @@ func runFolderTests(t *testing.T, folder Folder) {
 	}
 
 	folder.MkDir("stuff")
-	outStream := folder.OpenOut("stuff/hello")
-	if outStream == nil {
-		t.Errorf("OpenOut")
+	outStream, err := folder.OpenOut("stuff/hello")
+	if outStream == nil || err != nil {
+		t.Errorf("OpenOut: %v", err)
 	}
 	outStream.WriteBytes([]byte("hi"), 2)
 	outStream.Close()