Skip to content

Commit 6756606

Browse files
committed
- gc - replace node-specific-gc __dbFinalizerCreate() with more-webassembly-friendly FinalizationRegistry()
1 parent d0a9887 commit 6756606

8 files changed

Lines changed: 256 additions & 191 deletions

File tree

.ci.sh

Lines changed: 123 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -583,145 +583,137 @@ shCiBuildWasm() {(set -e
583583
printf '' > .tmp.js
584584
printf '
585585
/*jslint-disable*/
586-
var initSqlJsPromise = undefined;
587-
var initSqlJs = function (moduleConfig) {
588-
if (initSqlJsPromise){
589-
return initSqlJsPromise;
590-
}
591-
initSqlJsPromise = new Promise(function (resolveModule, reject) {
592-
var Module = typeof moduleConfig !== "undefined" ? moduleConfig : {};
593-
var originalOnAbortFunction = Module["onAbort"];
594-
Module["onAbort"] = function (errorThatCausedAbort) {
595-
reject(new Error(errorThatCausedAbort));
596-
if (originalOnAbortFunction){
597-
originalOnAbortFunction(errorThatCausedAbort);
598-
}
599-
};
600-
Module["postRun"] = Module["postRun"] || [];
601-
Module["postRun"].push(function () {
602-
resolveModule(Module);
603-
});
604-
module = undefined;
586+
(function () {
587+
"use strict";
605588
' >> .tmp.js
606589
cat sqlmath_wasm.js | sed -e "s|/\*jslint-[a-z]*\*/||g" >> .tmp.js
607590
printf '
608-
return Module;
609-
}); // The end of the promise being returned
610-
return initSqlJsPromise;
611-
} // The end of our initSqlJs function
612-
if (typeof exports === "object" && typeof module === "object"){
613-
module.exports = initSqlJs;
614-
module.exports.default = initSqlJs;
615-
}
616-
else if (typeof define === "function" && define["amd"]) {
617-
define([], function() { return initSqlJs; });
618-
}
619-
else if (typeof exports === "object"){
620-
exports["Module"] = initSqlJs;
621-
}
622-
/* global initSqlJs */
623-
/* eslint-env worker */
624-
/* eslint no-restricted-globals: ["error"] */
625-
626-
"use strict";
627-
628-
// hack-sqljs - conditional-worker
629-
if ((/\\binitSqlJsWorker=1\\b/).test(typeof location === "object" && location && location.search)) {
630-
var db;
631-
632-
function onModuleReady(SQL) {
633-
function createDb(data) {
634-
if (db != null) db.close();
635-
db = new SQL.Database(data);
636-
return db;
637-
}
638-
639-
var buff; var data; var result;
640-
data = this["data"];
641-
var config = data["config"] ? data["config"] : {};
642-
switch (data && data["action"]) {
643-
case "open":
644-
buff = data["buffer"];
645-
createDb(buff && new Uint8Array(buff));
646-
return postMessage({
647-
id: data["id"],
648-
ready: true
649-
});
650-
case "exec":
651-
if (db === null) {
652-
createDb();
653-
}
654-
if (!data["sql"]) {
655-
throw "exec: Missing query string";
656-
}
657-
return postMessage({
658-
id: data["id"],
659-
results: db.exec(data["sql"], data["params"], config)
660-
});
661-
case "each":
662-
if (db === null) {
663-
createDb();
664-
}
665-
var callback = function callback(row) {
666-
return postMessage({
667-
id: data["id"],
668-
row: row,
669-
finished: false
670-
});
671-
};
672-
var done = function done() {
673-
return postMessage({
674-
id: data["id"],
675-
finished: true
676-
});
677-
};
678-
return db.each(data["sql"], data["params"], callback, done, config);
679-
case "export":
680-
buff = db["export"]();
681-
result = {
682-
id: data["id"],
683-
buffer: buff
684-
};
685-
try {
686-
return postMessage(result, [result]);
687-
} catch (error) {
688-
return postMessage(result);
689-
}
690-
case "close":
691-
if (db) {
692-
db.close();
693-
}
694-
return postMessage({
695-
id: data["id"]
696-
});
697-
default:
698-
throw new Error("Invalid action : " + (data && data["action"]));
699-
}
700-
}
701-
702-
function onError(err) {
703-
return postMessage({
704-
id: this["data"]["id"],
705-
error: err["message"]
706-
});
707-
}
708-
709-
// hack-sqljs - conditional-worker
710-
if (typeof importScripts === "function") {
711-
db = null;
712-
var sqlModuleReady = initSqlJs();
713-
self.onmessage = function onmessage(event) {
714-
return sqlModuleReady
715-
.then(onModuleReady.bind(event))
716-
.catch(onError.bind(event));
717-
};
718-
}
719-
}
591+
}());
720592
/*jslint-enable*/
721593
' >> .tmp.js
722594
mv .tmp.js sqlmath_wasm.js
723595
)}
724596

