// sp_close closes the pointer and sets it to nil // to ensure it cannot be closed twice. func sp_close(p *unsafe.Pointer) error { if nil == *p { return nil } if 0 != C.sp_destroy(*p) { return sp_error(*p) } *p = nil return nil }
// Get retrieves the value for the key. func (db *Database) Get(key []byte) ([]byte, error) { var vptr unsafe.Pointer var size C.size_t e := C.sp_get(db.Pointer, unsafe.Pointer(&key[0]), C.size_t(len(key)), &vptr, (*C.size_t)(&size)) switch int(e) { case -1: return nil, db.Error() case 0: return nil, ErrNotFound case 1: // Continue after the switch default: return nil, fmt.Errorf("ERROR: unexpected return value from sp_get: %v", e) } value := C.GoBytes(vptr, C.int(size)) C.sp_destroy(vptr) return value, nil }