diff options
author | stephan <stephan@noemail.net> | 2022-10-09 13:26:15 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-10-09 13:26:15 +0000 |
commit | 4fbf90ee11aea78557c40c4614a2d5ea95f3bea8 (patch) | |
tree | 2c043de585a2094ca9c9e05458f901926b6e72ac /ext/wasm/api/sqlite3-wasm.c | |
parent | d35b5587df9b6e68ac5a1a1907a95ce6e3abee51 (diff) | |
download | sqlite-4fbf90ee11aea78557c40c4614a2d5ea95f3bea8.tar.gz sqlite-4fbf90ee11aea78557c40c4614a2d5ea95f3bea8.zip |
Refactor kvvfs JS bits to make use of [ea370b9b05f7ed7eaa]. At main-thread startup, if kvvfs is available, replace the kvvfs I/O methods with JS impls. Checkin part 2 of 2, to account for cherrypicking [ea370b9b05f7ed7eaa] into the kv-vfs branch.
FossilOrigin-Name: a9047e020a097b2259bc9935b63ca1c538a3a7f1d050e15f0d0a08cfb84acc7c
Diffstat (limited to 'ext/wasm/api/sqlite3-wasm.c')
-rw-r--r-- | ext/wasm/api/sqlite3-wasm.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c index 7ed58dbe0..cfeb99e92 100644 --- a/ext/wasm/api/sqlite3-wasm.c +++ b/ext/wasm/api/sqlite3-wasm.c @@ -13,6 +13,8 @@ ** emcc -o sqlite3.wasm ... -I/path/to/sqlite3-c-and-h sqlite3-wasm.c */ +#define SQLITE_WASM + /* ** Threading and file locking: JS is single-threaded. Each Worker ** thread is a separate instance of the JS engine so can never access @@ -87,7 +89,7 @@ #endif /* -** WASM_KEEP is identical to EMSCRIPTEN_KEEPALIVE but is not +** SQLITE_WASM_KEEP is identical to EMSCRIPTEN_KEEPALIVE but is not ** Emscripten-specific. It explicitly marks functions for export into ** the target wasm file without requiring explicit listing of those ** functions in Emscripten's -sEXPORTED_FUNCTIONS=... list (or @@ -683,6 +685,14 @@ const char * sqlite3_wasm_enum_json(void){ } _StructBinder; #undef CurrentStruct +#define CurrentStruct sqlite3_kvvfs_methods + StructBinder { + M(xRead,"i(sspi)"); + M(xWrite,"i(sss)"); + M(xDelete,"i(ss)"); + M(nKeySize,"i"); + } _StructBinder; + } out( "]"/*structs*/); out("}"/*top-level object*/); @@ -820,6 +830,39 @@ int sqlite3_wasm_db_serialize( sqlite3* pDb, unsigned char **pOut, sqlite3_int64 } } +/* +** This function is NOT part of the sqlite3 public API. It is strictly +** for use by the sqlite project's own JS/WASM bindings. +** +** Allocates sqlite3KvvfsMethods.nKeySize bytes from +** sqlite3_wasm_pstack_alloc() and returns 0 if that allocation fails, +** else it passes that string to kvstorageMakeKey() and returns a +** NUL-terminated pointer to that string. It is up to the caller to +** use sqlite3_wasm_pstack_restore() to free the returned pointer. +*/ +WASM_KEEP +char * sqlite3_wasm_kvvfsMakeKeyOnPstack(const char *zClass, + const char *zKeyIn){ + assert(sqlite3KvvfsMethods.nKeySize>24); + char *zKeyOut = + (char *)sqlite3_wasm_pstack_alloc(sqlite3KvvfsMethods.nKeySize); + if(zKeyOut){ + kvstorageMakeKey(zClass, zKeyIn, zKeyOut); + } + return zKeyOut; +} + +/* +** This function is NOT part of the sqlite3 public API. It is strictly +** for use by the sqlite project's own JS/WASM bindings. +** +** Returns the pointer to the singleton object which holds the kvvfs +** I/O methods and associated state. +*/ +WASM_KEEP +sqlite3_kvvfs_methods * sqlite3_wasm_kvvfs_methods(void){ + return &sqlite3KvvfsMethods; +} #if defined(__EMSCRIPTEN__) && defined(SQLITE_WASM_WASMFS) #include <emscripten/wasmfs.h> |