Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: improve support for static linking #19

Merged
merged 5 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bridge/bridge.c → bridge.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "bridge.h"
#include <sqlite3ext.h>

SQLITE_EXTENSION_INIT3

Expand Down
4 changes: 0 additions & 4 deletions bridge.go

This file was deleted.

2 changes: 1 addition & 1 deletion bridge/bridge.h → bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// Most of the methods follow the convention of prefixing the sqlite api function with an underscore.
// The bridge isn't extensive and doesn't cover the whole sqlite api.

#include "../sqlite3.h"
#include <sqlite3ext.h>

//- routine that work with sqlite3_context; see: https://sqlite.org/c3ref/context.html
//-----------------------------
Expand Down
7 changes: 0 additions & 7 deletions bridge/vendor_fix.go

This file was deleted.

4 changes: 2 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package sqlite

// #include <stdlib.h>
// #include "sqlite3.h"
// #include "bridge/bridge.h"
// #include <sqlite3ext.h>
// #include "bridge.h"
//
// extern void pointer_destructor_hook_tramp(void*);
import "C"
Expand Down
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package sqlite

// #include "sqlite3.h"
// #include <sqlite3ext.h>
import "C"
import "fmt"

Expand Down
2 changes: 1 addition & 1 deletion extension.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file contains the SQLite3 extension entry-point routine
// as defined here https://sqlite.org/loadext.html
#include "sqlite3.h"
#include <sqlite3ext.h>

SQLITE_EXTENSION_INIT1

Expand Down
13 changes: 11 additions & 2 deletions extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package sqlite
// #cgo CFLAGS: -fPIC
//
// #include <stdlib.h>
// #include "sqlite3.h"
// #include "bridge/bridge.h"
// #include <sqlite3ext.h>
// #include "bridge.h"
//
// extern int commit_hook_tramp(void*);
// extern void rollback_hook_tramp(void*);
Expand Down Expand Up @@ -48,6 +48,15 @@ func go_sqlite3_extension_init(name *C.char, db *C.struct_sqlite3, msg **C.char)
return code
}

// UnderlyingConnection represents a handle to an open sqlite3 database connection object.
type UnderlyingConnection *C.struct_sqlite3

// RegisterWith registers the given extension with the provided connection object.
// The intended use-case is to provide support for statically linked extensions.
func RegisterWith(conn UnderlyingConnection, fn ExtensionFunc) (ErrorCode, error) {
return fn(&ExtensionApi{db: (*C.struct_sqlite3)(conn)})
}

// ExtensionApi wraps the underlying sqlite_api_routines and allows Go code to hook into
// sqlite's extension facility.
type ExtensionApi struct {
Expand Down
4 changes: 2 additions & 2 deletions func.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package sqlite

// #include <stdlib.h>
// #include "sqlite3.h"
// #include "bridge/bridge.h"
// #include <sqlite3ext.h>
// #include "bridge.h"
//
// extern void scalar_function_apply_tramp(sqlite3_context*, int, sqlite3_value**);
// extern void aggregate_function_step_tramp(sqlite3_context*, int, sqlite3_value**);
Expand Down
Loading