From: stephan Date: Sat, 20 Sep 2025 00:43:47 +0000 (+0000) Subject: Baby steps towards 64-bit pointers. Get it building and testing again in 32-bit builds. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6a03f2029b5a75f34f391fe25e210af331ce3807;p=thirdparty%2Fsqlite.git Baby steps towards 64-bit pointers. Get it building and testing again in 32-bit builds. FossilOrigin-Name: f35bb66e3eb939d321afb3545c184013633ce35fa4cbd67b6be17a64997ece9d --- diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index dc132f162c..a3ed17804b 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -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 ?= 1 +emcc.MEMORY64 ?= 0 ######################################################################## # https://emscripten.org/docs/tools_reference/settings_reference.html#memory64 # diff --git a/ext/wasm/api/sqlite3-api-glue.c-pp.js b/ext/wasm/api/sqlite3-api-glue.c-pp.js index 5aa0e2af18..05e9569701 100644 --- a/ext/wasm/api/sqlite3-api-glue.c-pp.js +++ b/ext/wasm/api/sqlite3-api-glue.c-pp.js @@ -732,6 +732,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ alloc: wasm.alloc, dealloc: wasm.dealloc, bigIntEnabled: wasm.bigIntEnabled, + ptrIR: wasm.pointerIR, memberPrefix: /* Never change this: this prefix is baked into any amount of code and client-facing docs. (Much later: it probably should have been '$$', but see diff --git a/ext/wasm/common/whwasmutil.js b/ext/wasm/common/whwasmutil.js index 2cc5b6d2ec..ad6ce32c21 100644 --- a/ext/wasm/common/whwasmutil.js +++ b/ext/wasm/common/whwasmutil.js @@ -269,7 +269,9 @@ globalThis.WhWasmUtilInstaller = function(target){ The number 0 as either type Number or BigInt, depending on target.pointerIR. */ - target.NullPtr = __asPtrType(0); + const __NullPtr = __asPtrType(0); + + target.NullPtr = __NullPtr; /** Stores various cached state. */ const cache = Object.create(null); @@ -1379,9 +1381,9 @@ globalThis.WhWasmUtilInstaller = function(target){ } const a = [m]; for(let i = 1; i < howMany; ++i){ - m += (safePtrSize ? 8 : ptrSizeof); + m = __ptrAdd(m, (safePtrSize ? 8 : ptrSizeof)); a[i] = m; - target.poke(m, 0, pIr); + target.poke(m, __NullPtr, pIr); } return a; }; diff --git a/ext/wasm/jaccwabyt/jaccwabyt.js b/ext/wasm/jaccwabyt/jaccwabyt.js index 5a971f6e65..f876142f78 100644 --- a/ext/wasm/jaccwabyt/jaccwabyt.js +++ b/ext/wasm/jaccwabyt/jaccwabyt.js @@ -64,14 +64,32 @@ globalThis.Jaccwabyt = function StructBinderFactory(config){ BigInt = globalThis['BigInt'], BigInt64Array = globalThis['BigInt64Array'], /* Undocumented (on purpose) config options: */ - ptrSizeof = config.ptrSizeof || 4, - ptrIR = config.ptrIR || 'i32' + ptrIR = config.ptrIR || 'i32', + ptrSizeof = config.ptrSizeof || ('i32'===ptrIR ? 4 : 8) ; const __asPtrType = ('i32'==ptrIR) ? Number - : (target.bigIntEnabled + : (bigIntEnabled ? (v)=>BigInt(v || 0) : toss("Missing BigInt support")); + const __NullPtr = __asPtrType(0); + /** + Expects any number of numeric arguments, each one of either type + Number or BigInt. It sums them up (from an implicit starting + point of 0 or 0n) and returns them as a number of the same type + which target.asPtrType() uses. + + This is a workaround for not being able to mix Number/BigInt in + addition/subtraction expressions (which we frequently need for + calculating pointer offsets). + */ + const __ptrAdd = function(...args){ + let rc = __NullPtr; + for( let i = 0; i < args.length; ++i ){ + rc += __asPtrType(args[i]); + } + return rc; + }; if(!SBF.debugFlags){ SBF.__makeDebugFlags = function(deriveFrom=null){ @@ -293,7 +311,7 @@ globalThis.Jaccwabyt = function StructBinderFactory(config){ const __memoryDump = function(){ const p = this.pointer; return p - ? new Uint8Array(heap().slice(p, p+this.structInfo.sizeof)) + ? new Uint8Array(heap().slice(Number(p), Number(p) + this.structInfo.sizeof)) : null; }; @@ -667,11 +685,12 @@ globalThis.Jaccwabyt = function StructBinderFactory(config){ const zeroAsPtr = __asPtrType(0); const StructCtor = function StructCtor(externalMemory){ externalMemory = __asPtrType(externalMemory); + //console.warn("externalMemory",externalMemory,arguments[0]); if(!(this instanceof StructCtor)){ toss("The",structName,"constructor may only be called via 'new'."); }else if(arguments.length){ - if(externalMemory<=zeroAsPtr){ - toss("Invalid pointer value for",structName,"constructor."); + if(Number.isNaN(externalMemory) || externalMemory<=zeroAsPtr){ + toss("Invalid pointer value",arguments[0],"for",structName,"constructor."); } __allocStruct(StructCtor, this, externalMemory); }else{ diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index ec77e0bc9a..9c9f5e7191 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -160,6 +160,8 @@ globalThis.sqlite3InitModule = sqlite3InitModule; const roundMs = (ms)=>Math.round(ms*100)/100; + const looksLikePtr = (v)=> v>=0; + /** Helpers for writing sqlite3-specific tests. */ @@ -685,21 +687,21 @@ globalThis.sqlite3InitModule = sqlite3InitModule; const p1 = w.scopedAlloc(16), p2 = w.scopedAlloc(16); T.assert(1===w.scopedAlloc.level) - .assert(Number.isFinite(p1)) - .assert(Number.isFinite(p2)) + .assert(looksLikePtr(p1)) + .assert(looksLikePtr(p2)) .assert(asc[0] === p1) .assert(asc[1]===p2); asc2 = w.scopedAllocPush(); const p3 = w.scopedAlloc(16); T.assert(2===w.scopedAlloc.level) - .assert(Number.isFinite(p3)) + .assert(looksLikePtr(p3)) .assert(2===asc.length) .assert(p3===asc2[0]); const [z1, z2, z3] = w.scopedAllocPtr(3); - T.assert('number'===typeof z1).assert(z2>z1).assert(z3>z2) - .assert(0===w.peek32(z1), 'allocPtr() must zero the targets') - .assert(0===w.peek32(z3)); + T.assert(typeof w.NullPtr===typeof z1).assert(z2>z1).assert(z3>z2) + .assert(w.NullPtr===w.peekPtr(z1), 'allocPtr() must zero the targets') + .assert(w.NullPtr===w.peekPtr(z3)); }finally{ // Pop them in "incorrect" order to make sure they behave: w.scopedAllocPop(asc); @@ -719,15 +721,15 @@ globalThis.sqlite3InitModule = sqlite3InitModule; T.assert(1===w.scopedAlloc.level); const [cstr, n] = w.scopedAllocCString("hello, world", true); T.assert(12 === n) - .assert(0===w.peek8(cstr+n)) - .assert(chr('d')===w.peek8(cstr+n-1)); + .assert(0===w.peek8( w.ptrAdd(cstr,n) )) + .assert(chr('d')===w.peek8( w.ptrAdd(cstr, n, -1) )); }); }/*scopedAlloc()*/ //log("xCall()..."); { const pJson = w.xCall('sqlite3__wasm_enum_json'); - T.assert(Number.isFinite(pJson)).assert(w.cstrlen(pJson)>300); + T.assert(looksLikePtr(pJson)).assert(w.cstrlen(pJson)>300); } //log("xWrap()..."); @@ -741,7 +743,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; let rc = fw(); T.assert('string'===typeof rc).assert(rc.length>5); rc = w.xCallWrapped('sqlite3__wasm_enum_json','*'); - T.assert(rc>0 && Number.isFinite(rc)); + T.assert(rc>0 && looksLikePtr(rc)); rc = w.xCallWrapped('sqlite3__wasm_enum_json','utf8'); T.assert('string'===typeof rc).assert(rc.length>300); @@ -840,8 +842,8 @@ globalThis.sqlite3InitModule = sqlite3InitModule; T.assert(12n===rc); w.scopedAllocCall(function(){ - const pI1 = w.scopedAlloc(8), pI2 = pI1+4; - w.pokePtr([pI1, pI2], 0); + const pI1 = w.scopedAlloc(8), pI2 = w.ptrAdd(pI1, 4); + w.pokePtr([pI1, pI2], w.NullPtr); const f = w.xWrap('sqlite3__wasm_test_int64_minmax',undefined,['i64*','i64*']); const [r1, r2] = w.peek64([pI1, pI2]); T.assert(!Number.isSafeInteger(r1)).assert(!Number.isSafeInteger(r2)); @@ -859,23 +861,34 @@ globalThis.sqlite3InitModule = sqlite3InitModule; test: function(sqlite3){ const S = sqlite3, W = S.wasm; const MyStructDef = { - sizeof: 16, - members: { - p4: {offset: 0, sizeof: 4, signature: "i"}, - pP: {offset: 4, sizeof: 4, signature: "P"}, - ro: {offset: 8, sizeof: 4, signature: "i", readOnly: true}, - cstr: {offset: 12, sizeof: 4, signature: "s"} - } + sizeof: 0, members: {} + }; + const addMember = function(tgt, name, member){ + member.offset = tgt.sizeof; + tgt.sizeof += member.sizeof; + tgt.members[name] = member; }; + const msd = MyStructDef; + addMember(msd, 'p4', {sizeof: 4, signature: "i"}); + addMember(msd, 'pP', {sizeof: wasm.ptrSizeof, signature: "P"}); + addMember(msd, 'ro', { + sizeof: 4, + signature: "i", + readOnly: true + }); + addMember(msd, 'cstr', { + sizeof: wasm.ptrSizeof, + signature: "s" + }); if(W.bigIntEnabled){ - const m = MyStructDef; - m.members.p8 = {offset: m.sizeof, sizeof: 8, signature: "j"}; - m.sizeof += m.members.p8.sizeof; + addMember(msd, 'p8', {sizeof: 8, signature: "j"}); } const StructType = S.StructBinder.StructType; const K = S.StructBinder('my_struct',MyStructDef); T.mustThrowMatching(()=>K(), /via 'new'/). - mustThrowMatching(()=>new K('hi'), /^Invalid pointer/); + mustThrowMatching(()=>new K('hi'), (err)=>{ + return /^Invalid pointer/.test(err.message) || /.*bigint.*/i.test(err.message); + }); const k1 = new K(), k2 = new K(); try { T.assert(k1.constructor === K). @@ -895,10 +908,10 @@ globalThis.sqlite3InitModule = sqlite3InitModule; "for "+key+" but got: "+k1[key]+ " from "+k1.memoryDump()); }); - T.assert('number' === typeof k1.pointer). + T.assert(looksLikePtr(k1.pointer)). mustThrowMatching(()=>k1.pointer = 1, /pointer/); k1.$p4 = 1; k1.$pP = 2; - T.assert(1 === k1.$p4).assert(2 === k1.$pP); + T.assert(1 == k1.$p4).assert(2 == k1.$pP); if(MyStructDef.members.$p8){ k1.$p8 = 1/*must not throw despite not being a BigInt*/; k1.$p8 = BigInt(Number.MAX_SAFE_INTEGER * 2); diff --git a/manifest b/manifest index eefc42c85c..5bf700d9de 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Initial\sexperimentation\swith\sa\s-sMEMORY64=1\swasm\sbuild\s(full\s64-bit).\sThis\scompiles\sbut\sdoes\snot\spass\stests\sdue\sto\sfriction\sbetween\sBigInt\sand\sNumber\stypes\s(e.g.\sNumber(null)===0\sbut\sBigInt(null)\sthrows,\smany\sfunctions\sare\sfussy\sabout\swhich\sof\sthose\stypes\sthey'll\stake,\sand\swe\scannot\ssimply\smix\sand\smatch\sthe\stwo\stypes\stransparently\s(1n+1\sis\snot\slegal\s(but\s1n>=1\sis),\sso\swe\scan\sno\slonger\sdo\spointer\sarithmatic\swithout\shoop-jumping)).\sThe\slibrary\sbootstraps\sbut\sit's\sfailing\searly\son\sin\stests\sdue\sto\sthis\sfriction. -D 2025-09-19T23:21:00.279 +C Baby\ssteps\stowards\s64-bit\spointers.\sGet\sit\sbuilding\sand\stesting\sagain\sin\s32-bit\sbuilds. +D 2025-09-20T00:43:47.828 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 d7f9818a7fca38dc4975422da7de2bf1c8b6e5d617317ed9a2cdb122d35f5716 +F ext/wasm/GNUmakefile 5a4ce7cd670405e7d638f7138699f1c1d30bc934213ac05e489eb5f9d3f42b57 F ext/wasm/README-dist.txt f01081a850ce38a56706af6b481e3a7878e24e42b314cfcd4b129f0f8427066a F ext/wasm/README.md 66ace67ae98a45e4116f2ca5425b716887bcee4d64febee804ff6398e1ae9ec7 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -597,7 +597,7 @@ F ext/wasm/api/post-js-footer.js 365405929f41ca0e6d389ed8a8da3f3c93e11d3ef43a90a F ext/wasm/api/post-js-header.js 53740d824e5d9027eb1e6fd59e216abbd2136740ce260ea5f0699ff2acb0a701 F ext/wasm/api/pre-js.c-pp.js 58f823de197e2c10d76179aa05410a593b7ae03e1ece983bb42ffd818e8857e1 F ext/wasm/api/sqlite3-api-cleanup.js 3ac1786e461ada63033143be8c3b00b26b939540661f3e839515bb92f2e35359 -F ext/wasm/api/sqlite3-api-glue.c-pp.js 05cff4e731a667c27451456204c238e6ef2c24dd346d5efdd57f3ec58d7fd190 +F ext/wasm/api/sqlite3-api-glue.c-pp.js a7e51c50c89146329e5caa1784eed37c95e4fde2a5d872351723dbff372c7362 F ext/wasm/api/sqlite3-api-oo1.c-pp.js dc8573267f0dd49ae314a295c0dbe86de921f6d6beabbb7a447029ca1ea4e1d9 F ext/wasm/api/sqlite3-api-prologue.js a5e104261e76495715c99837cb51b14a6b78eb959da45258ecce54cad2058f79 F ext/wasm/api/sqlite3-api-worker1.c-pp.js 760191cd13416e6f5adfd9fcc8a97fed5645c9e0a5fbac213a2d4ce2d79a4334 @@ -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 0fdbecc28f15b80c2d1170a0c08c5641d3018fe430ac6fff27ecd68ae870ee06 +F ext/wasm/common/whwasmutil.js 2bf2920d2ef25f0e0c7342ab761e91ff6060345e956869dc8e3312e0832af0cb F ext/wasm/config.make.in c424ae1cc3c89274520ad312509d36c4daa34a3fce5d0c688e5f8f4365e1049a F ext/wasm/demo-123-worker.html a0b58d9caef098a626a1a1db567076fca4245e8d60ba94557ede8684350a81ed F ext/wasm/demo-123.html 8c70a412ce386bd3796534257935eb1e3ea5c581e5d5aea0490b8232e570a508 @@ -637,7 +637,7 @@ F ext/wasm/fiddle/fiddle.js f0b96f978c7c77fea8d092aa79c77849ce111d7b1ba60ffba076 F ext/wasm/fiddle/index.html 17c7d6b21f40fbf462162c4311b63d760b065e419d9f5a96534963b0e52af940 F ext/wasm/index-dist.html 56132399702b15d70c474c3f1952541e25cb0922942868f70daf188f024b3730 F ext/wasm/index.html bcaa00eca521b372a6a62c7e7b17a870b0fcdf3e418a5921df1fd61e5344080d -F ext/wasm/jaccwabyt/jaccwabyt.js b0f777ad9038c8b17f109cbae50cb452a4ea25e29d71ec078ba97fa326d2f0df +F ext/wasm/jaccwabyt/jaccwabyt.js 8135dff039727ecdfc807d0d4f25f1966a1c50e4e893838f157e685d565bcad6 F ext/wasm/jaccwabyt/jaccwabyt.md 1128e3563e7eff90b5a373395251fc76cb32386fad1fea6075b0f34a8f1b9bdf F ext/wasm/mkwasmbuilds.c cc66cfaf8673ece3c30ca7fe28f6111481090648098a143ea619a8820b8fbe82 F ext/wasm/module-symbols.html dc476b403369b26a1a23773e13b80f41b9a49f0825e81435fe3600a7cfbbe337 @@ -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 4ddf0715915abc98768fb678fa4e06b87136440119821040871c5394cae42225 +F ext/wasm/tester1.c-pp.js b20b0771e2e3ec14071f4ab37c505089e6b6f8117333b1fa43cf1116324a893b 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,11 +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 0b14fd35ca37075bb65b2ab398f3324dc851347b1c042566eac23724013653f8 -R d6a5d771720545ddaa81aa730696b2f5 -T *branch * wasm-64bit -T *sym-wasm-64bit * -T -sym-trunk * Cancelled\sby\sbranch. +P cfd5c746a6111f49c9c83a56c3ef65223456306f2de6e20b36b1ca0c98b593e9 +R da42d6d14ac4ef5c5b8683e064208718 U stephan -Z 3266854e43016c8ffb49e94aa674169f +Z 27b1d88685e7413724f033cba49e1430 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 59ee375390..8fb07b7fa9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cfd5c746a6111f49c9c83a56c3ef65223456306f2de6e20b36b1ca0c98b593e9 +f35bb66e3eb939d321afb3545c184013633ce35fa4cbd67b6be17a64997ece9d