lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [3/5] lucy git commit: Return uintptr instead of unsafe.Pointer.
Date Tue, 07 Apr 2015 00:03:57 GMT
Return uintptr instead of unsafe.Pointer.

Force users to import `unsafe` if they want to perform unsafe
operations.


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

Branch: refs/heads/master
Commit: 81e861c727e6b6d2fdaf0eced11bd7e0cc079db1
Parents: e0ad52e
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Sat Mar 28 16:59:07 2015 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Sat Apr 4 17:51:29 2015 -0700

----------------------------------------------------------------------
 go/lucy/analysis.go | 10 +++++-----
 go/lucy/index.go    |  8 +++++---
 go/lucy/plan.go     | 17 ++++++++++-------
 go/lucy/search.go   | 14 +++++++-------
 4 files changed, 27 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/81e861c7/go/lucy/analysis.go
----------------------------------------------------------------------
diff --git a/go/lucy/analysis.go b/go/lucy/analysis.go
index d538a86..679643c 100644
--- a/go/lucy/analysis.go
+++ b/go/lucy/analysis.go
@@ -28,7 +28,7 @@ import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
 
 type Analyzer interface {
 	clownfish.Obj
-	ToAnalyzerPtr() unsafe.Pointer
+	ToAnalyzerPtr() uintptr
 }
 
 type EasyAnalyzer struct {
@@ -38,7 +38,7 @@ type EasyAnalyzer struct {
 func NewEasyAnalyzer(language string) *EasyAnalyzer {
 	lang := clownfish.NewString(language)
 	obj := &EasyAnalyzer{
-		C.lucy_EasyAnalyzer_new((*C.cfish_String)(lang.ToPtr())),
+		C.lucy_EasyAnalyzer_new((*C.cfish_String)(unsafe.Pointer(lang.ToPtr()))),
 	}
 	runtime.SetFinalizer(obj, (*EasyAnalyzer).finalize)
 	return obj
@@ -49,10 +49,10 @@ func (obj *EasyAnalyzer) finalize() {
 	obj.ref = nil
 }
 
-func (obj *EasyAnalyzer) ToPtr() unsafe.Pointer {
-	return unsafe.Pointer(obj.ref)
+func (obj *EasyAnalyzer) ToPtr() uintptr {
+	return uintptr(unsafe.Pointer(obj.ref))
 }
 
-func (obj *EasyAnalyzer) ToAnalyzerPtr() unsafe.Pointer {
+func (obj *EasyAnalyzer) ToAnalyzerPtr() uintptr {
 	return obj.ToPtr()
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/81e861c7/go/lucy/index.go
----------------------------------------------------------------------
diff --git a/go/lucy/index.go b/go/lucy/index.go
index f0e0979..7440d8b 100644
--- a/go/lucy/index.go
+++ b/go/lucy/index.go
@@ -75,7 +75,8 @@ func OpenIndexer(args *OpenIndexerArgs) (obj *Indexer, err error) {
 	}
 	err = clownfish.TrapErr(func() {
 		obj = &Indexer{
-			C.lucy_Indexer_new(schemaC, (*C.cfish_Obj)(ixLoc.ToPtr()),
+			C.lucy_Indexer_new(schemaC,
+				(*C.cfish_Obj)(unsafe.Pointer(ixLoc.ToPtr())),
 				managerC, C.int32_t(flags)),
 			nil,
 		}
@@ -124,8 +125,9 @@ func (obj *Indexer) AddDoc(doc interface{}) error {
 		value := docValue.Field(i).String()
 		fieldC := obj.findFieldC(field)
 		valueC := clownfish.NewString(value)
-		C.CFISH_Hash_Store(docFields, (*C.cfish_Obj)(fieldC.ToPtr()),
-			C.cfish_inc_refcount(valueC.ToPtr()))
+		C.CFISH_Hash_Store(docFields,
+			(*C.cfish_Obj)(unsafe.Pointer(fieldC.ToPtr())),
+			C.cfish_inc_refcount(unsafe.Pointer(valueC.ToPtr())))
 	}
 
 	// TODO create an additional method AddDocWithBoost which allows the

http://git-wip-us.apache.org/repos/asf/lucy/blob/81e861c7/go/lucy/plan.go
----------------------------------------------------------------------
diff --git a/go/lucy/plan.go b/go/lucy/plan.go
index 673f861..dbc9d5f 100644
--- a/go/lucy/plan.go
+++ b/go/lucy/plan.go
@@ -32,7 +32,7 @@ type Schema struct {
 
 type FieldType interface {
 	clownfish.Obj
-	ToFieldTypePtr() unsafe.Pointer
+	ToFieldTypePtr() uintptr
 }
 
 type FullTextType struct {
@@ -54,13 +54,16 @@ func (obj *Schema) finalize() {
 
 func (obj *Schema) SpecField(field string, fieldType FieldType) {
 	fieldCF := clownfish.NewString(field)
-	C.LUCY_Schema_Spec_Field(obj.ref, (*C.cfish_String)(fieldCF.ToPtr()),
-		(*C.lucy_FieldType)(fieldType.ToFieldTypePtr()))
+	C.LUCY_Schema_Spec_Field(obj.ref,
+		(*C.cfish_String)(unsafe.Pointer(fieldCF.ToPtr())),
+		(*C.lucy_FieldType)(unsafe.Pointer(fieldType.ToFieldTypePtr())))
 }
 
 func NewFullTextType(analyzer Analyzer) *FullTextType {
 	obj := &FullTextType{
-		C.lucy_FullTextType_new((*C.lucy_Analyzer)(analyzer.ToAnalyzerPtr())),
+		C.lucy_FullTextType_new(
+			(*C.lucy_Analyzer)(unsafe.Pointer(analyzer.ToAnalyzerPtr())),
+		),
 	}
 	runtime.SetFinalizer(obj, (*FullTextType).finalize)
 	return obj
@@ -71,10 +74,10 @@ func (obj *FullTextType) finalize() {
 	obj.ref = nil
 }
 
-func (obj *FullTextType) ToPtr() unsafe.Pointer {
-	return unsafe.Pointer(obj.ref)
+func (obj *FullTextType) ToPtr() uintptr {
+	return uintptr(unsafe.Pointer(obj.ref))
 }
 
-func (obj *FullTextType) ToFieldTypePtr() unsafe.Pointer {
+func (obj *FullTextType) ToFieldTypePtr() uintptr {
 	return obj.ToPtr()
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/81e861c7/go/lucy/search.go
----------------------------------------------------------------------
diff --git a/go/lucy/search.go b/go/lucy/search.go
index 558ca99..cf3c3e6 100644
--- a/go/lucy/search.go
+++ b/go/lucy/search.go
@@ -37,12 +37,12 @@ import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
 
 type Query interface {
 	clownfish.Obj
-	ToQueryPtr() unsafe.Pointer
+	ToQueryPtr() uintptr
 }
 
 type Searcher interface {
 	clownfish.Obj
-	ToSearcherPtr() unsafe.Pointer
+	ToSearcherPtr() uintptr
 	Hits(query interface{}, offset uint32, numWanted uint32, sortSpec *SortSpec) (*Hits, error)
 }
 
@@ -64,7 +64,7 @@ func OpenIndexSearcher(index interface{}) (obj *IndexSearcher, err error)
{
 	switch index.(type) {
 	case string:
 		ixLoc := clownfish.NewString(index.(string))
-		indexC = (*C.cfish_Obj)(ixLoc.ToPtr())
+		indexC = (*C.cfish_Obj)(unsafe.Pointer(ixLoc.ToPtr()))
 	default:
 		panic("TODO: support Folder")
 	}
@@ -86,11 +86,11 @@ func (obj *IndexSearcher) Close() error {
 	})
 }
 
-func (obj *IndexSearcher) ToPtr() unsafe.Pointer {
-	return unsafe.Pointer(obj.ref)
+func (obj *IndexSearcher) ToPtr() uintptr {
+	return uintptr(unsafe.Pointer(obj.ref))
 }
 
-func (obj *IndexSearcher) ToSearcherPtr() unsafe.Pointer {
+func (obj *IndexSearcher) ToSearcherPtr() uintptr {
 	return obj.ToPtr()
 }
 
@@ -106,7 +106,7 @@ func (obj *IndexSearcher) Hits(query interface{}, offset uint32, numWanted
uint3
 		queryStringC := clownfish.NewString(query.(string))
 		err = clownfish.TrapErr(func() {
 			hitsC = C.LUCY_IxSearcher_Hits(obj.ref,
-				(*C.cfish_Obj)(queryStringC.ToPtr()),
+				(*C.cfish_Obj)(unsafe.Pointer(queryStringC.ToPtr())),
 				C.uint32_t(offset), C.uint32_t(numWanted), sortSpecC)
 		})
 	default:


Mime
View raw message