mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
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
This commit is contained in:
@@ -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>
|
||||
|
Reference in New Issue
Block a user