1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-10-24 09:53:10 +03:00

Get the wasm tests running in a 64-bit build up through (but not including) the oo1 bits.

FossilOrigin-Name: a5af46174a05e1414370884d1a99827af9286a60eff1c8ae1551e7fad3903f7a
This commit is contained in:
stephan
2025-09-20 11:09:20 +00:00
parent 22f9ca64db
commit bd5d297fec
8 changed files with 87 additions and 64 deletions

View File

@@ -443,7 +443,7 @@ cflags.common = -I. -I$(dir $(sqlite3.c))
# disables certain features if BigInt is not enabled and such builds
# _are not tested_ on any regular basis.
emcc.WASM_BIGINT ?= 1
emcc.MEMORY64 ?= 0
emcc.MEMORY64 ?= 1
########################################################################
# https://emscripten.org/docs/tools_reference/settings_reference.html#memory64
#
@@ -465,12 +465,11 @@ emcc.MEMORY64 ?= 0
# Notes related to getting it working with MEMORY64 with emcc
# versions 4.0.11-15:
#
# - MEMORY64=1 fails to build with: "tables may not be 64-bit" with
# emcc 4.0.11, but no location information about where that error is
# coming from. The only reference to it on the web is:
# https://chromium.googlesource.com/external/github.com/WebAssembly/wabt/+/refs/tags/1.0.20/src/binary-reader.cc
# It turns out that we need a newer wasm-strip for this (1.0.36 does
# the job).
# WebAssembly.Table.get(ARG) wants BigInt if MEMORY64=1 but a number
# if MEMORY64=2.
#
# Requires wasm-strip 1.0.36 (maybe 1.0.35, but not 1.0.34) or
# will fail to strip with "tables may not be 64-bit".
#
# [^wasm3]: https://webassembly.org/news/2025-09-17-wasm-3.0/
########################################################################

View File

