Add files using upload-large-folder tool
Browse files- local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_button_add.png +3 -0
- local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_edittext_search.png +3 -0
- local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_launcher_freerdp.png +3 -0
- local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_disconnect.png +3 -0
- local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_ext_keyboard.png +3 -0
- local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_settings.png +3 -0
- local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_down_arrow_black.png +3 -0
- local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_right_arrow.png +3 -0
- local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_up_arrow.png +3 -0
- local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_reset.png +3 -0
- local-test-sqlite3-delta-02/afc-sqlite3/ext/recover/recoverfault2.test +102 -0
- local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/SQLTester/GNUmakefile +55 -0
- local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/api/README.md +166 -0
- local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/api/post-js-footer.js +4 -0
- local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/api/pre-js.c-pp.js +121 -0
- local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/api/sqlite3-api-cleanup.js +63 -0
- local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/api/sqlite3-api-worker1.c-pp.js +656 -0
- local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/api/sqlite3-wasm.c +1950 -0
- local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/fiddle/fiddle-worker.js +381 -0
- local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/jaccwabyt/jaccwabyt.js +696 -0
local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_button_add.png
ADDED
|
|
Git LFS Details
|
local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_edittext_search.png
ADDED
|
|
Git LFS Details
|
local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_launcher_freerdp.png
ADDED
|
|
Git LFS Details
|
local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_disconnect.png
ADDED
|
|
Git LFS Details
|
local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_ext_keyboard.png
ADDED
|
|
Git LFS Details
|
local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable-ldpi/icon_menu_settings.png
ADDED
|
|
Git LFS Details
|
local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_down_arrow_black.png
ADDED
|
Git LFS Details
|
local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_right_arrow.png
ADDED
|
Git LFS Details
|
local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable/sym_keyboard_up_arrow.png
ADDED
|
Git LFS Details
|
local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/freeRDPCore/src/main/res/drawable/touch_pointer_reset.png
ADDED
|
Git LFS Details
|
local-test-sqlite3-delta-02/afc-sqlite3/ext/recover/recoverfault2.test
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2022 August 28
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
|
| 13 |
+
source [file join [file dirname [info script]] recover_common.tcl]
|
| 14 |
+
set testprefix recoverfault2
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
#--------------------------------------------------------------------------
|
| 18 |
+
proc compare_result {db1 db2 sql} {
|
| 19 |
+
set r1 [$db1 eval $sql]
|
| 20 |
+
set r2 [$db2 eval $sql]
|
| 21 |
+
if {$r1 != $r2} {
|
| 22 |
+
puts "r1: $r1"
|
| 23 |
+
puts "r2: $r2"
|
| 24 |
+
error "mismatch for $sql"
|
| 25 |
+
}
|
| 26 |
+
return ""
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
proc compare_dbs {db1 db2} {
|
| 30 |
+
compare_result $db1 $db2 "SELECT sql FROM sqlite_master ORDER BY 1"
|
| 31 |
+
foreach tbl [$db1 eval {SELECT name FROM sqlite_master WHERE type='table'}] {
|
| 32 |
+
compare_result $db1 $db2 "SELECT * FROM $tbl"
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
#--------------------------------------------------------------------------
|
| 36 |
+
|
| 37 |
+
do_execsql_test 1.0 "
|
| 38 |
+
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
|
| 39 |
+
INSERT INTO t1 VALUES(2, '\012hello\015world\012today\n');
|
| 40 |
+
"
|
| 41 |
+
faultsim_save_and_close
|
| 42 |
+
|
| 43 |
+
proc my_sql_hook {sql} {
|
| 44 |
+
lappend ::lSql $sql
|
| 45 |
+
return 0
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
do_faultsim_test 1 -faults oom* -prep {
|
| 49 |
+
catch { db2 close }
|
| 50 |
+
faultsim_restore_and_reopen
|
| 51 |
+
set ::lSql [list]
|
| 52 |
+
} -body {
|
| 53 |
+
set R [sqlite3_recover_init_sql db main my_sql_hook]
|
| 54 |
+
$R run
|
| 55 |
+
$R finish
|
| 56 |
+
} -test {
|
| 57 |
+
faultsim_test_result {0 {}} {1 {}}
|
| 58 |
+
if {$testrc==0} {
|
| 59 |
+
sqlite3 db2 ""
|
| 60 |
+
db2 eval [join $::lSql ";"]
|
| 61 |
+
compare_dbs db db2
|
| 62 |
+
db2 close
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
ifcapable utf16 {
|
| 67 |
+
reset_db
|
| 68 |
+
do_execsql_test 2.0 "
|
| 69 |
+
PRAGMA encoding='utf-16';
|
| 70 |
+
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
|
| 71 |
+
INSERT INTO t1 VALUES(2, '\012hello\015world\012today\n');
|
| 72 |
+
"
|
| 73 |
+
faultsim_save_and_close
|
| 74 |
+
|
| 75 |
+
proc my_sql_hook {sql} {
|
| 76 |
+
lappend ::lSql $sql
|
| 77 |
+
return 0
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
do_faultsim_test 2 -faults oom-t* -prep {
|
| 81 |
+
catch { db2 close }
|
| 82 |
+
faultsim_restore_and_reopen
|
| 83 |
+
set ::lSql [list]
|
| 84 |
+
} -body {
|
| 85 |
+
set R [sqlite3_recover_init_sql db main my_sql_hook]
|
| 86 |
+
$R run
|
| 87 |
+
$R finish
|
| 88 |
+
} -test {
|
| 89 |
+
faultsim_test_result {0 {}} {1 {}}
|
| 90 |
+
if {$testrc==0} {
|
| 91 |
+
sqlite3 db2 ""
|
| 92 |
+
db2 eval [join $::lSql ";"]
|
| 93 |
+
compare_dbs db db2
|
| 94 |
+
db2 close
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
finish_test
|
| 102 |
+
|
local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/SQLTester/GNUmakefile
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/this/is/make
|
| 2 |
+
#
|
| 3 |
+
# This makefile compiles SQLTester test files into something
|
| 4 |
+
# we can readily import into JavaScript.
|
| 5 |
+
all:
|
| 6 |
+
|
| 7 |
+
SHELL := $(shell which bash 2>/dev/null)
|
| 8 |
+
MAKEFILE := $(lastword $(MAKEFILE_LIST))
|
| 9 |
+
CLEAN_FILES :=
|
| 10 |
+
DISTCLEAN_FILES := ./--dummy-- *~
|
| 11 |
+
|
| 12 |
+
test-list.mjs := test-list.mjs
|
| 13 |
+
test-list.mjs.gz := $(test-list.mjs).gz
|
| 14 |
+
CLEAN_FILES += $(test-list.mjs)
|
| 15 |
+
|
| 16 |
+
tests.dir := $(firstword $(wildcard tests ../../jni/src/tests))
|
| 17 |
+
$(info test script dir=$(tests.dir))
|
| 18 |
+
|
| 19 |
+
tests.all := $(wildcard $(tests.dir)/*.test)
|
| 20 |
+
|
| 21 |
+
bin.touint8array := ./touint8array
|
| 22 |
+
$(bin.touint8array): $(bin.touint8array).c $(MAKEFILE)
|
| 23 |
+
$(CC) -o $@ $<
|
| 24 |
+
CLEAN_FILES += $(bin.touint8array)
|
| 25 |
+
|
| 26 |
+
ifneq (,$(tests.all))
|
| 27 |
+
$(test-list.mjs): $(bin.touint8array) $(tests.all) $(MAKEFILE)
|
| 28 |
+
@{\
|
| 29 |
+
echo 'export default ['; \
|
| 30 |
+
sep=''; \
|
| 31 |
+
for f in $(sort $(tests.all)); do \
|
| 32 |
+
echo -en $$sep'{"name": "'$${f##*/}'", "content":'; \
|
| 33 |
+
$(bin.touint8array) < $$f; \
|
| 34 |
+
echo -n '}'; \
|
| 35 |
+
sep=',\n'; \
|
| 36 |
+
done; \
|
| 37 |
+
echo '];'; \
|
| 38 |
+
} > $@
|
| 39 |
+
@echo "Created $@"
|
| 40 |
+
$(test-list.mjs.gz): $(test-list.mjs)
|
| 41 |
+
gzip -c $< > $@
|
| 42 |
+
CLEAN_FILES += $(test-list.mjs.gz)
|
| 43 |
+
all: $(test-list.mjs.gz)
|
| 44 |
+
else
|
| 45 |
+
@echo "Cannot build $(test-list.mjs) for lack of input test files."; \
|
| 46 |
+
echo "Symlink ./tests to a directory containing SQLTester-format "; \
|
| 47 |
+
echo "test scripts named *.test, then try again"; \
|
| 48 |
+
exit 1
|
| 49 |
+
endif
|
| 50 |
+
|
| 51 |
+
.PHONY: clean distclean
|
| 52 |
+
clean:
|
| 53 |
+
-rm -f $(CLEAN_FILES)
|
| 54 |
+
distclean: clean
|
| 55 |
+
-rm -f $(DISTCLEAN_FILES)
|
local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/api/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# sqlite3-api.js And Friends
|
| 2 |
+
|
| 3 |
+
This is the README for the files `sqlite3-*.js` and
|
| 4 |
+
`sqlite3-wasm.c`. This collection of files is used to build a
|
| 5 |
+
single-file distribution of the sqlite3 WASM API. It is broken into
|
| 6 |
+
multiple JS files because:
|
| 7 |
+
|
| 8 |
+
1. To facilitate including or excluding certain components for
|
| 9 |
+
specific use cases. e.g. by removing `sqlite3-api-oo1.js` if the
|
| 10 |
+
OO#1 API is not needed.
|
| 11 |
+
|
| 12 |
+
2. To facilitate modularizing the pieces for use in different WASM
|
| 13 |
+
build environments. e.g. the files `post-js-*.js` are for use with
|
| 14 |
+
Emscripten's `--post-js` feature, and nowhere else.
|
| 15 |
+
|
| 16 |
+
3. Certain components must be in their own standalone files in order
|
| 17 |
+
to be loaded as JS Workers.
|
| 18 |
+
|
| 19 |
+
Note that the structure described here is the current state of things,
|
| 20 |
+
as of this writing, but is not set in stone forever and may change
|
| 21 |
+
at any time.
|
| 22 |
+
|
| 23 |
+
The overall idea is that the following files get concatenated
|
| 24 |
+
together, in the listed order, the resulting file is loaded by a
|
| 25 |
+
browser client:
|
| 26 |
+
|
| 27 |
+
- **`sqlite3-api-prologue.js`**\
|
| 28 |
+
Contains the initial bootstrap setup of the sqlite3 API
|
| 29 |
+
objects. This is exposed as a function, rather than objects, so that
|
| 30 |
+
the next step can pass in a config object which abstracts away parts
|
| 31 |
+
of the WASM environment, to facilitate plugging it in to arbitrary
|
| 32 |
+
WASM toolchains.
|
| 33 |
+
- **`../common/whwasmutil.js`**\
|
| 34 |
+
A semi-third-party collection of JS/WASM utility code intended to
|
| 35 |
+
replace much of the Emscripten glue. The sqlite3 APIs internally use
|
| 36 |
+
these APIs instead of their Emscripten counterparts, in order to be
|
| 37 |
+
more portable to arbitrary WASM toolchains. This API is
|
| 38 |
+
configurable, in principle, for use with arbitrary WASM
|
| 39 |
+
toolchains. It is "semi-third-party" in that it was created in order
|
| 40 |
+
to support this tree but is standalone and maintained together
|
| 41 |
+
with...
|
| 42 |
+
- **`../jaccwabyt/jaccwabyt.js`**\
|
| 43 |
+
Another semi-third-party API which creates bindings between JS
|
| 44 |
+
and C structs, such that changes to the struct state from either JS
|
| 45 |
+
or C are visible to the other end of the connection. This is also an
|
| 46 |
+
independent spinoff project, conceived for the sqlite3 project but
|
| 47 |
+
maintained separately.
|
| 48 |
+
- **`sqlite3-api-glue.js`**\
|
| 49 |
+
Invokes functionality exposed by the previous two files to flesh out
|
| 50 |
+
low-level parts of `sqlite3-api-prologue.js`. Most of these pieces
|
| 51 |
+
related to populating the `sqlite3.capi.wasm` object. This file
|
| 52 |
+
also deletes most global-scope symbols the above files create,
|
| 53 |
+
effectively moving them into the scope being used for initializing
|
| 54 |
+
the API.
|
| 55 |
+
- **`<build>/sqlite3-api-build-version.js`**\
|
| 56 |
+
Gets created by the build process and populates the
|
| 57 |
+
`sqlite3.version` object. This part is not critical, but records the
|
| 58 |
+
version of the library against which this module was built.
|
| 59 |
+
- **`sqlite3-api-oo1.js`**\
|
| 60 |
+
Provides a high-level object-oriented wrapper to the lower-level C
|
| 61 |
+
API, colloquially known as OO API #1. Its API is similar to other
|
| 62 |
+
high-level sqlite3 JS wrappers and should feel relatively familiar
|
| 63 |
+
to anyone familiar with such APIs. That said, it is not a "required
|
| 64 |
+
component" and can be elided from builds which do not want it.
|
| 65 |
+
- **`sqlite3-api-worker1.js`**\
|
| 66 |
+
A Worker-thread-based API which uses OO API #1 to provide an
|
| 67 |
+
interface to a database which can be driven from the main Window
|
| 68 |
+
thread via the Worker message-passing interface. Like OO API #1,
|
| 69 |
+
this is an optional component, offering one of any number of
|
| 70 |
+
potential implementations for such an API.
|
| 71 |
+
- **`sqlite3-worker1.js`**\
|
| 72 |
+
Is not part of the amalgamated sources and is intended to be
|
| 73 |
+
loaded by a client Worker thread. It loads the sqlite3 module
|
| 74 |
+
and runs the Worker #1 API which is implemented in
|
| 75 |
+
`sqlite3-api-worker1.js`.
|
| 76 |
+
- **`sqlite3-worker1-promiser.js`**\
|
| 77 |
+
Is likewise not part of the amalgamated sources and provides
|
| 78 |
+
a Promise-based interface into the Worker #1 API. This is
|
| 79 |
+
a far user-friendlier way to interface with databases running
|
| 80 |
+
in a Worker thread.
|
| 81 |
+
- **`sqlite3-vfs-helper.js`**\
|
| 82 |
+
Installs the `sqlite3.vfs` namespace, which contain helpers for use
|
| 83 |
+
by downstream code which creates `sqlite3_vfs` implementations.
|
| 84 |
+
- **`sqlite3-vtab-helper.js`**\
|
| 85 |
+
Installs the `sqlite3.vtab` namespace, which contain helpers for use
|
| 86 |
+
by downstream code which creates `sqlite3_module` implementations.
|
| 87 |
+
- **`sqlite3-vfs-opfs.c-pp.js`**\
|
| 88 |
+
is an sqlite3 VFS implementation which supports the Origin-Private
|
| 89 |
+
FileSystem (OPFS) as a storage layer to provide persistent storage
|
| 90 |
+
for database files in a browser. It requires...
|
| 91 |
+
- **`sqlite3-opfs-async-proxy.js`**\
|
| 92 |
+
is the asynchronous backend part of the OPFS proxy. It speaks
|
| 93 |
+
directly to the (async) OPFS API and channels those results back
|
| 94 |
+
to its synchronous counterpart. This file, because it must be
|
| 95 |
+
started in its own Worker, is not part of the amalgamation.
|
| 96 |
+
- **`sqlite3-vfs-opfs-sahpool.c-pp.js`**\
|
| 97 |
+
is another sqlite3 VFS supporting the OPFS, but uses a completely
|
| 98 |
+
different approach that the above-listed one.
|
| 99 |
+
- **`sqlite3-api-cleanup.js`**\
|
| 100 |
+
The previous files do not immediately extend the library. Instead
|
| 101 |
+
they add callback functions to be called during its
|
| 102 |
+
bootstrapping. Some also temporarily create global objects in order
|
| 103 |
+
to communicate their state to the files which follow them. This file
|
| 104 |
+
cleans up any dangling globals and runs the API bootstrapping
|
| 105 |
+
process, which is what finally executes the initialization code
|
| 106 |
+
installed by the previous files. As of this writing, this code
|
| 107 |
+
ensures that the previous files leave no more than a single global
|
| 108 |
+
symbol installed. When adapting the API for non-Emscripten
|
| 109 |
+
toolchains, this "should" be the only file where changes are needed.
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
**Files with the extension `.c-pp.js`** are intended [to be processed
|
| 113 |
+
with `c-pp`](#c-pp), noting that such preprocessing may be applied
|
| 114 |
+
after all of the relevant files are concatenated. That extension is
|
| 115 |
+
used primarily to keep the code maintainers cognisant of the fact that
|
| 116 |
+
those files contain constructs which may not run as-is in any given
|
| 117 |
+
JavaScript environment.
|
| 118 |
+
|
| 119 |
+
The build process glues those files together, resulting in
|
| 120 |
+
`sqlite3-api.js`, which is everything except for the
|
| 121 |
+
`pre/post-js-*.js` files, and `sqlite3.js`, which is the
|
| 122 |
+
Emscripten-generated amalgamated output and includes the
|
| 123 |
+
`pre/post-js-*.js` parts, as well as the Emscripten-provided module
|
| 124 |
+
loading pieces.
|
| 125 |
+
|
| 126 |
+
The non-JS outlier file is `sqlite3-wasm.c`: it is a proxy for
|
| 127 |
+
`sqlite3.c` which `#include`'s that file and adds a couple more
|
| 128 |
+
WASM-specific helper functions, at least one of which requires access
|
| 129 |
+
to private/static `sqlite3.c` internals. `sqlite3.wasm` is compiled
|
| 130 |
+
from this file rather than `sqlite3.c`.
|
| 131 |
+
|
| 132 |
+
The following files are part of the build process but are injected
|
| 133 |
+
into the build-generated `sqlite3.js` along with `sqlite3-api.js`.
|
| 134 |
+
|
| 135 |
+
- `extern-pre-js.js`\
|
| 136 |
+
Emscripten-specific header for Emscripten's `--extern-pre-js`
|
| 137 |
+
flag. As of this writing, that file is only used for experimentation
|
| 138 |
+
purposes and holds no code relevant to the production deliverables.
|
| 139 |
+
- `pre-js.c-pp.js`\
|
| 140 |
+
Emscripten-specific header for Emscripten's `--pre-js` flag. This
|
| 141 |
+
file is intended as a place to override certain Emscripten behavior
|
| 142 |
+
before it starts up, but corner-case Emscripten bugs keep that from
|
| 143 |
+
being a reality.
|
| 144 |
+
- `post-js-header.js`\
|
| 145 |
+
Emscripten-specific header for the `--post-js` input. It opens up
|
| 146 |
+
a lexical scope by starting a post-run handler for Emscripten.
|
| 147 |
+
- `post-js-footer.js`\
|
| 148 |
+
Emscripten-specific footer for the `--post-js` input. This closes
|
| 149 |
+
off the lexical scope opened by `post-js-header.js`.
|
| 150 |
+
- `extern-post-js.c-pp.js`\
|
| 151 |
+
Emscripten-specific header for Emscripten's `--extern-post-js`
|
| 152 |
+
flag. This file overwrites the Emscripten-installed
|
| 153 |
+
`sqlite3InitModule()` function with one which, after the module is
|
| 154 |
+
loaded, also initializes the asynchronous parts of the sqlite3
|
| 155 |
+
module. For example, the OPFS VFS support.
|
| 156 |
+
|
| 157 |
+
<a id='c-pp'></a>
|
| 158 |
+
Preprocessing of Source Files
|
| 159 |
+
------------------------------------------------------------------------
|
| 160 |
+
|
| 161 |
+
Certain files in the build require preprocessing to filter in/out
|
| 162 |
+
parts which differ between vanilla JS, ES6 Modules, and node.js
|
| 163 |
+
builds. The preprocessor application itself is in
|
| 164 |
+
[`c-pp.c`](/file/ext/wasm/c-pp.c) and the complete technical details
|
| 165 |
+
of such preprocessing are maintained in
|
| 166 |
+
[`GNUMakefile`](/file/ext/wasm/GNUmakefile).
|
local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/api/post-js-footer.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* The current function scope was opened via post-js-header.js, which
|
| 2 |
+
gets prepended to this at build-time. This file closes that
|
| 3 |
+
scope. */
|
| 4 |
+
})/*postRun.push(...)*/;
|
local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/api/pre-js.c-pp.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
BEGIN FILE: api/pre-js.js
|
| 3 |
+
|
| 4 |
+
This file is intended to be prepended to the sqlite3.js build using
|
| 5 |
+
Emscripten's --pre-js=THIS_FILE flag (or equivalent).
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
// See notes in extern-post-js.js
|
| 9 |
+
const sqlite3InitModuleState = globalThis.sqlite3InitModuleState
|
| 10 |
+
|| Object.assign(Object.create(null),{
|
| 11 |
+
debugModule: ()=>{}
|
| 12 |
+
});
|
| 13 |
+
delete globalThis.sqlite3InitModuleState;
|
| 14 |
+
sqlite3InitModuleState.debugModule('globalThis.location =',globalThis.location);
|
| 15 |
+
|
| 16 |
+
//#ifnot target=es6-bundler-friendly
|
| 17 |
+
/**
|
| 18 |
+
This custom locateFile() tries to figure out where to load `path`
|
| 19 |
+
from. The intent is to provide a way for foo/bar/X.js loaded from a
|
| 20 |
+
Worker constructor or importScripts() to be able to resolve
|
| 21 |
+
foo/bar/X.wasm (in the latter case, with some help):
|
| 22 |
+
|
| 23 |
+
1) If URL param named the same as `path` is set, it is returned.
|
| 24 |
+
|
| 25 |
+
2) If sqlite3InitModuleState.sqlite3Dir is set, then (thatName + path)
|
| 26 |
+
is returned (note that it's assumed to end with '/').
|
| 27 |
+
|
| 28 |
+
3) If this code is running in the main UI thread AND it was loaded
|
| 29 |
+
from a SCRIPT tag, the directory part of that URL is used
|
| 30 |
+
as the prefix. (This form of resolution unfortunately does not
|
| 31 |
+
function for scripts loaded via importScripts().)
|
| 32 |
+
|
| 33 |
+
4) If none of the above apply, (prefix+path) is returned.
|
| 34 |
+
*/
|
| 35 |
+
Module['locateFile'] = function(path, prefix) {
|
| 36 |
+
//#if target=es6-module
|
| 37 |
+
return new URL(path, import.meta.url).href;
|
| 38 |
+
//#else
|
| 39 |
+
'use strict';
|
| 40 |
+
let theFile;
|
| 41 |
+
const up = this.urlParams;
|
| 42 |
+
if(up.has(path)){
|
| 43 |
+
theFile = up.get(path);
|
| 44 |
+
}else if(this.sqlite3Dir){
|
| 45 |
+
theFile = this.sqlite3Dir + path;
|
| 46 |
+
}else if(this.scriptDir){
|
| 47 |
+
theFile = this.scriptDir + path;
|
| 48 |
+
}else{
|
| 49 |
+
theFile = prefix + path;
|
| 50 |
+
}
|
| 51 |
+
this.debugModule(
|
| 52 |
+
"locateFile(",arguments[0], ',', arguments[1],")",
|
| 53 |
+
'sqlite3InitModuleState.scriptDir =',this.scriptDir,
|
| 54 |
+
'up.entries() =',Array.from(up.entries()),
|
| 55 |
+
"result =", theFile
|
| 56 |
+
);
|
| 57 |
+
return theFile;
|
| 58 |
+
//#endif target=es6-module
|
| 59 |
+
}.bind(sqlite3InitModuleState);
|
| 60 |
+
//#endif ifnot target=es6-bundler-friendly
|
| 61 |
+
|
| 62 |
+
//#if custom-Module.instantiateModule
|
| 63 |
+
/**
|
| 64 |
+
Bug warning: a custom Module.instantiateWasm() does not work
|
| 65 |
+
in WASMFS builds:
|
| 66 |
+
|
| 67 |
+
https://github.com/emscripten-core/emscripten/issues/17951
|
| 68 |
+
|
| 69 |
+
In such builds we must disable this.
|
| 70 |
+
*/
|
| 71 |
+
const xNameOfInstantiateWasm =
|
| 72 |
+
//#if wasmfs
|
| 73 |
+
false
|
| 74 |
+
//#else
|
| 75 |
+
true /* This works, but it does not have the testing coverage in the
|
| 76 |
+
wild which Emscripten's default impl does, so we'll save
|
| 77 |
+
this option until we really need a custom
|
| 78 |
+
Module.instantiateWasm() */
|
| 79 |
+
//#endif
|
| 80 |
+
? 'instantiateWasm'
|
| 81 |
+
: 'emscripten-bug-17951';
|
| 82 |
+
Module[xNameOfInstantiateWasm] = function callee(imports,onSuccess){
|
| 83 |
+
imports.env.foo = function(){};
|
| 84 |
+
const uri = Module.locateFile(
|
| 85 |
+
callee.uri, (
|
| 86 |
+
('undefined'===typeof scriptDirectory/*var defined by Emscripten glue*/)
|
| 87 |
+
? "" : scriptDirectory)
|
| 88 |
+
);
|
| 89 |
+
sqlite3InitModuleState.debugModule(
|
| 90 |
+
"instantiateWasm() uri =", uri
|
| 91 |
+
);
|
| 92 |
+
//console.warn("Custom instantiateModule",uri);
|
| 93 |
+
const wfetch = ()=>fetch(uri, {credentials: 'same-origin'});
|
| 94 |
+
const loadWasm = WebAssembly.instantiateStreaming
|
| 95 |
+
? async ()=>{
|
| 96 |
+
return WebAssembly.instantiateStreaming(wfetch(), imports)
|
| 97 |
+
.then((arg)=>onSuccess(arg.instance, arg.module));
|
| 98 |
+
}
|
| 99 |
+
: async ()=>{ // Safari < v15
|
| 100 |
+
return wfetch()
|
| 101 |
+
.then(response => response.arrayBuffer())
|
| 102 |
+
.then(bytes => WebAssembly.instantiate(bytes, imports))
|
| 103 |
+
.then((arg)=>onSuccess(arg.instance, arg.module));
|
| 104 |
+
};
|
| 105 |
+
loadWasm();
|
| 106 |
+
return {};
|
| 107 |
+
};
|
| 108 |
+
/*
|
| 109 |
+
It is literally impossible to reliably get the name of _this_ script
|
| 110 |
+
at runtime, so impossible to derive X.wasm from script name
|
| 111 |
+
X.js. Thus we need, at build-time, to redefine
|
| 112 |
+
Module[xNameOfInstantiateWasm].uri by appending it to a build-specific
|
| 113 |
+
copy of this file with the name of the wasm file. This is apparently
|
| 114 |
+
why Emscripten hard-codes the name of the wasm file into their glue
|
| 115 |
+
scripts.
|
| 116 |
+
*/
|
| 117 |
+
Module[xNameOfInstantiateWasm].uri = 'sqlite3.wasm';
|
| 118 |
+
//#endif custom-Module.instantiateModule
|
| 119 |
+
/* END FILE: api/pre-js.js, noting that the build process may add a
|
| 120 |
+
line after this one to change the above .uri to a build-specific
|
| 121 |
+
one. */
|
local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/api/sqlite3-api-cleanup.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
2022-07-22
|
| 3 |
+
|
| 4 |
+
The author disclaims copyright to this source code. In place of a
|
| 5 |
+
legal notice, here is a blessing:
|
| 6 |
+
|
| 7 |
+
* May you do good and not evil.
|
| 8 |
+
* May you find forgiveness for yourself and forgive others.
|
| 9 |
+
* May you share freely, never taking more than you give.
|
| 10 |
+
|
| 11 |
+
***********************************************************************
|
| 12 |
+
|
| 13 |
+
This file is the tail end of the sqlite3-api.js constellation,
|
| 14 |
+
intended to be appended after all other sqlite3-api-*.js files so
|
| 15 |
+
that it can finalize any setup and clean up any global symbols
|
| 16 |
+
temporarily used for setting up the API's various subsystems.
|
| 17 |
+
*/
|
| 18 |
+
'use strict';
|
| 19 |
+
if('undefined' !== typeof Module){ // presumably an Emscripten build
|
| 20 |
+
/**
|
| 21 |
+
Install a suitable default configuration for sqlite3ApiBootstrap().
|
| 22 |
+
*/
|
| 23 |
+
const SABC = Object.assign(
|
| 24 |
+
Object.create(null), {
|
| 25 |
+
exports: ('undefined'===typeof wasmExports)
|
| 26 |
+
? Module['asm']/* emscripten <=3.1.43 */
|
| 27 |
+
: wasmExports /* emscripten >=3.1.44 */,
|
| 28 |
+
memory: Module.wasmMemory /* gets set if built with -sIMPORTED_MEMORY */
|
| 29 |
+
},
|
| 30 |
+
globalThis.sqlite3ApiConfig || {}
|
| 31 |
+
);
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
For current (2022-08-22) purposes, automatically call
|
| 35 |
+
sqlite3ApiBootstrap(). That decision will be revisited at some
|
| 36 |
+
point, as we really want client code to be able to call this to
|
| 37 |
+
configure certain parts. Clients may modify
|
| 38 |
+
globalThis.sqlite3ApiBootstrap.defaultConfig to tweak the default
|
| 39 |
+
configuration used by a no-args call to sqlite3ApiBootstrap(),
|
| 40 |
+
but must have first loaded their WASM module in order to be
|
| 41 |
+
able to provide the necessary configuration state.
|
| 42 |
+
*/
|
| 43 |
+
//console.warn("globalThis.sqlite3ApiConfig = ",globalThis.sqlite3ApiConfig);
|
| 44 |
+
globalThis.sqlite3ApiConfig = SABC;
|
| 45 |
+
let sqlite3;
|
| 46 |
+
try{
|
| 47 |
+
sqlite3 = globalThis.sqlite3ApiBootstrap();
|
| 48 |
+
}catch(e){
|
| 49 |
+
console.error("sqlite3ApiBootstrap() error:",e);
|
| 50 |
+
throw e;
|
| 51 |
+
}finally{
|
| 52 |
+
delete globalThis.sqlite3ApiBootstrap;
|
| 53 |
+
delete globalThis.sqlite3ApiConfig;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
Module.sqlite3 = sqlite3 /* Needed for customized sqlite3InitModule() to be able to
|
| 57 |
+
pass the sqlite3 object off to the client. */;
|
| 58 |
+
}else{
|
| 59 |
+
console.warn("This is not running in an Emscripten module context, so",
|
| 60 |
+
"globalThis.sqlite3ApiBootstrap() is _not_ being called due to lack",
|
| 61 |
+
"of config info for the WASM environment.",
|
| 62 |
+
"It must be called manually.");
|
| 63 |
+
}
|
local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/api/sqlite3-api-worker1.c-pp.js
ADDED
|
@@ -0,0 +1,656 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//#ifnot omit-oo1
|
| 2 |
+
/**
|
| 3 |
+
2022-07-22
|
| 4 |
+
|
| 5 |
+
The author disclaims copyright to this source code. In place of a
|
| 6 |
+
legal notice, here is a blessing:
|
| 7 |
+
|
| 8 |
+
* May you do good and not evil.
|
| 9 |
+
* May you find forgiveness for yourself and forgive others.
|
| 10 |
+
* May you share freely, never taking more than you give.
|
| 11 |
+
|
| 12 |
+
***********************************************************************
|
| 13 |
+
|
| 14 |
+
This file implements the initializer for SQLite's "Worker API #1", a
|
| 15 |
+
very basic DB access API intended to be scripted from a main window
|
| 16 |
+
thread via Worker-style messages. Because of limitations in that
|
| 17 |
+
type of communication, this API is minimalistic and only capable of
|
| 18 |
+
serving relatively basic DB requests (e.g. it cannot process nested
|
| 19 |
+
query loops concurrently).
|
| 20 |
+
|
| 21 |
+
This file requires that the core C-style sqlite3 API and OO API #1
|
| 22 |
+
have been loaded.
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
sqlite3.initWorker1API() implements a Worker-based wrapper around
|
| 27 |
+
SQLite3 OO API #1, colloquially known as "Worker API #1".
|
| 28 |
+
|
| 29 |
+
In order to permit this API to be loaded in worker threads without
|
| 30 |
+
automatically registering onmessage handlers, initializing the
|
| 31 |
+
worker API requires calling initWorker1API(). If this function is
|
| 32 |
+
called from a non-worker thread then it throws an exception. It
|
| 33 |
+
must only be called once per Worker.
|
| 34 |
+
|
| 35 |
+
When initialized, it installs message listeners to receive Worker
|
| 36 |
+
messages and then it posts a message in the form:
|
| 37 |
+
|
| 38 |
+
```
|
| 39 |
+
{type:'sqlite3-api', result:'worker1-ready'}
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
to let the client know that it has been initialized. Clients may
|
| 43 |
+
optionally depend on this function not returning until
|
| 44 |
+
initialization is complete, as the initialization is synchronous.
|
| 45 |
+
In some contexts, however, listening for the above message is
|
| 46 |
+
a better fit.
|
| 47 |
+
|
| 48 |
+
Note that the worker-based interface can be slightly quirky because
|
| 49 |
+
of its async nature. In particular, any number of messages may be posted
|
| 50 |
+
to the worker before it starts handling any of them. If, e.g., an
|
| 51 |
+
"open" operation fails, any subsequent messages will fail. The
|
| 52 |
+
Promise-based wrapper for this API (`sqlite3-worker1-promiser.js`)
|
| 53 |
+
is more comfortable to use in that regard.
|
| 54 |
+
|
| 55 |
+
The documentation for the input and output worker messages for
|
| 56 |
+
this API follows...
|
| 57 |
+
|
| 58 |
+
====================================================================
|
| 59 |
+
Common message format...
|
| 60 |
+
|
| 61 |
+
Each message posted to the worker has an operation-independent
|
| 62 |
+
envelope and operation-dependent arguments:
|
| 63 |
+
|
| 64 |
+
```
|
| 65 |
+
{
|
| 66 |
+
type: string, // one of: 'open', 'close', 'exec', 'export', 'config-get'
|
| 67 |
+
|
| 68 |
+
messageId: OPTIONAL arbitrary value. The worker will copy it as-is
|
| 69 |
+
into response messages to assist in client-side dispatching.
|
| 70 |
+
|
| 71 |
+
dbId: a db identifier string (returned by 'open') which tells the
|
| 72 |
+
operation which database instance to work on. If not provided, the
|
| 73 |
+
first-opened db is used. This is an "opaque" value, with no
|
| 74 |
+
inherently useful syntax or information. Its value is subject to
|
| 75 |
+
change with any given build of this API and cannot be used as a
|
| 76 |
+
basis for anything useful beyond its one intended purpose.
|
| 77 |
+
|
| 78 |
+
args: ...operation-dependent arguments...
|
| 79 |
+
|
| 80 |
+
// the framework may add other properties for testing or debugging
|
| 81 |
+
// purposes.
|
| 82 |
+
|
| 83 |
+
}
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
Response messages, posted back to the main thread, look like:
|
| 87 |
+
|
| 88 |
+
```
|
| 89 |
+
{
|
| 90 |
+
type: string. Same as above except for error responses, which have the type
|
| 91 |
+
'error',
|
| 92 |
+
|
| 93 |
+
messageId: same value, if any, provided by the inbound message
|
| 94 |
+
|
| 95 |
+
dbId: the id of the db which was operated on, if any, as returned
|
| 96 |
+
by the corresponding 'open' operation.
|
| 97 |
+
|
| 98 |
+
result: ...operation-dependent result...
|
| 99 |
+
|
| 100 |
+
}
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
====================================================================
|
| 104 |
+
Error responses
|
| 105 |
+
|
| 106 |
+
Errors are reported messages in an operation-independent format:
|
| 107 |
+
|
| 108 |
+
```
|
| 109 |
+
{
|
| 110 |
+
type: "error",
|
| 111 |
+
|
| 112 |
+
messageId: ...as above...,
|
| 113 |
+
|
| 114 |
+
dbId: ...as above...
|
| 115 |
+
|
| 116 |
+
result: {
|
| 117 |
+
|
| 118 |
+
operation: type of the triggering operation: 'open', 'close', ...
|
| 119 |
+
|
| 120 |
+
message: ...error message text...
|
| 121 |
+
|
| 122 |
+
errorClass: string. The ErrorClass.name property from the thrown exception.
|
| 123 |
+
|
| 124 |
+
input: the message object which triggered the error.
|
| 125 |
+
|
| 126 |
+
stack: _if available_, a stack trace array.
|
| 127 |
+
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
}
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
====================================================================
|
| 135 |
+
"config-get"
|
| 136 |
+
|
| 137 |
+
This operation fetches the serializable parts of the sqlite3 API
|
| 138 |
+
configuration.
|
| 139 |
+
|
| 140 |
+
Message format:
|
| 141 |
+
|
| 142 |
+
```
|
| 143 |
+
{
|
| 144 |
+
type: "config-get",
|
| 145 |
+
messageId: ...as above...,
|
| 146 |
+
args: currently ignored and may be elided.
|
| 147 |
+
}
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
Response:
|
| 151 |
+
|
| 152 |
+
```
|
| 153 |
+
{
|
| 154 |
+
type: "config-get",
|
| 155 |
+
messageId: ...as above...,
|
| 156 |
+
result: {
|
| 157 |
+
|
| 158 |
+
version: sqlite3.version object
|
| 159 |
+
|
| 160 |
+
bigIntEnabled: bool. True if BigInt support is enabled.
|
| 161 |
+
|
| 162 |
+
vfsList: result of sqlite3.capi.sqlite3_js_vfs_list()
|
| 163 |
+
}
|
| 164 |
+
}
|
| 165 |
+
```
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
====================================================================
|
| 169 |
+
"open" a database
|
| 170 |
+
|
| 171 |
+
Message format:
|
| 172 |
+
|
| 173 |
+
```
|
| 174 |
+
{
|
| 175 |
+
type: "open",
|
| 176 |
+
messageId: ...as above...,
|
| 177 |
+
args:{
|
| 178 |
+
|
| 179 |
+
filename [=":memory:" or "" (unspecified)]: the db filename.
|
| 180 |
+
See the sqlite3.oo1.DB constructor for peculiarities and
|
| 181 |
+
transformations,
|
| 182 |
+
|
| 183 |
+
vfs: sqlite3_vfs name. Ignored if filename is ":memory:" or "".
|
| 184 |
+
This may change how the given filename is resolved.
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
```
|
| 188 |
+
|
| 189 |
+
Response:
|
| 190 |
+
|
| 191 |
+
```
|
| 192 |
+
{
|
| 193 |
+
type: "open",
|
| 194 |
+
messageId: ...as above...,
|
| 195 |
+
result: {
|
| 196 |
+
filename: db filename, possibly differing from the input.
|
| 197 |
+
|
| 198 |
+
dbId: an opaque ID value which must be passed in the message
|
| 199 |
+
envelope to other calls in this API to tell them which db to
|
| 200 |
+
use. If it is not provided to future calls, they will default to
|
| 201 |
+
operating on the least-recently-opened db. This property is, for
|
| 202 |
+
API consistency's sake, also part of the containing message
|
| 203 |
+
envelope. Only the `open` operation includes it in the `result`
|
| 204 |
+
property.
|
| 205 |
+
|
| 206 |
+
persistent: true if the given filename resides in the
|
| 207 |
+
known-persistent storage, else false.
|
| 208 |
+
|
| 209 |
+
vfs: name of the VFS the "main" db is using.
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
```
|
| 213 |
+
|
| 214 |
+
====================================================================
|
| 215 |
+
"close" a database
|
| 216 |
+
|
| 217 |
+
Message format:
|
| 218 |
+
|
| 219 |
+
```
|
| 220 |
+
{
|
| 221 |
+
type: "close",
|
| 222 |
+
messageId: ...as above...
|
| 223 |
+
dbId: ...as above...
|
| 224 |
+
args: OPTIONAL {unlink: boolean}
|
| 225 |
+
}
|
| 226 |
+
```
|
| 227 |
+
|
| 228 |
+
If the `dbId` does not refer to an opened ID, this is a no-op. If
|
| 229 |
+
the `args` object contains a truthy `unlink` value then the database
|
| 230 |
+
will be unlinked (deleted) after closing it. The inability to close a
|
| 231 |
+
db (because it's not opened) or delete its file does not trigger an
|
| 232 |
+
error.
|
| 233 |
+
|
| 234 |
+
Response:
|
| 235 |
+
|
| 236 |
+
```
|
| 237 |
+
{
|
| 238 |
+
type: "close",
|
| 239 |
+
messageId: ...as above...,
|
| 240 |
+
result: {
|
| 241 |
+
|
| 242 |
+
filename: filename of closed db, or undefined if no db was closed
|
| 243 |
+
|
| 244 |
+
}
|
| 245 |
+
}
|
| 246 |
+
```
|
| 247 |
+
|
| 248 |
+
====================================================================
|
| 249 |
+
"exec" SQL
|
| 250 |
+
|
| 251 |
+
All SQL execution is processed through the exec operation. It offers
|
| 252 |
+
most of the features of the oo1.DB.exec() method, with a few limitations
|
| 253 |
+
imposed by the state having to cross thread boundaries.
|
| 254 |
+
|
| 255 |
+
Message format:
|
| 256 |
+
|
| 257 |
+
```
|
| 258 |
+
{
|
| 259 |
+
type: "exec",
|
| 260 |
+
messageId: ...as above...
|
| 261 |
+
dbId: ...as above...
|
| 262 |
+
args: string (SQL) or {... see below ...}
|
| 263 |
+
}
|
| 264 |
+
```
|
| 265 |
+
|
| 266 |
+
Response:
|
| 267 |
+
|
| 268 |
+
```
|
| 269 |
+
{
|
| 270 |
+
type: "exec",
|
| 271 |
+
messageId: ...as above...,
|
| 272 |
+
dbId: ...as above...
|
| 273 |
+
result: {
|
| 274 |
+
input arguments, possibly modified. See below.
|
| 275 |
+
}
|
| 276 |
+
}
|
| 277 |
+
```
|
| 278 |
+
|
| 279 |
+
The arguments are in the same form accepted by oo1.DB.exec(), with
|
| 280 |
+
the exceptions noted below.
|
| 281 |
+
|
| 282 |
+
If the `countChanges` arguments property (added in version 3.43) is
|
| 283 |
+
truthy then the `result` property contained by the returned object
|
| 284 |
+
will have a `changeCount` property which holds the number of changes
|
| 285 |
+
made by the provided SQL. Because the SQL may contain an arbitrary
|
| 286 |
+
number of statements, the `changeCount` is calculated by calling
|
| 287 |
+
`sqlite3_total_changes()` before and after the SQL is evaluated. If
|
| 288 |
+
the value of `countChanges` is 64 then the `changeCount` property
|
| 289 |
+
will be returned as a 64-bit integer in the form of a BigInt (noting
|
| 290 |
+
that that will trigger an exception if used in a BigInt-incapable
|
| 291 |
+
build). In the latter case, the number of changes is calculated by
|
| 292 |
+
calling `sqlite3_total_changes64()` before and after the SQL is
|
| 293 |
+
evaluated.
|
| 294 |
+
|
| 295 |
+
A function-type args.callback property cannot cross
|
| 296 |
+
the window/Worker boundary, so is not useful here. If
|
| 297 |
+
args.callback is a string then it is assumed to be a
|
| 298 |
+
message type key, in which case a callback function will be
|
| 299 |
+
applied which posts each row result via:
|
| 300 |
+
|
| 301 |
+
postMessage({type: thatKeyType,
|
| 302 |
+
rowNumber: 1-based-#,
|
| 303 |
+
row: theRow,
|
| 304 |
+
columnNames: anArray
|
| 305 |
+
})
|
| 306 |
+
|
| 307 |
+
And, at the end of the result set (whether or not any result rows
|
| 308 |
+
were produced), it will post an identical message with
|
| 309 |
+
(row=undefined, rowNumber=null) to alert the caller than the result
|
| 310 |
+
set is completed. Note that a row value of `null` is a legal row
|
| 311 |
+
result for certain arg.rowMode values.
|
| 312 |
+
|
| 313 |
+
(Design note: we don't use (row=undefined, rowNumber=undefined) to
|
| 314 |
+
indicate end-of-results because fetching those would be
|
| 315 |
+
indistinguishable from fetching from an empty object unless the
|
| 316 |
+
client used hasOwnProperty() (or similar) to distinguish "missing
|
| 317 |
+
property" from "property with the undefined value". Similarly,
|
| 318 |
+
`null` is a legal value for `row` in some case , whereas the db
|
| 319 |
+
layer won't emit a result value of `undefined`.)
|
| 320 |
+
|
| 321 |
+
The callback proxy must not recurse into this interface. An exec()
|
| 322 |
+
call will tie up the Worker thread, causing any recursion attempt
|
| 323 |
+
to wait until the first exec() is completed.
|
| 324 |
+
|
| 325 |
+
The response is the input options object (or a synthesized one if
|
| 326 |
+
passed only a string), noting that options.resultRows and
|
| 327 |
+
options.columnNames may be populated by the call to db.exec().
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
====================================================================
|
| 331 |
+
"export" the current db
|
| 332 |
+
|
| 333 |
+
To export the underlying database as a byte array...
|
| 334 |
+
|
| 335 |
+
Message format:
|
| 336 |
+
|
| 337 |
+
```
|
| 338 |
+
{
|
| 339 |
+
type: "export",
|
| 340 |
+
messageId: ...as above...,
|
| 341 |
+
dbId: ...as above...
|
| 342 |
+
}
|
| 343 |
+
```
|
| 344 |
+
|
| 345 |
+
Response:
|
| 346 |
+
|
| 347 |
+
```
|
| 348 |
+
{
|
| 349 |
+
type: "export",
|
| 350 |
+
messageId: ...as above...,
|
| 351 |
+
dbId: ...as above...
|
| 352 |
+
result: {
|
| 353 |
+
byteArray: Uint8Array (as per sqlite3_js_db_export()),
|
| 354 |
+
filename: the db filename,
|
| 355 |
+
mimetype: "application/x-sqlite3"
|
| 356 |
+
}
|
| 357 |
+
}
|
| 358 |
+
```
|
| 359 |
+
|
| 360 |
+
*/
|
| 361 |
+
globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
| 362 |
+
const util = sqlite3.util;
|
| 363 |
+
sqlite3.initWorker1API = function(){
|
| 364 |
+
'use strict';
|
| 365 |
+
const toss = (...args)=>{throw new Error(args.join(' '))};
|
| 366 |
+
if(!(globalThis.WorkerGlobalScope instanceof Function)){
|
| 367 |
+
toss("initWorker1API() must be run from a Worker thread.");
|
| 368 |
+
}
|
| 369 |
+
const sqlite3 = this.sqlite3 || toss("Missing this.sqlite3 object.");
|
| 370 |
+
const DB = sqlite3.oo1.DB;
|
| 371 |
+
|
| 372 |
+
/**
|
| 373 |
+
Returns the app-wide unique ID for the given db, creating one if
|
| 374 |
+
needed.
|
| 375 |
+
*/
|
| 376 |
+
const getDbId = function(db){
|
| 377 |
+
let id = wState.idMap.get(db);
|
| 378 |
+
if(id) return id;
|
| 379 |
+
id = 'db#'+(++wState.idSeq)+'@'+db.pointer;
|
| 380 |
+
/** ^^^ can't simply use db.pointer b/c closing/opening may re-use
|
| 381 |
+
the same address, which could map pending messages to a wrong
|
| 382 |
+
instance. */
|
| 383 |
+
wState.idMap.set(db, id);
|
| 384 |
+
return id;
|
| 385 |
+
};
|
| 386 |
+
|
| 387 |
+
/**
|
| 388 |
+
Internal helper for managing Worker-level state.
|
| 389 |
+
*/
|
| 390 |
+
const wState = {
|
| 391 |
+
/**
|
| 392 |
+
Each opened DB is added to this.dbList, and the first entry in
|
| 393 |
+
that list is the default db. As each db is closed, its entry is
|
| 394 |
+
removed from the list.
|
| 395 |
+
*/
|
| 396 |
+
dbList: [],
|
| 397 |
+
/** Sequence number of dbId generation. */
|
| 398 |
+
idSeq: 0,
|
| 399 |
+
/** Map of DB instances to dbId. */
|
| 400 |
+
idMap: new WeakMap,
|
| 401 |
+
/** Temp holder for "transferable" postMessage() state. */
|
| 402 |
+
xfer: [],
|
| 403 |
+
open: function(opt){
|
| 404 |
+
const db = new DB(opt);
|
| 405 |
+
this.dbs[getDbId(db)] = db;
|
| 406 |
+
if(this.dbList.indexOf(db)<0) this.dbList.push(db);
|
| 407 |
+
return db;
|
| 408 |
+
},
|
| 409 |
+
close: function(db,alsoUnlink){
|
| 410 |
+
if(db){
|
| 411 |
+
delete this.dbs[getDbId(db)];
|
| 412 |
+
const filename = db.filename;
|
| 413 |
+
const pVfs = util.sqlite3__wasm_db_vfs(db.pointer, 0);
|
| 414 |
+
db.close();
|
| 415 |
+
const ddNdx = this.dbList.indexOf(db);
|
| 416 |
+
if(ddNdx>=0) this.dbList.splice(ddNdx, 1);
|
| 417 |
+
if(alsoUnlink && filename && pVfs){
|
| 418 |
+
util.sqlite3__wasm_vfs_unlink(pVfs, filename);
|
| 419 |
+
}
|
| 420 |
+
}
|
| 421 |
+
},
|
| 422 |
+
/**
|
| 423 |
+
Posts the given worker message value. If xferList is provided,
|
| 424 |
+
it must be an array, in which case a copy of it passed as
|
| 425 |
+
postMessage()'s second argument and xferList.length is set to
|
| 426 |
+
0.
|
| 427 |
+
*/
|
| 428 |
+
post: function(msg,xferList){
|
| 429 |
+
if(xferList && xferList.length){
|
| 430 |
+
globalThis.postMessage( msg, Array.from(xferList) );
|
| 431 |
+
xferList.length = 0;
|
| 432 |
+
}else{
|
| 433 |
+
globalThis.postMessage(msg);
|
| 434 |
+
}
|
| 435 |
+
},
|
| 436 |
+
/** Map of DB IDs to DBs. */
|
| 437 |
+
dbs: Object.create(null),
|
| 438 |
+
/** Fetch the DB for the given id. Throw if require=true and the
|
| 439 |
+
id is not valid, else return the db or undefined. */
|
| 440 |
+
getDb: function(id,require=true){
|
| 441 |
+
return this.dbs[id]
|
| 442 |
+
|| (require ? toss("Unknown (or closed) DB ID:",id) : undefined);
|
| 443 |
+
}
|
| 444 |
+
};
|
| 445 |
+
|
| 446 |
+
/** Throws if the given db is falsy or not opened, else returns its
|
| 447 |
+
argument. */
|
| 448 |
+
const affirmDbOpen = function(db = wState.dbList[0]){
|
| 449 |
+
return (db && db.pointer) ? db : toss("DB is not opened.");
|
| 450 |
+
};
|
| 451 |
+
|
| 452 |
+
/** Extract dbId from the given message payload. */
|
| 453 |
+
const getMsgDb = function(msgData,affirmExists=true){
|
| 454 |
+
const db = wState.getDb(msgData.dbId,false) || wState.dbList[0];
|
| 455 |
+
return affirmExists ? affirmDbOpen(db) : db;
|
| 456 |
+
};
|
| 457 |
+
|
| 458 |
+
const getDefaultDbId = function(){
|
| 459 |
+
return wState.dbList[0] && getDbId(wState.dbList[0]);
|
| 460 |
+
};
|
| 461 |
+
|
| 462 |
+
const isSpecialDbFilename = (n)=>{
|
| 463 |
+
return ""===n || ':'===n[0];
|
| 464 |
+
};
|
| 465 |
+
|
| 466 |
+
/**
|
| 467 |
+
A level of "organizational abstraction" for the Worker1
|
| 468 |
+
API. Each method in this object must map directly to a Worker1
|
| 469 |
+
message type key. The onmessage() dispatcher attempts to
|
| 470 |
+
dispatch all inbound messages to a method of this object,
|
| 471 |
+
passing it the event.data part of the inbound event object. All
|
| 472 |
+
methods must return a plain Object containing any result
|
| 473 |
+
state, which the dispatcher may amend. All methods must throw
|
| 474 |
+
on error.
|
| 475 |
+
*/
|
| 476 |
+
const wMsgHandler = {
|
| 477 |
+
open: function(ev){
|
| 478 |
+
const oargs = Object.create(null), args = (ev.args || Object.create(null));
|
| 479 |
+
if(args.simulateError){ // undocumented internal testing option
|
| 480 |
+
toss("Throwing because of simulateError flag.");
|
| 481 |
+
}
|
| 482 |
+
const rc = Object.create(null);
|
| 483 |
+
oargs.vfs = args.vfs;
|
| 484 |
+
oargs.filename = args.filename || "";
|
| 485 |
+
const db = wState.open(oargs);
|
| 486 |
+
rc.filename = db.filename;
|
| 487 |
+
rc.persistent = !!sqlite3.capi.sqlite3_js_db_uses_vfs(db.pointer, "opfs");
|
| 488 |
+
rc.dbId = getDbId(db);
|
| 489 |
+
rc.vfs = db.dbVfsName();
|
| 490 |
+
return rc;
|
| 491 |
+
},
|
| 492 |
+
|
| 493 |
+
close: function(ev){
|
| 494 |
+
const db = getMsgDb(ev,false);
|
| 495 |
+
const response = {
|
| 496 |
+
filename: db && db.filename
|
| 497 |
+
};
|
| 498 |
+
if(db){
|
| 499 |
+
const doUnlink = ((ev.args && 'object'===typeof ev.args)
|
| 500 |
+
? !!ev.args.unlink : false);
|
| 501 |
+
wState.close(db, doUnlink);
|
| 502 |
+
}
|
| 503 |
+
return response;
|
| 504 |
+
},
|
| 505 |
+
|
| 506 |
+
exec: function(ev){
|
| 507 |
+
const rc = (
|
| 508 |
+
'string'===typeof ev.args
|
| 509 |
+
) ? {sql: ev.args} : (ev.args || Object.create(null));
|
| 510 |
+
if('stmt'===rc.rowMode){
|
| 511 |
+
toss("Invalid rowMode for 'exec': stmt mode",
|
| 512 |
+
"does not work in the Worker API.");
|
| 513 |
+
}else if(!rc.sql){
|
| 514 |
+
toss("'exec' requires input SQL.");
|
| 515 |
+
}
|
| 516 |
+
const db = getMsgDb(ev);
|
| 517 |
+
if(rc.callback || Array.isArray(rc.resultRows)){
|
| 518 |
+
// Part of a copy-avoidance optimization for blobs
|
| 519 |
+
db._blobXfer = wState.xfer;
|
| 520 |
+
}
|
| 521 |
+
const theCallback = rc.callback;
|
| 522 |
+
let rowNumber = 0;
|
| 523 |
+
const hadColNames = !!rc.columnNames;
|
| 524 |
+
if('string' === typeof theCallback){
|
| 525 |
+
if(!hadColNames) rc.columnNames = [];
|
| 526 |
+
/* Treat this as a worker message type and post each
|
| 527 |
+
row as a message of that type. */
|
| 528 |
+
rc.callback = function(row,stmt){
|
| 529 |
+
wState.post({
|
| 530 |
+
type: theCallback,
|
| 531 |
+
columnNames: rc.columnNames,
|
| 532 |
+
rowNumber: ++rowNumber,
|
| 533 |
+
row: row
|
| 534 |
+
}, wState.xfer);
|
| 535 |
+
}
|
| 536 |
+
}
|
| 537 |
+
try {
|
| 538 |
+
const changeCount = !!rc.countChanges
|
| 539 |
+
? db.changes(true,(64===rc.countChanges))
|
| 540 |
+
: undefined;
|
| 541 |
+
db.exec(rc);
|
| 542 |
+
if(undefined !== changeCount){
|
| 543 |
+
rc.changeCount = db.changes(true,64===rc.countChanges) - changeCount;
|
| 544 |
+
}
|
| 545 |
+
if(rc.callback instanceof Function){
|
| 546 |
+
rc.callback = theCallback;
|
| 547 |
+
/* Post a sentinel message to tell the client that the end
|
| 548 |
+
of the result set has been reached (possibly with zero
|
| 549 |
+
rows). */
|
| 550 |
+
wState.post({
|
| 551 |
+
type: theCallback,
|
| 552 |
+
columnNames: rc.columnNames,
|
| 553 |
+
rowNumber: null /*null to distinguish from "property not set"*/,
|
| 554 |
+
row: undefined /*undefined because null is a legal row value
|
| 555 |
+
for some rowType values, but undefined is not*/
|
| 556 |
+
});
|
| 557 |
+
}
|
| 558 |
+
}finally{
|
| 559 |
+
delete db._blobXfer;
|
| 560 |
+
if(rc.callback) rc.callback = theCallback;
|
| 561 |
+
}
|
| 562 |
+
return rc;
|
| 563 |
+
}/*exec()*/,
|
| 564 |
+
|
| 565 |
+
'config-get': function(){
|
| 566 |
+
const rc = Object.create(null), src = sqlite3.config;
|
| 567 |
+
[
|
| 568 |
+
'bigIntEnabled'
|
| 569 |
+
].forEach(function(k){
|
| 570 |
+
if(Object.getOwnPropertyDescriptor(src, k)) rc[k] = src[k];
|
| 571 |
+
});
|
| 572 |
+
rc.version = sqlite3.version;
|
| 573 |
+
rc.vfsList = sqlite3.capi.sqlite3_js_vfs_list();
|
| 574 |
+
return rc;
|
| 575 |
+
},
|
| 576 |
+
|
| 577 |
+
/**
|
| 578 |
+
Exports the database to a byte array, as per
|
| 579 |
+
sqlite3_serialize(). Response is an object:
|
| 580 |
+
|
| 581 |
+
{
|
| 582 |
+
byteArray: Uint8Array (db file contents),
|
| 583 |
+
filename: the current db filename,
|
| 584 |
+
mimetype: 'application/x-sqlite3'
|
| 585 |
+
}
|
| 586 |
+
*/
|
| 587 |
+
export: function(ev){
|
| 588 |
+
const db = getMsgDb(ev);
|
| 589 |
+
const response = {
|
| 590 |
+
byteArray: sqlite3.capi.sqlite3_js_db_export(db.pointer),
|
| 591 |
+
filename: db.filename,
|
| 592 |
+
mimetype: 'application/x-sqlite3'
|
| 593 |
+
};
|
| 594 |
+
wState.xfer.push(response.byteArray.buffer);
|
| 595 |
+
return response;
|
| 596 |
+
}/*export()*/,
|
| 597 |
+
|
| 598 |
+
toss: function(ev){
|
| 599 |
+
toss("Testing worker exception");
|
| 600 |
+
}
|
| 601 |
+
}/*wMsgHandler*/;
|
| 602 |
+
|
| 603 |
+
globalThis.onmessage = async function(ev){
|
| 604 |
+
ev = ev.data;
|
| 605 |
+
let result, dbId = ev.dbId, evType = ev.type;
|
| 606 |
+
const arrivalTime = performance.now();
|
| 607 |
+
try {
|
| 608 |
+
if(wMsgHandler.hasOwnProperty(evType) &&
|
| 609 |
+
wMsgHandler[evType] instanceof Function){
|
| 610 |
+
result = await wMsgHandler[evType](ev);
|
| 611 |
+
}else{
|
| 612 |
+
toss("Unknown db worker message type:",ev.type);
|
| 613 |
+
}
|
| 614 |
+
}catch(err){
|
| 615 |
+
evType = 'error';
|
| 616 |
+
result = {
|
| 617 |
+
operation: ev.type,
|
| 618 |
+
message: err.message,
|
| 619 |
+
errorClass: err.name,
|
| 620 |
+
input: ev
|
| 621 |
+
};
|
| 622 |
+
if(err.stack){
|
| 623 |
+
result.stack = ('string'===typeof err.stack)
|
| 624 |
+
? err.stack.split(/\n\s*/) : err.stack;
|
| 625 |
+
}
|
| 626 |
+
if(0) sqlite3.config.warn("Worker is propagating an exception to main thread.",
|
| 627 |
+
"Reporting it _here_ for the stack trace:",err,result);
|
| 628 |
+
}
|
| 629 |
+
if(!dbId){
|
| 630 |
+
dbId = result.dbId/*from 'open' cmd*/
|
| 631 |
+
|| getDefaultDbId();
|
| 632 |
+
}
|
| 633 |
+
// Timing info is primarily for use in testing this API. It's not part of
|
| 634 |
+
// the public API. arrivalTime = when the worker got the message.
|
| 635 |
+
wState.post({
|
| 636 |
+
type: evType,
|
| 637 |
+
dbId: dbId,
|
| 638 |
+
messageId: ev.messageId,
|
| 639 |
+
workerReceivedTime: arrivalTime,
|
| 640 |
+
workerRespondTime: performance.now(),
|
| 641 |
+
departureTime: ev.departureTime,
|
| 642 |
+
// TODO: move the timing bits into...
|
| 643 |
+
//timing:{
|
| 644 |
+
// departure: ev.departureTime,
|
| 645 |
+
// workerReceived: arrivalTime,
|
| 646 |
+
// workerResponse: performance.now();
|
| 647 |
+
//},
|
| 648 |
+
result: result
|
| 649 |
+
}, wState.xfer);
|
| 650 |
+
};
|
| 651 |
+
globalThis.postMessage({type:'sqlite3-api',result:'worker1-ready'});
|
| 652 |
+
}.bind({sqlite3});
|
| 653 |
+
});
|
| 654 |
+
//#else
|
| 655 |
+
/* Built with the omit-oo1 flag. */
|
| 656 |
+
//#endif ifnot omit-oo1
|
local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/api/sqlite3-wasm.c
ADDED
|
@@ -0,0 +1,1950 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
** This file requires access to sqlite3.c static state in order to
|
| 3 |
+
** implement certain WASM-specific features, and thus directly
|
| 4 |
+
** includes that file. Unlike the rest of sqlite3.c, this file
|
| 5 |
+
** requires compiling with -std=c99 (or equivalent, or a later C
|
| 6 |
+
** version) because it makes use of features not available in C89.
|
| 7 |
+
**
|
| 8 |
+
** At its simplest, to build sqlite3.wasm either place this file
|
| 9 |
+
** in the same directory as sqlite3.c/h before compilation or use the
|
| 10 |
+
** -I/path flag to tell the compiler where to find both of those
|
| 11 |
+
** files, then compile this file. For example:
|
| 12 |
+
**
|
| 13 |
+
** emcc -o sqlite3.wasm ... -I/path/to/sqlite3-c-and-h sqlite3-wasm.c
|
| 14 |
+
*/
|
| 15 |
+
#define SQLITE_WASM
|
| 16 |
+
#ifdef SQLITE_WASM_ENABLE_C_TESTS
|
| 17 |
+
# undef SQLITE_WASM_ENABLE_C_TESTS
|
| 18 |
+
# define SQLITE_WASM_ENABLE_C_TESTS 1
|
| 19 |
+
/*
|
| 20 |
+
** Code blocked off by SQLITE_WASM_ENABLE_C_TESTS is intended solely
|
| 21 |
+
** for use in unit/regression testing. They may be safely omitted from
|
| 22 |
+
** client-side builds. The main unit test script, tester1.js, will
|
| 23 |
+
** skip related tests if it doesn't find the corresponding functions
|
| 24 |
+
** in the WASM exports.
|
| 25 |
+
*/
|
| 26 |
+
#else
|
| 27 |
+
# define SQLITE_WASM_ENABLE_C_TESTS 0
|
| 28 |
+
#endif
|
| 29 |
+
|
| 30 |
+
/*
|
| 31 |
+
** Threading and file locking: JS is single-threaded. Each Worker
|
| 32 |
+
** thread is a separate instance of the JS engine so can never access
|
| 33 |
+
** the same db handle as another thread, thus multi-threading support
|
| 34 |
+
** is unnecessary in the library. Because the filesystems are virtual
|
| 35 |
+
** and local to a given wasm runtime instance, two Workers can never
|
| 36 |
+
** access the same db file at once, with the exception of OPFS.
|
| 37 |
+
**
|
| 38 |
+
** Summary: except for the case of OPFS, which supports locking using
|
| 39 |
+
** its own API, threading and file locking support are unnecessary in
|
| 40 |
+
** the wasm build.
|
| 41 |
+
*/
|
| 42 |
+
|
| 43 |
+
/*
|
| 44 |
+
** Undefine any SQLITE_... config flags which we specifically do not
|
| 45 |
+
** want defined. Please keep these alphabetized.
|
| 46 |
+
*/
|
| 47 |
+
#undef SQLITE_OMIT_DESERIALIZE
|
| 48 |
+
#undef SQLITE_OMIT_MEMORYDB
|
| 49 |
+
|
| 50 |
+
/*
|
| 51 |
+
** Define any SQLITE_... config defaults we want if they aren't
|
| 52 |
+
** overridden by the builder. Please keep these alphabetized.
|
| 53 |
+
*/
|
| 54 |
+
|
| 55 |
+
/**********************************************************************/
|
| 56 |
+
/* SQLITE_D... */
|
| 57 |
+
#ifndef SQLITE_DEFAULT_CACHE_SIZE
|
| 58 |
+
/*
|
| 59 |
+
** The OPFS impls benefit tremendously from an increased cache size
|
| 60 |
+
** when working on large workloads, e.g. speedtest1 --size 50 or
|
| 61 |
+
** higher. On smaller workloads, e.g. speedtest1 --size 25, they
|
| 62 |
+
** clearly benefit from having 4mb of cache, but not as much as a
|
| 63 |
+
** larger cache benefits the larger workloads. Speed differences
|
| 64 |
+
** between 2x and nearly 3x have been measured with ample page cache.
|
| 65 |
+
*/
|
| 66 |
+
# define SQLITE_DEFAULT_CACHE_SIZE -16384
|
| 67 |
+
#endif
|
| 68 |
+
#if !defined(SQLITE_DEFAULT_PAGE_SIZE)
|
| 69 |
+
/*
|
| 70 |
+
** OPFS performance is improved by approx. 12% with a page size of 8kb
|
| 71 |
+
** instead of 4kb. Performance with 16kb is equivalent to 8kb.
|
| 72 |
+
**
|
| 73 |
+
** Performance difference of kvvfs with a page size of 8kb compared to
|
| 74 |
+
** 4kb, as measured by speedtest1 --size 4, is indeterminate:
|
| 75 |
+
** measurements are all over the place either way and not
|
| 76 |
+
** significantly different.
|
| 77 |
+
*/
|
| 78 |
+
# define SQLITE_DEFAULT_PAGE_SIZE 8192
|
| 79 |
+
#endif
|
| 80 |
+
#ifndef SQLITE_DEFAULT_UNIX_VFS
|
| 81 |
+
# define SQLITE_DEFAULT_UNIX_VFS "unix-none"
|
| 82 |
+
#endif
|
| 83 |
+
#undef SQLITE_DQS
|
| 84 |
+
#define SQLITE_DQS 0
|
| 85 |
+
|
| 86 |
+
/**********************************************************************/
|
| 87 |
+
/* SQLITE_ENABLE_... */
|
| 88 |
+
/*
|
| 89 |
+
** Unconditionally enable API_ARMOR in the WASM build. It ensures that
|
| 90 |
+
** public APIs behave predictable in the face of passing illegal NULLs
|
| 91 |
+
** or ranges which might otherwise invoke undefined behavior.
|
| 92 |
+
*/
|
| 93 |
+
#undef SQLITE_ENABLE_API_ARMOR
|
| 94 |
+
#define SQLITE_ENABLE_API_ARMOR 1
|
| 95 |
+
|
| 96 |
+
/**********************************************************************/
|
| 97 |
+
/* SQLITE_O... */
|
| 98 |
+
#undef SQLITE_OMIT_DEPRECATED
|
| 99 |
+
#define SQLITE_OMIT_DEPRECATED 1
|
| 100 |
+
#undef SQLITE_OMIT_LOAD_EXTENSION
|
| 101 |
+
#define SQLITE_OMIT_LOAD_EXTENSION 1
|
| 102 |
+
#undef SQLITE_OMIT_SHARED_CACHE
|
| 103 |
+
#define SQLITE_OMIT_SHARED_CACHE 1
|
| 104 |
+
#undef SQLITE_OMIT_UTF16
|
| 105 |
+
#define SQLITE_OMIT_UTF16 1
|
| 106 |
+
#undef SQLITE_OS_KV_OPTIONAL
|
| 107 |
+
#define SQLITE_OS_KV_OPTIONAL 1
|
| 108 |
+
|
| 109 |
+
/**********************************************************************/
|
| 110 |
+
/* SQLITE_S... */
|
| 111 |
+
#ifndef SQLITE_STRICT_SUBTYPE
|
| 112 |
+
# define SQLITE_STRICT_SUBTYPE 1
|
| 113 |
+
#endif
|
| 114 |
+
|
| 115 |
+
/**********************************************************************/
|
| 116 |
+
/* SQLITE_T... */
|
| 117 |
+
#ifndef SQLITE_TEMP_STORE
|
| 118 |
+
# define SQLITE_TEMP_STORE 2
|
| 119 |
+
#endif
|
| 120 |
+
#ifndef SQLITE_THREADSAFE
|
| 121 |
+
# define SQLITE_THREADSAFE 0
|
| 122 |
+
#endif
|
| 123 |
+
|
| 124 |
+
/**********************************************************************/
|
| 125 |
+
/* SQLITE_USE_... */
|
| 126 |
+
#ifndef SQLITE_USE_URI
|
| 127 |
+
# define SQLITE_USE_URI 1
|
| 128 |
+
#endif
|
| 129 |
+
|
| 130 |
+
#ifdef SQLITE_WASM_EXTRA_INIT
|
| 131 |
+
# define SQLITE_EXTRA_INIT sqlite3_wasm_extra_init
|
| 132 |
+
#endif
|
| 133 |
+
|
| 134 |
+
/*
|
| 135 |
+
** If SQLITE_WASM_BARE_BONES is defined, undefine most of the ENABLE
|
| 136 |
+
** macros.
|
| 137 |
+
*/
|
| 138 |
+
#ifdef SQLITE_WASM_BARE_BONES
|
| 139 |
+
# undef SQLITE_ENABLE_DBPAGE_VTAB
|
| 140 |
+
# undef SQLITE_ENABLE_DBSTAT_VTAB
|
| 141 |
+
# undef SQLITE_ENABLE_EXPLAIN_COMMENTS
|
| 142 |
+
# undef SQLITE_ENABLE_FTS5
|
| 143 |
+
# undef SQLITE_ENABLE_OFFSET_SQL_FUNC
|
| 144 |
+
# undef SQLITE_ENABLE_PREUPDATE_HOOK
|
| 145 |
+
# undef SQLITE_ENABLE_RTREE
|
| 146 |
+
# undef SQLITE_ENABLE_SESSION
|
| 147 |
+
# undef SQLITE_ENABLE_STMTVTAB
|
| 148 |
+
# undef SQLITE_OMIT_AUTHORIZATION
|
| 149 |
+
# define SQLITE_OMIT_AUTHORIZATION
|
| 150 |
+
# undef SQLITE_OMIT_GET_TABLE
|
| 151 |
+
# define SQLITE_OMIT_GET_TABLE
|
| 152 |
+
# undef SQLITE_OMIT_INCRBLOB
|
| 153 |
+
# define SQLITE_OMIT_INCRBLOB
|
| 154 |
+
# undef SQLITE_OMIT_INTROSPECTION_PRAGMAS
|
| 155 |
+
# define SQLITE_OMIT_INTROSPECTION_PRAGMAS
|
| 156 |
+
# undef SQLITE_OMIT_JSON
|
| 157 |
+
# define SQLITE_OMIT_JSON
|
| 158 |
+
# undef SQLITE_OMIT_PROGRESS_CALLBACK
|
| 159 |
+
# define SQLITE_OMIT_PROGRESS_CALLBACK
|
| 160 |
+
# undef SQLITE_OMIT_WAL
|
| 161 |
+
# define SQLITE_OMIT_WAL
|
| 162 |
+
/*
|
| 163 |
+
The following OMITs do not work with the standard amalgamation, so
|
| 164 |
+
require a custom build:
|
| 165 |
+
|
| 166 |
+
fossil clean -x
|
| 167 |
+
./configure
|
| 168 |
+
OPTS='...' make -e sqlite3
|
| 169 |
+
|
| 170 |
+
where ... has a -D... for each of the following OMIT flags:
|
| 171 |
+
|
| 172 |
+
# undef SQLITE_OMIT_EXPLAIN
|
| 173 |
+
# define SQLITE_OMIT_EXPLAIN
|
| 174 |
+
|
| 175 |
+
# undef SQLITE_OMIT_TRIGGER
|
| 176 |
+
# define SQLITE_OMIT_TRIGGER
|
| 177 |
+
|
| 178 |
+
# undef SQLITE_OMIT_VIRTUALTABLE
|
| 179 |
+
# define SQLITE_OMIT_VIRTUALTABLE
|
| 180 |
+
|
| 181 |
+
# undef SQLITE_OMIT_WINDOWFUNC
|
| 182 |
+
# define SQLITE_OMIT_WINDOWFUNC
|
| 183 |
+
|
| 184 |
+
As of this writing (2024-07-25), such a build fails in various ways
|
| 185 |
+
for as-yet-unknown reasons.
|
| 186 |
+
*/
|
| 187 |
+
#endif
|
| 188 |
+
|
| 189 |
+
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_WASM_BARE_BONES)
|
| 190 |
+
# define SQLITE_WASM_HAS_VTAB 1
|
| 191 |
+
#else
|
| 192 |
+
# define SQLITE_WASM_HAS_VTAB 0
|
| 193 |
+
#endif
|
| 194 |
+
|
| 195 |
+
#include <assert.h>
|
| 196 |
+
|
| 197 |
+
/*
|
| 198 |
+
** SQLITE_WASM_EXPORT is functionally identical to EMSCRIPTEN_KEEPALIVE
|
| 199 |
+
** but is not Emscripten-specific. It explicitly marks functions for
|
| 200 |
+
** export into the target wasm file without requiring explicit listing
|
| 201 |
+
** of those functions in Emscripten's -sEXPORTED_FUNCTIONS=... list
|
| 202 |
+
** (or equivalent in other build platforms). Any function with neither
|
| 203 |
+
** this attribute nor which is listed as an explicit export will not
|
| 204 |
+
** be exported from the wasm file (but may still be used internally
|
| 205 |
+
** within the wasm file).
|
| 206 |
+
**
|
| 207 |
+
** The functions in this file (sqlite3-wasm.c) which require exporting
|
| 208 |
+
** are marked with this flag. They may also be added to any explicit
|
| 209 |
+
** build-time export list but need not be. All of these APIs are
|
| 210 |
+
** intended for use only within the project's own JS/WASM code, and
|
| 211 |
+
** not by client code, so an argument can be made for reducing their
|
| 212 |
+
** visibility by not including them in any build-time export lists.
|
| 213 |
+
**
|
| 214 |
+
** 2022-09-11: it's not yet _proven_ that this approach works in
|
| 215 |
+
** non-Emscripten builds. If not, such builds will need to export
|
| 216 |
+
** those using the --export=... wasm-ld flag (or equivalent). As of
|
| 217 |
+
** this writing we are tied to Emscripten for various reasons
|
| 218 |
+
** and cannot test the library with other build environments.
|
| 219 |
+
*/
|
| 220 |
+
#define SQLITE_WASM_EXPORT __attribute__((used,visibility("default")))
|
| 221 |
+
// See also:
|
| 222 |
+
//__attribute__((export_name("theExportedName"), used, visibility("default")))
|
| 223 |
+
|
| 224 |
+
/*
|
| 225 |
+
** Which sqlite3.c we're using needs to be configurable to enable
|
| 226 |
+
** building against a custom copy, e.g. the SEE variant. Note that we
|
| 227 |
+
** #include the .c file, rather than the header, so that the WASM
|
| 228 |
+
** extensions have access to private API internals.
|
| 229 |
+
**
|
| 230 |
+
** The caveat here is that custom variants need to account for
|
| 231 |
+
** exporting any necessary symbols (e.g. sqlite3_activate_see()). We
|
| 232 |
+
** cannot export them from here using SQLITE_WASM_EXPORT because that
|
| 233 |
+
** attribute (apparently) has to be part of the function definition.
|
| 234 |
+
*/
|
| 235 |
+
#ifndef SQLITE_C
|
| 236 |
+
# define SQLITE_C sqlite3.c /* yes, .c instead of .h. */
|
| 237 |
+
#endif
|
| 238 |
+
#define INC__STRINGIFY_(f) #f
|
| 239 |
+
#define INC__STRINGIFY(f) INC__STRINGIFY_(f)
|
| 240 |
+
#include INC__STRINGIFY(SQLITE_C)
|
| 241 |
+
#undef INC__STRINGIFY_
|
| 242 |
+
#undef INC__STRINGIFY
|
| 243 |
+
#undef SQLITE_C
|
| 244 |
+
|
| 245 |
+
#if 0
|
| 246 |
+
/*
|
| 247 |
+
** An EXPERIMENT in implementing a stack-based allocator analog to
|
| 248 |
+
** Emscripten's stackSave(), stackAlloc(), stackRestore().
|
| 249 |
+
** Unfortunately, this cannot work together with Emscripten because
|
| 250 |
+
** Emscripten defines its own native one and we'd stomp on each
|
| 251 |
+
** other's memory. Other than that complication, basic tests show it
|
| 252 |
+
** to work just fine.
|
| 253 |
+
**
|
| 254 |
+
** Another option is to malloc() a chunk of our own and call that our
|
| 255 |
+
** "stack".
|
| 256 |
+
*/
|
| 257 |
+
SQLITE_WASM_EXPORT void * sqlite3__wasm_stack_end(void){
|
| 258 |
+
extern void __heap_base
|
| 259 |
+
/* see https://stackoverflow.com/questions/10038964 */;
|
| 260 |
+
return &__heap_base;
|
| 261 |
+
}
|
| 262 |
+
SQLITE_WASM_EXPORT void * sqlite3__wasm_stack_begin(void){
|
| 263 |
+
extern void __data_end;
|
| 264 |
+
return &__data_end;
|
| 265 |
+
}
|
| 266 |
+
static void * pWasmStackPtr = 0;
|
| 267 |
+
SQLITE_WASM_EXPORT void * sqlite3__wasm_stack_ptr(void){
|
| 268 |
+
if(!pWasmStackPtr) pWasmStackPtr = sqlite3__wasm_stack_end();
|
| 269 |
+
return pWasmStackPtr;
|
| 270 |
+
}
|
| 271 |
+
SQLITE_WASM_EXPORT void sqlite3__wasm_stack_restore(void * p){
|
| 272 |
+
pWasmStackPtr = p;
|
| 273 |
+
}
|
| 274 |
+
SQLITE_WASM_EXPORT void * sqlite3__wasm_stack_alloc(int n){
|
| 275 |
+
if(n<=0) return 0;
|
| 276 |
+
n = (n + 7) & ~7 /* align to 8-byte boundary */;
|
| 277 |
+
unsigned char * const p = (unsigned char *)sqlite3__wasm_stack_ptr();
|
| 278 |
+
unsigned const char * const b = (unsigned const char *)sqlite3__wasm_stack_begin();
|
| 279 |
+
if(b + n >= p || b + n < b/*overflow*/) return 0;
|
| 280 |
+
return pWasmStackPtr = p - n;
|
| 281 |
+
}
|
| 282 |
+
#endif /* stack allocator experiment */
|
| 283 |
+
|
| 284 |
+
/*
|
| 285 |
+
** State for the "pseudo-stack" allocator implemented in
|
| 286 |
+
** sqlite3__wasm_pstack_xyz(). In order to avoid colliding with
|
| 287 |
+
** Emscripten-controled stack space, it carves out a bit of stack
|
| 288 |
+
** memory to use for that purpose. This memory ends up in the
|
| 289 |
+
** WASM-managed memory, such that routines which manipulate the wasm
|
| 290 |
+
** heap can also be used to manipulate this memory.
|
| 291 |
+
**
|
| 292 |
+
** This particular allocator is intended for small allocations such as
|
| 293 |
+
** storage for output pointers. We cannot reasonably size it large
|
| 294 |
+
** enough for general-purpose string conversions because some of our
|
| 295 |
+
** tests use input files (strings) of 16MB+.
|
| 296 |
+
*/
|
| 297 |
+
static unsigned char PStack_mem[512 * 8] = {0};
|
| 298 |
+
static struct {
|
| 299 |
+
unsigned const char * const pBegin;/* Start (inclusive) of memory */
|
| 300 |
+
unsigned const char * const pEnd; /* One-after-the-end of memory */
|
| 301 |
+
unsigned char * pPos; /* Current stack pointer */
|
| 302 |
+
} PStack = {
|
| 303 |
+
&PStack_mem[0],
|
| 304 |
+
&PStack_mem[0] + sizeof(PStack_mem),
|
| 305 |
+
&PStack_mem[0] + sizeof(PStack_mem)
|
| 306 |
+
};
|
| 307 |
+
/*
|
| 308 |
+
** Returns the current pstack position.
|
| 309 |
+
*/
|
| 310 |
+
SQLITE_WASM_EXPORT void * sqlite3__wasm_pstack_ptr(void){
|
| 311 |
+
return PStack.pPos;
|
| 312 |
+
}
|
| 313 |
+
/*
|
| 314 |
+
** Sets the pstack position poitner to p. Results are undefined if the
|
| 315 |
+
** given value did not come from sqlite3__wasm_pstack_ptr().
|
| 316 |
+
*/
|
| 317 |
+
SQLITE_WASM_EXPORT void sqlite3__wasm_pstack_restore(unsigned char * p){
|
| 318 |
+
assert(p>=PStack.pBegin && p<=PStack.pEnd && p>=PStack.pPos);
|
| 319 |
+
assert(0==((unsigned long long)p & 0x7));
|
| 320 |
+
if(p>=PStack.pBegin && p<=PStack.pEnd /*&& p>=PStack.pPos*/){
|
| 321 |
+
PStack.pPos = p;
|
| 322 |
+
}
|
| 323 |
+
}
|
| 324 |
+
/*
|
| 325 |
+
** Allocate and zero out n bytes from the pstack. Returns a pointer to
|
| 326 |
+
** the memory on success, 0 on error (including a negative n value). n
|
| 327 |
+
** is always adjusted to be a multiple of 8 and returned memory is
|
| 328 |
+
** always zeroed out before returning (because this keeps the client
|
| 329 |
+
** JS code from having to do so, and most uses of the pstack will
|
| 330 |
+
** call for doing so).
|
| 331 |
+
*/
|
| 332 |
+
SQLITE_WASM_EXPORT void * sqlite3__wasm_pstack_alloc(int n){
|
| 333 |
+
if( n<=0 ) return 0;
|
| 334 |
+
//if( n & 0x7 ) n += 8 - (n & 0x7) /* align to 8-byte boundary */;
|
| 335 |
+
n = (n + 7) & ~7 /* align to 8-byte boundary */;
|
| 336 |
+
if( PStack.pBegin + n > PStack.pPos /*not enough space left*/
|
| 337 |
+
|| PStack.pBegin + n <= PStack.pBegin /*overflow*/ ) return 0;
|
| 338 |
+
memset((PStack.pPos = PStack.pPos - n), 0, (unsigned int)n);
|
| 339 |
+
return PStack.pPos;
|
| 340 |
+
}
|
| 341 |
+
/*
|
| 342 |
+
** Return the number of bytes left which can be
|
| 343 |
+
** sqlite3__wasm_pstack_alloc()'d.
|
| 344 |
+
*/
|
| 345 |
+
SQLITE_WASM_EXPORT int sqlite3__wasm_pstack_remaining(void){
|
| 346 |
+
assert(PStack.pPos >= PStack.pBegin);
|
| 347 |
+
assert(PStack.pPos <= PStack.pEnd);
|
| 348 |
+
return (int)(PStack.pPos - PStack.pBegin);
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
/*
|
| 352 |
+
** Return the total number of bytes available in the pstack, including
|
| 353 |
+
** any space which is currently allocated. This value is a
|
| 354 |
+
** compile-time constant.
|
| 355 |
+
*/
|
| 356 |
+
SQLITE_WASM_EXPORT int sqlite3__wasm_pstack_quota(void){
|
| 357 |
+
return (int)(PStack.pEnd - PStack.pBegin);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
/*
|
| 361 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 362 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 363 |
+
**
|
| 364 |
+
** For purposes of certain hand-crafted C/Wasm function bindings, we
|
| 365 |
+
** need a way of reporting errors which is consistent with the rest of
|
| 366 |
+
** the C API, as opposed to throwing JS exceptions. To that end, this
|
| 367 |
+
** internal-use-only function is a thin proxy around
|
| 368 |
+
** sqlite3ErrorWithMessage(). The intent is that it only be used from
|
| 369 |
+
** Wasm bindings such as sqlite3_prepare_v2/v3(), and definitely not
|
| 370 |
+
** from client code.
|
| 371 |
+
**
|
| 372 |
+
** Returns err_code.
|
| 373 |
+
*/
|
| 374 |
+
SQLITE_WASM_EXPORT
|
| 375 |
+
int sqlite3__wasm_db_error(sqlite3*db, int err_code, const char *zMsg){
|
| 376 |
+
if( db!=0 ){
|
| 377 |
+
if( 0!=zMsg ){
|
| 378 |
+
const int nMsg = sqlite3Strlen30(zMsg);
|
| 379 |
+
sqlite3_mutex_enter(sqlite3_db_mutex(db));
|
| 380 |
+
sqlite3ErrorWithMsg(db, err_code, "%.*s", nMsg, zMsg);
|
| 381 |
+
sqlite3_mutex_leave(sqlite3_db_mutex(db));
|
| 382 |
+
}else{
|
| 383 |
+
sqlite3ErrorWithMsg(db, err_code, NULL);
|
| 384 |
+
}
|
| 385 |
+
}
|
| 386 |
+
return err_code;
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
#if SQLITE_WASM_ENABLE_C_TESTS
|
| 390 |
+
struct WasmTestStruct {
|
| 391 |
+
int v4;
|
| 392 |
+
void * ppV;
|
| 393 |
+
const char * cstr;
|
| 394 |
+
int64_t v8;
|
| 395 |
+
void (*xFunc)(void*);
|
| 396 |
+
};
|
| 397 |
+
typedef struct WasmTestStruct WasmTestStruct;
|
| 398 |
+
SQLITE_WASM_EXPORT
|
| 399 |
+
void sqlite3__wasm_test_struct(WasmTestStruct * s){
|
| 400 |
+
if(s){
|
| 401 |
+
s->v4 *= 2;
|
| 402 |
+
s->v8 = s->v4 * 2;
|
| 403 |
+
s->ppV = s;
|
| 404 |
+
s->cstr = __FILE__;
|
| 405 |
+
if(s->xFunc) s->xFunc(s);
|
| 406 |
+
}
|
| 407 |
+
return;
|
| 408 |
+
}
|
| 409 |
+
#endif /* SQLITE_WASM_ENABLE_C_TESTS */
|
| 410 |
+
|
| 411 |
+
/*
|
| 412 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 413 |
+
** for use by the sqlite project's own JS/WASM bindings. Unlike the
|
| 414 |
+
** rest of the sqlite3 API, this part requires C99 for snprintf() and
|
| 415 |
+
** variadic macros.
|
| 416 |
+
**
|
| 417 |
+
** Returns a string containing a JSON-format "enum" of C-level
|
| 418 |
+
** constants and struct-related metadata intended to be imported into
|
| 419 |
+
** the JS environment. The JSON is initialized the first time this
|
| 420 |
+
** function is called and that result is reused for all future calls.
|
| 421 |
+
**
|
| 422 |
+
** If this function returns NULL then it means that the internal
|
| 423 |
+
** buffer is not large enough for the generated JSON and needs to be
|
| 424 |
+
** increased. In debug builds that will trigger an assert().
|
| 425 |
+
*/
|
| 426 |
+
SQLITE_WASM_EXPORT
|
| 427 |
+
const char * sqlite3__wasm_enum_json(void){
|
| 428 |
+
static char aBuffer[1024 * 20] = {0} /* where the JSON goes */;
|
| 429 |
+
int n = 0, nChildren = 0, nStruct = 0
|
| 430 |
+
/* output counters for figuring out where commas go */;
|
| 431 |
+
char * zPos = &aBuffer[1] /* skip first byte for now to help protect
|
| 432 |
+
** against a small race condition */;
|
| 433 |
+
char const * const zEnd = &aBuffer[0] + sizeof(aBuffer) /* one-past-the-end */;
|
| 434 |
+
if(aBuffer[0]) return aBuffer;
|
| 435 |
+
/* Leave aBuffer[0] at 0 until the end to help guard against a tiny
|
| 436 |
+
** race condition. If this is called twice concurrently, they might
|
| 437 |
+
** end up both writing to aBuffer, but they'll both write the same
|
| 438 |
+
** thing, so that's okay. If we set byte 0 up front then the 2nd
|
| 439 |
+
** instance might return and use the string before the 1st instance
|
| 440 |
+
** is done filling it. */
|
| 441 |
+
|
| 442 |
+
/* Core output macros... */
|
| 443 |
+
#define lenCheck assert(zPos < zEnd - 128 \
|
| 444 |
+
&& "sqlite3__wasm_enum_json() buffer is too small."); \
|
| 445 |
+
if( zPos >= zEnd - 128 ) return 0
|
| 446 |
+
#define outf(format,...) \
|
| 447 |
+
zPos += snprintf(zPos, ((size_t)(zEnd - zPos)), format, __VA_ARGS__); \
|
| 448 |
+
lenCheck
|
| 449 |
+
#define out(TXT) outf("%s",TXT)
|
| 450 |
+
#define CloseBrace(LEVEL) \
|
| 451 |
+
assert(LEVEL<5); memset(zPos, '}', LEVEL); zPos+=LEVEL; lenCheck
|
| 452 |
+
|
| 453 |
+
/* Macros for emitting maps of integer- and string-type macros to
|
| 454 |
+
** their values. */
|
| 455 |
+
#define DefGroup(KEY) n = 0; \
|
| 456 |
+
outf("%s\"" #KEY "\": {",(nChildren++ ? "," : ""));
|
| 457 |
+
#define DefInt(KEY) \
|
| 458 |
+
outf("%s\"%s\": %d", (n++ ? ", " : ""), #KEY, (int)KEY)
|
| 459 |
+
#define DefStr(KEY) \
|
| 460 |
+
outf("%s\"%s\": \"%s\"", (n++ ? ", " : ""), #KEY, KEY)
|
| 461 |
+
#define _DefGroup CloseBrace(1)
|
| 462 |
+
|
| 463 |
+
/* The following groups are sorted alphabetic by group name. */
|
| 464 |
+
DefGroup(access){
|
| 465 |
+
DefInt(SQLITE_ACCESS_EXISTS);
|
| 466 |
+
DefInt(SQLITE_ACCESS_READWRITE);
|
| 467 |
+
DefInt(SQLITE_ACCESS_READ)/*docs say this is unused*/;
|
| 468 |
+
} _DefGroup;
|
| 469 |
+
|
| 470 |
+
DefGroup(authorizer){
|
| 471 |
+
DefInt(SQLITE_DENY);
|
| 472 |
+
DefInt(SQLITE_IGNORE);
|
| 473 |
+
DefInt(SQLITE_CREATE_INDEX);
|
| 474 |
+
DefInt(SQLITE_CREATE_TABLE);
|
| 475 |
+
DefInt(SQLITE_CREATE_TEMP_INDEX);
|
| 476 |
+
DefInt(SQLITE_CREATE_TEMP_TABLE);
|
| 477 |
+
DefInt(SQLITE_CREATE_TEMP_TRIGGER);
|
| 478 |
+
DefInt(SQLITE_CREATE_TEMP_VIEW);
|
| 479 |
+
DefInt(SQLITE_CREATE_TRIGGER);
|
| 480 |
+
DefInt(SQLITE_CREATE_VIEW);
|
| 481 |
+
DefInt(SQLITE_DELETE);
|
| 482 |
+
DefInt(SQLITE_DROP_INDEX);
|
| 483 |
+
DefInt(SQLITE_DROP_TABLE);
|
| 484 |
+
DefInt(SQLITE_DROP_TEMP_INDEX);
|
| 485 |
+
DefInt(SQLITE_DROP_TEMP_TABLE);
|
| 486 |
+
DefInt(SQLITE_DROP_TEMP_TRIGGER);
|
| 487 |
+
DefInt(SQLITE_DROP_TEMP_VIEW);
|
| 488 |
+
DefInt(SQLITE_DROP_TRIGGER);
|
| 489 |
+
DefInt(SQLITE_DROP_VIEW);
|
| 490 |
+
DefInt(SQLITE_INSERT);
|
| 491 |
+
DefInt(SQLITE_PRAGMA);
|
| 492 |
+
DefInt(SQLITE_READ);
|
| 493 |
+
DefInt(SQLITE_SELECT);
|
| 494 |
+
DefInt(SQLITE_TRANSACTION);
|
| 495 |
+
DefInt(SQLITE_UPDATE);
|
| 496 |
+
DefInt(SQLITE_ATTACH);
|
| 497 |
+
DefInt(SQLITE_DETACH);
|
| 498 |
+
DefInt(SQLITE_ALTER_TABLE);
|
| 499 |
+
DefInt(SQLITE_REINDEX);
|
| 500 |
+
DefInt(SQLITE_ANALYZE);
|
| 501 |
+
DefInt(SQLITE_CREATE_VTABLE);
|
| 502 |
+
DefInt(SQLITE_DROP_VTABLE);
|
| 503 |
+
DefInt(SQLITE_FUNCTION);
|
| 504 |
+
DefInt(SQLITE_SAVEPOINT);
|
| 505 |
+
//DefInt(SQLITE_COPY) /* No longer used */;
|
| 506 |
+
DefInt(SQLITE_RECURSIVE);
|
| 507 |
+
} _DefGroup;
|
| 508 |
+
|
| 509 |
+
DefGroup(blobFinalizers) {
|
| 510 |
+
/* SQLITE_STATIC/TRANSIENT need to be handled explicitly as
|
| 511 |
+
** integers to avoid casting-related warnings. */
|
| 512 |
+
out("\"SQLITE_STATIC\":0, \"SQLITE_TRANSIENT\":-1");
|
| 513 |
+
outf(",\"SQLITE_WASM_DEALLOC\": %lld",
|
| 514 |
+
(sqlite3_int64)(sqlite3_free));
|
| 515 |
+
} _DefGroup;
|
| 516 |
+
|
| 517 |
+
DefGroup(changeset){
|
| 518 |
+
#ifdef SQLITE_CHANGESETSTART_INVERT
|
| 519 |
+
DefInt(SQLITE_CHANGESETSTART_INVERT);
|
| 520 |
+
DefInt(SQLITE_CHANGESETAPPLY_NOSAVEPOINT);
|
| 521 |
+
DefInt(SQLITE_CHANGESETAPPLY_INVERT);
|
| 522 |
+
DefInt(SQLITE_CHANGESETAPPLY_IGNORENOOP);
|
| 523 |
+
|
| 524 |
+
DefInt(SQLITE_CHANGESET_DATA);
|
| 525 |
+
DefInt(SQLITE_CHANGESET_NOTFOUND);
|
| 526 |
+
DefInt(SQLITE_CHANGESET_CONFLICT);
|
| 527 |
+
DefInt(SQLITE_CHANGESET_CONSTRAINT);
|
| 528 |
+
DefInt(SQLITE_CHANGESET_FOREIGN_KEY);
|
| 529 |
+
|
| 530 |
+
DefInt(SQLITE_CHANGESET_OMIT);
|
| 531 |
+
DefInt(SQLITE_CHANGESET_REPLACE);
|
| 532 |
+
DefInt(SQLITE_CHANGESET_ABORT);
|
| 533 |
+
#endif
|
| 534 |
+
} _DefGroup;
|
| 535 |
+
|
| 536 |
+
DefGroup(config){
|
| 537 |
+
DefInt(SQLITE_CONFIG_SINGLETHREAD);
|
| 538 |
+
DefInt(SQLITE_CONFIG_MULTITHREAD);
|
| 539 |
+
DefInt(SQLITE_CONFIG_SERIALIZED);
|
| 540 |
+
DefInt(SQLITE_CONFIG_MALLOC);
|
| 541 |
+
DefInt(SQLITE_CONFIG_GETMALLOC);
|
| 542 |
+
DefInt(SQLITE_CONFIG_SCRATCH);
|
| 543 |
+
DefInt(SQLITE_CONFIG_PAGECACHE);
|
| 544 |
+
DefInt(SQLITE_CONFIG_HEAP);
|
| 545 |
+
DefInt(SQLITE_CONFIG_MEMSTATUS);
|
| 546 |
+
DefInt(SQLITE_CONFIG_MUTEX);
|
| 547 |
+
DefInt(SQLITE_CONFIG_GETMUTEX);
|
| 548 |
+
/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
|
| 549 |
+
DefInt(SQLITE_CONFIG_LOOKASIDE);
|
| 550 |
+
DefInt(SQLITE_CONFIG_PCACHE);
|
| 551 |
+
DefInt(SQLITE_CONFIG_GETPCACHE);
|
| 552 |
+
DefInt(SQLITE_CONFIG_LOG);
|
| 553 |
+
DefInt(SQLITE_CONFIG_URI);
|
| 554 |
+
DefInt(SQLITE_CONFIG_PCACHE2);
|
| 555 |
+
DefInt(SQLITE_CONFIG_GETPCACHE2);
|
| 556 |
+
DefInt(SQLITE_CONFIG_COVERING_INDEX_SCAN);
|
| 557 |
+
DefInt(SQLITE_CONFIG_SQLLOG);
|
| 558 |
+
DefInt(SQLITE_CONFIG_MMAP_SIZE);
|
| 559 |
+
DefInt(SQLITE_CONFIG_WIN32_HEAPSIZE);
|
| 560 |
+
DefInt(SQLITE_CONFIG_PCACHE_HDRSZ);
|
| 561 |
+
DefInt(SQLITE_CONFIG_PMASZ);
|
| 562 |
+
DefInt(SQLITE_CONFIG_STMTJRNL_SPILL);
|
| 563 |
+
DefInt(SQLITE_CONFIG_SMALL_MALLOC);
|
| 564 |
+
DefInt(SQLITE_CONFIG_SORTERREF_SIZE);
|
| 565 |
+
DefInt(SQLITE_CONFIG_MEMDB_MAXSIZE);
|
| 566 |
+
/* maintenance note: we specifically do not include
|
| 567 |
+
SQLITE_CONFIG_ROWID_IN_VIEW here, on the grounds that
|
| 568 |
+
it's only for legacy support and no apps written with
|
| 569 |
+
this API require that. */
|
| 570 |
+
} _DefGroup;
|
| 571 |
+
|
| 572 |
+
DefGroup(dataTypes) {
|
| 573 |
+
DefInt(SQLITE_INTEGER);
|
| 574 |
+
DefInt(SQLITE_FLOAT);
|
| 575 |
+
DefInt(SQLITE_TEXT);
|
| 576 |
+
DefInt(SQLITE_BLOB);
|
| 577 |
+
DefInt(SQLITE_NULL);
|
| 578 |
+
} _DefGroup;
|
| 579 |
+
|
| 580 |
+
DefGroup(dbConfig){
|
| 581 |
+
DefInt(SQLITE_DBCONFIG_MAINDBNAME);
|
| 582 |
+
DefInt(SQLITE_DBCONFIG_LOOKASIDE);
|
| 583 |
+
DefInt(SQLITE_DBCONFIG_ENABLE_FKEY);
|
| 584 |
+
DefInt(SQLITE_DBCONFIG_ENABLE_TRIGGER);
|
| 585 |
+
DefInt(SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION);
|
| 586 |
+
DefInt(SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE);
|
| 587 |
+
DefInt(SQLITE_DBCONFIG_ENABLE_QPSG);
|
| 588 |
+
DefInt(SQLITE_DBCONFIG_TRIGGER_EQP);
|
| 589 |
+
DefInt(SQLITE_DBCONFIG_RESET_DATABASE);
|
| 590 |
+
DefInt(SQLITE_DBCONFIG_DEFENSIVE);
|
| 591 |
+
DefInt(SQLITE_DBCONFIG_WRITABLE_SCHEMA);
|
| 592 |
+
DefInt(SQLITE_DBCONFIG_LEGACY_ALTER_TABLE);
|
| 593 |
+
DefInt(SQLITE_DBCONFIG_DQS_DML);
|
| 594 |
+
DefInt(SQLITE_DBCONFIG_DQS_DDL);
|
| 595 |
+
DefInt(SQLITE_DBCONFIG_ENABLE_VIEW);
|
| 596 |
+
DefInt(SQLITE_DBCONFIG_LEGACY_FILE_FORMAT);
|
| 597 |
+
DefInt(SQLITE_DBCONFIG_TRUSTED_SCHEMA);
|
| 598 |
+
DefInt(SQLITE_DBCONFIG_STMT_SCANSTATUS);
|
| 599 |
+
DefInt(SQLITE_DBCONFIG_REVERSE_SCANORDER);
|
| 600 |
+
DefInt(SQLITE_DBCONFIG_MAX);
|
| 601 |
+
} _DefGroup;
|
| 602 |
+
|
| 603 |
+
DefGroup(dbStatus){
|
| 604 |
+
DefInt(SQLITE_DBSTATUS_LOOKASIDE_USED);
|
| 605 |
+
DefInt(SQLITE_DBSTATUS_CACHE_USED);
|
| 606 |
+
DefInt(SQLITE_DBSTATUS_SCHEMA_USED);
|
| 607 |
+
DefInt(SQLITE_DBSTATUS_STMT_USED);
|
| 608 |
+
DefInt(SQLITE_DBSTATUS_LOOKASIDE_HIT);
|
| 609 |
+
DefInt(SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE);
|
| 610 |
+
DefInt(SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL);
|
| 611 |
+
DefInt(SQLITE_DBSTATUS_CACHE_HIT);
|
| 612 |
+
DefInt(SQLITE_DBSTATUS_CACHE_MISS);
|
| 613 |
+
DefInt(SQLITE_DBSTATUS_CACHE_WRITE);
|
| 614 |
+
DefInt(SQLITE_DBSTATUS_DEFERRED_FKS);
|
| 615 |
+
DefInt(SQLITE_DBSTATUS_CACHE_USED_SHARED);
|
| 616 |
+
DefInt(SQLITE_DBSTATUS_CACHE_SPILL);
|
| 617 |
+
DefInt(SQLITE_DBSTATUS_MAX);
|
| 618 |
+
} _DefGroup;
|
| 619 |
+
|
| 620 |
+
DefGroup(encodings) {
|
| 621 |
+
/* Noting that the wasm binding only aims to support UTF-8. */
|
| 622 |
+
DefInt(SQLITE_UTF8);
|
| 623 |
+
DefInt(SQLITE_UTF16LE);
|
| 624 |
+
DefInt(SQLITE_UTF16BE);
|
| 625 |
+
DefInt(SQLITE_UTF16);
|
| 626 |
+
/*deprecated DefInt(SQLITE_ANY); */
|
| 627 |
+
DefInt(SQLITE_UTF16_ALIGNED);
|
| 628 |
+
} _DefGroup;
|
| 629 |
+
|
| 630 |
+
DefGroup(fcntl) {
|
| 631 |
+
DefInt(SQLITE_FCNTL_LOCKSTATE);
|
| 632 |
+
DefInt(SQLITE_FCNTL_GET_LOCKPROXYFILE);
|
| 633 |
+
DefInt(SQLITE_FCNTL_SET_LOCKPROXYFILE);
|
| 634 |
+
DefInt(SQLITE_FCNTL_LAST_ERRNO);
|
| 635 |
+
DefInt(SQLITE_FCNTL_SIZE_HINT);
|
| 636 |
+
DefInt(SQLITE_FCNTL_CHUNK_SIZE);
|
| 637 |
+
DefInt(SQLITE_FCNTL_FILE_POINTER);
|
| 638 |
+
DefInt(SQLITE_FCNTL_SYNC_OMITTED);
|
| 639 |
+
DefInt(SQLITE_FCNTL_WIN32_AV_RETRY);
|
| 640 |
+
DefInt(SQLITE_FCNTL_PERSIST_WAL);
|
| 641 |
+
DefInt(SQLITE_FCNTL_OVERWRITE);
|
| 642 |
+
DefInt(SQLITE_FCNTL_VFSNAME);
|
| 643 |
+
DefInt(SQLITE_FCNTL_POWERSAFE_OVERWRITE);
|
| 644 |
+
DefInt(SQLITE_FCNTL_PRAGMA);
|
| 645 |
+
DefInt(SQLITE_FCNTL_BUSYHANDLER);
|
| 646 |
+
DefInt(SQLITE_FCNTL_TEMPFILENAME);
|
| 647 |
+
DefInt(SQLITE_FCNTL_MMAP_SIZE);
|
| 648 |
+
DefInt(SQLITE_FCNTL_TRACE);
|
| 649 |
+
DefInt(SQLITE_FCNTL_HAS_MOVED);
|
| 650 |
+
DefInt(SQLITE_FCNTL_SYNC);
|
| 651 |
+
DefInt(SQLITE_FCNTL_COMMIT_PHASETWO);
|
| 652 |
+
DefInt(SQLITE_FCNTL_WIN32_SET_HANDLE);
|
| 653 |
+
DefInt(SQLITE_FCNTL_WAL_BLOCK);
|
| 654 |
+
DefInt(SQLITE_FCNTL_ZIPVFS);
|
| 655 |
+
DefInt(SQLITE_FCNTL_RBU);
|
| 656 |
+
DefInt(SQLITE_FCNTL_VFS_POINTER);
|
| 657 |
+
DefInt(SQLITE_FCNTL_JOURNAL_POINTER);
|
| 658 |
+
DefInt(SQLITE_FCNTL_WIN32_GET_HANDLE);
|
| 659 |
+
DefInt(SQLITE_FCNTL_PDB);
|
| 660 |
+
DefInt(SQLITE_FCNTL_BEGIN_ATOMIC_WRITE);
|
| 661 |
+
DefInt(SQLITE_FCNTL_COMMIT_ATOMIC_WRITE);
|
| 662 |
+
DefInt(SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE);
|
| 663 |
+
DefInt(SQLITE_FCNTL_LOCK_TIMEOUT);
|
| 664 |
+
DefInt(SQLITE_FCNTL_DATA_VERSION);
|
| 665 |
+
DefInt(SQLITE_FCNTL_SIZE_LIMIT);
|
| 666 |
+
DefInt(SQLITE_FCNTL_CKPT_DONE);
|
| 667 |
+
DefInt(SQLITE_FCNTL_RESERVE_BYTES);
|
| 668 |
+
DefInt(SQLITE_FCNTL_CKPT_START);
|
| 669 |
+
DefInt(SQLITE_FCNTL_EXTERNAL_READER);
|
| 670 |
+
DefInt(SQLITE_FCNTL_CKSM_FILE);
|
| 671 |
+
DefInt(SQLITE_FCNTL_RESET_CACHE);
|
| 672 |
+
} _DefGroup;
|
| 673 |
+
|
| 674 |
+
DefGroup(flock) {
|
| 675 |
+
DefInt(SQLITE_LOCK_NONE);
|
| 676 |
+
DefInt(SQLITE_LOCK_SHARED);
|
| 677 |
+
DefInt(SQLITE_LOCK_RESERVED);
|
| 678 |
+
DefInt(SQLITE_LOCK_PENDING);
|
| 679 |
+
DefInt(SQLITE_LOCK_EXCLUSIVE);
|
| 680 |
+
} _DefGroup;
|
| 681 |
+
|
| 682 |
+
DefGroup(ioCap) {
|
| 683 |
+
DefInt(SQLITE_IOCAP_ATOMIC);
|
| 684 |
+
DefInt(SQLITE_IOCAP_ATOMIC512);
|
| 685 |
+
DefInt(SQLITE_IOCAP_ATOMIC1K);
|
| 686 |
+
DefInt(SQLITE_IOCAP_ATOMIC2K);
|
| 687 |
+
DefInt(SQLITE_IOCAP_ATOMIC4K);
|
| 688 |
+
DefInt(SQLITE_IOCAP_ATOMIC8K);
|
| 689 |
+
DefInt(SQLITE_IOCAP_ATOMIC16K);
|
| 690 |
+
DefInt(SQLITE_IOCAP_ATOMIC32K);
|
| 691 |
+
DefInt(SQLITE_IOCAP_ATOMIC64K);
|
| 692 |
+
DefInt(SQLITE_IOCAP_SAFE_APPEND);
|
| 693 |
+
DefInt(SQLITE_IOCAP_SEQUENTIAL);
|
| 694 |
+
DefInt(SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN);
|
| 695 |
+
DefInt(SQLITE_IOCAP_POWERSAFE_OVERWRITE);
|
| 696 |
+
DefInt(SQLITE_IOCAP_IMMUTABLE);
|
| 697 |
+
DefInt(SQLITE_IOCAP_BATCH_ATOMIC);
|
| 698 |
+
} _DefGroup;
|
| 699 |
+
|
| 700 |
+
DefGroup(limits) {
|
| 701 |
+
DefInt(SQLITE_MAX_ALLOCATION_SIZE);
|
| 702 |
+
DefInt(SQLITE_LIMIT_LENGTH);
|
| 703 |
+
DefInt(SQLITE_MAX_LENGTH);
|
| 704 |
+
DefInt(SQLITE_LIMIT_SQL_LENGTH);
|
| 705 |
+
DefInt(SQLITE_MAX_SQL_LENGTH);
|
| 706 |
+
DefInt(SQLITE_LIMIT_COLUMN);
|
| 707 |
+
DefInt(SQLITE_MAX_COLUMN);
|
| 708 |
+
DefInt(SQLITE_LIMIT_EXPR_DEPTH);
|
| 709 |
+
DefInt(SQLITE_MAX_EXPR_DEPTH);
|
| 710 |
+
DefInt(SQLITE_LIMIT_COMPOUND_SELECT);
|
| 711 |
+
DefInt(SQLITE_MAX_COMPOUND_SELECT);
|
| 712 |
+
DefInt(SQLITE_LIMIT_VDBE_OP);
|
| 713 |
+
DefInt(SQLITE_MAX_VDBE_OP);
|
| 714 |
+
DefInt(SQLITE_LIMIT_FUNCTION_ARG);
|
| 715 |
+
DefInt(SQLITE_MAX_FUNCTION_ARG);
|
| 716 |
+
DefInt(SQLITE_LIMIT_ATTACHED);
|
| 717 |
+
DefInt(SQLITE_MAX_ATTACHED);
|
| 718 |
+
DefInt(SQLITE_LIMIT_LIKE_PATTERN_LENGTH);
|
| 719 |
+
DefInt(SQLITE_MAX_LIKE_PATTERN_LENGTH);
|
| 720 |
+
DefInt(SQLITE_LIMIT_VARIABLE_NUMBER);
|
| 721 |
+
DefInt(SQLITE_MAX_VARIABLE_NUMBER);
|
| 722 |
+
DefInt(SQLITE_LIMIT_TRIGGER_DEPTH);
|
| 723 |
+
DefInt(SQLITE_MAX_TRIGGER_DEPTH);
|
| 724 |
+
DefInt(SQLITE_LIMIT_WORKER_THREADS);
|
| 725 |
+
DefInt(SQLITE_MAX_WORKER_THREADS);
|
| 726 |
+
} _DefGroup;
|
| 727 |
+
|
| 728 |
+
DefGroup(openFlags) {
|
| 729 |
+
/* Noting that not all of these will have any effect in
|
| 730 |
+
** WASM-space. */
|
| 731 |
+
DefInt(SQLITE_OPEN_READONLY);
|
| 732 |
+
DefInt(SQLITE_OPEN_READWRITE);
|
| 733 |
+
DefInt(SQLITE_OPEN_CREATE);
|
| 734 |
+
DefInt(SQLITE_OPEN_URI);
|
| 735 |
+
DefInt(SQLITE_OPEN_MEMORY);
|
| 736 |
+
DefInt(SQLITE_OPEN_NOMUTEX);
|
| 737 |
+
DefInt(SQLITE_OPEN_FULLMUTEX);
|
| 738 |
+
DefInt(SQLITE_OPEN_SHAREDCACHE);
|
| 739 |
+
DefInt(SQLITE_OPEN_PRIVATECACHE);
|
| 740 |
+
DefInt(SQLITE_OPEN_EXRESCODE);
|
| 741 |
+
DefInt(SQLITE_OPEN_NOFOLLOW);
|
| 742 |
+
/* OPEN flags for use with VFSes... */
|
| 743 |
+
DefInt(SQLITE_OPEN_MAIN_DB);
|
| 744 |
+
DefInt(SQLITE_OPEN_MAIN_JOURNAL);
|
| 745 |
+
DefInt(SQLITE_OPEN_TEMP_DB);
|
| 746 |
+
DefInt(SQLITE_OPEN_TEMP_JOURNAL);
|
| 747 |
+
DefInt(SQLITE_OPEN_TRANSIENT_DB);
|
| 748 |
+
DefInt(SQLITE_OPEN_SUBJOURNAL);
|
| 749 |
+
DefInt(SQLITE_OPEN_SUPER_JOURNAL);
|
| 750 |
+
DefInt(SQLITE_OPEN_WAL);
|
| 751 |
+
DefInt(SQLITE_OPEN_DELETEONCLOSE);
|
| 752 |
+
DefInt(SQLITE_OPEN_EXCLUSIVE);
|
| 753 |
+
} _DefGroup;
|
| 754 |
+
|
| 755 |
+
DefGroup(prepareFlags) {
|
| 756 |
+
DefInt(SQLITE_PREPARE_PERSISTENT);
|
| 757 |
+
DefInt(SQLITE_PREPARE_NORMALIZE);
|
| 758 |
+
DefInt(SQLITE_PREPARE_NO_VTAB);
|
| 759 |
+
} _DefGroup;
|
| 760 |
+
|
| 761 |
+
DefGroup(resultCodes) {
|
| 762 |
+
DefInt(SQLITE_OK);
|
| 763 |
+
DefInt(SQLITE_ERROR);
|
| 764 |
+
DefInt(SQLITE_INTERNAL);
|
| 765 |
+
DefInt(SQLITE_PERM);
|
| 766 |
+
DefInt(SQLITE_ABORT);
|
| 767 |
+
DefInt(SQLITE_BUSY);
|
| 768 |
+
DefInt(SQLITE_LOCKED);
|
| 769 |
+
DefInt(SQLITE_NOMEM);
|
| 770 |
+
DefInt(SQLITE_READONLY);
|
| 771 |
+
DefInt(SQLITE_INTERRUPT);
|
| 772 |
+
DefInt(SQLITE_IOERR);
|
| 773 |
+
DefInt(SQLITE_CORRUPT);
|
| 774 |
+
DefInt(SQLITE_NOTFOUND);
|
| 775 |
+
DefInt(SQLITE_FULL);
|
| 776 |
+
DefInt(SQLITE_CANTOPEN);
|
| 777 |
+
DefInt(SQLITE_PROTOCOL);
|
| 778 |
+
DefInt(SQLITE_EMPTY);
|
| 779 |
+
DefInt(SQLITE_SCHEMA);
|
| 780 |
+
DefInt(SQLITE_TOOBIG);
|
| 781 |
+
DefInt(SQLITE_CONSTRAINT);
|
| 782 |
+
DefInt(SQLITE_MISMATCH);
|
| 783 |
+
DefInt(SQLITE_MISUSE);
|
| 784 |
+
DefInt(SQLITE_NOLFS);
|
| 785 |
+
DefInt(SQLITE_AUTH);
|
| 786 |
+
DefInt(SQLITE_FORMAT);
|
| 787 |
+
DefInt(SQLITE_RANGE);
|
| 788 |
+
DefInt(SQLITE_NOTADB);
|
| 789 |
+
DefInt(SQLITE_NOTICE);
|
| 790 |
+
DefInt(SQLITE_WARNING);
|
| 791 |
+
DefInt(SQLITE_ROW);
|
| 792 |
+
DefInt(SQLITE_DONE);
|
| 793 |
+
// Extended Result Codes
|
| 794 |
+
DefInt(SQLITE_ERROR_MISSING_COLLSEQ);
|
| 795 |
+
DefInt(SQLITE_ERROR_RETRY);
|
| 796 |
+
DefInt(SQLITE_ERROR_SNAPSHOT);
|
| 797 |
+
DefInt(SQLITE_IOERR_READ);
|
| 798 |
+
DefInt(SQLITE_IOERR_SHORT_READ);
|
| 799 |
+
DefInt(SQLITE_IOERR_WRITE);
|
| 800 |
+
DefInt(SQLITE_IOERR_FSYNC);
|
| 801 |
+
DefInt(SQLITE_IOERR_DIR_FSYNC);
|
| 802 |
+
DefInt(SQLITE_IOERR_TRUNCATE);
|
| 803 |
+
DefInt(SQLITE_IOERR_FSTAT);
|
| 804 |
+
DefInt(SQLITE_IOERR_UNLOCK);
|
| 805 |
+
DefInt(SQLITE_IOERR_RDLOCK);
|
| 806 |
+
DefInt(SQLITE_IOERR_DELETE);
|
| 807 |
+
DefInt(SQLITE_IOERR_BLOCKED);
|
| 808 |
+
DefInt(SQLITE_IOERR_NOMEM);
|
| 809 |
+
DefInt(SQLITE_IOERR_ACCESS);
|
| 810 |
+
DefInt(SQLITE_IOERR_CHECKRESERVEDLOCK);
|
| 811 |
+
DefInt(SQLITE_IOERR_LOCK);
|
| 812 |
+
DefInt(SQLITE_IOERR_CLOSE);
|
| 813 |
+
DefInt(SQLITE_IOERR_DIR_CLOSE);
|
| 814 |
+
DefInt(SQLITE_IOERR_SHMOPEN);
|
| 815 |
+
DefInt(SQLITE_IOERR_SHMSIZE);
|
| 816 |
+
DefInt(SQLITE_IOERR_SHMLOCK);
|
| 817 |
+
DefInt(SQLITE_IOERR_SHMMAP);
|
| 818 |
+
DefInt(SQLITE_IOERR_SEEK);
|
| 819 |
+
DefInt(SQLITE_IOERR_DELETE_NOENT);
|
| 820 |
+
DefInt(SQLITE_IOERR_MMAP);
|
| 821 |
+
DefInt(SQLITE_IOERR_GETTEMPPATH);
|
| 822 |
+
DefInt(SQLITE_IOERR_CONVPATH);
|
| 823 |
+
DefInt(SQLITE_IOERR_VNODE);
|
| 824 |
+
DefInt(SQLITE_IOERR_AUTH);
|
| 825 |
+
DefInt(SQLITE_IOERR_BEGIN_ATOMIC);
|
| 826 |
+
DefInt(SQLITE_IOERR_COMMIT_ATOMIC);
|
| 827 |
+
DefInt(SQLITE_IOERR_ROLLBACK_ATOMIC);
|
| 828 |
+
DefInt(SQLITE_IOERR_DATA);
|
| 829 |
+
DefInt(SQLITE_IOERR_CORRUPTFS);
|
| 830 |
+
DefInt(SQLITE_LOCKED_SHAREDCACHE);
|
| 831 |
+
DefInt(SQLITE_LOCKED_VTAB);
|
| 832 |
+
DefInt(SQLITE_BUSY_RECOVERY);
|
| 833 |
+
DefInt(SQLITE_BUSY_SNAPSHOT);
|
| 834 |
+
DefInt(SQLITE_BUSY_TIMEOUT);
|
| 835 |
+
DefInt(SQLITE_CANTOPEN_NOTEMPDIR);
|
| 836 |
+
DefInt(SQLITE_CANTOPEN_ISDIR);
|
| 837 |
+
DefInt(SQLITE_CANTOPEN_FULLPATH);
|
| 838 |
+
DefInt(SQLITE_CANTOPEN_CONVPATH);
|
| 839 |
+
//DefInt(SQLITE_CANTOPEN_DIRTYWAL)/*docs say not used*/;
|
| 840 |
+
DefInt(SQLITE_CANTOPEN_SYMLINK);
|
| 841 |
+
DefInt(SQLITE_CORRUPT_VTAB);
|
| 842 |
+
DefInt(SQLITE_CORRUPT_SEQUENCE);
|
| 843 |
+
DefInt(SQLITE_CORRUPT_INDEX);
|
| 844 |
+
DefInt(SQLITE_READONLY_RECOVERY);
|
| 845 |
+
DefInt(SQLITE_READONLY_CANTLOCK);
|
| 846 |
+
DefInt(SQLITE_READONLY_ROLLBACK);
|
| 847 |
+
DefInt(SQLITE_READONLY_DBMOVED);
|
| 848 |
+
DefInt(SQLITE_READONLY_CANTINIT);
|
| 849 |
+
DefInt(SQLITE_READONLY_DIRECTORY);
|
| 850 |
+
DefInt(SQLITE_ABORT_ROLLBACK);
|
| 851 |
+
DefInt(SQLITE_CONSTRAINT_CHECK);
|
| 852 |
+
DefInt(SQLITE_CONSTRAINT_COMMITHOOK);
|
| 853 |
+
DefInt(SQLITE_CONSTRAINT_FOREIGNKEY);
|
| 854 |
+
DefInt(SQLITE_CONSTRAINT_FUNCTION);
|
| 855 |
+
DefInt(SQLITE_CONSTRAINT_NOTNULL);
|
| 856 |
+
DefInt(SQLITE_CONSTRAINT_PRIMARYKEY);
|
| 857 |
+
DefInt(SQLITE_CONSTRAINT_TRIGGER);
|
| 858 |
+
DefInt(SQLITE_CONSTRAINT_UNIQUE);
|
| 859 |
+
DefInt(SQLITE_CONSTRAINT_VTAB);
|
| 860 |
+
DefInt(SQLITE_CONSTRAINT_ROWID);
|
| 861 |
+
DefInt(SQLITE_CONSTRAINT_PINNED);
|
| 862 |
+
DefInt(SQLITE_CONSTRAINT_DATATYPE);
|
| 863 |
+
DefInt(SQLITE_NOTICE_RECOVER_WAL);
|
| 864 |
+
DefInt(SQLITE_NOTICE_RECOVER_ROLLBACK);
|
| 865 |
+
DefInt(SQLITE_WARNING_AUTOINDEX);
|
| 866 |
+
DefInt(SQLITE_AUTH_USER);
|
| 867 |
+
DefInt(SQLITE_OK_LOAD_PERMANENTLY);
|
| 868 |
+
//DefInt(SQLITE_OK_SYMLINK) /* internal use only */;
|
| 869 |
+
} _DefGroup;
|
| 870 |
+
|
| 871 |
+
DefGroup(serialize){
|
| 872 |
+
DefInt(SQLITE_SERIALIZE_NOCOPY);
|
| 873 |
+
DefInt(SQLITE_DESERIALIZE_FREEONCLOSE);
|
| 874 |
+
DefInt(SQLITE_DESERIALIZE_READONLY);
|
| 875 |
+
DefInt(SQLITE_DESERIALIZE_RESIZEABLE);
|
| 876 |
+
} _DefGroup;
|
| 877 |
+
|
| 878 |
+
DefGroup(session){
|
| 879 |
+
#ifdef SQLITE_SESSION_CONFIG_STRMSIZE
|
| 880 |
+
DefInt(SQLITE_SESSION_CONFIG_STRMSIZE);
|
| 881 |
+
DefInt(SQLITE_SESSION_OBJCONFIG_SIZE);
|
| 882 |
+
#endif
|
| 883 |
+
} _DefGroup;
|
| 884 |
+
|
| 885 |
+
DefGroup(sqlite3Status){
|
| 886 |
+
DefInt(SQLITE_STATUS_MEMORY_USED);
|
| 887 |
+
DefInt(SQLITE_STATUS_PAGECACHE_USED);
|
| 888 |
+
DefInt(SQLITE_STATUS_PAGECACHE_OVERFLOW);
|
| 889 |
+
//DefInt(SQLITE_STATUS_SCRATCH_USED) /* NOT USED */;
|
| 890 |
+
//DefInt(SQLITE_STATUS_SCRATCH_OVERFLOW) /* NOT USED */;
|
| 891 |
+
DefInt(SQLITE_STATUS_MALLOC_SIZE);
|
| 892 |
+
DefInt(SQLITE_STATUS_PARSER_STACK);
|
| 893 |
+
DefInt(SQLITE_STATUS_PAGECACHE_SIZE);
|
| 894 |
+
//DefInt(SQLITE_STATUS_SCRATCH_SIZE) /* NOT USED */;
|
| 895 |
+
DefInt(SQLITE_STATUS_MALLOC_COUNT);
|
| 896 |
+
} _DefGroup;
|
| 897 |
+
|
| 898 |
+
DefGroup(stmtStatus){
|
| 899 |
+
DefInt(SQLITE_STMTSTATUS_FULLSCAN_STEP);
|
| 900 |
+
DefInt(SQLITE_STMTSTATUS_SORT);
|
| 901 |
+
DefInt(SQLITE_STMTSTATUS_AUTOINDEX);
|
| 902 |
+
DefInt(SQLITE_STMTSTATUS_VM_STEP);
|
| 903 |
+
DefInt(SQLITE_STMTSTATUS_REPREPARE);
|
| 904 |
+
DefInt(SQLITE_STMTSTATUS_RUN);
|
| 905 |
+
DefInt(SQLITE_STMTSTATUS_FILTER_MISS);
|
| 906 |
+
DefInt(SQLITE_STMTSTATUS_FILTER_HIT);
|
| 907 |
+
DefInt(SQLITE_STMTSTATUS_MEMUSED);
|
| 908 |
+
} _DefGroup;
|
| 909 |
+
|
| 910 |
+
DefGroup(syncFlags) {
|
| 911 |
+
DefInt(SQLITE_SYNC_NORMAL);
|
| 912 |
+
DefInt(SQLITE_SYNC_FULL);
|
| 913 |
+
DefInt(SQLITE_SYNC_DATAONLY);
|
| 914 |
+
} _DefGroup;
|
| 915 |
+
|
| 916 |
+
DefGroup(trace) {
|
| 917 |
+
DefInt(SQLITE_TRACE_STMT);
|
| 918 |
+
DefInt(SQLITE_TRACE_PROFILE);
|
| 919 |
+
DefInt(SQLITE_TRACE_ROW);
|
| 920 |
+
DefInt(SQLITE_TRACE_CLOSE);
|
| 921 |
+
} _DefGroup;
|
| 922 |
+
|
| 923 |
+
DefGroup(txnState){
|
| 924 |
+
DefInt(SQLITE_TXN_NONE);
|
| 925 |
+
DefInt(SQLITE_TXN_READ);
|
| 926 |
+
DefInt(SQLITE_TXN_WRITE);
|
| 927 |
+
} _DefGroup;
|
| 928 |
+
|
| 929 |
+
DefGroup(udfFlags) {
|
| 930 |
+
DefInt(SQLITE_DETERMINISTIC);
|
| 931 |
+
DefInt(SQLITE_DIRECTONLY);
|
| 932 |
+
DefInt(SQLITE_INNOCUOUS);
|
| 933 |
+
DefInt(SQLITE_SUBTYPE);
|
| 934 |
+
DefInt(SQLITE_RESULT_SUBTYPE);
|
| 935 |
+
} _DefGroup;
|
| 936 |
+
|
| 937 |
+
DefGroup(version) {
|
| 938 |
+
DefInt(SQLITE_VERSION_NUMBER);
|
| 939 |
+
DefStr(SQLITE_VERSION);
|
| 940 |
+
DefStr(SQLITE_SOURCE_ID);
|
| 941 |
+
} _DefGroup;
|
| 942 |
+
|
| 943 |
+
DefGroup(vtab) {
|
| 944 |
+
#if SQLITE_WASM_HAS_VTAB
|
| 945 |
+
DefInt(SQLITE_INDEX_SCAN_UNIQUE);
|
| 946 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_EQ);
|
| 947 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_GT);
|
| 948 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_LE);
|
| 949 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_LT);
|
| 950 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_GE);
|
| 951 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_MATCH);
|
| 952 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_LIKE);
|
| 953 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_GLOB);
|
| 954 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_REGEXP);
|
| 955 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_NE);
|
| 956 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_ISNOT);
|
| 957 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_ISNOTNULL);
|
| 958 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_ISNULL);
|
| 959 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_IS);
|
| 960 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_LIMIT);
|
| 961 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_OFFSET);
|
| 962 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_FUNCTION);
|
| 963 |
+
DefInt(SQLITE_VTAB_CONSTRAINT_SUPPORT);
|
| 964 |
+
DefInt(SQLITE_VTAB_INNOCUOUS);
|
| 965 |
+
DefInt(SQLITE_VTAB_DIRECTONLY);
|
| 966 |
+
DefInt(SQLITE_VTAB_USES_ALL_SCHEMAS);
|
| 967 |
+
DefInt(SQLITE_ROLLBACK);
|
| 968 |
+
//DefInt(SQLITE_IGNORE); // Also used by sqlite3_authorizer() callback
|
| 969 |
+
DefInt(SQLITE_FAIL);
|
| 970 |
+
//DefInt(SQLITE_ABORT); // Also an error code
|
| 971 |
+
DefInt(SQLITE_REPLACE);
|
| 972 |
+
#endif /*SQLITE_WASM_HAS_VTAB*/
|
| 973 |
+
} _DefGroup;
|
| 974 |
+
|
| 975 |
+
#undef DefGroup
|
| 976 |
+
#undef DefStr
|
| 977 |
+
#undef DefInt
|
| 978 |
+
#undef _DefGroup
|
| 979 |
+
|
| 980 |
+
/*
|
| 981 |
+
** Emit an array of "StructBinder" struct descripions, which look
|
| 982 |
+
** like:
|
| 983 |
+
**
|
| 984 |
+
** {
|
| 985 |
+
** "name": "MyStruct",
|
| 986 |
+
** "sizeof": 16,
|
| 987 |
+
** "members": {
|
| 988 |
+
** "member1": {"offset": 0,"sizeof": 4,"signature": "i"},
|
| 989 |
+
** "member2": {"offset": 4,"sizeof": 4,"signature": "p"},
|
| 990 |
+
** "member3": {"offset": 8,"sizeof": 8,"signature": "j"}
|
| 991 |
+
** }
|
| 992 |
+
** }
|
| 993 |
+
**
|
| 994 |
+
** Detailed documentation for those bits are in the docs for the
|
| 995 |
+
** Jaccwabyt JS-side component.
|
| 996 |
+
*/
|
| 997 |
+
|
| 998 |
+
/** Macros for emitting StructBinder description. */
|
| 999 |
+
#define StructBinder__(TYPE) \
|
| 1000 |
+
n = 0; \
|
| 1001 |
+
outf("%s{", (nStruct++ ? ", " : "")); \
|
| 1002 |
+
out("\"name\": \"" # TYPE "\","); \
|
| 1003 |
+
outf("\"sizeof\": %d", (int)sizeof(TYPE)); \
|
| 1004 |
+
out(",\"members\": {");
|
| 1005 |
+
#define StructBinder_(T) StructBinder__(T)
|
| 1006 |
+
/** ^^^ indirection needed to expand CurrentStruct */
|
| 1007 |
+
#define StructBinder StructBinder_(CurrentStruct)
|
| 1008 |
+
#define _StructBinder CloseBrace(2)
|
| 1009 |
+
#define M(MEMBER,SIG) \
|
| 1010 |
+
outf("%s\"%s\": " \
|
| 1011 |
+
"{\"offset\":%d,\"sizeof\": %d,\"signature\":\"%s\"}", \
|
| 1012 |
+
(n++ ? ", " : ""), #MEMBER, \
|
| 1013 |
+
(int)offsetof(CurrentStruct,MEMBER), \
|
| 1014 |
+
(int)sizeof(((CurrentStruct*)0)->MEMBER), \
|
| 1015 |
+
SIG)
|
| 1016 |
+
|
| 1017 |
+
nStruct = 0;
|
| 1018 |
+
out(", \"structs\": ["); {
|
| 1019 |
+
|
| 1020 |
+
#define CurrentStruct sqlite3_vfs
|
| 1021 |
+
StructBinder {
|
| 1022 |
+
M(iVersion, "i");
|
| 1023 |
+
M(szOsFile, "i");
|
| 1024 |
+
M(mxPathname, "i");
|
| 1025 |
+
M(pNext, "p");
|
| 1026 |
+
M(zName, "s");
|
| 1027 |
+
M(pAppData, "p");
|
| 1028 |
+
M(xOpen, "i(pppip)");
|
| 1029 |
+
M(xDelete, "i(ppi)");
|
| 1030 |
+
M(xAccess, "i(ppip)");
|
| 1031 |
+
M(xFullPathname, "i(ppip)");
|
| 1032 |
+
M(xDlOpen, "p(pp)");
|
| 1033 |
+
M(xDlError, "p(pip)");
|
| 1034 |
+
M(xDlSym, "p()");
|
| 1035 |
+
M(xDlClose, "v(pp)");
|
| 1036 |
+
M(xRandomness, "i(pip)");
|
| 1037 |
+
M(xSleep, "i(pi)");
|
| 1038 |
+
M(xCurrentTime, "i(pp)");
|
| 1039 |
+
M(xGetLastError, "i(pip)");
|
| 1040 |
+
M(xCurrentTimeInt64, "i(pp)");
|
| 1041 |
+
M(xSetSystemCall, "i(ppp)");
|
| 1042 |
+
M(xGetSystemCall, "p(pp)");
|
| 1043 |
+
M(xNextSystemCall, "p(pp)");
|
| 1044 |
+
} _StructBinder;
|
| 1045 |
+
#undef CurrentStruct
|
| 1046 |
+
|
| 1047 |
+
#define CurrentStruct sqlite3_io_methods
|
| 1048 |
+
StructBinder {
|
| 1049 |
+
M(iVersion, "i");
|
| 1050 |
+
M(xClose, "i(p)");
|
| 1051 |
+
M(xRead, "i(ppij)");
|
| 1052 |
+
M(xWrite, "i(ppij)");
|
| 1053 |
+
M(xTruncate, "i(pj)");
|
| 1054 |
+
M(xSync, "i(pi)");
|
| 1055 |
+
M(xFileSize, "i(pp)");
|
| 1056 |
+
M(xLock, "i(pi)");
|
| 1057 |
+
M(xUnlock, "i(pi)");
|
| 1058 |
+
M(xCheckReservedLock, "i(pp)");
|
| 1059 |
+
M(xFileControl, "i(pip)");
|
| 1060 |
+
M(xSectorSize, "i(p)");
|
| 1061 |
+
M(xDeviceCharacteristics, "i(p)");
|
| 1062 |
+
M(xShmMap, "i(piiip)");
|
| 1063 |
+
M(xShmLock, "i(piii)");
|
| 1064 |
+
M(xShmBarrier, "v(p)");
|
| 1065 |
+
M(xShmUnmap, "i(pi)");
|
| 1066 |
+
M(xFetch, "i(pjip)");
|
| 1067 |
+
M(xUnfetch, "i(pjp)");
|
| 1068 |
+
} _StructBinder;
|
| 1069 |
+
#undef CurrentStruct
|
| 1070 |
+
|
| 1071 |
+
#define CurrentStruct sqlite3_file
|
| 1072 |
+
StructBinder {
|
| 1073 |
+
M(pMethods, "p");
|
| 1074 |
+
} _StructBinder;
|
| 1075 |
+
#undef CurrentStruct
|
| 1076 |
+
|
| 1077 |
+
#define CurrentStruct sqlite3_kvvfs_methods
|
| 1078 |
+
StructBinder {
|
| 1079 |
+
M(xRead, "i(sspi)");
|
| 1080 |
+
M(xWrite, "i(sss)");
|
| 1081 |
+
M(xDelete, "i(ss)");
|
| 1082 |
+
M(nKeySize, "i");
|
| 1083 |
+
} _StructBinder;
|
| 1084 |
+
#undef CurrentStruct
|
| 1085 |
+
|
| 1086 |
+
|
| 1087 |
+
#if SQLITE_WASM_HAS_VTAB
|
| 1088 |
+
#define CurrentStruct sqlite3_vtab
|
| 1089 |
+
StructBinder {
|
| 1090 |
+
M(pModule, "p");
|
| 1091 |
+
M(nRef, "i");
|
| 1092 |
+
M(zErrMsg, "p");
|
| 1093 |
+
} _StructBinder;
|
| 1094 |
+
#undef CurrentStruct
|
| 1095 |
+
|
| 1096 |
+
#define CurrentStruct sqlite3_vtab_cursor
|
| 1097 |
+
StructBinder {
|
| 1098 |
+
M(pVtab, "p");
|
| 1099 |
+
} _StructBinder;
|
| 1100 |
+
#undef CurrentStruct
|
| 1101 |
+
|
| 1102 |
+
#define CurrentStruct sqlite3_module
|
| 1103 |
+
StructBinder {
|
| 1104 |
+
M(iVersion, "i");
|
| 1105 |
+
M(xCreate, "i(ppippp)");
|
| 1106 |
+
M(xConnect, "i(ppippp)");
|
| 1107 |
+
M(xBestIndex, "i(pp)");
|
| 1108 |
+
M(xDisconnect, "i(p)");
|
| 1109 |
+
M(xDestroy, "i(p)");
|
| 1110 |
+
M(xOpen, "i(pp)");
|
| 1111 |
+
M(xClose, "i(p)");
|
| 1112 |
+
M(xFilter, "i(pisip)");
|
| 1113 |
+
M(xNext, "i(p)");
|
| 1114 |
+
M(xEof, "i(p)");
|
| 1115 |
+
M(xColumn, "i(ppi)");
|
| 1116 |
+
M(xRowid, "i(pp)");
|
| 1117 |
+
M(xUpdate, "i(pipp)");
|
| 1118 |
+
M(xBegin, "i(p)");
|
| 1119 |
+
M(xSync, "i(p)");
|
| 1120 |
+
M(xCommit, "i(p)");
|
| 1121 |
+
M(xRollback, "i(p)");
|
| 1122 |
+
M(xFindFunction, "i(pispp)");
|
| 1123 |
+
M(xRename, "i(ps)");
|
| 1124 |
+
// ^^^ v1. v2+ follows...
|
| 1125 |
+
M(xSavepoint, "i(pi)");
|
| 1126 |
+
M(xRelease, "i(pi)");
|
| 1127 |
+
M(xRollbackTo, "i(pi)");
|
| 1128 |
+
// ^^^ v2. v3+ follows...
|
| 1129 |
+
M(xShadowName, "i(s)");
|
| 1130 |
+
} _StructBinder;
|
| 1131 |
+
#undef CurrentStruct
|
| 1132 |
+
|
| 1133 |
+
/**
|
| 1134 |
+
** Workaround: in order to map the various inner structs from
|
| 1135 |
+
** sqlite3_index_info, we have to uplift those into constructs we
|
| 1136 |
+
** can access by type name. These structs _must_ match their
|
| 1137 |
+
** in-sqlite3_index_info counterparts byte for byte.
|
| 1138 |
+
*/
|
| 1139 |
+
typedef struct {
|
| 1140 |
+
int iColumn;
|
| 1141 |
+
unsigned char op;
|
| 1142 |
+
unsigned char usable;
|
| 1143 |
+
int iTermOffset;
|
| 1144 |
+
} sqlite3_index_constraint;
|
| 1145 |
+
typedef struct {
|
| 1146 |
+
int iColumn;
|
| 1147 |
+
unsigned char desc;
|
| 1148 |
+
} sqlite3_index_orderby;
|
| 1149 |
+
typedef struct {
|
| 1150 |
+
int argvIndex;
|
| 1151 |
+
unsigned char omit;
|
| 1152 |
+
} sqlite3_index_constraint_usage;
|
| 1153 |
+
{ /* Validate that the above struct sizeof()s match
|
| 1154 |
+
** expectations. We could improve upon this by
|
| 1155 |
+
** checking the offsetof() for each member. */
|
| 1156 |
+
const sqlite3_index_info siiCheck;
|
| 1157 |
+
#define IndexSzCheck(T,M) \
|
| 1158 |
+
(sizeof(T) == sizeof(*siiCheck.M))
|
| 1159 |
+
if(!IndexSzCheck(sqlite3_index_constraint,aConstraint)
|
| 1160 |
+
|| !IndexSzCheck(sqlite3_index_orderby,aOrderBy)
|
| 1161 |
+
|| !IndexSzCheck(sqlite3_index_constraint_usage,aConstraintUsage)){
|
| 1162 |
+
assert(!"sizeof mismatch in sqlite3_index_... struct(s)");
|
| 1163 |
+
return 0;
|
| 1164 |
+
}
|
| 1165 |
+
#undef IndexSzCheck
|
| 1166 |
+
}
|
| 1167 |
+
|
| 1168 |
+
#define CurrentStruct sqlite3_index_constraint
|
| 1169 |
+
StructBinder {
|
| 1170 |
+
M(iColumn, "i");
|
| 1171 |
+
M(op, "C");
|
| 1172 |
+
M(usable, "C");
|
| 1173 |
+
M(iTermOffset, "i");
|
| 1174 |
+
} _StructBinder;
|
| 1175 |
+
#undef CurrentStruct
|
| 1176 |
+
|
| 1177 |
+
#define CurrentStruct sqlite3_index_orderby
|
| 1178 |
+
StructBinder {
|
| 1179 |
+
M(iColumn, "i");
|
| 1180 |
+
M(desc, "C");
|
| 1181 |
+
} _StructBinder;
|
| 1182 |
+
#undef CurrentStruct
|
| 1183 |
+
|
| 1184 |
+
#define CurrentStruct sqlite3_index_constraint_usage
|
| 1185 |
+
StructBinder {
|
| 1186 |
+
M(argvIndex, "i");
|
| 1187 |
+
M(omit, "C");
|
| 1188 |
+
} _StructBinder;
|
| 1189 |
+
#undef CurrentStruct
|
| 1190 |
+
|
| 1191 |
+
#define CurrentStruct sqlite3_index_info
|
| 1192 |
+
StructBinder {
|
| 1193 |
+
M(nConstraint, "i");
|
| 1194 |
+
M(aConstraint, "p");
|
| 1195 |
+
M(nOrderBy, "i");
|
| 1196 |
+
M(aOrderBy, "p");
|
| 1197 |
+
M(aConstraintUsage, "p");
|
| 1198 |
+
M(idxNum, "i");
|
| 1199 |
+
M(idxStr, "p");
|
| 1200 |
+
M(needToFreeIdxStr, "i");
|
| 1201 |
+
M(orderByConsumed, "i");
|
| 1202 |
+
M(estimatedCost, "d");
|
| 1203 |
+
M(estimatedRows, "j");
|
| 1204 |
+
M(idxFlags, "i");
|
| 1205 |
+
M(colUsed, "j");
|
| 1206 |
+
} _StructBinder;
|
| 1207 |
+
#undef CurrentStruct
|
| 1208 |
+
|
| 1209 |
+
#endif /*SQLITE_WASM_HAS_VTAB*/
|
| 1210 |
+
|
| 1211 |
+
#if SQLITE_WASM_ENABLE_C_TESTS
|
| 1212 |
+
#define CurrentStruct WasmTestStruct
|
| 1213 |
+
StructBinder {
|
| 1214 |
+
M(v4, "i");
|
| 1215 |
+
M(cstr, "s");
|
| 1216 |
+
M(ppV, "p");
|
| 1217 |
+
M(v8, "j");
|
| 1218 |
+
M(xFunc, "v(p)");
|
| 1219 |
+
} _StructBinder;
|
| 1220 |
+
#undef CurrentStruct
|
| 1221 |
+
#endif /*SQLITE_WASM_ENABLE_C_TESTS*/
|
| 1222 |
+
|
| 1223 |
+
} out( "]"/*structs*/);
|
| 1224 |
+
|
| 1225 |
+
out("}"/*top-level object*/);
|
| 1226 |
+
*zPos = 0;
|
| 1227 |
+
aBuffer[0] = '{'/*end of the race-condition workaround*/;
|
| 1228 |
+
return aBuffer;
|
| 1229 |
+
#undef StructBinder
|
| 1230 |
+
#undef StructBinder_
|
| 1231 |
+
#undef StructBinder__
|
| 1232 |
+
#undef M
|
| 1233 |
+
#undef _StructBinder
|
| 1234 |
+
#undef CloseBrace
|
| 1235 |
+
#undef out
|
| 1236 |
+
#undef outf
|
| 1237 |
+
#undef lenCheck
|
| 1238 |
+
}
|
| 1239 |
+
|
| 1240 |
+
/*
|
| 1241 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1242 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1243 |
+
**
|
| 1244 |
+
** This function invokes the xDelete method of the given VFS (or the
|
| 1245 |
+
** default VFS if pVfs is NULL), passing on the given filename. If
|
| 1246 |
+
** zName is NULL, no default VFS is found, or it has no xDelete
|
| 1247 |
+
** method, SQLITE_MISUSE is returned, else the result of the xDelete()
|
| 1248 |
+
** call is returned.
|
| 1249 |
+
*/
|
| 1250 |
+
SQLITE_WASM_EXPORT
|
| 1251 |
+
int sqlite3__wasm_vfs_unlink(sqlite3_vfs *pVfs, const char *zName){
|
| 1252 |
+
int rc = SQLITE_MISUSE /* ??? */;
|
| 1253 |
+
if( 0==pVfs && 0!=zName ) pVfs = sqlite3_vfs_find(0);
|
| 1254 |
+
if( zName && pVfs && pVfs->xDelete ){
|
| 1255 |
+
rc = pVfs->xDelete(pVfs, zName, 1);
|
| 1256 |
+
}
|
| 1257 |
+
return rc;
|
| 1258 |
+
}
|
| 1259 |
+
|
| 1260 |
+
/*
|
| 1261 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1262 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1263 |
+
**
|
| 1264 |
+
** Returns a pointer to the given DB's VFS for the given DB name,
|
| 1265 |
+
** defaulting to "main" if zDbName is 0. Returns 0 if no db with the
|
| 1266 |
+
** given name is open.
|
| 1267 |
+
*/
|
| 1268 |
+
SQLITE_WASM_EXPORT
|
| 1269 |
+
sqlite3_vfs * sqlite3__wasm_db_vfs(sqlite3 *pDb, const char *zDbName){
|
| 1270 |
+
sqlite3_vfs * pVfs = 0;
|
| 1271 |
+
sqlite3_file_control(pDb, zDbName ? zDbName : "main",
|
| 1272 |
+
SQLITE_FCNTL_VFS_POINTER, &pVfs);
|
| 1273 |
+
return pVfs;
|
| 1274 |
+
}
|
| 1275 |
+
|
| 1276 |
+
/*
|
| 1277 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1278 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1279 |
+
**
|
| 1280 |
+
** This function resets the given db pointer's database as described at
|
| 1281 |
+
**
|
| 1282 |
+
** https://sqlite.org/c3ref/c_dbconfig_defensive.html#sqlitedbconfigresetdatabase
|
| 1283 |
+
**
|
| 1284 |
+
** But beware: virtual tables destroyed that way do not have their
|
| 1285 |
+
** xDestroy() called, so will leak if they require that function for
|
| 1286 |
+
** proper cleanup.
|
| 1287 |
+
**
|
| 1288 |
+
** Returns 0 on success, an SQLITE_xxx code on error. Returns
|
| 1289 |
+
** SQLITE_MISUSE if pDb is NULL.
|
| 1290 |
+
*/
|
| 1291 |
+
SQLITE_WASM_EXPORT
|
| 1292 |
+
int sqlite3__wasm_db_reset(sqlite3 *pDb){
|
| 1293 |
+
int rc = SQLITE_MISUSE;
|
| 1294 |
+
if( pDb ){
|
| 1295 |
+
sqlite3_table_column_metadata(pDb, "main", 0, 0, 0, 0, 0, 0, 0);
|
| 1296 |
+
rc = sqlite3_db_config(pDb, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
|
| 1297 |
+
if( 0==rc ){
|
| 1298 |
+
rc = sqlite3_exec(pDb, "VACUUM", 0, 0, 0);
|
| 1299 |
+
sqlite3_db_config(pDb, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
|
| 1300 |
+
}
|
| 1301 |
+
}
|
| 1302 |
+
return rc;
|
| 1303 |
+
}
|
| 1304 |
+
|
| 1305 |
+
/*
|
| 1306 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1307 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1308 |
+
**
|
| 1309 |
+
** Uses the given database's VFS xRead to stream the db file's
|
| 1310 |
+
** contents out to the given callback. The callback gets a single
|
| 1311 |
+
** chunk of size n (its 2nd argument) on each call and must return 0
|
| 1312 |
+
** on success, non-0 on error. This function returns 0 on success,
|
| 1313 |
+
** SQLITE_NOTFOUND if no db is open, or propagates any other non-0
|
| 1314 |
+
** code from the callback. Note that this is not thread-friendly: it
|
| 1315 |
+
** expects that it will be the only thread reading the db file and
|
| 1316 |
+
** takes no measures to ensure that is the case.
|
| 1317 |
+
**
|
| 1318 |
+
** This implementation appears to work fine, but
|
| 1319 |
+
** sqlite3__wasm_db_serialize() is arguably the better way to achieve
|
| 1320 |
+
** this.
|
| 1321 |
+
*/
|
| 1322 |
+
SQLITE_WASM_EXPORT
|
| 1323 |
+
int sqlite3__wasm_db_export_chunked( sqlite3* pDb,
|
| 1324 |
+
int (*xCallback)(unsigned const char *zOut, int n) ){
|
| 1325 |
+
sqlite3_int64 nSize = 0;
|
| 1326 |
+
sqlite3_int64 nPos = 0;
|
| 1327 |
+
sqlite3_file * pFile = 0;
|
| 1328 |
+
unsigned char buf[1024 * 8];
|
| 1329 |
+
int nBuf = (int)sizeof(buf);
|
| 1330 |
+
int rc = pDb
|
| 1331 |
+
? sqlite3_file_control(pDb, "main",
|
| 1332 |
+
SQLITE_FCNTL_FILE_POINTER, &pFile)
|
| 1333 |
+
: SQLITE_NOTFOUND;
|
| 1334 |
+
if( rc ) return rc;
|
| 1335 |
+
rc = pFile->pMethods->xFileSize(pFile, &nSize);
|
| 1336 |
+
if( rc ) return rc;
|
| 1337 |
+
if(nSize % nBuf){
|
| 1338 |
+
/* DB size is not an even multiple of the buffer size. Reduce
|
| 1339 |
+
** buffer size so that we do not unduly inflate the db size
|
| 1340 |
+
** with zero-padding when exporting. */
|
| 1341 |
+
if(0 == nSize % 4096) nBuf = 4096;
|
| 1342 |
+
else if(0 == nSize % 2048) nBuf = 2048;
|
| 1343 |
+
else if(0 == nSize % 1024) nBuf = 1024;
|
| 1344 |
+
else nBuf = 512;
|
| 1345 |
+
}
|
| 1346 |
+
for( ; 0==rc && nPos<nSize; nPos += nBuf ){
|
| 1347 |
+
rc = pFile->pMethods->xRead(pFile, buf, nBuf, nPos);
|
| 1348 |
+
if( SQLITE_IOERR_SHORT_READ == rc ){
|
| 1349 |
+
rc = (nPos + nBuf) < nSize ? rc : 0/*assume EOF*/;
|
| 1350 |
+
}
|
| 1351 |
+
if( 0==rc ) rc = xCallback(buf, nBuf);
|
| 1352 |
+
}
|
| 1353 |
+
return rc;
|
| 1354 |
+
}
|
| 1355 |
+
|
| 1356 |
+
/*
|
| 1357 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1358 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1359 |
+
**
|
| 1360 |
+
** A proxy for sqlite3_serialize() which serializes the schema zSchema
|
| 1361 |
+
** of pDb, placing the serialized output in pOut and nOut. nOut may be
|
| 1362 |
+
** NULL. If zSchema is NULL then "main" is assumed. If pDb or pOut are
|
| 1363 |
+
** NULL then SQLITE_MISUSE is returned. If allocation of the
|
| 1364 |
+
** serialized copy fails, SQLITE_NOMEM is returned. On success, 0 is
|
| 1365 |
+
** returned and `*pOut` will contain a pointer to the memory unless
|
| 1366 |
+
** mFlags includes SQLITE_SERIALIZE_NOCOPY and the database has no
|
| 1367 |
+
** contiguous memory representation, in which case `*pOut` will be
|
| 1368 |
+
** NULL but 0 will be returned.
|
| 1369 |
+
**
|
| 1370 |
+
** If `*pOut` is not NULL, the caller is responsible for passing it to
|
| 1371 |
+
** sqlite3_free() to free it.
|
| 1372 |
+
*/
|
| 1373 |
+
SQLITE_WASM_EXPORT
|
| 1374 |
+
int sqlite3__wasm_db_serialize( sqlite3 *pDb, const char *zSchema,
|
| 1375 |
+
unsigned char **pOut,
|
| 1376 |
+
sqlite3_int64 *nOut, unsigned int mFlags ){
|
| 1377 |
+
unsigned char * z;
|
| 1378 |
+
if( !pDb || !pOut ) return SQLITE_MISUSE;
|
| 1379 |
+
if( nOut ) *nOut = 0;
|
| 1380 |
+
z = sqlite3_serialize(pDb, zSchema ? zSchema : "main", nOut, mFlags);
|
| 1381 |
+
if( z || (SQLITE_SERIALIZE_NOCOPY & mFlags) ){
|
| 1382 |
+
*pOut = z;
|
| 1383 |
+
return 0;
|
| 1384 |
+
}else{
|
| 1385 |
+
return SQLITE_NOMEM;
|
| 1386 |
+
}
|
| 1387 |
+
}
|
| 1388 |
+
|
| 1389 |
+
/*
|
| 1390 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1391 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1392 |
+
**
|
| 1393 |
+
** ACHTUNG: it was discovered on 2023-08-11 that, with SQLITE_DEBUG,
|
| 1394 |
+
** this function's out-of-scope use of the sqlite3_vfs/file/io_methods
|
| 1395 |
+
** APIs leads to triggering of assertions in the core library. Its use
|
| 1396 |
+
** is now deprecated and VFS-specific APIs for importing files need to
|
| 1397 |
+
** be found to replace it. sqlite3__wasm_posix_create_file() is
|
| 1398 |
+
** suitable for the "unix" family of VFSes.
|
| 1399 |
+
**
|
| 1400 |
+
** Creates a new file using the I/O API of the given VFS, containing
|
| 1401 |
+
** the given number of bytes of the given data. If the file exists, it
|
| 1402 |
+
** is truncated to the given length and populated with the given
|
| 1403 |
+
** data.
|
| 1404 |
+
**
|
| 1405 |
+
** This function exists so that we can implement the equivalent of
|
| 1406 |
+
** Emscripten's FS.createDataFile() in a VFS-agnostic way. This
|
| 1407 |
+
** functionality is intended for use in uploading database files.
|
| 1408 |
+
**
|
| 1409 |
+
** Not all VFSes support this functionality, e.g. the "kvvfs" does
|
| 1410 |
+
** not.
|
| 1411 |
+
**
|
| 1412 |
+
** If pVfs is NULL, sqlite3_vfs_find(0) is used.
|
| 1413 |
+
**
|
| 1414 |
+
** If zFile is NULL, pVfs is NULL (and sqlite3_vfs_find(0) returns
|
| 1415 |
+
** NULL), or nData is negative, SQLITE_MISUSE are returned.
|
| 1416 |
+
**
|
| 1417 |
+
** On success, it creates a new file with the given name, populated
|
| 1418 |
+
** with the fist nData bytes of pData. If pData is NULL, the file is
|
| 1419 |
+
** created and/or truncated to nData bytes.
|
| 1420 |
+
**
|
| 1421 |
+
** Whether or not directory components of zFilename are created
|
| 1422 |
+
** automatically or not is unspecified: that detail is left to the
|
| 1423 |
+
** VFS. The "opfs" VFS, for example, creates them.
|
| 1424 |
+
**
|
| 1425 |
+
** If an error happens while populating or truncating the file, the
|
| 1426 |
+
** target file will be deleted (if needed) if this function created
|
| 1427 |
+
** it. If this function did not create it, it is not deleted but may
|
| 1428 |
+
** be left in an undefined state.
|
| 1429 |
+
**
|
| 1430 |
+
** Returns 0 on success. On error, it returns a code described above
|
| 1431 |
+
** or propagates a code from one of the I/O methods.
|
| 1432 |
+
**
|
| 1433 |
+
** Design note: nData is an integer, instead of int64, for WASM
|
| 1434 |
+
** portability, so that the API can still work in builds where BigInt
|
| 1435 |
+
** support is disabled or unavailable.
|
| 1436 |
+
*/
|
| 1437 |
+
SQLITE_WASM_EXPORT
|
| 1438 |
+
int sqlite3__wasm_vfs_create_file( sqlite3_vfs *pVfs,
|
| 1439 |
+
const char *zFilename,
|
| 1440 |
+
const unsigned char * pData,
|
| 1441 |
+
int nData ){
|
| 1442 |
+
int rc;
|
| 1443 |
+
sqlite3_file *pFile = 0;
|
| 1444 |
+
sqlite3_io_methods const *pIo;
|
| 1445 |
+
const int openFlags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
|
| 1446 |
+
#if 0 && defined(SQLITE_DEBUG)
|
| 1447 |
+
| SQLITE_OPEN_MAIN_JOURNAL
|
| 1448 |
+
/* ^^^^ This is for testing a horrible workaround to avoid
|
| 1449 |
+
triggering a specific assert() in os_unix.c:unixOpen(). Please
|
| 1450 |
+
do not enable this in real builds. */
|
| 1451 |
+
#endif
|
| 1452 |
+
;
|
| 1453 |
+
int flagsOut = 0;
|
| 1454 |
+
int fileExisted = 0;
|
| 1455 |
+
int doUnlock = 0;
|
| 1456 |
+
const unsigned char *pPos = pData;
|
| 1457 |
+
const int blockSize = 512
|
| 1458 |
+
/* Because we are using pFile->pMethods->xWrite() for writing, and
|
| 1459 |
+
** it may have a buffer limit related to sqlite3's pager size, we
|
| 1460 |
+
** conservatively write in 512-byte blocks (smallest page
|
| 1461 |
+
** size). */;
|
| 1462 |
+
//fprintf(stderr, "pVfs=%p, zFilename=%s, nData=%d\n", pVfs, zFilename, nData);
|
| 1463 |
+
if( !pVfs ) pVfs = sqlite3_vfs_find(0);
|
| 1464 |
+
if( !pVfs || !zFilename || nData<0 ) return SQLITE_MISUSE;
|
| 1465 |
+
pVfs->xAccess(pVfs, zFilename, SQLITE_ACCESS_EXISTS, &fileExisted);
|
| 1466 |
+
rc = sqlite3OsOpenMalloc(pVfs, zFilename, &pFile, openFlags, &flagsOut);
|
| 1467 |
+
#if 0
|
| 1468 |
+
# define RC fprintf(stderr,"create_file(%s,%s) @%d rc=%d\n", \
|
| 1469 |
+
pVfs->zName, zFilename, __LINE__, rc);
|
| 1470 |
+
#else
|
| 1471 |
+
# define RC
|
| 1472 |
+
#endif
|
| 1473 |
+
RC;
|
| 1474 |
+
if(rc) return rc;
|
| 1475 |
+
pIo = pFile->pMethods;
|
| 1476 |
+
if( pIo->xLock ) {
|
| 1477 |
+
/* We need xLock() in order to accommodate the OPFS VFS, as it
|
| 1478 |
+
** obtains a writeable handle via the lock operation and releases
|
| 1479 |
+
** it in xUnlock(). If we don't do those here, we have to add code
|
| 1480 |
+
** to the VFS to account check whether it was locked before
|
| 1481 |
+
** xFileSize(), xTruncate(), and the like, and release the lock
|
| 1482 |
+
** only if it was unlocked when the op was started. */
|
| 1483 |
+
rc = pIo->xLock(pFile, SQLITE_LOCK_EXCLUSIVE);
|
| 1484 |
+
RC;
|
| 1485 |
+
doUnlock = 0==rc;
|
| 1486 |
+
}
|
| 1487 |
+
if( 0==rc ){
|
| 1488 |
+
rc = pIo->xTruncate(pFile, nData);
|
| 1489 |
+
RC;
|
| 1490 |
+
}
|
| 1491 |
+
if( 0==rc && 0!=pData && nData>0 ){
|
| 1492 |
+
while( 0==rc && nData>0 ){
|
| 1493 |
+
const int n = nData>=blockSize ? blockSize : nData;
|
| 1494 |
+
rc = pIo->xWrite(pFile, pPos, n, (sqlite3_int64)(pPos - pData));
|
| 1495 |
+
RC;
|
| 1496 |
+
nData -= n;
|
| 1497 |
+
pPos += n;
|
| 1498 |
+
}
|
| 1499 |
+
if( 0==rc && nData>0 ){
|
| 1500 |
+
assert( nData<blockSize );
|
| 1501 |
+
rc = pIo->xWrite(pFile, pPos, nData,
|
| 1502 |
+
(sqlite3_int64)(pPos - pData));
|
| 1503 |
+
RC;
|
| 1504 |
+
}
|
| 1505 |
+
}
|
| 1506 |
+
if( pIo->xUnlock && doUnlock!=0 ){
|
| 1507 |
+
pIo->xUnlock(pFile, SQLITE_LOCK_NONE);
|
| 1508 |
+
}
|
| 1509 |
+
pIo->xClose(pFile);
|
| 1510 |
+
if( rc!=0 && 0==fileExisted ){
|
| 1511 |
+
pVfs->xDelete(pVfs, zFilename, 1);
|
| 1512 |
+
}
|
| 1513 |
+
RC;
|
| 1514 |
+
#undef RC
|
| 1515 |
+
return rc;
|
| 1516 |
+
}
|
| 1517 |
+
|
| 1518 |
+
/**
|
| 1519 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1520 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1521 |
+
**
|
| 1522 |
+
** Creates or overwrites a file using the POSIX file API,
|
| 1523 |
+
** i.e. Emscripten's virtual filesystem. Creates or truncates
|
| 1524 |
+
** zFilename, appends pData bytes to it, and returns 0 on success or
|
| 1525 |
+
** SQLITE_IOERR on error.
|
| 1526 |
+
*/
|
| 1527 |
+
SQLITE_WASM_EXPORT
|
| 1528 |
+
int sqlite3__wasm_posix_create_file( const char *zFilename,
|
| 1529 |
+
const unsigned char * pData,
|
| 1530 |
+
int nData ){
|
| 1531 |
+
int rc;
|
| 1532 |
+
FILE * pFile = 0;
|
| 1533 |
+
int fileExisted = 0;
|
| 1534 |
+
size_t nWrote = 1;
|
| 1535 |
+
|
| 1536 |
+
if( !zFilename || nData<0 || (pData==0 && nData>0) ) return SQLITE_MISUSE;
|
| 1537 |
+
pFile = fopen(zFilename, "w");
|
| 1538 |
+
if( 0==pFile ) return SQLITE_IOERR;
|
| 1539 |
+
if( nData>0 ){
|
| 1540 |
+
nWrote = fwrite(pData, (size_t)nData, 1, pFile);
|
| 1541 |
+
}
|
| 1542 |
+
fclose(pFile);
|
| 1543 |
+
return 1==nWrote ? 0 : SQLITE_IOERR;
|
| 1544 |
+
}
|
| 1545 |
+
|
| 1546 |
+
/*
|
| 1547 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1548 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1549 |
+
**
|
| 1550 |
+
** Allocates sqlite3KvvfsMethods.nKeySize bytes from
|
| 1551 |
+
** sqlite3__wasm_pstack_alloc() and returns 0 if that allocation fails,
|
| 1552 |
+
** else it passes that string to kvstorageMakeKey() and returns a
|
| 1553 |
+
** NUL-terminated pointer to that string. It is up to the caller to
|
| 1554 |
+
** use sqlite3__wasm_pstack_restore() to free the returned pointer.
|
| 1555 |
+
*/
|
| 1556 |
+
SQLITE_WASM_EXPORT
|
| 1557 |
+
char * sqlite3__wasm_kvvfsMakeKeyOnPstack(const char *zClass,
|
| 1558 |
+
const char *zKeyIn){
|
| 1559 |
+
assert(sqlite3KvvfsMethods.nKeySize>24);
|
| 1560 |
+
char *zKeyOut =
|
| 1561 |
+
(char *)sqlite3__wasm_pstack_alloc(sqlite3KvvfsMethods.nKeySize);
|
| 1562 |
+
if(zKeyOut){
|
| 1563 |
+
kvstorageMakeKey(zClass, zKeyIn, zKeyOut);
|
| 1564 |
+
}
|
| 1565 |
+
return zKeyOut;
|
| 1566 |
+
}
|
| 1567 |
+
|
| 1568 |
+
/*
|
| 1569 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1570 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1571 |
+
**
|
| 1572 |
+
** Returns the pointer to the singleton object which holds the kvvfs
|
| 1573 |
+
** I/O methods and associated state.
|
| 1574 |
+
*/
|
| 1575 |
+
SQLITE_WASM_EXPORT
|
| 1576 |
+
sqlite3_kvvfs_methods * sqlite3__wasm_kvvfs_methods(void){
|
| 1577 |
+
return &sqlite3KvvfsMethods;
|
| 1578 |
+
}
|
| 1579 |
+
|
| 1580 |
+
#if SQLITE_WASM_HAS_VTAB
|
| 1581 |
+
/*
|
| 1582 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1583 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1584 |
+
**
|
| 1585 |
+
** This is a proxy for the variadic sqlite3_vtab_config() which passes
|
| 1586 |
+
** its argument on, or not, to sqlite3_vtab_config(), depending on the
|
| 1587 |
+
** value of its 2nd argument. Returns the result of
|
| 1588 |
+
** sqlite3_vtab_config(), or SQLITE_MISUSE if the 2nd arg is not a
|
| 1589 |
+
** valid value.
|
| 1590 |
+
*/
|
| 1591 |
+
SQLITE_WASM_EXPORT
|
| 1592 |
+
int sqlite3__wasm_vtab_config(sqlite3 *pDb, int op, int arg){
|
| 1593 |
+
switch(op){
|
| 1594 |
+
case SQLITE_VTAB_DIRECTONLY:
|
| 1595 |
+
case SQLITE_VTAB_INNOCUOUS:
|
| 1596 |
+
return sqlite3_vtab_config(pDb, op);
|
| 1597 |
+
case SQLITE_VTAB_CONSTRAINT_SUPPORT:
|
| 1598 |
+
return sqlite3_vtab_config(pDb, op, arg);
|
| 1599 |
+
default:
|
| 1600 |
+
return SQLITE_MISUSE;
|
| 1601 |
+
}
|
| 1602 |
+
}
|
| 1603 |
+
#endif /*SQLITE_WASM_HAS_VTAB*/
|
| 1604 |
+
|
| 1605 |
+
/*
|
| 1606 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1607 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1608 |
+
**
|
| 1609 |
+
** Wrapper for the variants of sqlite3_db_config() which take
|
| 1610 |
+
** (int,int*) variadic args.
|
| 1611 |
+
*/
|
| 1612 |
+
SQLITE_WASM_EXPORT
|
| 1613 |
+
int sqlite3__wasm_db_config_ip(sqlite3 *pDb, int op, int arg1, int* pArg2){
|
| 1614 |
+
switch(op){
|
| 1615 |
+
case SQLITE_DBCONFIG_ENABLE_FKEY:
|
| 1616 |
+
case SQLITE_DBCONFIG_ENABLE_TRIGGER:
|
| 1617 |
+
case SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER:
|
| 1618 |
+
case SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION:
|
| 1619 |
+
case SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE:
|
| 1620 |
+
case SQLITE_DBCONFIG_ENABLE_QPSG:
|
| 1621 |
+
case SQLITE_DBCONFIG_TRIGGER_EQP:
|
| 1622 |
+
case SQLITE_DBCONFIG_RESET_DATABASE:
|
| 1623 |
+
case SQLITE_DBCONFIG_DEFENSIVE:
|
| 1624 |
+
case SQLITE_DBCONFIG_WRITABLE_SCHEMA:
|
| 1625 |
+
case SQLITE_DBCONFIG_LEGACY_ALTER_TABLE:
|
| 1626 |
+
case SQLITE_DBCONFIG_DQS_DML:
|
| 1627 |
+
case SQLITE_DBCONFIG_DQS_DDL:
|
| 1628 |
+
case SQLITE_DBCONFIG_ENABLE_VIEW:
|
| 1629 |
+
case SQLITE_DBCONFIG_LEGACY_FILE_FORMAT:
|
| 1630 |
+
case SQLITE_DBCONFIG_TRUSTED_SCHEMA:
|
| 1631 |
+
case SQLITE_DBCONFIG_STMT_SCANSTATUS:
|
| 1632 |
+
case SQLITE_DBCONFIG_REVERSE_SCANORDER:
|
| 1633 |
+
return sqlite3_db_config(pDb, op, arg1, pArg2);
|
| 1634 |
+
default: return SQLITE_MISUSE;
|
| 1635 |
+
}
|
| 1636 |
+
}
|
| 1637 |
+
|
| 1638 |
+
/*
|
| 1639 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1640 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1641 |
+
**
|
| 1642 |
+
** Wrapper for the variants of sqlite3_db_config() which take
|
| 1643 |
+
** (void*,int,int) variadic args.
|
| 1644 |
+
*/
|
| 1645 |
+
SQLITE_WASM_EXPORT
|
| 1646 |
+
int sqlite3__wasm_db_config_pii(sqlite3 *pDb, int op, void * pArg1, int arg2, int arg3){
|
| 1647 |
+
switch(op){
|
| 1648 |
+
case SQLITE_DBCONFIG_LOOKASIDE:
|
| 1649 |
+
return sqlite3_db_config(pDb, op, pArg1, arg2, arg3);
|
| 1650 |
+
default: return SQLITE_MISUSE;
|
| 1651 |
+
}
|
| 1652 |
+
}
|
| 1653 |
+
|
| 1654 |
+
/*
|
| 1655 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1656 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1657 |
+
**
|
| 1658 |
+
** Wrapper for the variants of sqlite3_db_config() which take
|
| 1659 |
+
** (const char *) variadic args.
|
| 1660 |
+
*/
|
| 1661 |
+
SQLITE_WASM_EXPORT
|
| 1662 |
+
int sqlite3__wasm_db_config_s(sqlite3 *pDb, int op, const char *zArg){
|
| 1663 |
+
switch(op){
|
| 1664 |
+
case SQLITE_DBCONFIG_MAINDBNAME:
|
| 1665 |
+
return sqlite3_db_config(pDb, op, zArg);
|
| 1666 |
+
default: return SQLITE_MISUSE;
|
| 1667 |
+
}
|
| 1668 |
+
}
|
| 1669 |
+
|
| 1670 |
+
|
| 1671 |
+
/*
|
| 1672 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1673 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1674 |
+
**
|
| 1675 |
+
** Binding for combinations of sqlite3_config() arguments which take
|
| 1676 |
+
** a single integer argument.
|
| 1677 |
+
*/
|
| 1678 |
+
SQLITE_WASM_EXPORT
|
| 1679 |
+
int sqlite3__wasm_config_i(int op, int arg){
|
| 1680 |
+
return sqlite3_config(op, arg);
|
| 1681 |
+
}
|
| 1682 |
+
|
| 1683 |
+
/*
|
| 1684 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1685 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1686 |
+
**
|
| 1687 |
+
** Binding for combinations of sqlite3_config() arguments which take
|
| 1688 |
+
** two int arguments.
|
| 1689 |
+
*/
|
| 1690 |
+
SQLITE_WASM_EXPORT
|
| 1691 |
+
int sqlite3__wasm_config_ii(int op, int arg1, int arg2){
|
| 1692 |
+
return sqlite3_config(op, arg1, arg2);
|
| 1693 |
+
}
|
| 1694 |
+
|
| 1695 |
+
/*
|
| 1696 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1697 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1698 |
+
**
|
| 1699 |
+
** Binding for combinations of sqlite3_config() arguments which take
|
| 1700 |
+
** a single i64 argument.
|
| 1701 |
+
*/
|
| 1702 |
+
SQLITE_WASM_EXPORT
|
| 1703 |
+
int sqlite3__wasm_config_j(int op, sqlite3_int64 arg){
|
| 1704 |
+
return sqlite3_config(op, arg);
|
| 1705 |
+
}
|
| 1706 |
+
|
| 1707 |
+
/*
|
| 1708 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1709 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1710 |
+
**
|
| 1711 |
+
** If z is not NULL, returns the result of passing z to
|
| 1712 |
+
** sqlite3_mprintf()'s %Q modifier (if addQuotes is true) or %q (if
|
| 1713 |
+
** addQuotes is 0). Returns NULL if z is NULL or on OOM.
|
| 1714 |
+
*/
|
| 1715 |
+
SQLITE_WASM_EXPORT
|
| 1716 |
+
char * sqlite3__wasm_qfmt_token(char *z, int addQuotes){
|
| 1717 |
+
char * rc = 0;
|
| 1718 |
+
if( z ){
|
| 1719 |
+
rc = addQuotes
|
| 1720 |
+
? sqlite3_mprintf("%Q", z)
|
| 1721 |
+
: sqlite3_mprintf("%q", z);
|
| 1722 |
+
}
|
| 1723 |
+
return rc;
|
| 1724 |
+
}
|
| 1725 |
+
|
| 1726 |
+
#if defined(__EMSCRIPTEN__) && defined(SQLITE_ENABLE_WASMFS)
|
| 1727 |
+
#include <emscripten/console.h>
|
| 1728 |
+
#include <emscripten/wasmfs.h>
|
| 1729 |
+
|
| 1730 |
+
/*
|
| 1731 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1732 |
+
** for use by the sqlite project's own JS/WASM bindings, specifically
|
| 1733 |
+
** only when building with Emscripten's WASMFS support.
|
| 1734 |
+
**
|
| 1735 |
+
** This function should only be called if the JS side detects the
|
| 1736 |
+
** existence of the Origin-Private FileSystem (OPFS) APIs in the
|
| 1737 |
+
** client. The first time it is called, this function instantiates a
|
| 1738 |
+
** WASMFS backend impl for OPFS. On success, subsequent calls are
|
| 1739 |
+
** no-ops.
|
| 1740 |
+
**
|
| 1741 |
+
** This function may be passed a "mount point" name, which must have a
|
| 1742 |
+
** leading "/" and is currently restricted to a single path component,
|
| 1743 |
+
** e.g. "/foo" is legal but "/foo/" and "/foo/bar" are not. If it is
|
| 1744 |
+
** NULL or empty, it defaults to "/opfs".
|
| 1745 |
+
**
|
| 1746 |
+
** Returns 0 on success, SQLITE_NOMEM if instantiation of the backend
|
| 1747 |
+
** object fails, SQLITE_IOERR if mkdir() of the zMountPoint dir in
|
| 1748 |
+
** the virtual FS fails. In builds compiled without SQLITE_ENABLE_WASMFS
|
| 1749 |
+
** defined, SQLITE_NOTFOUND is returned without side effects.
|
| 1750 |
+
*/
|
| 1751 |
+
SQLITE_WASM_EXPORT
|
| 1752 |
+
int sqlite3__wasm_init_wasmfs(const char *zMountPoint){
|
| 1753 |
+
static backend_t pOpfs = 0;
|
| 1754 |
+
if( !zMountPoint || !*zMountPoint ) zMountPoint = "/opfs";
|
| 1755 |
+
if( !pOpfs ){
|
| 1756 |
+
pOpfs = wasmfs_create_opfs_backend();
|
| 1757 |
+
}
|
| 1758 |
+
/** It's not enough to instantiate the backend. We have to create a
|
| 1759 |
+
mountpoint in the VFS and attach the backend to it. */
|
| 1760 |
+
if( pOpfs && 0!=access(zMountPoint, F_OK) ){
|
| 1761 |
+
/* Note that this check and is not robust but it will
|
| 1762 |
+
hypothetically suffice for the transient wasm-based virtual
|
| 1763 |
+
filesystem we're currently running in. */
|
| 1764 |
+
const int rc = wasmfs_create_directory(zMountPoint, 0777, pOpfs);
|
| 1765 |
+
/*emscripten_console_logf("OPFS mkdir(%s) rc=%d", zMountPoint, rc);*/
|
| 1766 |
+
if(rc) return SQLITE_IOERR;
|
| 1767 |
+
}
|
| 1768 |
+
return pOpfs ? 0 : SQLITE_NOMEM;
|
| 1769 |
+
}
|
| 1770 |
+
#else
|
| 1771 |
+
SQLITE_WASM_EXPORT
|
| 1772 |
+
int sqlite3__wasm_init_wasmfs(const char *zUnused){
|
| 1773 |
+
//emscripten_console_warn("WASMFS OPFS is not compiled in.");
|
| 1774 |
+
if(zUnused){/*unused*/}
|
| 1775 |
+
return SQLITE_NOTFOUND;
|
| 1776 |
+
}
|
| 1777 |
+
#endif /* __EMSCRIPTEN__ && SQLITE_ENABLE_WASMFS */
|
| 1778 |
+
|
| 1779 |
+
#if SQLITE_WASM_ENABLE_C_TESTS
|
| 1780 |
+
|
| 1781 |
+
SQLITE_WASM_EXPORT
|
| 1782 |
+
int sqlite3__wasm_test_intptr(int * p){
|
| 1783 |
+
return *p = *p * 2;
|
| 1784 |
+
}
|
| 1785 |
+
|
| 1786 |
+
SQLITE_WASM_EXPORT
|
| 1787 |
+
void * sqlite3__wasm_test_voidptr(void * p){
|
| 1788 |
+
return p;
|
| 1789 |
+
}
|
| 1790 |
+
|
| 1791 |
+
SQLITE_WASM_EXPORT
|
| 1792 |
+
int64_t sqlite3__wasm_test_int64_max(void){
|
| 1793 |
+
return (int64_t)0x7fffffffffffffff;
|
| 1794 |
+
}
|
| 1795 |
+
|
| 1796 |
+
SQLITE_WASM_EXPORT
|
| 1797 |
+
int64_t sqlite3__wasm_test_int64_min(void){
|
| 1798 |
+
return ~sqlite3__wasm_test_int64_max();
|
| 1799 |
+
}
|
| 1800 |
+
|
| 1801 |
+
SQLITE_WASM_EXPORT
|
| 1802 |
+
int64_t sqlite3__wasm_test_int64_times2(int64_t x){
|
| 1803 |
+
return x * 2;
|
| 1804 |
+
}
|
| 1805 |
+
|
| 1806 |
+
SQLITE_WASM_EXPORT
|
| 1807 |
+
void sqlite3__wasm_test_int64_minmax(int64_t * min, int64_t *max){
|
| 1808 |
+
*max = sqlite3__wasm_test_int64_max();
|
| 1809 |
+
*min = sqlite3__wasm_test_int64_min();
|
| 1810 |
+
/*printf("minmax: min=%lld, max=%lld\n", *min, *max);*/
|
| 1811 |
+
}
|
| 1812 |
+
|
| 1813 |
+
SQLITE_WASM_EXPORT
|
| 1814 |
+
int64_t sqlite3__wasm_test_int64ptr(int64_t * p){
|
| 1815 |
+
/*printf("sqlite3__wasm_test_int64ptr( @%lld = 0x%llx )\n", (int64_t)p, *p);*/
|
| 1816 |
+
return *p = *p * 2;
|
| 1817 |
+
}
|
| 1818 |
+
|
| 1819 |
+
SQLITE_WASM_EXPORT
|
| 1820 |
+
void sqlite3__wasm_test_stack_overflow(int recurse){
|
| 1821 |
+
if(recurse) sqlite3__wasm_test_stack_overflow(recurse);
|
| 1822 |
+
}
|
| 1823 |
+
|
| 1824 |
+
/* For testing the 'string:dealloc' whwasmutil.xWrap() conversion. */
|
| 1825 |
+
SQLITE_WASM_EXPORT
|
| 1826 |
+
char * sqlite3__wasm_test_str_hello(int fail){
|
| 1827 |
+
char * s = fail ? 0 : (char *)sqlite3_malloc(6);
|
| 1828 |
+
if(s){
|
| 1829 |
+
memcpy(s, "hello", 5);
|
| 1830 |
+
s[5] = 0;
|
| 1831 |
+
}
|
| 1832 |
+
return s;
|
| 1833 |
+
}
|
| 1834 |
+
|
| 1835 |
+
/*
|
| 1836 |
+
** For testing using SQLTester scripts.
|
| 1837 |
+
**
|
| 1838 |
+
** Return non-zero if string z matches glob pattern zGlob and zero if the
|
| 1839 |
+
** pattern does not match.
|
| 1840 |
+
**
|
| 1841 |
+
** To repeat:
|
| 1842 |
+
**
|
| 1843 |
+
** zero == no match
|
| 1844 |
+
** non-zero == match
|
| 1845 |
+
**
|
| 1846 |
+
** Globbing rules:
|
| 1847 |
+
**
|
| 1848 |
+
** '*' Matches any sequence of zero or more characters.
|
| 1849 |
+
**
|
| 1850 |
+
** '?' Matches exactly one character.
|
| 1851 |
+
**
|
| 1852 |
+
** [...] Matches one character from the enclosed list of
|
| 1853 |
+
** characters.
|
| 1854 |
+
**
|
| 1855 |
+
** [^...] Matches one character not in the enclosed list.
|
| 1856 |
+
**
|
| 1857 |
+
** '#' Matches any sequence of one or more digits with an
|
| 1858 |
+
** optional + or - sign in front, or a hexadecimal
|
| 1859 |
+
** literal of the form 0x...
|
| 1860 |
+
*/
|
| 1861 |
+
static int sqlite3__wasm_SQLTester_strnotglob(const char *zGlob, const char *z){
|
| 1862 |
+
int c, c2;
|
| 1863 |
+
int invert;
|
| 1864 |
+
int seen;
|
| 1865 |
+
typedef int (*recurse_f)(const char *,const char *);
|
| 1866 |
+
static const recurse_f recurse = sqlite3__wasm_SQLTester_strnotglob;
|
| 1867 |
+
|
| 1868 |
+
while( (c = (*(zGlob++)))!=0 ){
|
| 1869 |
+
if( c=='*' ){
|
| 1870 |
+
while( (c=(*(zGlob++))) == '*' || c=='?' ){
|
| 1871 |
+
if( c=='?' && (*(z++))==0 ) return 0;
|
| 1872 |
+
}
|
| 1873 |
+
if( c==0 ){
|
| 1874 |
+
return 1;
|
| 1875 |
+
}else if( c=='[' ){
|
| 1876 |
+
while( *z && recurse(zGlob-1,z)==0 ){
|
| 1877 |
+
z++;
|
| 1878 |
+
}
|
| 1879 |
+
return (*z)!=0;
|
| 1880 |
+
}
|
| 1881 |
+
while( (c2 = (*(z++)))!=0 ){
|
| 1882 |
+
while( c2!=c ){
|
| 1883 |
+
c2 = *(z++);
|
| 1884 |
+
if( c2==0 ) return 0;
|
| 1885 |
+
}
|
| 1886 |
+
if( recurse(zGlob,z) ) return 1;
|
| 1887 |
+
}
|
| 1888 |
+
return 0;
|
| 1889 |
+
}else if( c=='?' ){
|
| 1890 |
+
if( (*(z++))==0 ) return 0;
|
| 1891 |
+
}else if( c=='[' ){
|
| 1892 |
+
int prior_c = 0;
|
| 1893 |
+
seen = 0;
|
| 1894 |
+
invert = 0;
|
| 1895 |
+
c = *(z++);
|
| 1896 |
+
if( c==0 ) return 0;
|
| 1897 |
+
c2 = *(zGlob++);
|
| 1898 |
+
if( c2=='^' ){
|
| 1899 |
+
invert = 1;
|
| 1900 |
+
c2 = *(zGlob++);
|
| 1901 |
+
}
|
| 1902 |
+
if( c2==']' ){
|
| 1903 |
+
if( c==']' ) seen = 1;
|
| 1904 |
+
c2 = *(zGlob++);
|
| 1905 |
+
}
|
| 1906 |
+
while( c2 && c2!=']' ){
|
| 1907 |
+
if( c2=='-' && zGlob[0]!=']' && zGlob[0]!=0 && prior_c>0 ){
|
| 1908 |
+
c2 = *(zGlob++);
|
| 1909 |
+
if( c>=prior_c && c<=c2 ) seen = 1;
|
| 1910 |
+
prior_c = 0;
|
| 1911 |
+
}else{
|
| 1912 |
+
if( c==c2 ){
|
| 1913 |
+
seen = 1;
|
| 1914 |
+
}
|
| 1915 |
+
prior_c = c2;
|
| 1916 |
+
}
|
| 1917 |
+
c2 = *(zGlob++);
|
| 1918 |
+
}
|
| 1919 |
+
if( c2==0 || (seen ^ invert)==0 ) return 0;
|
| 1920 |
+
}else if( c=='#' ){
|
| 1921 |
+
if( z[0]=='0'
|
| 1922 |
+
&& (z[1]=='x' || z[1]=='X')
|
| 1923 |
+
&& sqlite3Isxdigit(z[2])
|
| 1924 |
+
){
|
| 1925 |
+
z += 3;
|
| 1926 |
+
while( sqlite3Isxdigit(z[0]) ){ z++; }
|
| 1927 |
+
}else{
|
| 1928 |
+
if( (z[0]=='-' || z[0]=='+') && sqlite3Isdigit(z[1]) ) z++;
|
| 1929 |
+
if( !sqlite3Isdigit(z[0]) ) return 0;
|
| 1930 |
+
z++;
|
| 1931 |
+
while( sqlite3Isdigit(z[0]) ){ z++; }
|
| 1932 |
+
}
|
| 1933 |
+
}else{
|
| 1934 |
+
if( c!=(*(z++)) ) return 0;
|
| 1935 |
+
}
|
| 1936 |
+
}
|
| 1937 |
+
return *z==0;
|
| 1938 |
+
}
|
| 1939 |
+
|
| 1940 |
+
SQLITE_WASM_EXPORT
|
| 1941 |
+
int sqlite3__wasm_SQLTester_strglob(const char *zGlob, const char *z){
|
| 1942 |
+
return !sqlite3__wasm_SQLTester_strnotglob(zGlob, z);
|
| 1943 |
+
}
|
| 1944 |
+
|
| 1945 |
+
#endif /* SQLITE_WASM_ENABLE_C_TESTS */
|
| 1946 |
+
|
| 1947 |
+
#undef SQLITE_WASM_EXPORT
|
| 1948 |
+
#undef SQLITE_WASM_HAS_VTAB
|
| 1949 |
+
#undef SQLITE_WASM_BARE_BONES
|
| 1950 |
+
#undef SQLITE_WASM_ENABLE_C_TESTS
|
local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/fiddle/fiddle-worker.js
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
2022-05-20
|
| 3 |
+
|
| 4 |
+
The author disclaims copyright to this source code. In place of a
|
| 5 |
+
legal notice, here is a blessing:
|
| 6 |
+
|
| 7 |
+
* May you do good and not evil.
|
| 8 |
+
* May you find forgiveness for yourself and forgive others.
|
| 9 |
+
* May you share freely, never taking more than you give.
|
| 10 |
+
|
| 11 |
+
***********************************************************************
|
| 12 |
+
|
| 13 |
+
This is the JS Worker file for the sqlite3 fiddle app. It loads the
|
| 14 |
+
sqlite3 wasm module and offers access to the db via the Worker
|
| 15 |
+
message-passing interface.
|
| 16 |
+
|
| 17 |
+
Forewarning: this API is still very much Under Construction and
|
| 18 |
+
subject to any number of changes as experience reveals what those
|
| 19 |
+
need to be.
|
| 20 |
+
|
| 21 |
+
Because we can have only a single message handler, as opposed to an
|
| 22 |
+
arbitrary number of discrete event listeners like with DOM elements,
|
| 23 |
+
we have to define a lower-level message API. Messages abstractly
|
| 24 |
+
look like:
|
| 25 |
+
|
| 26 |
+
{ type: string, data: type-specific value }
|
| 27 |
+
|
| 28 |
+
Where 'type' is used for dispatching and 'data' is a
|
| 29 |
+
'type'-dependent value.
|
| 30 |
+
|
| 31 |
+
The 'type' values expected by each side of the main/worker
|
| 32 |
+
connection vary. The types are described below but subject to
|
| 33 |
+
change at any time as this experiment evolves.
|
| 34 |
+
|
| 35 |
+
Workers-to-Main types
|
| 36 |
+
|
| 37 |
+
- stdout, stderr: indicate stdout/stderr output from the wasm
|
| 38 |
+
layer. The data property is the string of the output, noting
|
| 39 |
+
that the emscripten binding emits these one line at a time. Thus,
|
| 40 |
+
if a C-side puts() emits multiple lines in a single call, the JS
|
| 41 |
+
side will see that as multiple calls. Example:
|
| 42 |
+
|
| 43 |
+
{type:'stdout', data: 'Hi, world.'}
|
| 44 |
+
|
| 45 |
+
- module: Status text. This is intended to alert the main thread
|
| 46 |
+
about module loading status so that, e.g., the main thread can
|
| 47 |
+
update a progress widget and DTRT when the module is finished
|
| 48 |
+
loading and available for work. Status messages come in the form
|
| 49 |
+
|
| 50 |
+
{type:'module', data:{
|
| 51 |
+
type:'status',
|
| 52 |
+
data: {text:string|null, step:1-based-integer}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
with an incrementing step value for each subsequent message. When
|
| 56 |
+
the module loading is complete, a message with a text value of
|
| 57 |
+
null is posted.
|
| 58 |
+
|
| 59 |
+
- working: data='start'|'end'. Indicates that work is about to be
|
| 60 |
+
sent to the module or has just completed. This can be used, e.g.,
|
| 61 |
+
to disable UI elements which should not be activated while work
|
| 62 |
+
is pending. Example:
|
| 63 |
+
|
| 64 |
+
{type:'working', data:'start'}
|
| 65 |
+
|
| 66 |
+
Main-to-Worker types:
|
| 67 |
+
|
| 68 |
+
- shellExec: data=text to execute as if it had been entered in the
|
| 69 |
+
sqlite3 CLI shell app (as opposed to sqlite3_exec()). This event
|
| 70 |
+
causes the worker to emit a 'working' event (data='start') before
|
| 71 |
+
it starts and a 'working' event (data='end') when it finished. If
|
| 72 |
+
called while work is currently being executed it emits stderr
|
| 73 |
+
message instead of doing actual work, as the underlying db cannot
|
| 74 |
+
handle concurrent tasks. Example:
|
| 75 |
+
|
| 76 |
+
{type:'shellExec', data: 'select * from sqlite_master'}
|
| 77 |
+
|
| 78 |
+
- More TBD as the higher-level db layer develops.
|
| 79 |
+
*/
|
| 80 |
+
|
| 81 |
+
/*
|
| 82 |
+
Apparent browser(s) bug: console messages emitted may be duplicated
|
| 83 |
+
in the console, even though they're provably only run once. See:
|
| 84 |
+
|
| 85 |
+
https://stackoverflow.com/questions/49659464
|
| 86 |
+
|
| 87 |
+
Noting that it happens in Firefox as well as Chrome. Harmless but
|
| 88 |
+
annoying.
|
| 89 |
+
*/
|
| 90 |
+
"use strict";
|
| 91 |
+
(function(){
|
| 92 |
+
/**
|
| 93 |
+
Posts a message in the form {type,data}. If passed more than 2
|
| 94 |
+
args, the 3rd must be an array of "transferable" values to pass
|
| 95 |
+
as the 2nd argument to postMessage(). */
|
| 96 |
+
const wMsg =
|
| 97 |
+
(type,data,transferables)=>{
|
| 98 |
+
postMessage({type, data}, transferables || []);
|
| 99 |
+
};
|
| 100 |
+
const stdout = (...args)=>wMsg('stdout', args);
|
| 101 |
+
const stderr = (...args)=>wMsg('stderr', args);
|
| 102 |
+
const toss = (...args)=>{
|
| 103 |
+
throw new Error(args.join(' '));
|
| 104 |
+
};
|
| 105 |
+
const fixmeOPFS = "(FIXME: won't work with OPFS-over-sqlite3_vfs.)";
|
| 106 |
+
let sqlite3 /* gets assigned when the wasm module is loaded */;
|
| 107 |
+
|
| 108 |
+
self.onerror = function(/*message, source, lineno, colno, error*/) {
|
| 109 |
+
const err = arguments[4];
|
| 110 |
+
if(err && 'ExitStatus'==err.name){
|
| 111 |
+
/* This is relevant for the sqlite3 shell binding but not the
|
| 112 |
+
lower-level binding. */
|
| 113 |
+
fiddleModule.isDead = true;
|
| 114 |
+
stderr("FATAL ERROR:", err.message);
|
| 115 |
+
stderr("Restarting the app requires reloading the page.");
|
| 116 |
+
wMsg('error', err);
|
| 117 |
+
}
|
| 118 |
+
console.error(err);
|
| 119 |
+
fiddleModule.setStatus('Exception thrown, see JavaScript console: '+err);
|
| 120 |
+
};
|
| 121 |
+
|
| 122 |
+
const Sqlite3Shell = {
|
| 123 |
+
/** Returns the name of the currently-opened db. */
|
| 124 |
+
dbFilename: function f(){
|
| 125 |
+
if(!f._) f._ = sqlite3.wasm.xWrap('fiddle_db_filename', "string", ['string']);
|
| 126 |
+
return f._(0);
|
| 127 |
+
},
|
| 128 |
+
dbHandle: function f(){
|
| 129 |
+
if(!f._) f._ = sqlite3.wasm.xWrap("fiddle_db_handle", "sqlite3*");
|
| 130 |
+
return f._();
|
| 131 |
+
},
|
| 132 |
+
dbIsOpfs: function f(){
|
| 133 |
+
return sqlite3.opfs && sqlite3.capi.sqlite3_js_db_uses_vfs(
|
| 134 |
+
this.dbHandle(), "opfs"
|
| 135 |
+
);
|
| 136 |
+
},
|
| 137 |
+
runMain: function f(){
|
| 138 |
+
if(f.argv) return 0===f.argv.rc;
|
| 139 |
+
const dbName = "/fiddle.sqlite3";
|
| 140 |
+
f.argv = [
|
| 141 |
+
'sqlite3-fiddle.wasm',
|
| 142 |
+
'-bail', '-safe',
|
| 143 |
+
dbName
|
| 144 |
+
/* Reminder: because of how we run fiddle, we have to ensure
|
| 145 |
+
that any argv strings passed to its main() are valid until
|
| 146 |
+
the wasm environment shuts down. */
|
| 147 |
+
];
|
| 148 |
+
const capi = sqlite3.capi, wasm = sqlite3.wasm;
|
| 149 |
+
/* We need to call sqlite3_shutdown() in order to avoid numerous
|
| 150 |
+
legitimate warnings from the shell about it being initialized
|
| 151 |
+
after sqlite3_initialize() has been called. This means,
|
| 152 |
+
however, that any initialization done by the JS code may need
|
| 153 |
+
to be re-done (e.g. re-registration of dynamically-loaded
|
| 154 |
+
VFSes). We need a more generic approach to running such
|
| 155 |
+
init-level code. */
|
| 156 |
+
capi.sqlite3_shutdown();
|
| 157 |
+
f.argv.pArgv = wasm.allocMainArgv(f.argv);
|
| 158 |
+
f.argv.rc = wasm.exports.fiddle_main(
|
| 159 |
+
f.argv.length, f.argv.pArgv
|
| 160 |
+
);
|
| 161 |
+
if(f.argv.rc){
|
| 162 |
+
stderr("Fatal error initializing sqlite3 shell.");
|
| 163 |
+
fiddleModule.isDead = true;
|
| 164 |
+
return false;
|
| 165 |
+
}
|
| 166 |
+
stdout("SQLite version", capi.sqlite3_libversion(),
|
| 167 |
+
capi.sqlite3_sourceid().substr(0,19));
|
| 168 |
+
stdout('Welcome to the "fiddle" shell.');
|
| 169 |
+
if(capi.sqlite3_vfs_find("opfs")){
|
| 170 |
+
stdout("\nOPFS is available. To open a persistent db, use:\n\n",
|
| 171 |
+
" .open file:name?vfs=opfs\n\nbut note that some",
|
| 172 |
+
"features (e.g. upload) do not yet work with OPFS.");
|
| 173 |
+
}
|
| 174 |
+
stdout('\nEnter ".help" for usage hints.');
|
| 175 |
+
this.exec([ // initialization commands...
|
| 176 |
+
'.nullvalue NULL',
|
| 177 |
+
'.headers on'
|
| 178 |
+
].join('\n'));
|
| 179 |
+
return true;
|
| 180 |
+
},
|
| 181 |
+
/**
|
| 182 |
+
Runs the given text through the shell as if it had been typed
|
| 183 |
+
in by a user. Fires a working/start event before it starts and
|
| 184 |
+
working/end event when it finishes.
|
| 185 |
+
*/
|
| 186 |
+
exec: function f(sql){
|
| 187 |
+
if(!f._){
|
| 188 |
+
if(!this.runMain()) return;
|
| 189 |
+
f._ = sqlite3.wasm.xWrap('fiddle_exec', null, ['string']);
|
| 190 |
+
}
|
| 191 |
+
if(fiddleModule.isDead){
|
| 192 |
+
stderr("shell module has exit()ed. Cannot run SQL.");
|
| 193 |
+
return;
|
| 194 |
+
}
|
| 195 |
+
wMsg('working','start');
|
| 196 |
+
try {
|
| 197 |
+
if(f._running){
|
| 198 |
+
stderr('Cannot run multiple commands concurrently.');
|
| 199 |
+
}else if(sql){
|
| 200 |
+
if(Array.isArray(sql)) sql = sql.join('');
|
| 201 |
+
f._running = true;
|
| 202 |
+
f._(sql);
|
| 203 |
+
}
|
| 204 |
+
}finally{
|
| 205 |
+
delete f._running;
|
| 206 |
+
wMsg('working','end');
|
| 207 |
+
}
|
| 208 |
+
},
|
| 209 |
+
resetDb: function f(){
|
| 210 |
+
if(!f._) f._ = sqlite3.wasm.xWrap('fiddle_reset_db', null);
|
| 211 |
+
stdout("Resetting database.");
|
| 212 |
+
f._();
|
| 213 |
+
stdout("Reset",this.dbFilename());
|
| 214 |
+
},
|
| 215 |
+
/* Interrupt can't work: this Worker is tied up working, so won't get the
|
| 216 |
+
interrupt event which would be needed to perform the interrupt. */
|
| 217 |
+
interrupt: function f(){
|
| 218 |
+
if(!f._) f._ = sqlite3.wasm.xWrap('fiddle_interrupt', null);
|
| 219 |
+
stdout("Requesting interrupt.");
|
| 220 |
+
f._();
|
| 221 |
+
}
|
| 222 |
+
};
|
| 223 |
+
|
| 224 |
+
self.onmessage = function f(ev){
|
| 225 |
+
ev = ev.data;
|
| 226 |
+
if(!f.cache){
|
| 227 |
+
f.cache = {
|
| 228 |
+
prevFilename: null
|
| 229 |
+
};
|
| 230 |
+
}
|
| 231 |
+
//console.debug("worker: onmessage.data",ev);
|
| 232 |
+
switch(ev.type){
|
| 233 |
+
case 'shellExec': Sqlite3Shell.exec(ev.data); return;
|
| 234 |
+
case 'db-reset': Sqlite3Shell.resetDb(); return;
|
| 235 |
+
case 'interrupt': Sqlite3Shell.interrupt(); return;
|
| 236 |
+
/** Triggers the export of the current db. Fires an
|
| 237 |
+
event in the form:
|
| 238 |
+
|
| 239 |
+
{type:'db-export',
|
| 240 |
+
data:{
|
| 241 |
+
filename: name of db,
|
| 242 |
+
buffer: contents of the db file (Uint8Array),
|
| 243 |
+
error: on error, a message string and no buffer property.
|
| 244 |
+
}
|
| 245 |
+
}
|
| 246 |
+
*/
|
| 247 |
+
case 'db-export': {
|
| 248 |
+
const fn = Sqlite3Shell.dbFilename();
|
| 249 |
+
stdout("Exporting",fn+".");
|
| 250 |
+
const fn2 = fn ? fn.split(/[/\\]/).pop() : null;
|
| 251 |
+
try{
|
| 252 |
+
if(!fn2) toss("DB appears to be closed.");
|
| 253 |
+
const buffer = sqlite3.capi.sqlite3_js_db_export(
|
| 254 |
+
Sqlite3Shell.dbHandle()
|
| 255 |
+
);
|
| 256 |
+
wMsg('db-export',{filename: fn2, buffer: buffer.buffer}, [buffer.buffer]);
|
| 257 |
+
}catch(e){
|
| 258 |
+
console.error("Export failed:",e);
|
| 259 |
+
/* Post a failure message so that UI elements disabled
|
| 260 |
+
during the export can be re-enabled. */
|
| 261 |
+
wMsg('db-export',{
|
| 262 |
+
filename: fn,
|
| 263 |
+
error: e.message
|
| 264 |
+
});
|
| 265 |
+
}
|
| 266 |
+
return;
|
| 267 |
+
}
|
| 268 |
+
case 'open': {
|
| 269 |
+
/* Expects: {
|
| 270 |
+
buffer: ArrayBuffer | Uint8Array,
|
| 271 |
+
filename: the filename for the db. Any dir part is
|
| 272 |
+
stripped.
|
| 273 |
+
}
|
| 274 |
+
*/
|
| 275 |
+
const opt = ev.data;
|
| 276 |
+
let buffer = opt.buffer;
|
| 277 |
+
stderr('open():',fixmeOPFS);
|
| 278 |
+
if(buffer instanceof ArrayBuffer){
|
| 279 |
+
buffer = new Uint8Array(buffer);
|
| 280 |
+
}else if(!(buffer instanceof Uint8Array)){
|
| 281 |
+
stderr("'open' expects {buffer:Uint8Array} containing an uploaded db.");
|
| 282 |
+
return;
|
| 283 |
+
}
|
| 284 |
+
const fn = (
|
| 285 |
+
opt.filename
|
| 286 |
+
? opt.filename.split(/[/\\]/).pop().replace('"','_')
|
| 287 |
+
: ("db-"+((Math.random() * 10000000) | 0)+
|
| 288 |
+
"-"+((Math.random() * 10000000) | 0)+".sqlite3")
|
| 289 |
+
);
|
| 290 |
+
try {
|
| 291 |
+
/* We cannot delete the existing db file until the new one
|
| 292 |
+
is installed, which means that we risk overflowing our
|
| 293 |
+
quota (if any) by having both the previous and current
|
| 294 |
+
db briefly installed in the virtual filesystem. */
|
| 295 |
+
const fnAbs = '/'+fn;
|
| 296 |
+
const oldName = Sqlite3Shell.dbFilename();
|
| 297 |
+
if(oldName && oldName===fnAbs){
|
| 298 |
+
/* We cannot create the replacement file while the current file
|
| 299 |
+
is opened, nor does the shell have a .close command, so we
|
| 300 |
+
must temporarily switch to another db... */
|
| 301 |
+
Sqlite3Shell.exec('.open :memory:');
|
| 302 |
+
fiddleModule.FS.unlink(fnAbs);
|
| 303 |
+
}
|
| 304 |
+
fiddleModule.FS.createDataFile("/", fn, buffer, true, true);
|
| 305 |
+
Sqlite3Shell.exec('.open "'+fnAbs+'"');
|
| 306 |
+
if(oldName && oldName!==fnAbs){
|
| 307 |
+
try{fiddleModule.fsUnlink(oldName)}
|
| 308 |
+
catch(e){/*ignored*/}
|
| 309 |
+
}
|
| 310 |
+
stdout("Replaced DB with",fn+".");
|
| 311 |
+
}catch(e){
|
| 312 |
+
stderr("Error installing db",fn+":",e.message);
|
| 313 |
+
}
|
| 314 |
+
return;
|
| 315 |
+
}
|
| 316 |
+
};
|
| 317 |
+
console.warn("Unknown fiddle-worker message type:",ev);
|
| 318 |
+
};
|
| 319 |
+
|
| 320 |
+
/**
|
| 321 |
+
emscripten module for use with build mode -sMODULARIZE.
|
| 322 |
+
*/
|
| 323 |
+
const fiddleModule = {
|
| 324 |
+
print: stdout,
|
| 325 |
+
printErr: stderr,
|
| 326 |
+
/**
|
| 327 |
+
Intercepts status updates from the emscripting module init
|
| 328 |
+
and fires worker events with a type of 'status' and a
|
| 329 |
+
payload of:
|
| 330 |
+
|
| 331 |
+
{
|
| 332 |
+
text: string | null, // null at end of load process
|
| 333 |
+
step: integer // starts at 1, increments 1 per call
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
We have no way of knowing in advance how many steps will
|
| 337 |
+
be processed/posted, so creating a "percentage done" view is
|
| 338 |
+
not really practical. One can be approximated by giving it a
|
| 339 |
+
current value of message.step and max value of message.step+1,
|
| 340 |
+
though.
|
| 341 |
+
|
| 342 |
+
When work is finished, a message with a text value of null is
|
| 343 |
+
submitted.
|
| 344 |
+
|
| 345 |
+
After a message with text==null is posted, the module may later
|
| 346 |
+
post messages about fatal problems, e.g. an exit() being
|
| 347 |
+
triggered, so it is recommended that UI elements for posting
|
| 348 |
+
status messages not be outright removed from the DOM when
|
| 349 |
+
text==null, and that they instead be hidden until/unless
|
| 350 |
+
text!=null.
|
| 351 |
+
*/
|
| 352 |
+
setStatus: function f(text){
|
| 353 |
+
if(!f.last) f.last = { step: 0, text: '' };
|
| 354 |
+
else if(text === f.last.text) return;
|
| 355 |
+
f.last.text = text;
|
| 356 |
+
wMsg('module',{
|
| 357 |
+
type:'status',
|
| 358 |
+
data:{step: ++f.last.step, text: text||null}
|
| 359 |
+
});
|
| 360 |
+
}
|
| 361 |
+
};
|
| 362 |
+
|
| 363 |
+
importScripts('fiddle-module.js'+self.location.search);
|
| 364 |
+
/**
|
| 365 |
+
initFiddleModule() is installed via fiddle-module.js due to
|
| 366 |
+
building with:
|
| 367 |
+
|
| 368 |
+
emcc ... -sMODULARIZE=1 -sEXPORT_NAME=initFiddleModule
|
| 369 |
+
*/
|
| 370 |
+
sqlite3InitModule(fiddleModule).then((_sqlite3)=>{
|
| 371 |
+
sqlite3 = _sqlite3;
|
| 372 |
+
console.warn("Installing sqlite3 module globally (in Worker)",
|
| 373 |
+
"for use in the dev console.", sqlite3);
|
| 374 |
+
globalThis.sqlite3 = sqlite3;
|
| 375 |
+
const dbVfs = sqlite3.wasm.xWrap('fiddle_db_vfs', "*", ['string']);
|
| 376 |
+
fiddleModule.fsUnlink = (fn)=>fiddleModule.FS.unlink(fn);
|
| 377 |
+
wMsg('fiddle-ready');
|
| 378 |
+
}).catch(e=>{
|
| 379 |
+
console.error("Fiddle worker init failed:",e);
|
| 380 |
+
});
|
| 381 |
+
})();
|
local-test-sqlite3-delta-02/afc-sqlite3/ext/wasm/jaccwabyt/jaccwabyt.js
ADDED
|
@@ -0,0 +1,696 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
2022-06-30
|
| 3 |
+
|
| 4 |
+
The author disclaims copyright to this source code. In place of a
|
| 5 |
+
legal notice, here is a blessing:
|
| 6 |
+
|
| 7 |
+
* May you do good and not evil.
|
| 8 |
+
* May you find forgiveness for yourself and forgive others.
|
| 9 |
+
* May you share freely, never taking more than you give.
|
| 10 |
+
|
| 11 |
+
***********************************************************************
|
| 12 |
+
|
| 13 |
+
The Jaccwabyt API is documented in detail in an external file,
|
| 14 |
+
_possibly_ called jaccwabyt.md in the same directory as this file.
|
| 15 |
+
|
| 16 |
+
Project homes:
|
| 17 |
+
- https://fossil.wanderinghorse.net/r/jaccwabyt
|
| 18 |
+
- https://sqlite.org/src/dir/ext/wasm/jaccwabyt
|
| 19 |
+
|
| 20 |
+
*/
|
| 21 |
+
'use strict';
|
| 22 |
+
globalThis.Jaccwabyt = function StructBinderFactory(config){
|
| 23 |
+
/* ^^^^ it is recommended that clients move that object into wherever
|
| 24 |
+
they'd like to have it and delete the self-held copy ("self" being
|
| 25 |
+
the global window or worker object). This API does not require the
|
| 26 |
+
global reference - it is simply installed as a convenience for
|
| 27 |
+
connecting these bits to other co-developed code before it gets
|
| 28 |
+
removed from the global namespace.
|
| 29 |
+
*/
|
| 30 |
+
|
| 31 |
+
/** Throws a new Error, the message of which is the concatenation
|
| 32 |
+
all args with a space between each. */
|
| 33 |
+
const toss = (...args)=>{throw new Error(args.join(' '))};
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
Implementing function bindings revealed significant
|
| 37 |
+
shortcomings in Emscripten's addFunction()/removeFunction()
|
| 38 |
+
interfaces:
|
| 39 |
+
|
| 40 |
+
https://github.com/emscripten-core/emscripten/issues/17323
|
| 41 |
+
|
| 42 |
+
Until those are resolved, or a suitable replacement can be
|
| 43 |
+
implemented, our function-binding API will be more limited
|
| 44 |
+
and/or clumsier to use than initially hoped.
|
| 45 |
+
*/
|
| 46 |
+
if(!(config.heap instanceof WebAssembly.Memory)
|
| 47 |
+
&& !(config.heap instanceof Function)){
|
| 48 |
+
toss("config.heap must be WebAssembly.Memory instance or a function.");
|
| 49 |
+
}
|
| 50 |
+
['alloc','dealloc'].forEach(function(k){
|
| 51 |
+
(config[k] instanceof Function) ||
|
| 52 |
+
toss("Config option '"+k+"' must be a function.");
|
| 53 |
+
});
|
| 54 |
+
const SBF = StructBinderFactory;
|
| 55 |
+
const heap = (config.heap instanceof Function)
|
| 56 |
+
? config.heap : (()=>new Uint8Array(config.heap.buffer)),
|
| 57 |
+
alloc = config.alloc,
|
| 58 |
+
dealloc = config.dealloc,
|
| 59 |
+
log = config.log || console.log.bind(console),
|
| 60 |
+
memberPrefix = (config.memberPrefix || ""),
|
| 61 |
+
memberSuffix = (config.memberSuffix || ""),
|
| 62 |
+
bigIntEnabled = (undefined===config.bigIntEnabled
|
| 63 |
+
? !!globalThis['BigInt64Array'] : !!config.bigIntEnabled),
|
| 64 |
+
BigInt = globalThis['BigInt'],
|
| 65 |
+
BigInt64Array = globalThis['BigInt64Array'],
|
| 66 |
+
/* Undocumented (on purpose) config options: */
|
| 67 |
+
ptrSizeof = config.ptrSizeof || 4,
|
| 68 |
+
ptrIR = config.ptrIR || 'i32'
|
| 69 |
+
;
|
| 70 |
+
|
| 71 |
+
if(!SBF.debugFlags){
|
| 72 |
+
SBF.__makeDebugFlags = function(deriveFrom=null){
|
| 73 |
+
/* This is disgustingly overengineered. :/ */
|
| 74 |
+
if(deriveFrom && deriveFrom.__flags) deriveFrom = deriveFrom.__flags;
|
| 75 |
+
const f = function f(flags){
|
| 76 |
+
if(0===arguments.length){
|
| 77 |
+
return f.__flags;
|
| 78 |
+
}
|
| 79 |
+
if(flags<0){
|
| 80 |
+
delete f.__flags.getter; delete f.__flags.setter;
|
| 81 |
+
delete f.__flags.alloc; delete f.__flags.dealloc;
|
| 82 |
+
}else{
|
| 83 |
+
f.__flags.getter = 0!==(0x01 & flags);
|
| 84 |
+
f.__flags.setter = 0!==(0x02 & flags);
|
| 85 |
+
f.__flags.alloc = 0!==(0x04 & flags);
|
| 86 |
+
f.__flags.dealloc = 0!==(0x08 & flags);
|
| 87 |
+
}
|
| 88 |
+
return f._flags;
|
| 89 |
+
};
|
| 90 |
+
Object.defineProperty(f,'__flags', {
|
| 91 |
+
iterable: false, writable: false,
|
| 92 |
+
value: Object.create(deriveFrom)
|
| 93 |
+
});
|
| 94 |
+
if(!deriveFrom) f(0);
|
| 95 |
+
return f;
|
| 96 |
+
};
|
| 97 |
+
SBF.debugFlags = SBF.__makeDebugFlags();
|
| 98 |
+
}/*static init*/
|
| 99 |
+
|
| 100 |
+
const isLittleEndian = (function() {
|
| 101 |
+
const buffer = new ArrayBuffer(2);
|
| 102 |
+
new DataView(buffer).setInt16(0, 256, true /* littleEndian */);
|
| 103 |
+
// Int16Array uses the platform's endianness.
|
| 104 |
+
return new Int16Array(buffer)[0] === 256;
|
| 105 |
+
})();
|
| 106 |
+
/**
|
| 107 |
+
Some terms used in the internal docs:
|
| 108 |
+
|
| 109 |
+
StructType: a struct-wrapping class generated by this
|
| 110 |
+
framework.
|
| 111 |
+
DEF: struct description object.
|
| 112 |
+
SIG: struct member signature string.
|
| 113 |
+
*/
|
| 114 |
+
|
| 115 |
+
/** True if SIG s looks like a function signature, else
|
| 116 |
+
false. */
|
| 117 |
+
const isFuncSig = (s)=>'('===s[1];
|
| 118 |
+
/** True if SIG s is-a pointer signature. */
|
| 119 |
+
const isPtrSig = (s)=>'p'===s || 'P'===s;
|
| 120 |
+
const isAutoPtrSig = (s)=>'P'===s /*EXPERIMENTAL*/;
|
| 121 |
+
const sigLetter = (s)=>isFuncSig(s) ? 'p' : s[0];
|
| 122 |
+
/** Returns the WASM IR form of the Emscripten-conventional letter
|
| 123 |
+
at SIG s[0]. Throws for an unknown SIG. */
|
| 124 |
+
const sigIR = function(s){
|
| 125 |
+
switch(sigLetter(s)){
|
| 126 |
+
case 'c': case 'C': return 'i8';
|
| 127 |
+
case 'i': return 'i32';
|
| 128 |
+
case 'p': case 'P': case 's': return ptrIR;
|
| 129 |
+
case 'j': return 'i64';
|
| 130 |
+
case 'f': return 'float';
|
| 131 |
+
case 'd': return 'double';
|
| 132 |
+
}
|
| 133 |
+
toss("Unhandled signature IR:",s);
|
| 134 |
+
};
|
| 135 |
+
|
| 136 |
+
const affirmBigIntArray = BigInt64Array
|
| 137 |
+
? ()=>true : ()=>toss('BigInt64Array is not available.');
|
| 138 |
+
/** Returns the name of a DataView getter method corresponding
|
| 139 |
+
to the given SIG. */
|
| 140 |
+
const sigDVGetter = function(s){
|
| 141 |
+
switch(sigLetter(s)) {
|
| 142 |
+
case 'p': case 'P': case 's': {
|
| 143 |
+
switch(ptrSizeof){
|
| 144 |
+
case 4: return 'getInt32';
|
| 145 |
+
case 8: return affirmBigIntArray() && 'getBigInt64';
|
| 146 |
+
}
|
| 147 |
+
break;
|
| 148 |
+
}
|
| 149 |
+
case 'i': return 'getInt32';
|
| 150 |
+
case 'c': return 'getInt8';
|
| 151 |
+
case 'C': return 'getUint8';
|
| 152 |
+
case 'j': return affirmBigIntArray() && 'getBigInt64';
|
| 153 |
+
case 'f': return 'getFloat32';
|
| 154 |
+
case 'd': return 'getFloat64';
|
| 155 |
+
}
|
| 156 |
+
toss("Unhandled DataView getter for signature:",s);
|
| 157 |
+
};
|
| 158 |
+
/** Returns the name of a DataView setter method corresponding
|
| 159 |
+
to the given SIG. */
|
| 160 |
+
const sigDVSetter = function(s){
|
| 161 |
+
switch(sigLetter(s)){
|
| 162 |
+
case 'p': case 'P': case 's': {
|
| 163 |
+
switch(ptrSizeof){
|
| 164 |
+
case 4: return 'setInt32';
|
| 165 |
+
case 8: return affirmBigIntArray() && 'setBigInt64';
|
| 166 |
+
}
|
| 167 |
+
break;
|
| 168 |
+
}
|
| 169 |
+
case 'i': return 'setInt32';
|
| 170 |
+
case 'c': return 'setInt8';
|
| 171 |
+
case 'C': return 'setUint8';
|
| 172 |
+
case 'j': return affirmBigIntArray() && 'setBigInt64';
|
| 173 |
+
case 'f': return 'setFloat32';
|
| 174 |
+
case 'd': return 'setFloat64';
|
| 175 |
+
}
|
| 176 |
+
toss("Unhandled DataView setter for signature:",s);
|
| 177 |
+
};
|
| 178 |
+
/**
|
| 179 |
+
Returns either Number of BigInt, depending on the given
|
| 180 |
+
SIG. This constructor is used in property setters to coerce
|
| 181 |
+
the being-set value to the correct size.
|
| 182 |
+
*/
|
| 183 |
+
const sigDVSetWrapper = function(s){
|
| 184 |
+
switch(sigLetter(s)) {
|
| 185 |
+
case 'i': case 'f': case 'c': case 'C': case 'd': return Number;
|
| 186 |
+
case 'j': return affirmBigIntArray() && BigInt;
|
| 187 |
+
case 'p': case 'P': case 's':
|
| 188 |
+
switch(ptrSizeof){
|
| 189 |
+
case 4: return Number;
|
| 190 |
+
case 8: return affirmBigIntArray() && BigInt;
|
| 191 |
+
}
|
| 192 |
+
break;
|
| 193 |
+
}
|
| 194 |
+
toss("Unhandled DataView set wrapper for signature:",s);
|
| 195 |
+
};
|
| 196 |
+
|
| 197 |
+
/** Returns the given struct and member name in a form suitable for
|
| 198 |
+
debugging and error output. */
|
| 199 |
+
const sPropName = (s,k)=>s+'::'+k;
|
| 200 |
+
|
| 201 |
+
const __propThrowOnSet = function(structName,propName){
|
| 202 |
+
return ()=>toss(sPropName(structName,propName),"is read-only.");
|
| 203 |
+
};
|
| 204 |
+
|
| 205 |
+
/**
|
| 206 |
+
In order to completely hide StructBinder-bound struct
|
| 207 |
+
pointers from JS code, we store them in a scope-local
|
| 208 |
+
WeakMap which maps the struct-bound objects to their WASM
|
| 209 |
+
pointers. The pointers are accessible via
|
| 210 |
+
boundObject.pointer, which is gated behind an accessor
|
| 211 |
+
function, but are not exposed anywhere else in the
|
| 212 |
+
object. The main intention of that is to make it impossible
|
| 213 |
+
for stale copies to be made.
|
| 214 |
+
*/
|
| 215 |
+
const __instancePointerMap = new WeakMap();
|
| 216 |
+
|
| 217 |
+
/** Property name for the pointer-is-external marker. */
|
| 218 |
+
const xPtrPropName = '(pointer-is-external)';
|
| 219 |
+
|
| 220 |
+
/** Frees the obj.pointer memory and clears the pointer
|
| 221 |
+
property. */
|
| 222 |
+
const __freeStruct = function(ctor, obj, m){
|
| 223 |
+
if(!m) m = __instancePointerMap.get(obj);
|
| 224 |
+
if(m) {
|
| 225 |
+
__instancePointerMap.delete(obj);
|
| 226 |
+
if(Array.isArray(obj.ondispose)){
|
| 227 |
+
let x;
|
| 228 |
+
while((x = obj.ondispose.shift())){
|
| 229 |
+
try{
|
| 230 |
+
if(x instanceof Function) x.call(obj);
|
| 231 |
+
else if(x instanceof StructType) x.dispose();
|
| 232 |
+
else if('number' === typeof x) dealloc(x);
|
| 233 |
+
// else ignore. Strings are permitted to annotate entries
|
| 234 |
+
// to assist in debugging.
|
| 235 |
+
}catch(e){
|
| 236 |
+
console.warn("ondispose() for",ctor.structName,'@',
|
| 237 |
+
m,'threw. NOT propagating it.',e);
|
| 238 |
+
}
|
| 239 |
+
}
|
| 240 |
+
}else if(obj.ondispose instanceof Function){
|
| 241 |
+
try{obj.ondispose()}
|
| 242 |
+
catch(e){
|
| 243 |
+
/*do not rethrow: destructors must not throw*/
|
| 244 |
+
console.warn("ondispose() for",ctor.structName,'@',
|
| 245 |
+
m,'threw. NOT propagating it.',e);
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
delete obj.ondispose;
|
| 249 |
+
if(ctor.debugFlags.__flags.dealloc){
|
| 250 |
+
log("debug.dealloc:",(obj[xPtrPropName]?"EXTERNAL":""),
|
| 251 |
+
ctor.structName,"instance:",
|
| 252 |
+
ctor.structInfo.sizeof,"bytes @"+m);
|
| 253 |
+
}
|
| 254 |
+
if(!obj[xPtrPropName]) dealloc(m);
|
| 255 |
+
}
|
| 256 |
+
};
|
| 257 |
+
|
| 258 |
+
/** Returns a skeleton for a read-only property accessor wrapping
|
| 259 |
+
value v. */
|
| 260 |
+
const rop = (v)=>{return {configurable: false, writable: false,
|
| 261 |
+
iterable: false, value: v}};
|
| 262 |
+
|
| 263 |
+
/** Allocates obj's memory buffer based on the size defined in
|
| 264 |
+
ctor.structInfo.sizeof. */
|
| 265 |
+
const __allocStruct = function(ctor, obj, m){
|
| 266 |
+
let fill = !m;
|
| 267 |
+
if(m) Object.defineProperty(obj, xPtrPropName, rop(m));
|
| 268 |
+
else{
|
| 269 |
+
m = alloc(ctor.structInfo.sizeof);
|
| 270 |
+
if(!m) toss("Allocation of",ctor.structName,"structure failed.");
|
| 271 |
+
}
|
| 272 |
+
try {
|
| 273 |
+
if(ctor.debugFlags.__flags.alloc){
|
| 274 |
+
log("debug.alloc:",(fill?"":"EXTERNAL"),
|
| 275 |
+
ctor.structName,"instance:",
|
| 276 |
+
ctor.structInfo.sizeof,"bytes @"+m);
|
| 277 |
+
}
|
| 278 |
+
if(fill) heap().fill(0, m, m + ctor.structInfo.sizeof);
|
| 279 |
+
__instancePointerMap.set(obj, m);
|
| 280 |
+
}catch(e){
|
| 281 |
+
__freeStruct(ctor, obj, m);
|
| 282 |
+
throw e;
|
| 283 |
+
}
|
| 284 |
+
};
|
| 285 |
+
/** Gets installed as the memoryDump() method of all structs. */
|
| 286 |
+
const __memoryDump = function(){
|
| 287 |
+
const p = this.pointer;
|
| 288 |
+
return p
|
| 289 |
+
? new Uint8Array(heap().slice(p, p+this.structInfo.sizeof))
|
| 290 |
+
: null;
|
| 291 |
+
};
|
| 292 |
+
|
| 293 |
+
const __memberKey = (k)=>memberPrefix + k + memberSuffix;
|
| 294 |
+
const __memberKeyProp = rop(__memberKey);
|
| 295 |
+
|
| 296 |
+
/**
|
| 297 |
+
Looks up a struct member in structInfo.members. Throws if found
|
| 298 |
+
if tossIfNotFound is true, else returns undefined if not
|
| 299 |
+
found. The given name may be either the name of the
|
| 300 |
+
structInfo.members key (faster) or the key as modified by the
|
| 301 |
+
memberPrefix and memberSuffix settings.
|
| 302 |
+
*/
|
| 303 |
+
const __lookupMember = function(structInfo, memberName, tossIfNotFound=true){
|
| 304 |
+
let m = structInfo.members[memberName];
|
| 305 |
+
if(!m && (memberPrefix || memberSuffix)){
|
| 306 |
+
// Check for a match on members[X].key
|
| 307 |
+
for(const v of Object.values(structInfo.members)){
|
| 308 |
+
if(v.key===memberName){ m = v; break; }
|
| 309 |
+
}
|
| 310 |
+
if(!m && tossIfNotFound){
|
| 311 |
+
toss(sPropName(structInfo.name,memberName),'is not a mapped struct member.');
|
| 312 |
+
}
|
| 313 |
+
}
|
| 314 |
+
return m;
|
| 315 |
+
};
|
| 316 |
+
|
| 317 |
+
/**
|
| 318 |
+
Uses __lookupMember(obj.structInfo,memberName) to find a member,
|
| 319 |
+
throwing if not found. Returns its signature, either in this
|
| 320 |
+
framework's native format or in Emscripten format.
|
| 321 |
+
*/
|
| 322 |
+
const __memberSignature = function f(obj,memberName,emscriptenFormat=false){
|
| 323 |
+
if(!f._) f._ = (x)=>x.replace(/[^vipPsjrdcC]/g,"").replace(/[pPscC]/g,'i');
|
| 324 |
+
const m = __lookupMember(obj.structInfo, memberName, true);
|
| 325 |
+
return emscriptenFormat ? f._(m.signature) : m.signature;
|
| 326 |
+
};
|
| 327 |
+
|
| 328 |
+
const __ptrPropDescriptor = {
|
| 329 |
+
configurable: false, enumerable: false,
|
| 330 |
+
get: function(){return __instancePointerMap.get(this)},
|
| 331 |
+
set: ()=>toss("Cannot assign the 'pointer' property of a struct.")
|
| 332 |
+
// Reminder: leaving `set` undefined makes assignments
|
| 333 |
+
// to the property _silently_ do nothing. Current unit tests
|
| 334 |
+
// rely on it throwing, though.
|
| 335 |
+
};
|
| 336 |
+
|
| 337 |
+
/** Impl of X.memberKeys() for StructType and struct ctors. */
|
| 338 |
+
const __structMemberKeys = rop(function(){
|
| 339 |
+
const a = [];
|
| 340 |
+
for(const k of Object.keys(this.structInfo.members)){
|
| 341 |
+
a.push(this.memberKey(k));
|
| 342 |
+
}
|
| 343 |
+
return a;
|
| 344 |
+
});
|
| 345 |
+
|
| 346 |
+
const __utf8Decoder = new TextDecoder('utf-8');
|
| 347 |
+
const __utf8Encoder = new TextEncoder();
|
| 348 |
+
/** Internal helper to use in operations which need to distinguish
|
| 349 |
+
between SharedArrayBuffer heap memory and non-shared heap. */
|
| 350 |
+
const __SAB = ('undefined'===typeof SharedArrayBuffer)
|
| 351 |
+
? function(){} : SharedArrayBuffer;
|
| 352 |
+
const __utf8Decode = function(arrayBuffer, begin, end){
|
| 353 |
+
return __utf8Decoder.decode(
|
| 354 |
+
(arrayBuffer.buffer instanceof __SAB)
|
| 355 |
+
? arrayBuffer.slice(begin, end)
|
| 356 |
+
: arrayBuffer.subarray(begin, end)
|
| 357 |
+
);
|
| 358 |
+
};
|
| 359 |
+
/**
|
| 360 |
+
Uses __lookupMember() to find the given obj.structInfo key.
|
| 361 |
+
Returns that member if it is a string, else returns false. If the
|
| 362 |
+
member is not found, throws if tossIfNotFound is true, else
|
| 363 |
+
returns false.
|
| 364 |
+
*/
|
| 365 |
+
const __memberIsString = function(obj,memberName, tossIfNotFound=false){
|
| 366 |
+
const m = __lookupMember(obj.structInfo, memberName, tossIfNotFound);
|
| 367 |
+
return (m && 1===m.signature.length && 's'===m.signature[0]) ? m : false;
|
| 368 |
+
};
|
| 369 |
+
|
| 370 |
+
/**
|
| 371 |
+
Given a member description object, throws if member.signature is
|
| 372 |
+
not valid for assigning to or interpretation as a C-style string.
|
| 373 |
+
It optimistically assumes that any signature of (i,p,s) is
|
| 374 |
+
C-string compatible.
|
| 375 |
+
*/
|
| 376 |
+
const __affirmCStringSignature = function(member){
|
| 377 |
+
if('s'===member.signature) return;
|
| 378 |
+
toss("Invalid member type signature for C-string value:",
|
| 379 |
+
JSON.stringify(member));
|
| 380 |
+
};
|
| 381 |
+
|
| 382 |
+
/**
|
| 383 |
+
Looks up the given member in obj.structInfo. If it has a
|
| 384 |
+
signature of 's' then it is assumed to be a C-style UTF-8 string
|
| 385 |
+
and a decoded copy of the string at its address is returned. If
|
| 386 |
+
the signature is of any other type, it throws. If an s-type
|
| 387 |
+
member's address is 0, `null` is returned.
|
| 388 |
+
*/
|
| 389 |
+
const __memberToJsString = function f(obj,memberName){
|
| 390 |
+
const m = __lookupMember(obj.structInfo, memberName, true);
|
| 391 |
+
__affirmCStringSignature(m);
|
| 392 |
+
const addr = obj[m.key];
|
| 393 |
+
//log("addr =",addr,memberName,"m =",m);
|
| 394 |
+
if(!addr) return null;
|
| 395 |
+
let pos = addr;
|
| 396 |
+
const mem = heap();
|
| 397 |
+
for( ; mem[pos]!==0; ++pos ) {
|
| 398 |
+
//log("mem[",pos,"]",mem[pos]);
|
| 399 |
+
};
|
| 400 |
+
//log("addr =",addr,"pos =",pos);
|
| 401 |
+
return (addr===pos) ? "" : __utf8Decode(mem, addr, pos);
|
| 402 |
+
};
|
| 403 |
+
|
| 404 |
+
/**
|
| 405 |
+
Adds value v to obj.ondispose, creating ondispose,
|
| 406 |
+
or converting it to an array, if needed.
|
| 407 |
+
*/
|
| 408 |
+
const __addOnDispose = function(obj, ...v){
|
| 409 |
+
if(obj.ondispose){
|
| 410 |
+
if(!Array.isArray(obj.ondispose)){
|
| 411 |
+
obj.ondispose = [obj.ondispose];
|
| 412 |
+
}
|
| 413 |
+
}else{
|
| 414 |
+
obj.ondispose = [];
|
| 415 |
+
}
|
| 416 |
+
obj.ondispose.push(...v);
|
| 417 |
+
};
|
| 418 |
+
|
| 419 |
+
/**
|
| 420 |
+
Allocates a new UTF-8-encoded, NUL-terminated copy of the given
|
| 421 |
+
JS string and returns its address relative to heap(). If
|
| 422 |
+
allocation returns 0 this function throws. Ownership of the
|
| 423 |
+
memory is transfered to the caller, who must eventually pass it
|
| 424 |
+
to the configured dealloc() function.
|
| 425 |
+
*/
|
| 426 |
+
const __allocCString = function(str){
|
| 427 |
+
const u = __utf8Encoder.encode(str);
|
| 428 |
+
const mem = alloc(u.length+1);
|
| 429 |
+
if(!mem) toss("Allocation error while duplicating string:",str);
|
| 430 |
+
const h = heap();
|
| 431 |
+
//let i = 0;
|
| 432 |
+
//for( ; i < u.length; ++i ) h[mem + i] = u[i];
|
| 433 |
+
h.set(u, mem);
|
| 434 |
+
h[mem + u.length] = 0;
|
| 435 |
+
//log("allocCString @",mem," =",u);
|
| 436 |
+
return mem;
|
| 437 |
+
};
|
| 438 |
+
|
| 439 |
+
/**
|
| 440 |
+
Sets the given struct member of obj to a dynamically-allocated,
|
| 441 |
+
UTF-8-encoded, NUL-terminated copy of str. It is up to the caller
|
| 442 |
+
to free any prior memory, if appropriate. The newly-allocated
|
| 443 |
+
string is added to obj.ondispose so will be freed when the object
|
| 444 |
+
is disposed.
|
| 445 |
+
|
| 446 |
+
The given name may be either the name of the structInfo.members
|
| 447 |
+
key (faster) or the key as modified by the memberPrefix and
|
| 448 |
+
memberSuffix settings.
|
| 449 |
+
*/
|
| 450 |
+
const __setMemberCString = function(obj, memberName, str){
|
| 451 |
+
const m = __lookupMember(obj.structInfo, memberName, true);
|
| 452 |
+
__affirmCStringSignature(m);
|
| 453 |
+
/* Potential TODO: if obj.ondispose contains obj[m.key] then
|
| 454 |
+
dealloc that value and clear that ondispose entry */
|
| 455 |
+
const mem = __allocCString(str);
|
| 456 |
+
obj[m.key] = mem;
|
| 457 |
+
__addOnDispose(obj, mem);
|
| 458 |
+
return obj;
|
| 459 |
+
};
|
| 460 |
+
|
| 461 |
+
/**
|
| 462 |
+
Prototype for all StructFactory instances (the constructors
|
| 463 |
+
returned from StructBinder).
|
| 464 |
+
*/
|
| 465 |
+
const StructType = function ctor(structName, structInfo){
|
| 466 |
+
if(arguments[2]!==rop){
|
| 467 |
+
toss("Do not call the StructType constructor",
|
| 468 |
+
"from client-level code.");
|
| 469 |
+
}
|
| 470 |
+
Object.defineProperties(this,{
|
| 471 |
+
//isA: rop((v)=>v instanceof ctor),
|
| 472 |
+
structName: rop(structName),
|
| 473 |
+
structInfo: rop(structInfo)
|
| 474 |
+
});
|
| 475 |
+
};
|
| 476 |
+
|
| 477 |
+
/**
|
| 478 |
+
Properties inherited by struct-type-specific StructType instances
|
| 479 |
+
and (indirectly) concrete struct-type instances.
|
| 480 |
+
*/
|
| 481 |
+
StructType.prototype = Object.create(null, {
|
| 482 |
+
dispose: rop(function(){__freeStruct(this.constructor, this)}),
|
| 483 |
+
lookupMember: rop(function(memberName, tossIfNotFound=true){
|
| 484 |
+
return __lookupMember(this.structInfo, memberName, tossIfNotFound);
|
| 485 |
+
}),
|
| 486 |
+
memberToJsString: rop(function(memberName){
|
| 487 |
+
return __memberToJsString(this, memberName);
|
| 488 |
+
}),
|
| 489 |
+
memberIsString: rop(function(memberName, tossIfNotFound=true){
|
| 490 |
+
return __memberIsString(this, memberName, tossIfNotFound);
|
| 491 |
+
}),
|
| 492 |
+
memberKey: __memberKeyProp,
|
| 493 |
+
memberKeys: __structMemberKeys,
|
| 494 |
+
memberSignature: rop(function(memberName, emscriptenFormat=false){
|
| 495 |
+
return __memberSignature(this, memberName, emscriptenFormat);
|
| 496 |
+
}),
|
| 497 |
+
memoryDump: rop(__memoryDump),
|
| 498 |
+
pointer: __ptrPropDescriptor,
|
| 499 |
+
setMemberCString: rop(function(memberName, str){
|
| 500 |
+
return __setMemberCString(this, memberName, str);
|
| 501 |
+
})
|
| 502 |
+
});
|
| 503 |
+
// Function-type non-Property inherited members
|
| 504 |
+
Object.assign(StructType.prototype,{
|
| 505 |
+
addOnDispose: function(...v){
|
| 506 |
+
__addOnDispose(this,...v);
|
| 507 |
+
return this;
|
| 508 |
+
}
|
| 509 |
+
});
|
| 510 |
+
|
| 511 |
+
/**
|
| 512 |
+
"Static" properties for StructType.
|
| 513 |
+
*/
|
| 514 |
+
Object.defineProperties(StructType, {
|
| 515 |
+
allocCString: rop(__allocCString),
|
| 516 |
+
isA: rop((v)=>v instanceof StructType),
|
| 517 |
+
hasExternalPointer: rop((v)=>(v instanceof StructType) && !!v[xPtrPropName]),
|
| 518 |
+
memberKey: __memberKeyProp
|
| 519 |
+
});
|
| 520 |
+
|
| 521 |
+
const isNumericValue = (v)=>Number.isFinite(v) || (v instanceof (BigInt || Number));
|
| 522 |
+
|
| 523 |
+
/**
|
| 524 |
+
Pass this a StructBinder-generated prototype, and the struct
|
| 525 |
+
member description object. It will define property accessors for
|
| 526 |
+
proto[memberKey] which read from/write to memory in
|
| 527 |
+
this.pointer. It modifies descr to make certain downstream
|
| 528 |
+
operations much simpler.
|
| 529 |
+
*/
|
| 530 |
+
const makeMemberWrapper = function f(ctor,name, descr){
|
| 531 |
+
if(!f._){
|
| 532 |
+
/*cache all available getters/setters/set-wrappers for
|
| 533 |
+
direct reuse in each accessor function. */
|
| 534 |
+
f._ = {getters: {}, setters: {}, sw:{}};
|
| 535 |
+
const a = ['i','c','C','p','P','s','f','d','v()'];
|
| 536 |
+
if(bigIntEnabled) a.push('j');
|
| 537 |
+
a.forEach(function(v){
|
| 538 |
+
//const ir = sigIR(v);
|
| 539 |
+
f._.getters[v] = sigDVGetter(v) /* DataView[MethodName] values for GETTERS */;
|
| 540 |
+
f._.setters[v] = sigDVSetter(v) /* DataView[MethodName] values for SETTERS */;
|
| 541 |
+
f._.sw[v] = sigDVSetWrapper(v) /* BigInt or Number ctor to wrap around values
|
| 542 |
+
for conversion */;
|
| 543 |
+
});
|
| 544 |
+
const rxSig1 = /^[ipPsjfdcC]$/,
|
| 545 |
+
rxSig2 = /^[vipPsjfdcC]\([ipPsjfdcC]*\)$/;
|
| 546 |
+
f.sigCheck = function(obj, name, key,sig){
|
| 547 |
+
if(Object.prototype.hasOwnProperty.call(obj, key)){
|
| 548 |
+
toss(obj.structName,'already has a property named',key+'.');
|
| 549 |
+
}
|
| 550 |
+
rxSig1.test(sig) || rxSig2.test(sig)
|
| 551 |
+
|| toss("Malformed signature for",
|
| 552 |
+
sPropName(obj.structName,name)+":",sig);
|
| 553 |
+
};
|
| 554 |
+
}
|
| 555 |
+
const key = ctor.memberKey(name);
|
| 556 |
+
f.sigCheck(ctor.prototype, name, key, descr.signature);
|
| 557 |
+
descr.key = key;
|
| 558 |
+
descr.name = name;
|
| 559 |
+
const sigGlyph = sigLetter(descr.signature);
|
| 560 |
+
const xPropName = sPropName(ctor.prototype.structName,key);
|
| 561 |
+
const dbg = ctor.prototype.debugFlags.__flags;
|
| 562 |
+
/*
|
| 563 |
+
TODO?: set prototype of descr to an object which can set/fetch
|
| 564 |
+
its prefered representation, e.g. conversion to string or mapped
|
| 565 |
+
function. Advantage: we can avoid doing that via if/else if/else
|
| 566 |
+
in the get/set methods.
|
| 567 |
+
*/
|
| 568 |
+
const prop = Object.create(null);
|
| 569 |
+
prop.configurable = false;
|
| 570 |
+
prop.enumerable = false;
|
| 571 |
+
prop.get = function(){
|
| 572 |
+
if(dbg.getter){
|
| 573 |
+
log("debug.getter:",f._.getters[sigGlyph],"for", sigIR(sigGlyph),
|
| 574 |
+
xPropName,'@', this.pointer,'+',descr.offset,'sz',descr.sizeof);
|
| 575 |
+
}
|
| 576 |
+
let rc = (
|
| 577 |
+
new DataView(heap().buffer, this.pointer + descr.offset, descr.sizeof)
|
| 578 |
+
)[f._.getters[sigGlyph]](0, isLittleEndian);
|
| 579 |
+
if(dbg.getter) log("debug.getter:",xPropName,"result =",rc);
|
| 580 |
+
return rc;
|
| 581 |
+
};
|
| 582 |
+
if(descr.readOnly){
|
| 583 |
+
prop.set = __propThrowOnSet(ctor.prototype.structName,key);
|
| 584 |
+
}else{
|
| 585 |
+
prop.set = function(v){
|
| 586 |
+
if(dbg.setter){
|
| 587 |
+
log("debug.setter:",f._.setters[sigGlyph],"for", sigIR(sigGlyph),
|
| 588 |
+
xPropName,'@', this.pointer,'+',descr.offset,'sz',descr.sizeof, v);
|
| 589 |
+
}
|
| 590 |
+
if(!this.pointer){
|
| 591 |
+
toss("Cannot set struct property on disposed instance.");
|
| 592 |
+
}
|
| 593 |
+
if(null===v) v = 0;
|
| 594 |
+
else while(!isNumericValue(v)){
|
| 595 |
+
if(isAutoPtrSig(descr.signature) && (v instanceof StructType)){
|
| 596 |
+
// It's a struct instance: let's store its pointer value!
|
| 597 |
+
v = v.pointer || 0;
|
| 598 |
+
if(dbg.setter) log("debug.setter:",xPropName,"resolved to",v);
|
| 599 |
+
break;
|
| 600 |
+
}
|
| 601 |
+
toss("Invalid value for pointer-type",xPropName+'.');
|
| 602 |
+
}
|
| 603 |
+
(
|
| 604 |
+
new DataView(heap().buffer, this.pointer + descr.offset, descr.sizeof)
|
| 605 |
+
)[f._.setters[sigGlyph]](0, f._.sw[sigGlyph](v), isLittleEndian);
|
| 606 |
+
};
|
| 607 |
+
}
|
| 608 |
+
Object.defineProperty(ctor.prototype, key, prop);
|
| 609 |
+
}/*makeMemberWrapper*/;
|
| 610 |
+
|
| 611 |
+
/**
|
| 612 |
+
The main factory function which will be returned to the
|
| 613 |
+
caller.
|
| 614 |
+
*/
|
| 615 |
+
const StructBinder = function StructBinder(structName, structInfo){
|
| 616 |
+
if(1===arguments.length){
|
| 617 |
+
structInfo = structName;
|
| 618 |
+
structName = structInfo.name;
|
| 619 |
+
}else if(!structInfo.name){
|
| 620 |
+
structInfo.name = structName;
|
| 621 |
+
}
|
| 622 |
+
if(!structName) toss("Struct name is required.");
|
| 623 |
+
let lastMember = false;
|
| 624 |
+
Object.keys(structInfo.members).forEach((k)=>{
|
| 625 |
+
// Sanity checks of sizeof/offset info...
|
| 626 |
+
const m = structInfo.members[k];
|
| 627 |
+
if(!m.sizeof) toss(structName,"member",k,"is missing sizeof.");
|
| 628 |
+
else if(m.sizeof===1){
|
| 629 |
+
(m.signature === 'c' || m.signature === 'C') ||
|
| 630 |
+
toss("Unexpected sizeof==1 member",
|
| 631 |
+
sPropName(structInfo.name,k),
|
| 632 |
+
"with signature",m.signature);
|
| 633 |
+
}else{
|
| 634 |
+
// sizes and offsets of size-1 members may be odd values, but
|
| 635 |
+
// others may not.
|
| 636 |
+
if(0!==(m.sizeof%4)){
|
| 637 |
+
console.warn("Invalid struct member description =",m,"from",structInfo);
|
| 638 |
+
toss(structName,"member",k,"sizeof is not aligned. sizeof="+m.sizeof);
|
| 639 |
+
}
|
| 640 |
+
if(0!==(m.offset%4)){
|
| 641 |
+
console.warn("Invalid struct member description =",m,"from",structInfo);
|
| 642 |
+
toss(structName,"member",k,"offset is not aligned. offset="+m.offset);
|
| 643 |
+
}
|
| 644 |
+
}
|
| 645 |
+
if(!lastMember || lastMember.offset < m.offset) lastMember = m;
|
| 646 |
+
});
|
| 647 |
+
if(!lastMember) toss("No member property descriptions found.");
|
| 648 |
+
else if(structInfo.sizeof < lastMember.offset+lastMember.sizeof){
|
| 649 |
+
toss("Invalid struct config:",structName,
|
| 650 |
+
"max member offset ("+lastMember.offset+") ",
|
| 651 |
+
"extends past end of struct (sizeof="+structInfo.sizeof+").");
|
| 652 |
+
}
|
| 653 |
+
const debugFlags = rop(SBF.__makeDebugFlags(StructBinder.debugFlags));
|
| 654 |
+
/** Constructor for the StructCtor. */
|
| 655 |
+
const StructCtor = function StructCtor(externalMemory){
|
| 656 |
+
if(!(this instanceof StructCtor)){
|
| 657 |
+
toss("The",structName,"constructor may only be called via 'new'.");
|
| 658 |
+
}else if(arguments.length){
|
| 659 |
+
if(externalMemory!==(externalMemory|0) || externalMemory<=0){
|
| 660 |
+
toss("Invalid pointer value for",structName,"constructor.");
|
| 661 |
+
}
|
| 662 |
+
__allocStruct(StructCtor, this, externalMemory);
|
| 663 |
+
}else{
|
| 664 |
+
__allocStruct(StructCtor, this);
|
| 665 |
+
}
|
| 666 |
+
};
|
| 667 |
+
Object.defineProperties(StructCtor,{
|
| 668 |
+
debugFlags: debugFlags,
|
| 669 |
+
isA: rop((v)=>v instanceof StructCtor),
|
| 670 |
+
memberKey: __memberKeyProp,
|
| 671 |
+
memberKeys: __structMemberKeys,
|
| 672 |
+
methodInfoForKey: rop(function(mKey){
|
| 673 |
+
}),
|
| 674 |
+
structInfo: rop(structInfo),
|
| 675 |
+
structName: rop(structName)
|
| 676 |
+
});
|
| 677 |
+
StructCtor.prototype = new StructType(structName, structInfo, rop);
|
| 678 |
+
Object.defineProperties(StructCtor.prototype,{
|
| 679 |
+
debugFlags: debugFlags,
|
| 680 |
+
constructor: rop(StructCtor)
|
| 681 |
+
/*if we assign StructCtor.prototype and don't do
|
| 682 |
+
this then StructCtor!==instance.constructor!*/
|
| 683 |
+
});
|
| 684 |
+
Object.keys(structInfo.members).forEach(
|
| 685 |
+
(name)=>makeMemberWrapper(StructCtor, name, structInfo.members[name])
|
| 686 |
+
);
|
| 687 |
+
return StructCtor;
|
| 688 |
+
};
|
| 689 |
+
StructBinder.StructType = StructType;
|
| 690 |
+
StructBinder.config = config;
|
| 691 |
+
StructBinder.allocCString = __allocCString;
|
| 692 |
+
if(!StructBinder.debugFlags){
|
| 693 |
+
StructBinder.debugFlags = SBF.__makeDebugFlags(SBF.debugFlags);
|
| 694 |
+
}
|
| 695 |
+
return StructBinder;
|
| 696 |
+
}/*StructBinderFactory*/;
|