func fetchEntry(ivars *C.lucy_InverterIVARS, fieldGo string) *C.lucy_InverterEntry { field := (*C.cfish_String)(clownfish.GoToClownfish(fieldGo, unsafe.Pointer(C.CFISH_STRING), false)) defer C.cfish_decref(unsafe.Pointer(field)) schema := ivars.schema fieldNum := C.LUCY_Seg_Field_Num(ivars.segment, field) if fieldNum == 0 { // This field seems not to be in the segment yet. Try to find it in // the Schema. if C.LUCY_Schema_Fetch_Type(schema, field) != nil { // The field is in the Schema. Get a field num from the Segment. fieldNum = C.LUCY_Seg_Add_Field(ivars.segment, field) } else { // We've truly failed to find the field. The user must // not have spec'd it. fieldGo := clownfish.CFStringToGo(unsafe.Pointer(field)) err := clownfish.NewErr("Unknown field name: '" + fieldGo + "'") panic(err) } } entry := C.CFISH_Vec_Fetch(ivars.entry_pool, C.size_t(fieldNum)) if entry == nil { newEntry := C.lucy_InvEntry_new(schema, field, fieldNum) C.CFISH_Vec_Store(ivars.entry_pool, C.size_t(fieldNum), (*C.cfish_Obj)(unsafe.Pointer(entry))) return newEntry } return (*C.lucy_InverterEntry)(unsafe.Pointer(entry)) }
func goToVector(value interface{}, nullable bool) unsafe.Pointer { switch v := value.(type) { case []interface{}: if v == nil { if nullable { return nil } } else { size := len(v) vec := C.cfish_Vec_new(C.size_t(size)) for i := 0; i < size; i++ { elem := GoToClownfish(v[i], nil, true) C.CFISH_Vec_Store(vec, C.size_t(i), (*C.cfish_Obj)(elem)) } return unsafe.Pointer(vec) } case Obj: certifyCF(v, C.CFISH_VECTOR, nullable) return unsafe.Pointer(C.cfish_incref(unsafe.Pointer(v.TOPTR()))) } mess := fmt.Sprintf("Can't convert %T to clownfish.Vector", value) panic(NewErr(mess)) }