From 8a8244b5c104022b5d6b4072630f012e6daf174e Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 20 Oct 2022 18:31:32 +0000 Subject: [PATCH] Rename sqlite3_web_... to sqlite3_js_... Document the worker1.close.unlink option. Fix unlink usage in speedtest1.html. Minor JS build cleanups. FossilOrigin-Name: ac9af71b72a749b0a040273a88480d56f49570b569389a4ea20cc055f494d8ff --- ext/wasm/GNUmakefile | 11 +++++------ ext/wasm/api/sqlite3-api-glue.js | 2 +- ext/wasm/api/sqlite3-api-oo1.js | 10 +++++----- ext/wasm/api/sqlite3-api-prologue.js | 14 +++++++------- ext/wasm/api/sqlite3-api-worker1.js | 20 ++++++++++---------- ext/wasm/fiddle/fiddle-worker.js | 4 ++-- ext/wasm/speedtest1-worker.js | 2 +- ext/wasm/speedtest1.html | 13 +++++++------ manifest | 28 ++++++++++++++-------------- manifest.uuid | 2 +- 10 files changed, 53 insertions(+), 53 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 1bb14a65df..174e44ddf5 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -291,12 +291,11 @@ $(sqlite3-license-version.js): $(sqlite3.h) $(sqlite3-license-version-header.js) # name of the JS file on whose behalf this pre-js is for. define call-make-pre-js pre-post-$(1).flags ?= -pre-js-$(1).js: $$(pre-js.js) $$(MAKEFILE) +$$(dir.tmp)/pre-js-$(1).js: $$(pre-js.js) $$(MAKEFILE) cp $$(pre-js.js) $$@ echo "Module[xInstantiateWasm].uri = '$(1).wasm';" >> $$@ -CLEAN_FILES += pre-js-$(1).js -pre-post-$(1).deps := $$(pre-post-jses.deps) pre-js-$(1).js -pre-post-$(1).flags += --pre-js=pre-js-$(1).js +pre-post-$(1).deps := $$(pre-post-jses.deps) $$(dir.tmp)/pre-js-$(1).js +pre-post-$(1).flags += --pre-js=$$(dir.tmp)/pre-js-$(1).js endef #$(error $(call call-make-pre-js,sqlite3-wasmfs)) # /post-js and pre-js @@ -304,9 +303,9 @@ endef ######################################################################## # emcc flags for .c/.o/.wasm/.js. -emcc.flags = +emcc.flags := #emcc.flags += -v # _very_ loud but also informative about what it's doing -# -g is needed to keep -O2 and higher from creating broken JS via +# -g3 is needed to keep -O2 and higher from creating broken JS via # minification. ######################################################################## diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js index 5768e44cb2..7e467868ee 100644 --- a/ext/wasm/api/sqlite3-api-glue.js +++ b/ext/wasm/api/sqlite3-api-glue.js @@ -592,7 +592,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ For the given integer, returns the SQLITE_xxx result code as a string, or undefined if no such mapping is found. */ - capi.sqlite3_web_rc_str = (rc)=>__rcMap[rc]; + capi.sqlite3_js_rc_str = (rc)=>__rcMap[rc]; /* Bind all registered C-side structs... */ const notThese = Object.assign(Object.create(null),{ // Structs NOT to register diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js index f1014fcc00..c2e7eb14f1 100644 --- a/ext/wasm/api/sqlite3-api-oo1.js +++ b/ext/wasm/api/sqlite3-api-oo1.js @@ -1406,7 +1406,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ default: this._mayGet = false; console.warn("sqlite3_step() rc=",rc, - capi.sqlite3_web_rc_str(rc), + capi.sqlite3_js_rc_str(rc), "SQL =", capi.sqlite3_sql(this.pointer)); DB.checkRc(this.db.pointer, rc); } @@ -1662,8 +1662,8 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ }; const jdb = sqlite3.oo1.JsStorageDb; jdb.prototype = Object.create(DB.prototype); - /** Equivalent to sqlite3_web_kvvfs_clear(). */ - jdb.clearStorage = capi.sqlite3_web_kvvfs_clear; + /** Equivalent to sqlite3_js_kvvfs_clear(). */ + jdb.clearStorage = capi.sqlite3_js_kvvfs_clear; /** Clears this database instance's storage or throws if this instance has been closed. Returns the number of @@ -1672,8 +1672,8 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ jdb.prototype.clearStorage = function(){ return jdb.clearStorage(affirmDbOpen(this).filename); }; - /** Equivalent to sqlite3_web_kvvfs_size(). */ - jdb.storageSize = capi.sqlite3_web_kvvfs_size; + /** Equivalent to sqlite3_js_kvvfs_size(). */ + jdb.storageSize = capi.sqlite3_js_kvvfs_size; /** Returns the _approximate_ number of bytes this database takes up in its storage or throws if this instance has been closed. diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index d02d6b0540..ca1542e2b2 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -1107,7 +1107,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( bad arguments cause a conversion error when passing into wasm-space, false is returned. */ - capi.sqlite3_web_db_uses_vfs = function(pDb,vfsName,dbName="main"){ + capi.sqlite3_js_db_uses_vfs = function(pDb,vfsName,dbName="main"){ try{ const pK = capi.sqlite3_vfs_find(vfsName); if(!pK) return false; @@ -1134,7 +1134,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( Returns an array of the names of all currently-registered sqlite3 VFSes. */ - capi.sqlite3_web_vfs_list = function(){ + capi.sqlite3_js_vfs_list = function(){ const rc = []; let pVfs = capi.sqlite3_vfs_find(0); while(pVfs){ @@ -1151,7 +1151,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( sqlite3_serialize(). On success it returns a Uint8Array. On error it throws with a description of the problem. */ - capi.sqlite3_web_db_export = function(pDb){ + capi.sqlite3_js_db_export = function(pDb){ if(!pDb) toss('Invalid sqlite3* argument.'); if(!wasm.bigIntEnabled) toss('BigInt64 support is not enabled.'); const stack = wasm.pstack.pointer; @@ -1171,7 +1171,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( ); if(rc){ toss("Database serialization failed with code", - sqlite3.capi.sqlite3_web_rc_str(rc)); + sqlite3.capi.sqlite3_js_rc_str(rc)); } pOut = wasm.getPtrValue(ppOut); const nOut = wasm.getMemValue(pSize, 'i64'); @@ -1192,7 +1192,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( /* Features specific to the main window thread... */ /** - Internal helper for sqlite3_web_kvvfs_clear() and friends. + Internal helper for sqlite3_js_kvvfs_clear() and friends. Its argument should be one of ('local','session',''). */ const __kvvfsInfo = function(which){ @@ -1217,7 +1217,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( Returns the number of entries cleared. */ - capi.sqlite3_web_kvvfs_clear = function(which=''){ + capi.sqlite3_js_kvvfs_clear = function(which=''){ let rc = 0; const kvinfo = __kvvfsInfo(which); kvinfo.stores.forEach((s)=>{ @@ -1250,7 +1250,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( those limits are unspecified and may include per-entry overhead invisible to clients. */ - capi.sqlite3_web_kvvfs_size = function(which=''){ + capi.sqlite3_js_kvvfs_size = function(which=''){ let sz = 0; const kvinfo = __kvvfsInfo(which); kvinfo.stores.forEach((s)=>{ diff --git a/ext/wasm/api/sqlite3-api-worker1.js b/ext/wasm/api/sqlite3-api-worker1.js index 6c0900a506..fa6a438462 100644 --- a/ext/wasm/api/sqlite3-api-worker1.js +++ b/ext/wasm/api/sqlite3-api-worker1.js @@ -167,7 +167,7 @@ the non-WASMFS OPFS VFS to open a database via a URI-style db filename. - vfsList: result of sqlite3.capi.sqlite3_web_vfs_list() + vfsList: result of sqlite3.capi.sqlite3_js_vfs_list() } } ``` @@ -225,13 +225,15 @@ type: "close", messageId: ...as above... dbId: ...as above... - args: none + args: OPTIONAL {unlink: boolean} } ``` - If the dbId does not refer to an opened ID, this is a no-op. The - inability to close a db (because it's not opened) or delete its - file does not trigger an error. + If the `dbId` does not refer to an opened ID, this is a no-op. If + the `args` object contains a truthy `unlink` value then the database + will unlinked (deleted) after closing it. The inability to close a + db (because it's not opened) or delete its file does not trigger an + error. Response: @@ -432,15 +434,13 @@ sqlite3.initWorker1API = function(){ const pDir = sqlite3.capi.sqlite3_wasmfs_opfs_dir(); if(!args.filename || ':memory:'===args.filename){ oargs.filename = args.filename || ''; - }else if(pDir){ - oargs.filename = pDir + ('/'===args.filename[0] ? args.filename : ('/'+args.filename)); }else{ oargs.filename = args.filename; } const db = wState.open(oargs); rc.filename = db.filename; - rc.persistent = (!!pDir && db.filename.startsWith(pDir)) - || sqlite3.capi.sqlite3_web_db_uses_vfs(db.pointer, "opfs"); + rc.persistent = (!!pDir && db.filename.startsWith(pDir+'/')) + || sqlite3.capi.sqlite3_js_db_uses_vfs(db.pointer, "opfs"); rc.dbId = getDbId(db); return rc; }, @@ -521,7 +521,7 @@ sqlite3.initWorker1API = function(){ }); rc.wasmfsOpfsEnabled = !!sqlite3.capi.sqlite3_wasmfs_opfs_dir(); rc.version = sqlite3.version; - rc.vfsList = sqlite3.capi.sqlite3_web_vfs_list(); + rc.vfsList = sqlite3.capi.sqlite3_js_vfs_list(); return rc; }, diff --git a/ext/wasm/fiddle/fiddle-worker.js b/ext/wasm/fiddle/fiddle-worker.js index 581121826d..e3a2cbbe81 100644 --- a/ext/wasm/fiddle/fiddle-worker.js +++ b/ext/wasm/fiddle/fiddle-worker.js @@ -130,7 +130,7 @@ return f._(); }, dbIsOpfs: function f(){ - return sqlite3.opfs && sqlite3.capi.sqlite3_web_db_uses_vfs( + return sqlite3.opfs && sqlite3.capi.sqlite3_js_db_uses_vfs( this.dbHandle(), "opfs" ); }, @@ -251,7 +251,7 @@ const fn2 = fn ? fn.split(/[/\\]/).pop() : null; try{ if(!fn2) toss("DB appears to be closed."); - const buffer = sqlite3.capi.sqlite3_web_db_export( + const buffer = sqlite3.capi.sqlite3_js_db_export( Sqlite3Shell.dbHandle() ); wMsg('db-export',{filename: fn2, buffer: buffer.buffer}, [buffer.buffer]); diff --git a/ext/wasm/speedtest1-worker.js b/ext/wasm/speedtest1-worker.js index e3e4ef7f34..a4d6aedc58 100644 --- a/ext/wasm/speedtest1-worker.js +++ b/ext/wasm/speedtest1-worker.js @@ -96,6 +96,6 @@ //if(App.pDir) log("Persistent storage:",pDir); //else log("Using transient storage."); mPost('ready',true); - log("Registered VFSes:", ...S.capi.sqlite3_web_vfs_list()); + log("Registered VFSes:", ...S.capi.sqlite3_js_vfs_list()); }); })(); diff --git a/ext/wasm/speedtest1.html b/ext/wasm/speedtest1.html index a53b24c6df..b2b0b8e861 100644 --- a/ext/wasm/speedtest1.html +++ b/ext/wasm/speedtest1.html @@ -94,7 +94,6 @@ const runTests = function(sqlite3){ const capi = sqlite3.capi, wasm = capi.wasm; //console.debug('sqlite3 =',sqlite3); - const unlink = wasm.xWrap("sqlite3_wasm_vfs_unlink", "int", ["string"]); const pDir = wasmfsDir(wasm); if(pDir){ console.warn("Persistent storage:",pDir); @@ -108,9 +107,11 @@ } let forceSize = 0; + let vfs, pVfs = 0; if(urlParams.has('vfs')){ - const vfs = urlParams.get('vfs'); - if(!capi.sqlite3_vfs_find(vfs)){ + vfs = urlParams.get('vfs'); + pVfs = capi.sqlite3_vfs_find(vfs); + if(!pVfs){ log2('error',"Unknown VFS:",vfs); return; } @@ -121,7 +122,7 @@ dbFile = 'session'; log2('warning',"kvvfs VFS: forcing --size",forceSize, "and filename '"+dbFile+"'."); - capi.sqlite3_web_kvvfs_clear(dbFile); + capi.sqlite3_js_kvvfs_clear(dbFile); } } if(forceSize){ @@ -146,7 +147,7 @@ console.log("argv =",argv); // These log messages are not emitted to the UI until after main() returns. Fixing that // requires moving the main() call and related cleanup into a timeout handler. - if(pDir) unlink(dbFile); + if(pDir) wasm.sqlite3_wasm_vfs_unlink(pVfs,dbFile); log2('',"Starting native app:\n ",argv.join(' ')); log2('',"This will take a while and the browser might warn about the runaway JS.", "Give it time..."); @@ -155,7 +156,7 @@ wasm.xCall('wasm_main', argv.length, wasm.scopedAllocMainArgv(argv)); wasm.scopedAllocPop(scope); - if(pDir) unlink(dbFile); + if(pDir) wasm.sqlite3_wasm_vfs_unlink(pVfs,dbFile); logList.unshift("Done running native main(). Output:"); dumpLogList(); }, 50); diff --git a/manifest b/manifest index 15b79eaab1..7dc2026e7d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\sbit\sto\sthe\soptimization\sdisabling\smask\sfor\sthe\sindexed\sexpression\noptimization. -D 2022-10-20T16:30:05.203 +C Rename\ssqlite3_web_...\sto\ssqlite3_js_...\sDocument\sthe\sworker1.close.unlink\soption.\sFix\sunlink\susage\sin\sspeedtest1.html.\sMinor\sJS\sbuild\scleanups. +D 2022-10-20T18:31:32.249 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -472,7 +472,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile 6cd57a8ce51424220917c6ff766e8a7b7998cbdc6a1e364c4366992a77f11de4 +F ext/wasm/GNUmakefile 645bd5670a56acf2c8f1e969c427555e3e8e74dfd6eac8c948858f530617c7d5 F ext/wasm/README-dist.txt e78e44a58772d5b5d7a5a179b5bf639cd67b62249aac66138e2c319bd02dd243 F ext/wasm/README.md 1e5b28158b74ab3ffc9d54fcbc020f0bbeb82c2ff8bbd904214c86c70e8a3066 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 89983a8d122c35a90c65ec667844b95a78bcd04f3198a99c1e0c8368c1a0b03a @@ -484,11 +484,11 @@ F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08 F ext/wasm/api/post-js-header.js 2e5c886398013ba2af88028ecbced1e4b22dc96a86467f1ecc5ba9e64ef90a8b F ext/wasm/api/pre-js.js 151e0616614a49f3db19ed544fa13b38c87c108959fbcd4029ea8399a562d94f F ext/wasm/api/sqlite3-api-cleanup.js 4d07a7524dc9b7b050acfde57163e839243ad2383bd7ee0de0178b1b3e988588 -F ext/wasm/api/sqlite3-api-glue.js 2f5a337181e541cf3d74ceafb600ebb730a1241a5572710a21133b6dd5b2b2e2 -F ext/wasm/api/sqlite3-api-oo1.js 9a5f0c00d476c504f16dcd456e1743dbc2826ca3d10645dfa62663a39e3ed0d8 +F ext/wasm/api/sqlite3-api-glue.js 0b5240bd325d2561f269cd0d82bf686336526e5e276251c2241adfbda802abf8 +F ext/wasm/api/sqlite3-api-oo1.js dc9b6a61649ad32836044de388c5248790239d62ced4e1116023135fcb0fc68b F ext/wasm/api/sqlite3-api-opfs.js 22d60ba956e873b65e2e0591e239178082bd53a6d563c3c58db7dc03e562e8f7 -F ext/wasm/api/sqlite3-api-prologue.js 7eef0383646c851e3f6a78e21b51e9c078c82829c9d3d2ded9aa0215d71de36c -F ext/wasm/api/sqlite3-api-worker1.js c8133bb5848c082c6f0eb69722086dd876c389a3bc77cd404f23791a5c2a3300 +F ext/wasm/api/sqlite3-api-prologue.js 1366d538a7b388c299a389f441a79cf0b18af50208343545bd318936b6232acd +F ext/wasm/api/sqlite3-api-worker1.js cb07b321164483524a27cf2207d4358b905703c410fcd8256e0acca5ab2fffb2 F ext/wasm/api/sqlite3-license-version-header.js a661182fc93fc2cf212dfd0b987f8e138a3ac98f850b1112e29b5fbdaecc87c3 F ext/wasm/api/sqlite3-opfs-async-proxy.js 206ce6bbc3c30ad51a37d9c25e3a2712e70b586e0f9a2cf8cb0b9619017c2671 F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9 @@ -513,7 +513,7 @@ F ext/wasm/demo-worker1.js 8ba51d94c4601fa5c313d9e59b63b238f5305b5d5739ad21f4782 F ext/wasm/dist.make b3b156061ff6a35ce59715632c9446cb58e0fc497021a93c778fed051a04fde1 F ext/wasm/fiddle.make acdb1a402864f9b05a4c89805c5e91d88f5080652d8861f0865655b172243847 F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f -F ext/wasm/fiddle/fiddle-worker.js def4762721ff36e2fd1b5cb35725fc9f56933eb4fbf3dcdaab6eee164baa442e +F ext/wasm/fiddle/fiddle-worker.js 7ee53ca846071de5d46bb11a2a269a7990ef9cfd8abfae2a25cc948499783d78 F ext/wasm/fiddle/fiddle.html 5daf54e8f3d7777cbb1ca4f93affe28858dbfff25841cb4ab81d694efed28ec2 F ext/wasm/fiddle/fiddle.js 974b995119ac443685d7d94d3b3c58c6a36540e9eb3fed7069d5653284071715 F ext/wasm/index-dist.html cb0da16cba0f21cda2c25724c5869102d48eb0af04446acd3cd0ca031f80ed19 @@ -524,8 +524,8 @@ F ext/wasm/scratchpad-wasmfs-main.html 20cf6f1a8f368e70d01e8c17200e3eaa90f1c8e10 F ext/wasm/scratchpad-wasmfs-main.js 1aa32c1035cf1440a226a28fefcbb5762fbbcb020ccbe5895f8736d701695c63 F ext/wasm/speedtest1-wasmfs.html bc28eb29b69a73864b8d7aae428448f8b7e1de81d8bfb9bba99541322054dbd0 F ext/wasm/speedtest1-worker.html 7b0cceab6a68b2883738e19f61d21620fe1244ba36c1b2e38d0efde57ecce86d -F ext/wasm/speedtest1-worker.js b49358781aca651319eca3720857f19d0eae0868834992f8f6d666c1e976dff8 -F ext/wasm/speedtest1.html 00102689678b3c09ae6f5e4b3782e95f448e943a3491246e7be9ee349049bcaf +F ext/wasm/speedtest1-worker.js 490844a70af72d7bb16cc766d66621c1ca587d8a3f7e6b804c69327fa34881f7 +F ext/wasm/speedtest1.html 6303e620162b2058d5e212f966a7caed4a31a516b6140fbc64185cb296218e4f F ext/wasm/split-speedtest1-script.sh a3e271938d4d14ee49105eb05567c6a69ba4c1f1293583ad5af0cd3a3779e205 x F ext/wasm/sql/000-mandelbrot.sql 775337a4b80938ac8146aedf88808282f04d02d983d82675bd63d9c2d97a15f0 F ext/wasm/sql/001-sudoku.sql 35b7cb7239ba5d5f193bc05ec379bcf66891bce6f2a5b3879f2f78d0917299b5 @@ -2036,8 +2036,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 535867a9c8719358380f89fd80473c484def9bb72744dd2fd28ada65999ee901 -R 85216d994cb9632dd89733d6a41cd6c8 -U drh -Z 8b2ac4d684320c840aa3e0f63be89cad +P 56df1482ab45d4d41f937b27c5a877b52fa082bfc6809ea682b62b47a51333de +R afcc999df723d6bf12746efb0e783132 +U stephan +Z 97b1f226f03f5d4357dc526c8056da42 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8bf6cfe9ae..2f33d38322 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -56df1482ab45d4d41f937b27c5a877b52fa082bfc6809ea682b62b47a51333de \ No newline at end of file +ac9af71b72a749b0a040273a88480d56f49570b569389a4ea20cc055f494d8ff \ No newline at end of file