From bf037c61ce16437157479b4015a0c7e38ad50e5e Mon Sep 17 00:00:00 2001 From: Rob Mason Date: Sun, 21 Apr 2024 13:32:24 +0100 Subject: [PATCH 1/3] fix when building for windows using clang --- README.md | 2 +- auth.go | 6 ++---- sqlite.go | 31 +++++++++++++++---------------- wrappers.c | 9 +++++++++ 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 789aee3..93ba080 100644 --- a/README.md +++ b/README.md @@ -53,4 +53,4 @@ https://godoc.org/crawshaw.io/sqlite ## Platform specific considerations -By default it requires some pthreads DLL on Windows. To avoid it, supply `CGOLDFLAGS="-static"` when building your application. +By default it requires some pthreads DLL on Windows. To avoid it, supply `CGO_LDFLAGS="-static"` when building your application. diff --git a/auth.go b/auth.go index ec29a9c..1d2b630 100644 --- a/auth.go +++ b/auth.go @@ -2,10 +2,8 @@ package sqlite // #include // #include -// extern int go_sqlite_auth_tramp(uintptr_t, int, char*, char*, char*, char*); -// static int c_auth_tramp(void *userData, int action, const char* arg1, const char* arg2, const char* db, const char* trigger) { -// return go_sqlite_auth_tramp((uintptr_t)userData, action, (char*)arg1, (char*)arg2, (char*)db, (char*)trigger); -// } +// +// extern int c_auth_tramp(void*, int, const char*, const char*, const char*, const char*); // static int sqlite3_go_set_authorizer(sqlite3* conn, uintptr_t id) { // return sqlite3_set_authorizer(conn, c_auth_tramp, (void*)id); // } diff --git a/sqlite.go b/sqlite.go index 415eb30..37c23aa 100644 --- a/sqlite.go +++ b/sqlite.go @@ -52,9 +52,9 @@ package sqlite // return sqlite3_bind_blob(stmt, col, p, n, SQLITE_TRANSIENT); // } // -// extern void log_fn(void* pArg, int code, char* msg); +// extern void c_log_fn(void*, int, char*); // static void enable_logging() { -// sqlite3_config(SQLITE_CONFIG_LOG, log_fn, NULL); +// sqlite3_config(SQLITE_CONFIG_LOG, c_log_fn, NULL); // } // // static int db_config_onoff(sqlite3* db, int op, int onoff) { @@ -170,7 +170,6 @@ func openConn(path string, flags ...OpenFlags) (*Conn, error) { } } - return conn, nil } @@ -611,7 +610,7 @@ func (stmt *Stmt) ClearBindings() error { // // https://www.sqlite.org/c3ref/step.html // -// Shared cache +// # Shared cache // // As the sqlite package enables shared cache mode by default // and multiple writers are common in multi-threaded programs, @@ -987,11 +986,11 @@ func (stmt *Stmt) columnBytes(col int) []byte { // ColumnType are codes for each of the SQLite fundamental datatypes: // -// 64-bit signed integer -// 64-bit IEEE floating point number -// string -// BLOB -// NULL +// 64-bit signed integer +// 64-bit IEEE floating point number +// string +// BLOB +// NULL // // https://www.sqlite.org/c3ref/c_blob.html type ColumnType int @@ -1024,11 +1023,11 @@ func (t ColumnType) String() string { // ColumnType returns the datatype code for the initial data // type of the result column. The returned value is one of: // -// SQLITE_INTEGER -// SQLITE_FLOAT -// SQLITE_TEXT -// SQLITE_BLOB -// SQLITE_NULL +// SQLITE_INTEGER +// SQLITE_FLOAT +// SQLITE_TEXT +// SQLITE_BLOB +// SQLITE_NULL // // Column indices start at 0. // @@ -1224,8 +1223,8 @@ func sqliteInitFn() { } } -//export log_fn -func log_fn(_ unsafe.Pointer, code C.int, msg *C.char) { +//export go_log_fn +func go_log_fn(_ unsafe.Pointer, code C.int, msg *C.char) { var msgBytes []byte if msg != nil { str := C.GoString(msg) // TODO: do not copy msg. diff --git a/wrappers.c b/wrappers.c index cbe5d3b..6f9b09b 100644 --- a/wrappers.c +++ b/wrappers.c @@ -47,3 +47,12 @@ void c_destroy_tramp(void* ptr) { return go_destroy_tramp((uintptr_t)ptr); } +extern int go_sqlite_auth_tramp(uintptr_t, int, char*, char*, char*, char*); +int c_auth_tramp(void *userData, int action, const char* arg1, const char* arg2, const char* db, const char* trigger) { + return go_sqlite_auth_tramp((uintptr_t)userData, action, (char*)arg1, (char*)arg2, (char*)db, (char*)trigger); +} + +extern void go_log_fn(void*, int, char*); +void c_log_fn(void* pArg, int code, char* msg) { + return go_log_fn(pArg, code, msg); +} \ No newline at end of file From 79910f2db83441b906fa7d52ea38860678cd9235 Mon Sep 17 00:00:00 2001 From: Rob Mason Date: Sun, 21 Apr 2024 14:23:49 +0100 Subject: [PATCH 2/3] fix for warning cases, not just errors --- auth.go | 2 +- func.go | 22 +++++++++------------- session.go | 3 --- sqlite.go | 1 - wrappers.c | 15 +++++++++++++++ wrappers.h | 6 ++++++ 6 files changed, 31 insertions(+), 18 deletions(-) diff --git a/auth.go b/auth.go index 1d2b630..22d31e7 100644 --- a/auth.go +++ b/auth.go @@ -2,8 +2,8 @@ package sqlite // #include // #include +// #include "wrappers.h" // -// extern int c_auth_tramp(void*, int, const char*, const char*, const char*, const char*); // static int sqlite3_go_set_authorizer(sqlite3* conn, uintptr_t id) { // return sqlite3_set_authorizer(conn, c_auth_tramp, (void*)id); // } diff --git a/func.go b/func.go index e080599..9acd6f4 100644 --- a/func.go +++ b/func.go @@ -19,10 +19,6 @@ package sqlite // #include // #include "wrappers.h" // -// extern void func_tramp(sqlite3_context*, int, sqlite3_value**); -// extern void step_tramp(sqlite3_context*, int, sqlite3_value**); -// extern void final_tramp(sqlite3_context*); -// // static int go_sqlite3_create_function_v2( // sqlite3 *db, // const char *zFunctionName, @@ -167,10 +163,10 @@ func (conn *Conn) CreateFunction(name string, deterministic bool, numArgs int, x var funcfn, stepfn, finalfn *[0]byte if xFunc == nil { - stepfn = (*[0]byte)(C.step_tramp) - finalfn = (*[0]byte)(C.final_tramp) + stepfn = (*[0]byte)(C.c_step_tramp) + finalfn = (*[0]byte)(C.c_final_tramp) } else { - funcfn = (*[0]byte)(C.func_tramp) + funcfn = (*[0]byte)(C.c_func_tramp) } res := C.go_sqlite3_create_function_v2( @@ -197,8 +193,8 @@ func getxfuncs(ctx *C.sqlite3_context) *xfunc { return x } -//export func_tramp -func func_tramp(ctx *C.sqlite3_context, n C.int, valarray **C.sqlite3_value) { +//export go_func_tramp +func go_func_tramp(ctx *C.sqlite3_context, n C.int, valarray **C.sqlite3_value) { x := getxfuncs(ctx) var vals []Value if n > 0 { @@ -207,8 +203,8 @@ func func_tramp(ctx *C.sqlite3_context, n C.int, valarray **C.sqlite3_value) { x.xFunc(Context{ptr: ctx}, vals...) } -//export step_tramp -func step_tramp(ctx *C.sqlite3_context, n C.int, valarray **C.sqlite3_value) { +//export go_step_tramp +func go_step_tramp(ctx *C.sqlite3_context, n C.int, valarray **C.sqlite3_value) { x := getxfuncs(ctx) var vals []Value if n > 0 { @@ -217,8 +213,8 @@ func step_tramp(ctx *C.sqlite3_context, n C.int, valarray **C.sqlite3_value) { x.xStep(Context{ptr: ctx}, vals...) } -//export final_tramp -func final_tramp(ctx *C.sqlite3_context) { +//export go_final_tramp +func go_final_tramp(ctx *C.sqlite3_context) { x := getxfuncs(ctx) x.xFinal(Context{ptr: ctx}) } diff --git a/session.go b/session.go index eecfb84..8d00978 100644 --- a/session.go +++ b/session.go @@ -19,9 +19,6 @@ package sqlite // #include // #include "wrappers.h" // -// extern int go_strm_w_tramp(uintptr_t, char*, int); -// extern int go_strm_r_tramp(uintptr_t, char*, int*); -// // static int go_sqlite3session_changeset_strm( // sqlite3_session *pSession, // int (*xOutput)(void *pOut, const void *pData, int nData), diff --git a/sqlite.go b/sqlite.go index 37c23aa..1514978 100644 --- a/sqlite.go +++ b/sqlite.go @@ -52,7 +52,6 @@ package sqlite // return sqlite3_bind_blob(stmt, col, p, n, SQLITE_TRANSIENT); // } // -// extern void c_log_fn(void*, int, char*); // static void enable_logging() { // sqlite3_config(SQLITE_CONFIG_LOG, c_log_fn, NULL); // } diff --git a/wrappers.c b/wrappers.c index 6f9b09b..8177c58 100644 --- a/wrappers.c +++ b/wrappers.c @@ -42,6 +42,21 @@ int c_xapply_filter_tramp(void* pCtx, const char* zTab) { return go_xapply_filter_tramp((uintptr_t)pCtx, (char*)zTab); } +extern void go_func_tramp(sqlite3_context*, int, sqlite3_value**); +void c_func_tramp(sqlite3_context* ctx, int n, sqlite3_value** valarray) { + return go_func_tramp(ctx, n, valarray); +} + +extern void go_step_tramp(sqlite3_context*, int, sqlite3_value**); +void c_step_tramp(sqlite3_context* ctx, int n, sqlite3_value** valarray) { + return go_step_tramp(ctx, n, valarray); +} + +extern void go_final_tramp(sqlite3_context*); +void c_final_tramp(sqlite3_context* ctx) { + return go_final_tramp(ctx); +} + extern void go_destroy_tramp(uintptr_t); void c_destroy_tramp(void* ptr) { return go_destroy_tramp((uintptr_t)ptr); diff --git a/wrappers.h b/wrappers.h index 4dc38fc..c3c90e7 100644 --- a/wrappers.h +++ b/wrappers.h @@ -26,6 +26,12 @@ int c_strm_r_tramp(void*, const void*, int*); int c_xapply_conflict_tramp(void*, int, sqlite3_changeset_iter*); int c_xapply_filter_tramp(void*, const char*); +void c_log_fn(void*, int, char*); +int c_auth_tramp(void*, int, const char*, const char*, const char*, const char*); + +void c_func_tramp(sqlite3_context*, int, sqlite3_value**); +void c_step_tramp(sqlite3_context*, int, sqlite3_value**); +void c_final_tramp(sqlite3_context*); void c_destroy_tramp(void*); #endif // WRAPPERS_H From 727189b3907bcf77c8855eb041b8073f3582d81e Mon Sep 17 00:00:00 2001 From: Rob Mason Date: Sun, 21 Apr 2024 14:29:05 +0100 Subject: [PATCH 3/3] fix for maddening goland auto-reformat on git push --- sqlite.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/sqlite.go b/sqlite.go index 1514978..76d212a 100644 --- a/sqlite.go +++ b/sqlite.go @@ -609,7 +609,7 @@ func (stmt *Stmt) ClearBindings() error { // // https://www.sqlite.org/c3ref/step.html // -// # Shared cache +// Shared cache // // As the sqlite package enables shared cache mode by default // and multiple writers are common in multi-threaded programs, @@ -985,11 +985,11 @@ func (stmt *Stmt) columnBytes(col int) []byte { // ColumnType are codes for each of the SQLite fundamental datatypes: // -// 64-bit signed integer -// 64-bit IEEE floating point number -// string -// BLOB -// NULL +// 64-bit signed integer +// 64-bit IEEE floating point number +// string +// BLOB +// NULL // // https://www.sqlite.org/c3ref/c_blob.html type ColumnType int @@ -1022,11 +1022,11 @@ func (t ColumnType) String() string { // ColumnType returns the datatype code for the initial data // type of the result column. The returned value is one of: // -// SQLITE_INTEGER -// SQLITE_FLOAT -// SQLITE_TEXT -// SQLITE_BLOB -// SQLITE_NULL +// SQLITE_INTEGER +// SQLITE_FLOAT +// SQLITE_TEXT +// SQLITE_BLOB +// SQLITE_NULL // // Column indices start at 0. //