diff options
author | stephan <stephan@noemail.net> | 2022-11-30 11:50:16 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-11-30 11:50:16 +0000 |
commit | 8ae954557738b29ebaaa6b1eb954c4e9a703de36 (patch) | |
tree | 13ebb2de20c2a81ad812e77a0f1b71a130a0cb36 /ext/wasm/api | |
parent | c5141c9efa564dc6e6d39685b23741d6632dae5a (diff) | |
download | sqlite-8ae954557738b29ebaaa6b1eb954c4e9a703de36.tar.gz sqlite-8ae954557738b29ebaaa6b1eb954c4e9a703de36.zip |
Install sqlite3_malloc/sqlite3_free() as the JS-side WASM allocator (as opposed to replacing C-level's malloc()/free() with them). All tests work and this eliminates the potential for allocator discrepancies when using the (de)serialize APIs.
FossilOrigin-Name: 95c78f6b46e0d8efa4313061f47677479f48610b7a7261dc8d0fb1859aca2ad9
Diffstat (limited to 'ext/wasm/api')
-rw-r--r-- | ext/wasm/api/sqlite3-api-cleanup.js | 4 | ||||
-rw-r--r-- | ext/wasm/api/sqlite3-api-prologue.js | 16 |
2 files changed, 11 insertions, 9 deletions
diff --git a/ext/wasm/api/sqlite3-api-cleanup.js b/ext/wasm/api/sqlite3-api-cleanup.js index 0ec0fbfbe..30cd64b05 100644 --- a/ext/wasm/api/sqlite3-api-cleanup.js +++ b/ext/wasm/api/sqlite3-api-cleanup.js @@ -22,12 +22,10 @@ if('undefined' !== typeof Module){ // presumably an Emscripten build */ const SABC = Object.assign( Object.create(null), { - Module: Module /* ==> Currently needs to be exposed here for - test code. NOT part of the public API. */, exports: Module['asm'], memory: Module.wasmMemory /* gets set if built with -sIMPORT_MEMORY */ }, - self.sqlite3ApiConfig || Object.create(null) + self.sqlite3ApiConfig || {} ); /** diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index 59cdab929..31cd8aa53 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -65,11 +65,15 @@ - `allocExportName`: the name of the function, in `exports`, of the `malloc(3)`-compatible routine for the WASM environment. Defaults - to `"malloc"`. + to `"sqlite3_malloc"`. Beware that using any allocator other than + sqlite3_malloc() may require care in certain client-side code + regarding which allocator is uses. Notably, sqlite3_deserialize() + and sqlite3_serialize() can only safely use memory from different + allocators under very specific conditions. - `deallocExportName`: the name of the function, in `exports`, of the `free(3)`-compatible routine for the WASM - environment. Defaults to `"free"`. + environment. Defaults to `"sqlite3_free"`. - `wasmfsOpfsDir`[^1]: if the environment supports persistent storage using OPFS-over-WASMFS , this directory names the "mount @@ -104,8 +108,8 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( } return !!self.BigInt64Array; })(), - allocExportName: 'malloc', - deallocExportName: 'free', + allocExportName: 'sqlite3_malloc', + deallocExportName: 'sqlite3_free', wasmfsOpfsDir: '/opfs' }, apiConfig || {}); @@ -727,8 +731,8 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( return pRet; }; - const keyAlloc = config.allocExportName || 'malloc', - keyDealloc = config.deallocExportName || 'free'; + const keyAlloc = config.allocExportName, + keyDealloc = config.deallocExportName; for(const key of [keyAlloc, keyDealloc]){ const f = wasm.exports[key]; if(!(f instanceof Function)) toss3("Missing required exports[",key,"] function."); |