diff options
| author | Yip Coekjan <69834864+Coekjan@users.noreply.github.com> | 2024-07-13 18:52:24 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-13 12:52:24 +0200 |
| commit | 7a4a44292c2de397fe0f59cb5243bdc88af58027 (patch) | |
| tree | 09ede1ea87c48abef99d84e7068162714e400ff6 /src/wrapped/wrappedlibsqlite3.c | |
| parent | 98270a86016d537e343f516444e6a893e1e52b7f (diff) | |
| download | box64-7a4a44292c2de397fe0f59cb5243bdc88af58027.tar.gz box64-7a4a44292c2de397fe0f59cb5243bdc88af58027.zip | |
Wrap `sqlite3_exec` for libsqlite3 (#1674)
Diffstat (limited to 'src/wrapped/wrappedlibsqlite3.c')
| -rw-r--r-- | src/wrapped/wrappedlibsqlite3.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/wrapped/wrappedlibsqlite3.c b/src/wrapped/wrappedlibsqlite3.c index 8cf7f4dc..e1720667 100644 --- a/src/wrapped/wrappedlibsqlite3.c +++ b/src/wrapped/wrappedlibsqlite3.c @@ -25,8 +25,40 @@ const char* libsqlite3Name = "libsqlite3.so.0"; #include "generated/wrappedlibsqlite3types.h" -//#include "wrappercallback.h" +#include "wrappercallback.h" -// Insert my_* functions here... +#define SUPER() \ +GO(0) \ +GO(1) \ +GO(2) \ +GO(3) \ +GO(4) + +// sqlite3_exec ... +#define GO(A) \ +static uintptr_t my_sqlite3_exec_fct_##A = 0; \ +static int my_sqlite3_exec_##A(void* a, int b, char** c, char** d) { \ + return RunFunctionFmt(my_sqlite3_exec_fct_##A, "pipp", a, b, c, d); \ +} +SUPER() +#undef GO +static void *find_sqlite3_exec_fct(void *fct) { + if (!fct) return fct; + if (GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct); + #define GO(A) if (my_sqlite3_exec_fct_##A == (uintptr_t)fct) return my_sqlite3_exec_##A; + SUPER() + #undef GO + #define GO(A) if (my_sqlite3_exec_fct_##A == 0) {my_sqlite3_exec_fct_##A = (uintptr_t)fct; return my_sqlite3_exec_##A; } + SUPER() + #undef GO + printf_log(LOG_NONE, "Warning, no more slot for sqlite3_exec callback\n"); + return NULL; +} +#undef SUPER + +EXPORT int my_sqlite3_exec(x64emu_t* emu, void *db, char *sql, void* callback, void* data, char **errmsg) +{ + return my->sqlite3_exec(db, sql, find_sqlite3_exec_fct(callback), data, errmsg); +} #include "wrappedlib_init.h" |