diff --git a/pinner.go b/pinner.go deleted file mode 100644 index 63e14b92..00000000 --- a/pinner.go +++ /dev/null @@ -1,16 +0,0 @@ -package duckdb - -import "runtime" - -type pinnedValue[T any] struct { - pinner *runtime.Pinner - value T -} - -type unpinner interface { - unpin() -} - -func (v pinnedValue[T]) unpin() { - v.pinner.Unpin() -} diff --git a/scalar_udf.go b/scalar_udf.go index 7d2bbfab..2f055368 100644 --- a/scalar_udf.go +++ b/scalar_udf.go @@ -122,12 +122,6 @@ func RegisterScalarUDFSet(c *sql.Conn, name string, functions ...ScalarFunc) err return err } -func setFuncError(function_info C.duckdb_function_info, msg string) { - err := C.CString(msg) - C.duckdb_scalar_function_set_error(function_info, err) - C.duckdb_free(unsafe.Pointer(err)) -} - //export scalar_udf_callback func scalar_udf_callback(function_info C.duckdb_function_info, input C.duckdb_data_chunk, output C.duckdb_vector) { extraInfo := C.duckdb_scalar_function_get_extra_info(function_info) @@ -198,10 +192,8 @@ func scalar_udf_callback(function_info C.duckdb_function_info, input C.duckdb_da } //export scalar_udf_delete_callback -func scalar_udf_delete_callback(extraInfo unsafe.Pointer) { - h := (*cgo.Handle)(extraInfo) - h.Value().(unpinner).unpin() - h.Delete() +func scalar_udf_delete_callback(info unsafe.Pointer) { + udf_delete_callback(info) } func registerInputParams(config ScalarFuncConfig, f C.duckdb_scalar_function) error { diff --git a/udf_util.go b/udf_util.go new file mode 100644 index 00000000..91ef9541 --- /dev/null +++ b/udf_util.go @@ -0,0 +1,37 @@ +package duckdb + +/* +#include +*/ +import "C" + +import ( + "runtime" + "runtime/cgo" + "unsafe" +) + +type pinnedValue[T any] struct { + pinner *runtime.Pinner + value T +} + +type unpinner interface { + unpin() +} + +func (v pinnedValue[T]) unpin() { + v.pinner.Unpin() +} + +func setFuncError(function_info C.duckdb_function_info, msg string) { + err := C.CString(msg) + C.duckdb_scalar_function_set_error(function_info, err) + C.duckdb_free(unsafe.Pointer(err)) +} + +func udf_delete_callback(info unsafe.Pointer) { + h := (*cgo.Handle)(info) + h.Value().(unpinner).unpin() + h.Delete() +}