aboutsummaryrefslogtreecommitdiff
path: root/sqlite3.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2016-01-29 13:18:39 -0800
committerIan Lance Taylor <iant@golang.org>2016-01-29 13:18:39 -0800
commit8c66b9cf5ed003dff18db01a55cbd45d35a0990f (patch)
tree59470d810abce3c9236c102609978cfcadaf1b91 /sqlite3.go
parentMerge pull request #266 from tcyrus/patch-1 (diff)
downloadgolite-8c66b9cf5ed003dff18db01a55cbd45d35a0990f.tar.gz
golite-8c66b9cf5ed003dff18db01a55cbd45d35a0990f.tar.xz
callback: use handles rather than passing Go pointers
The cgo pointer passing rules forbid passing a Go pointer to C if that pointer points to memory containing other Go pointers. This is true even if the Go pointer is converted to uintptr. This change fixes the code to use a handle instead, and to look up the handle in the callback function.
Diffstat (limited to 'sqlite3.go')
-rw-r--r--sqlite3.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/sqlite3.go b/sqlite3.go
index f79ef2d..964acbb 100644
--- a/sqlite3.go
+++ b/sqlite3.go
@@ -367,7 +367,7 @@ func (c *SQLiteConn) RegisterFunc(name string, impl interface{}, pure bool) erro
if pure {
opts |= C.SQLITE_DETERMINISTIC
}
- 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)
+ rv := C._sqlite3_create_function(c.db, cname, C.int(numArgs), C.int(opts), C.uintptr_t(newHandle(c, &fi)), (*[0]byte)(unsafe.Pointer(C.callbackTrampoline)), nil, nil)
if rv != C.SQLITE_OK {
return c.lastError()
}
@@ -492,7 +492,7 @@ func (c *SQLiteConn) RegisterAggregator(name string, impl interface{}, pure bool
if pure {
opts |= C.SQLITE_DETERMINISTIC
}
- 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)))
+ rv := C._sqlite3_create_function(c.db, cname, C.int(stepNArgs), C.int(opts), C.uintptr_t(newHandle(c, &ai)), nil, (*[0]byte)(unsafe.Pointer(C.stepTrampoline)), (*[0]byte)(unsafe.Pointer(C.doneTrampoline)))
if rv != C.SQLITE_OK {
return c.lastError()
}
@@ -705,6 +705,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
// Close the connection.
func (c *SQLiteConn) Close() error {
+ deleteHandles(c)
rv := C.sqlite3_close_v2(c.db)
if rv != C.SQLITE_OK {
return c.lastError()