Skip to content

Commit e969434

Browse files
committed
avoid cgoCheckPointer. ref golang/go#12416
1 parent 5651a9d commit e969434

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

sqlite3.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ void _sqlite3_result_blob(sqlite3_context* ctx, const void* b, int l) {
7474
sqlite3_result_blob(ctx, b, l, SQLITE_TRANSIENT);
7575
}
7676
77+
78+
int _sqlite3_create_function(
79+
sqlite3 *db,
80+
const char *zFunctionName,
81+
int nArg,
82+
int eTextRep,
83+
uintptr_t pApp,
84+
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
85+
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
86+
void (*xFinal)(sqlite3_context*)
87+
) {
88+
return sqlite3_create_function(db, zFunctionName, nArg, eTextRep, (void*) pApp, xFunc, xStep, xFinal);
89+
}
90+
7791
void callbackTrampoline(sqlite3_context*, int, sqlite3_value**);
7892
void stepTrampoline(sqlite3_context*, int, sqlite3_value**);
7993
void doneTrampoline(sqlite3_context*);
@@ -353,7 +367,7 @@ func (c *SQLiteConn) RegisterFunc(name string, impl interface{}, pure bool) erro
353367
if pure {
354368
opts |= C.SQLITE_DETERMINISTIC
355369
}
356-
rv := C.sqlite3_create_function(c.db, cname, C.int(numArgs), C.int(opts), unsafe.Pointer(&fi), (*[0]byte)(unsafe.Pointer(C.callbackTrampoline)), nil, nil)
370+
rv := C._sqlite3_create_function(c.db, cname, C.int(numArgs), C.int(opts), C.uintptr_t(uintptr(unsafe.Pointer(&fi))), (*[0]byte)(unsafe.Pointer(C.callbackTrampoline)), nil, nil)
357371
if rv != C.SQLITE_OK {
358372
return c.lastError()
359373
}
@@ -478,7 +492,7 @@ func (c *SQLiteConn) RegisterAggregator(name string, impl interface{}, pure bool
478492
if pure {
479493
opts |= C.SQLITE_DETERMINISTIC
480494
}
481-
rv := C.sqlite3_create_function(c.db, cname, C.int(stepNArgs), C.int(opts), unsafe.Pointer(&ai), nil, (*[0]byte)(unsafe.Pointer(C.stepTrampoline)), (*[0]byte)(unsafe.Pointer(C.doneTrampoline)))
495+
rv := C._sqlite3_create_function(c.db, cname, C.int(stepNArgs), C.int(opts), C.uintptr_t(uintptr(unsafe.Pointer(&ai))), nil, (*[0]byte)(unsafe.Pointer(C.stepTrampoline)), (*[0]byte)(unsafe.Pointer(C.doneTrampoline)))
482496
if rv != C.SQLITE_OK {
483497
return c.lastError()
484498
}

0 commit comments

Comments
 (0)