aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-api-glue.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-12-05 11:30:39 +0000
committerstephan <stephan@noemail.net>2022-12-05 11:30:39 +0000
commit0adef0937451b9c93688c00e26a792915361af5d (patch)
treefc308f640ba6a2b065e1f4dfb6ae9131ba0abc2c /ext/wasm/api/sqlite3-api-glue.js
parent08fc64ea04d7b8ce458ba13608502159a2727738 (diff)
downloadsqlite-0adef0937451b9c93688c00e26a792915361af5d.tar.gz
sqlite-0adef0937451b9c93688c00e26a792915361af5d.zip
Export sqlite3_bind/value/result_pointer() to wasm. Add 'static-string' argument converter to support the lifetime requirements of bind/result_pointer()'s string argument. Correct an endless loop in wasm.cstrlen() when passed a non-C-string argument.
FossilOrigin-Name: a94552434a657376d5ce1831de05c1b15fb153020848cd825fb0df413c3baa70
Diffstat (limited to 'ext/wasm/api/sqlite3-api-glue.js')
-rw-r--r--ext/wasm/api/sqlite3-api-glue.js33
1 files changed, 32 insertions, 1 deletions
diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js
index c1c91136a..dc9db9435 100644
--- a/ext/wasm/api/sqlite3-api-glue.js
+++ b/ext/wasm/api/sqlite3-api-glue.js
@@ -43,7 +43,38 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
wasm.xWrap.argAdapter(
'flexible-string', (v)=>xString(util.flexibleString(v))
);
- }
+
+ /**
+ The 'static-string' argument adapter treats its argument as
+ either...
+
+ - WASM pointer: assumed to be a long-lived C-string which gets
+ returned as-is.
+
+ - Anything else: gets coerced to a JS string for use as a map
+ key. If a matching entry is found (as described next), it is
+ returned, else wasm.allocCString() is used to create a a new
+ string, map its pointer to (''+v) for the remainder of the
+ application's life, and returns that pointer value for this
+ call and all future calls which are passed a
+ string-equivalent argument.
+
+ Use case: sqlite3_bind_pointer() and sqlite3_result_pointer()
+ call for "a static string and preferably a string
+ literal". This converter is used to ensure that the string
+ value seen by those functions is long-lived and behaves as they
+ need it to.
+ */
+ wasm.xWrap.argAdapter(
+ 'static-string',
+ function(v){
+ if(wasm.isPtr(v)) return v;
+ v = ''+v;
+ let rc = this[v];
+ return rc || (rc = this[v] = wasm.allocCString(v));
+ }.bind(Object.create(null))
+ );
+ }/* special-case string-type argument conversions */
if(1){// WhWasmUtil.xWrap() bindings...
/**