@@ -62,8 +62,8 @@ const toExportForESM =
globalThis.sqlite3InitModule = function ff(...args){
//console.warn("Using replaced sqlite3InitModule()",globalThis.location);
return originalInit(...args).then((EmscriptenModule)=>{
//console.warn("originalInit() then() arg =",EmscriptenModule);
//console.warn("initModuleState =",initModuleState);
console.warn("originalInit() then() arg =",EmscriptenModule);
console.warn("initModuleState =",initModuleState);
EmscriptenModule.runSQLite3PostLoadInit(EmscriptenModule);
const s = EmscriptenModule.sqlite3;
s.scriptInfo = initModuleState;

View File

@@ -49,7 +49,8 @@
- `exports`[^1]: the "exports" object for the current WASM
environment. In an Emscripten-based build, this should be set to
`Module['asm']`.
`Module['asm']` (versions <=3.1.43) or `wasmExports` (versions
>=3.1.44).
- `memory`[^1]: optional WebAssembly.Memory object, defaulting to
`exports.memory`. In Emscripten environments this should be set
@@ -113,7 +114,9 @@
called, an alternative option for setting the configuration is to
define globalThis.sqlite3ApiConfig to an object. If it is set, it
is used instead of sqlite3ApiBootstrap.defaultConfig if
sqlite3ApiBootstrap() is called without arguments.
sqlite3ApiBootstrap() is called without arguments. Setting the
`exports` and `memory` parts require already having loaded the WASM
module, though.
Both sqlite3ApiBootstrap.defaultConfig and
globalThis.sqlite3ApiConfig get deleted by sqlite3ApiBootstrap()
@@ -339,22 +342,6 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
SharedArrayBuffer, else false. */
const isSharedTypedArray = (aTypedArray)=>(aTypedArray.buffer instanceof __SAB);
/**
Returns either aTypedArray.slice(begin,end) (if
aTypedArray.buffer is a SharedArrayBuffer) or
aTypedArray.subarray(begin,end) (if it's not).
This distinction is important for APIs which don't like to
work on SABs, e.g. TextDecoder, and possibly for our
own APIs which work on memory ranges which "might" be
modified by other threads while they're working.
*/
const typedArrayPart = (aTypedArray, begin, end)=>{
return isSharedTypedArray(aTypedArray)
? aTypedArray.slice(begin, end)
: aTypedArray.subarray(begin, end);
};
/**
Returns true if v appears to be one of our bind()-able TypedArray
types: Uint8Array or Int8Array or ArrayBuffer. Support for
@@ -391,18 +378,45 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|| toss3("Value is not of a supported TypedArray type.");
};
/**
Returns either aTypedArray.slice(begin,end) (if
aTypedArray.buffer is a SharedArrayBuffer) or
aTypedArray.subarray(begin,end) (if it's not).
This distinction is important for APIs which don't like to
work on SABs, e.g. TextDecoder, and possibly for our
own APIs which work on memory ranges which "might" be
modified by other threads while they're working.
*/
const typedArrayPart = (aTypedArray, begin, end)=>{
// slice() and subarray() do not like BigInt args.
if( 'bigint'===typeof begin ) begin = Number(begin);
if( 'bigint'===typeof end ) end = Number(end);
/*if( 8===wasm.pointerSizeof ){
begin = Number(begin);
end = Number(end);
}*/
return isSharedTypedArray(aTypedArray)
? aTypedArray.slice(begin, end)
: aTypedArray.subarray(begin, end);
};
const utf8Decoder = new TextDecoder('utf-8');
/**
Uses TextDecoder to decode the given half-open range of the
given TypedArray to a string. This differs from a simple
call to TextDecoder in that it accounts for whether the
first argument is backed by a SharedArrayBuffer or not,
and can work more efficiently if it's not (TextDecoder
refuses to act upon an SAB).
Uses TextDecoder to decode the given half-open range of the given
TypedArray to a string. This differs from a simple call to
TextDecoder in that it accounts for whether the first argument is
backed by a SharedArrayBuffer or not, and can work more
efficiently if it's not (TextDecoder refuses to act upon an SAB).
If begin/end are not provided or are falsy then each defaults to
the start/end of the string.
*/
const typedArrayToString = function(typedArray, begin, end){
return utf8Decoder.decode(typedArrayPart(typedArray, begin,end));
return utf8Decoder.decode(
typedArrayPart(typedArray, begin || 0, end || typedArray.length)
);
};
/**
@@ -414,7 +428,8 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
const flexibleString = function(v){
if(isSQLableTypedArray(v)){
return typedArrayToString(
(v instanceof ArrayBuffer) ? new Uint8Array(v) : v
(v instanceof ArrayBuffer) ? new Uint8Array(v) : v,
0, v.length
);
}
else if(Array.isArray(v)) return v.join("");
@@ -1227,7 +1242,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
&& 1===args[0].BYTES_PER_ELEMENT){
const ta = args[0];
if(0===ta.byteLength){
wasm.exports.sqlite3_randomness(0,0);
wasm.exports.sqlite3_randomness(0,wasm.NullPtr);
return ta;
}
const stack = wasm.pstack.pointer;
@@ -1240,7 +1255,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
do{
const j = (n>nAlloc ? nAlloc : n);
r(j, ptr);
ta.set(typedArrayPart(heap, ptr, ptr+j), offset);
ta.set(typedArrayPart(heap, ptr, wasm.ptrAdd(ptr,j)), offset);
n -= j;
offset += j;
} while(n > 0);

View File

@@ -377,7 +377,10 @@ typedef struct WasmTestStruct WasmTestStruct;
SQLITE_WASM_EXPORT
void sqlite3__wasm_test_struct(WasmTestStruct * s){
if(s){
if( 1 ){
if( 0 ){
/* Do not be alarmed by the small (and odd) pointer values.
Function pointers in WASM are their index into the
indirect function table, not their address. */
fprintf(stderr,"%s:%s()@%p s=@%p xFunc=@%p\n",
__FILE__, __func__,
(void*)sqlite3__wasm_test_struct,

View File

@@ -434,7 +434,7 @@ globalThis.WhWasmUtilInstaller = function(target){
*/
target.functionEntry = function(fptr){
const ft = target.functionTable();
console.debug("functionEntry(",arguments,")", __asPtrType(fptr));
//console.debug("functionEntry(",arguments,")", __asPtrType(fptr));
//-sMEMORY64=1: we get a BigInt fptr and ft.get() wants a BigInt.
//-sMEMORY64=2: we get a Number fptr and ft.get() wants a Number.
return fptr < ft.length ? ft.get(__asPtrType(fptr)) : undefined;
@@ -939,10 +939,12 @@ globalThis.WhWasmUtilInstaller = function(target){
const __SAB = ('undefined'===typeof SharedArrayBuffer)
? function(){} : SharedArrayBuffer;
const __utf8Decode = function(arrayBuffer, begin, end){
if( 8===ptrSizeof ){
//if( 'bigint'===typeof begin ) begin = Number(begin);
//if( 'bigint'===typeof end ) end = Number(end);
/*if( 8===ptrSizeof ){
begin = Number(begin);
end = Number(end);
}
}*/
return cache.utf8Decoder.decode(
(arrayBuffer.buffer instanceof __SAB)
? arrayBuffer.slice(begin, end)
@@ -958,9 +960,10 @@ globalThis.WhWasmUtilInstaller = function(target){
ptr is falsy or not a pointer, `null` is returned.
*/
target.cstrToJs = function(ptr){
ptr = Number(ptr) /*tag:64bit*/;
const n = target.cstrlen(ptr);
return n ? __utf8Decode(heapWrappers().HEAP8U, ptr, ptr+n) : (null===n ? n : "");
return n
? __utf8Decode(heapWrappers().HEAP8U, Number(ptr), Number(ptr)+n)
: (null===n ? n : "");
};
/**

View File

@@ -759,8 +759,9 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
// 'string:flexible' argAdapter() sanity checks...
w.scopedAllocCall(()=>{
const argAd = w.xWrap.argAdapter('string:flexible');
const cj = (v)=>w.cstrToJs(argAd(v));
const toFlexStr = w.xWrap.argAdapter('string:flexible');
const cj = (v)=>w.cstrToJs(toFlexStr(v));
//console.debug("toFlexStr(new Uint8Array([72, 73]))",toFlexStr(new Uint8Array([72, 73])));
T.assert('Hi' === cj('Hi'))
.assert('hi' === cj(['h','i']))
.assert('HI' === cj(new Uint8Array([72, 73])));
@@ -979,8 +980,8 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
}
wts.$v4 = 10; wts.$v8 = 20;
wts.$xFunc = W.installFunction(wtsFunc, wts.memberSignature('xFunc'))
console.debug("wts.memberSignature('xFunc')",wts.memberSignature('xFunc'));
console.debug("wts.$xFunc",wts.$xFunc, W.functionEntry(wts.$xFunc));
//console.debug("wts.memberSignature('xFunc')",wts.memberSignature('xFunc'));
//console.debug("wts.$xFunc",wts.$xFunc, W.functionEntry(wts.$xFunc));
T.assert(0===counter).assert(10 === wts.$v4).assert(20n === wts.$v8)
.assert(0 == wts.$ppV).assert(looksLikePtr(wts.$xFunc))
.assert(0 == wts.$cstr)
@@ -995,8 +996,10 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
buffer, so merely reading them back is actually part of
testing the struct-wrapping API. */
if( 0 ){
console.debug("wts",wts,"wts.pointer",wts.pointer,
"testFunc",testFunc/*FF v142 emits the wrong function here!*/);
}
testFunc(wts.pointer);
//log("wts.pointer, wts.$ppV",wts.pointer, wts.$ppV);
T.assert(1===counter).assert(20 === wts.$v4).assert(40n === wts.$v8)
@@ -1117,18 +1120,18 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
const n = 520;
const p = wasm.pstack.alloc(n);
T.assert(0===wasm.peek8(p))
.assert(0===wasm.peek8(p+n-1));
.assert(0===wasm.peek8(wasm.ptrAdd(p,n,-1)));
T.assert(undefined === capi.sqlite3_randomness(n - 10, p));
let j, check = 0;
const heap = wasm.heap8u();
for(j = 0; j < 10 && 0===check; ++j){
check += heap[p + j];
check += heap[wasm.ptrAdd(p, j)];
}
T.assert(check > 0);
check = 0;
// Ensure that the trailing bytes were not modified...
for(j = n - 10; j < n && 0===check; ++j){
check += heap[p + j];
check += heap[wasm.ptrAdd(p, j)];
}
T.assert(0===check);
}finally{

View File

@@ -1,5 +1,5 @@
C Get\sabout\s1/3rd\sof\sthe\stests\srunning\swith\sMEMORY64=1,\sbut\sthe\scode\snoise\slevel\sadded\sby\sthe\sBigInt/Number\sdiscrepancy\sis\smaking\sthis\svery\sunattractive.\sThere\sare\sapparently\sirreconcilable\sdifferences\sbetween\sMEMORY64=1\sand\s2,\sin\sthat\sthey\shave\sdifferent\sargument\stype\sexpectations\sfor\smethods\ssuch\sas\sWebAssembly.Table.get(),\swhere\sMEMORY64=1\srequires\sa\sBigInt\sa\sMEMORY64=2\srequires\sa\sNumber.\sWe\shave\sno\sway\sto\smake\sthat\sdistinction\sfrom\sthe\sJS\scode,\sand\sdon't\sknow\swhat\sother\sAPIs\sare\saffected\sby\sthat\squirk.
D 2025-09-20T03:02:36.219
C Get\sthe\swasm\stests\srunning\sin\sa\s64-bit\sbuild\sup\sthrough\s(but\snot\sincluding)\sthe\soo1\sbits.
D 2025-09-20T11:09:20.368
F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -578,7 +578,7 @@ F ext/session/sqlite3session.c 9cd47bfefb23c114b7a5d9ee5822d941398902f30516bf0dd
F ext/session/sqlite3session.h 7404723606074fcb2afdc6b72c206072cdb2b7d8ba097ca1559174a80bc26f7a
F ext/session/test_session.c 8766b5973a6323934cb51248f621c3dc87ad2a98f023c3cc280d79e7d78d36fb
F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c
F ext/wasm/GNUmakefile 5ff23f42123e0b40f7583a32f17111b8b145542d3767b3df97a67ce89043eefa
F ext/wasm/GNUmakefile 6709d45549fdb6dd0db6541dbddce11a35b684e6be82d1569c70da397c1fd6a7
F ext/wasm/README-dist.txt f01081a850ce38a56706af6b481e3a7878e24e42b314cfcd4b129f0f8427066a
F ext/wasm/README.md 66ace67ae98a45e4116f2ca5425b716887bcee4d64febee804ff6398e1ae9ec7
F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff
@@ -591,7 +591,7 @@ F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras cb4fa8842c875b6ee99381523792975
F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-see fb29e62082a658f0d81102488414d422c393c4b20cc2f685b216bc566237957b
F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287
F ext/wasm/api/README.md 7f029c5fe83b3493931d2fb915e2febd3536267d538a56408a6fef284ea38d29
F ext/wasm/api/extern-post-js.c-pp.js d8f5ffa354c790d89681d0a23594c02347d28046d60151bd598712fbdff6056c
F ext/wasm/api/extern-post-js.c-pp.js 88300aaf4cdb516f53ca3448dc19514a4182921ad9744e7b8fb8c2e3590ebb5e
F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41
F ext/wasm/api/post-js-footer.js 365405929f41ca0e6d389ed8a8da3f3c93e11d3ef43a90ae151e37fa9f75bf41
F ext/wasm/api/post-js-header.js 53740d824e5d9027eb1e6fd59e216abbd2136740ce260ea5f0699ff2acb0a701
@@ -599,7 +599,7 @@ F ext/wasm/api/pre-js.c-pp.js 58f823de197e2c10d76179aa05410a593b7ae03e1ece983bb4
F ext/wasm/api/sqlite3-api-cleanup.js 3ac1786e461ada63033143be8c3b00b26b939540661f3e839515bb92f2e35359
F ext/wasm/api/sqlite3-api-glue.c-pp.js c6a4271411caf9b0ff434436766fcd226e22cad484949fc207045d13ba960354
F ext/wasm/api/sqlite3-api-oo1.c-pp.js dc8573267f0dd49ae314a295c0dbe86de921f6d6beabbb7a447029ca1ea4e1d9
F ext/wasm/api/sqlite3-api-prologue.js 8ab2b1ad98240821ac98ec6d1c691f6018cdda8b73ba722a32a75c03e1754f6d
F ext/wasm/api/sqlite3-api-prologue.js 5812f5acb0eb17ce04cbea554fa33236acfcbe5eaaa6ddc04eb6454141040a98
F ext/wasm/api/sqlite3-api-worker1.c-pp.js 760191cd13416e6f5adfd9fcc8a97fed5645c9e0a5fbac213a2d4ce2d79a4334
F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89
F ext/wasm/api/sqlite3-opfs-async-proxy.js 9654b565b346dc609b75d15337f20acfa7af7d9d558da1afeb9b6d8eaa404966
@@ -607,7 +607,7 @@ F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c
F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 0f68a64e508598910e7c01214ae27d603dfc8baec6a184506fafac603a901931
F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 4ab0704ee198de7d1059eccedc7703c931510b588d10af0ee36ea5b3ebbac284
F ext/wasm/api/sqlite3-vtab-helper.c-pp.js e809739d71e8b35dfe1b55d24d91f02d04239e6aef7ca1ea92a15a29e704f616
F ext/wasm/api/sqlite3-wasm.c 38bf0af6328fd729c3db46843df92af413ed984174220602bf402b3eb3bcd5c0
F ext/wasm/api/sqlite3-wasm.c 75c50e7721136b60e2132537e039f6b85991449c761090709c2d920c4b82f420
F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js 4ad256b4ff7f839ad18931ed35d46cced544207bd2209665ec552e193f7f4544
F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5
F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7
@@ -618,7 +618,7 @@ F ext/wasm/c-pp.c cca55c5b55ebd8d29916adbedb0e40baa12caa9a2e8429f812683c308f9b0e
F ext/wasm/common/SqliteTestUtil.js 7adaeffef757d8708418dc9190f72df22367b531831775804b31598b44f6aa51
F ext/wasm/common/emscripten.css 11bd104b6c0d597c67d40cc8ecc0a60dae2b965151e3b6a37fa5708bac3acd15
F ext/wasm/common/testing.css e97549bab24126c24e0daabfe2de9bb478fb0a69fdb2ddd0a73a992c091aad6f
F ext/wasm/common/whwasmutil.js 9b805368c3c6466c4a52237dfe416654ff9fe4a32ef67c302804df5ab581b329
F ext/wasm/common/whwasmutil.js 1475e140bbd48d67e385603ce3e4bef7ca00d8ee3ec896d40cf4f55c7336b0c3
F ext/wasm/config.make.in c424ae1cc3c89274520ad312509d36c4daa34a3fce5d0c688e5f8f4365e1049a
F ext/wasm/demo-123-worker.html a0b58d9caef098a626a1a1db567076fca4245e8d60ba94557ede8684350a81ed
F ext/wasm/demo-123.html 8c70a412ce386bd3796534257935eb1e3ea5c581e5d5aea0490b8232e570a508
@@ -655,7 +655,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555
F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c
F ext/wasm/tester1-worker.html ebc4b820a128963afce328ecf63ab200bd923309eb939f4110510ab449e9814c
F ext/wasm/tester1.c-pp.html 1c1bc78b858af2019e663b1a31e76657b73dc24bede28ca92fbe917c3a972af2
F ext/wasm/tester1.c-pp.js ff69e6bdf40a7fd7d127a1396a5162926880caa66792cbc868a036174a8d6bbb
F ext/wasm/tester1.c-pp.js 827de6ae0b069709762afb58c452b769bbab092c6c7c850e5aab9581d82aff45
F ext/wasm/tests/opfs/concurrency/index.html 657578a6e9ce1e9b8be951549ed93a6a471f4520a99e5b545928668f4285fb5e
F ext/wasm/tests/opfs/concurrency/test.js d08889a5bb6e61937d0b8cbb78c9efbefbf65ad09f510589c779b7cc6a803a88
F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2
@@ -2175,8 +2175,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P f35bb66e3eb939d321afb3545c184013633ce35fa4cbd67b6be17a64997ece9d
R c35320c27f1fa89eaf4dc95d15eedb59
P 1e3b003ff99d2788d93e179504b711cb78846605774bf472589440d0136f20fa
R 5e413c78ac49f5649b20125a76a68b9e
U stephan
Z b704487a4e2713503ba05326e82a9d55
Z 40da1eb0811159ac3f90712f37f01328
# Remove this line to create a well-formed Fossil manifest.

View File

@@ -1 +1 @@
1e3b003ff99d2788d93e179504b711cb78846605774bf472589440d0136f20fa
a5af46174a05e1414370884d1a99827af9286a60eff1c8ae1551e7fad3903f7a