597+
shCiBuildWasm2() {(set -e
598+
# this function will build binaries in wasm
599+
shCiEmsdkExport
600+
# install emsdk
601+
shCiEmsdkInstall
602+
# cd ${EMSDK} && . ./emsdk_env.sh && cd ..
603+
# build wasm
604+
local OPTION
605+
local FILE
606+
local FILE2
607+
for FILE in \
608+
sqlite3.c \
609+
sqlite3_ext.c \
610+
sqlmath_custom.c
611+
do
612+
FILE2=".tmp/$(basename "$FILE").wasm.o"
613+
# optimization - skip rebuild of sqlite3.c if possible
614+
if [ "$FILE2" -nt "$FILE" ] && [ "$FILE" = sqlite3.c ]
615+
then
616+
continue
617+
fi
618+
OPTION=""
619+
case "$FILE" in
620+
sqlite3.c)
621+
OPTION="$OPTION -DSQLITE3_C2"
622+
;;
623+
*)
624+
OPTION="$OPTION -DSQLITE3_EXT_C2"
625+
;;
626+
esac
627+
emcc $OPTION \
628+
-DSQLITE_DISABLE_LFS \
629+
-DSQLITE_ENABLE_FTS3 \
630+
-DSQLITE_ENABLE_FTS3_PARENTHESIS \
631+
-DSQLITE_ENABLE_MATH_FUNCTIONS \
632+
-DSQLITE_ENABLE_NORMALIZE \
633+
-DSQLITE_HAVE_ZLIB \
634+
-DSQLITE_THREADSAFE=0 \
635+
\
636+
-DEMSCRIPTEN \
637+
-DSQLMATH_C_DISABLE \
638+
-I.tmp \
639+
\
640+
-O3 \
641+
-Wall \
642+
-flto \
643+
-s INLINING_LIMIT=50 \
644+
\
645+
-c "$FILE" -o "$FILE2"
646+
done
647+
emcc \
648+
-s EXPORTED_FUNCTIONS='[
649+
"_free",
650+
"_malloc",
651+
"_sqlite3_bind_blob",
652+
"_sqlite3_bind_double",
653+
"_sqlite3_bind_int",
654+
"_sqlite3_bind_parameter_index",
655+
"_sqlite3_bind_text",
656+
"_sqlite3_changes",
657+
"_sqlite3_clear_bindings",
658+
"_sqlite3_close_v2",
659+
"_sqlite3_column_blob",
660+
"_sqlite3_column_bytes",
661+
"_sqlite3_column_count",
662+
"_sqlite3_column_double",
663+
"_sqlite3_column_name",
664+
"_sqlite3_column_text",
665+
"_sqlite3_column_type",
666+
"_sqlite3_create_function_v2",
667+
"_sqlite3_data_count",
668+
"_sqlite3_errmsg",
669+
"_sqlite3_exec",
670+
"_sqlite3_finalize",
671+
"_sqlite3_free",
672+
"_sqlite3_normalized_sql",
673+
"_sqlite3_open",
674+
"_sqlite3_prepare_v2",
675+
"_sqlite3_reset",
676+
"_sqlite3_result_blob",
677+
"_sqlite3_result_double",
678+
"_sqlite3_result_error",
679+
"_sqlite3_result_int",
680+
"_sqlite3_result_int64",
681+
"_sqlite3_result_null",
682+
"_sqlite3_result_text",
683+
"_sqlite3_sql",
684+
"_sqlite3_step",
685+
"_sqlite3_value_blob",
686+
"_sqlite3_value_bytes",
687+
"_sqlite3_value_double",
688+
"_sqlite3_value_int",
689+
"_sqlite3_value_text",
690+
"_sqlite3_value_type"
691+
]' \
692+
-s EXPORTED_RUNTIME_METHODS='[
693+
"UTF8ToString",
694+
"cwrap",
695+
"stackAlloc",
696+
"stackRestore",
697+
"stackSave"
698+
]' \
699+
--memory-init-file 0 \
700+
-Wall \
701+
-s ALLOW_MEMORY_GROWTH=1 \
702+
-s ALLOW_TABLE_GROWTH=1 \
703+
-s NODEJS_CATCH_EXIT=0 \
704+
-s NODEJS_CATCH_REJECTION=0 \
705+
-s RESERVED_FUNCTION_POINTERS=64 \
706+
-s SINGLE_FILE=0 \
707+
-s USE_ZLIB \
708+
-s WASM=1 \
709+
\
710+
.tmp/sqlite3.c.wasm.o \
711+
.tmp/sqlite3_ext.c.wasm.o \
712+
.tmp/sqlmath_custom.c.wasm.o \
713+
\
714+
-o sqlmath_wasm2.js
715+
)}
716+
725717
shCiEmsdkExport() {
726718
# this function will export emsdk env
727719
export EMSCRIPTEN_VERSION=2.0.34

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# Changelog
22

33
# Todo
4+
- jenks - replace class-based api with static-function
5+
- wasm - replace sqljs-api with sqlmath-api in wasm
46
- sqlmath - add sql-extension carrayblob()
57
- none
68

79
# v2022.6.1-beta
10+
- gc - replace node-specific-gc __dbFinalizerCreate() with more-webassembly-friendly FinalizationRegistry()
811
- sqlmath - add sql-extension copyblob(), matrix2d_concat()
912
- sqlmath - re-include carray-extension
1013

jslint.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9805,6 +9805,7 @@ async function jstestDescribe(description, testFunction) {
98059805

98069806
let message;
98079807
let result;
9808+
let timerTimeout;
98089809

98099810
// Init jstestTimeStart.
98109811

@@ -9820,7 +9821,9 @@ async function jstestDescribe(description, testFunction) {
98209821

98219822
// Wait for jstestItList to resolve.
98229823

9824+
timerTimeout = setTimeout(noop, 0x40000000);
98239825
result = await Promise.all(jstestItList);
9826+
clearTimeout(timerTimeout);
98249827

98259828
// Print test results.
98269829

jslint_ci.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ import moduleFs from "fs";
437437
fileDict[file] = await moduleFs.promises.readFile(file, "utf8");
438438
}));
439439
Array.from(fileDict["CHANGELOG.md"].matchAll(
440-
/\n\n# (v\d\d\d\d\.\d\d?\.\d\d?(.*?)?)\n/g
440+
/\n\n# v(\d\d\d\d\.\d\d?\.\d\d?(-.*?)?)\n/g
441441
)).slice(0, 2).forEach(function ([
442442
ignore, version, isBeta
443443
]) {
@@ -449,12 +449,12 @@ import moduleFs from "fs";
449449
file: "README.md",
450450
src: fileDict["README.md"].replace((
451451
/\bv\d\d\d\d\.\d\d?\.\d\d?\b/m
452-
), versionMaster)
452+
), `v${versionMaster}`)
453453
}, {
454454
file: "package.json",
455455
src: fileDict["package.json"].replace((
456-
/("version": )".*?"/
457-
), "$1" + JSON.stringify(versionBeta.slice(1)))
456+
/ "version": "\d\d\d\d\.\d\d?\.\d\d?(?:-.*?)?"/
457+
), ` "version": "${versionBeta}"`)
458458
}
459459
].map(async function ({
460460
file,

0 commit comments

Comments
 (0)