diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js index b95f15e71b..80438e086e 100644 --- a/ext/wasm/api/sqlite3-api-glue.js +++ b/ext/wasm/api/sqlite3-api-glue.js @@ -197,8 +197,8 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ try { let aVals = [], aNames = [], i = 0, offset = 0; for( ; i < nCols; offset += (wasm.ptrSizeof * ++i) ){ - aVals.push( wasm.cstrToJs(wasm.getPtrValue(pColVals + offset)) ); - aNames.push( wasm.cstrToJs(wasm.getPtrValue(pColNames + offset)) ); + aVals.push( wasm.cstrToJs(wasm.peekPtr(pColVals + offset)) ); + aNames.push( wasm.cstrToJs(wasm.peekPtr(pColNames + offset)) ); } rc = callback(pVoid, nCols, aVals, aNames) | 0; /* The first 2 args of the callback are useless for JS but @@ -294,7 +294,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ let i, pVal, valType, arg; const tgt = []; for(i = 0; i < argc; ++i){ - pVal = wasm.getPtrValue(pArgv + (wasm.ptrSizeof * i)); + pVal = wasm.peekPtr(pArgv + (wasm.ptrSizeof * i)); /** Curiously: despite ostensibly requiring 8-byte alignment, the pArgv array is parcelled into chunks of @@ -693,7 +693,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ pstack = wasm.pstack; const kvvfsStorage = (zClass)=> - ((115/*=='s'*/===wasm.getMemValue(zClass)) + ((115/*=='s'*/===wasm.peek(zClass)) ? sessionStorage : localStorage); /** @@ -717,13 +717,13 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ C-string's byte length. */; if(nBuf<=0) return nV; else if(1===nBuf){ - wasm.setMemValue(zBuf, 0); + wasm.poke(zBuf, 0); return nV; } const zV = wasm.scopedAllocCString(jV); if(nBuf > nV + 1) nBuf = nV + 1; wasm.heap8u().copyWithin(zBuf, zV, zV + nBuf - 1); - wasm.setMemValue(zBuf + nBuf - 1, 0); + wasm.poke(zBuf + nBuf - 1, 0); return nBuf - 1; }catch(e){ console.error("kvstorageRead()",e); diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js index a73983e8ca..a593889a8e 100644 --- a/ext/wasm/api/sqlite3-api-oo1.js +++ b/ext/wasm/api/sqlite3-api-oo1.js @@ -156,7 +156,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ try { const pPtr = wasm.pstack.allocPtr() /* output (sqlite3**) arg */; let rc = capi.sqlite3_open_v2(fn, pPtr, oflags, vfsName || 0); - pDb = wasm.getPtrValue(pPtr); + pDb = wasm.peekPtr(pPtr); checkSqlite3Rc(pDb, rc); if(flagsStr.indexOf('t')>=0){ capi.sqlite3_trace_v2(pDb, capi.SQLITE_TRACE_STMT, @@ -636,7 +636,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ try{ ppStmt = wasm.pstack.alloc(8)/* output (sqlite3_stmt**) arg */; DB.checkRc(this, capi.sqlite3_prepare_v2(this.pointer, sql, -1, ppStmt, null)); - pStmt = wasm.getPtrValue(ppStmt); + pStmt = wasm.peekPtr(ppStmt); } finally { wasm.pstack.restore(stack); @@ -816,8 +816,8 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ const pSqlEnd = pSql + sqlByteLen; if(isTA) wasm.heap8().set(arg.sql, pSql); else wasm.jstrcpy(arg.sql, wasm.heap8(), pSql, sqlByteLen, false); - wasm.setMemValue(pSql + sqlByteLen, 0/*NUL terminator*/); - while(pSql && wasm.getMemValue(pSql, 'i8') + wasm.poke(pSql + sqlByteLen, 0/*NUL terminator*/); + while(pSql && wasm.peek(pSql, 'i8') /* Maintenance reminder:^^^ _must_ be 'i8' or else we will very likely cause an endless loop. What that's doing is checking for a terminating NUL byte. If we @@ -825,12 +825,12 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ around the NUL terminator, and get stuck in and endless loop at the end of the SQL, endlessly re-preparing an empty statement. */ ){ - wasm.setPtrValue([ppStmt, pzTail], 0); + wasm.pokePtr([ppStmt, pzTail], 0); DB.checkRc(this, capi.sqlite3_prepare_v3( this.pointer, pSql, sqlByteLen, 0, ppStmt, pzTail )); - const pStmt = wasm.getPtrValue(ppStmt); - pSql = wasm.getPtrValue(pzTail); + const pStmt = wasm.peekPtr(ppStmt); + pSql = wasm.peekPtr(pzTail); sqlByteLen = pSqlEnd - pSql; if(!pStmt) continue; if(Array.isArray(opt.saveSql)){ diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index dafe3c5239..22dd55e76b 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -586,7 +586,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( It returns its result and compiled statement as documented in the C API. Fetching the output pointers (5th and 6th - parameters) requires using `capi.wasm.getMemValue()` (or + parameters) requires using `capi.wasm.peek()` (or equivalent) and the `pzTail` will point to an address relative to the `sqlAsPointer` value. @@ -1121,7 +1121,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( space managed by Emscripten's stack-management, so does not collide with Emscripten-provided stack allocation APIs. The memory lives in the WASM heap and can be used with routines such - as wasm.setMemValue() and any wasm.heap8u().slice(). + as wasm.poke() and any wasm.heap8u().slice(). */ wasm.pstack = Object.assign(Object.create(null),{ /** @@ -1180,7 +1180,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( When a returned pointers will refer to a 64-bit value, e.g. a double or int64, and that value must be written or fetched, - e.g. using wasm.setMemValue() or wasm.getMemValue(), it is + e.g. using wasm.poke() or wasm.peek(), it is important that the pointer in question be aligned to an 8-byte boundary or else it will not be fetched or written properly and will corrupt or read neighboring memory. @@ -1413,8 +1413,8 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( toss3("Database serialization failed with code", sqlite3.capi.sqlite3_js_rc_str(rc)); } - pOut = wasm.getPtrValue(ppOut); - const nOut = wasm.getMemValue(pSize, 'i64'); + pOut = wasm.peekPtr(ppOut); + const nOut = wasm.peek(pSize, 'i64'); rc = nOut ? wasm.heap8u().slice(pOut, pOut + Number(nOut)) : new Uint8Array(); diff --git a/ext/wasm/api/sqlite3-v-helper.js b/ext/wasm/api/sqlite3-v-helper.js index 82c7c76be7..ab296172f3 100644 --- a/ext/wasm/api/sqlite3-v-helper.js +++ b/ext/wasm/api/sqlite3-v-helper.js @@ -386,7 +386,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ */ create: (ppOut)=>{ const rc = __xWrap(); - wasm.setPtrValue(ppOut, rc.pointer); + wasm.pokePtr(ppOut, rc.pointer); return rc; }, /** @@ -544,7 +544,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ implementations. It must be passed the final argument to one of those methods (an output pointer to an int64 row ID) and the value to store at the output pointer's address. Returns the same - as wasm.setMemValue() and will throw if the 1st or 2nd arguments + as wasm.poke() and will throw if the 1st or 2nd arguments are invalid for that function. Example xRowid impl: @@ -557,7 +557,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ }; ``` */ - vtab.xRowid = (ppRowid64, value)=>wasm.setMemValue(ppRowid64, value, 'i64'); + vtab.xRowid = (ppRowid64, value)=>wasm.poke(ppRowid64, value, 'i64'); /** A helper to initialize and set up an sqlite3_module object for @@ -650,8 +650,8 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ try{return func(...arguments) || 0} catch(e){ if(!(e instanceof sqlite3.WasmAllocError)){ - wasm.dealloc(wasm.getPtrValue(pzErr)); - wasm.setPtrValue(pzErr, wasm.allocCString(e.message)); + wasm.dealloc(wasm.peekPtr(pzErr)); + wasm.pokePtr(pzErr, wasm.allocCString(e.message)); } return vtab.xError(methodName, e); } diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js index ea8bc9b299..50be31a2bd 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js @@ -678,7 +678,7 @@ const installOpfsVfs = function callee(options){ given pFile is open. */ const f = __openFiles[pFile]; - wasm.setMemValue(pOut, f.lockType ? 1 : 0, 'i32'); + wasm.poke(pOut, f.lockType ? 1 : 0, 'i32'); return 0; }, xClose: function(pFile){ @@ -711,7 +711,7 @@ const installOpfsVfs = function callee(options){ if(0==rc){ try { const sz = state.s11n.deserialize()[0]; - wasm.setMemValue(pSz64, sz, 'i64'); + wasm.poke(pSz64, sz, 'i64'); }catch(e){ error("Unexpected error reading xFileSize() result:",e); rc = state.sq3Codes.SQLITE_IOERR; @@ -804,20 +804,20 @@ const installOpfsVfs = function callee(options){ xAccess: function(pVfs,zName,flags,pOut){ mTimeStart('xAccess'); const rc = opRun('xAccess', wasm.cstrToJs(zName)); - wasm.setMemValue( pOut, (rc ? 0 : 1), 'i32' ); + wasm.poke( pOut, (rc ? 0 : 1), 'i32' ); mTimeEnd(); return 0; }, xCurrentTime: function(pVfs,pOut){ /* If it turns out that we need to adjust for timezone, see: https://stackoverflow.com/a/11760121/1458521 */ - wasm.setMemValue(pOut, 2440587.5 + (new Date().getTime()/86400000), + wasm.poke(pOut, 2440587.5 + (new Date().getTime()/86400000), 'double'); return 0; }, xCurrentTimeInt64: function(pVfs,pOut){ // TODO: confirm that this calculation is correct - wasm.setMemValue(pOut, (2440587.5 * 86400000) + new Date().getTime(), + wasm.poke(pOut, (2440587.5 * 86400000) + new Date().getTime(), 'i64'); return 0; }, @@ -867,7 +867,7 @@ const installOpfsVfs = function callee(options){ /* Recall that sqlite3_vfs::xClose() will be called, even on error, unless pFile->pMethods is NULL. */ if(fh.readOnly){ - wasm.setMemValue(pOutFlags, capi.SQLITE_OPEN_READONLY, 'i32'); + wasm.poke(pOutFlags, capi.SQLITE_OPEN_READONLY, 'i32'); } __openFiles[pFile] = fh; fh.sabView = state.sabFileBufView; @@ -1202,7 +1202,7 @@ const installOpfsVfs = function callee(options){ log("deserialize() says:",rc); if("This is ä string."!==rc[0]) toss("String d13n error."); vfsSyncWrappers.xAccess(opfsVfs.pointer, zDbFile, 0, pOut); - rc = wasm.getMemValue(pOut,'i32'); + rc = wasm.peek(pOut,'i32'); log("xAccess(",dbFile,") exists ?=",rc); rc = vfsSyncWrappers.xOpen(opfsVfs.pointer, zDbFile, fid, openFlags, pOut); @@ -1213,21 +1213,21 @@ const installOpfsVfs = function callee(options){ return; } vfsSyncWrappers.xAccess(opfsVfs.pointer, zDbFile, 0, pOut); - rc = wasm.getMemValue(pOut,'i32'); + rc = wasm.peek(pOut,'i32'); if(!rc) toss("xAccess() failed to detect file."); rc = ioSyncWrappers.xSync(sq3File.pointer, 0); if(rc) toss('sync failed w/ rc',rc); rc = ioSyncWrappers.xTruncate(sq3File.pointer, 1024); if(rc) toss('truncate failed w/ rc',rc); - wasm.setMemValue(pOut,0,'i64'); + wasm.poke(pOut,0,'i64'); rc = ioSyncWrappers.xFileSize(sq3File.pointer, pOut); if(rc) toss('xFileSize failed w/ rc',rc); - log("xFileSize says:",wasm.getMemValue(pOut, 'i64')); + log("xFileSize says:",wasm.peek(pOut, 'i64')); rc = ioSyncWrappers.xWrite(sq3File.pointer, zDbFile, 10, 1); if(rc) toss("xWrite() failed!"); const readBuf = wasm.scopedAlloc(16); rc = ioSyncWrappers.xRead(sq3File.pointer, readBuf, 6, 2); - wasm.setMemValue(readBuf+6,0); + wasm.poke(readBuf+6,0); let jRead = wasm.cstrToJs(readBuf); log("xRead() got:",jRead); if("sanity"!==jRead) toss("Unexpected xRead() value."); @@ -1241,7 +1241,7 @@ const installOpfsVfs = function callee(options){ log("Deleting file:",dbFile); vfsSyncWrappers.xDelete(opfsVfs.pointer, zDbFile, 0x1234); vfsSyncWrappers.xAccess(opfsVfs.pointer, zDbFile, 0, pOut); - rc = wasm.getMemValue(pOut,'i32'); + rc = wasm.peek(pOut,'i32'); if(rc) toss("Expecting 0 from xAccess(",dbFile,") after xDelete()."); warn("End of OPFS sanity checks."); }finally{ diff --git a/ext/wasm/batch-runner.js b/ext/wasm/batch-runner.js index 11c43217ff..ff287a66e7 100644 --- a/ext/wasm/batch-runner.js +++ b/ext/wasm/batch-runner.js @@ -227,20 +227,20 @@ const pSqlEnd = pSqlBegin + sqlByteLen; t = performance.now(); wasm.heap8().set(sql, pSql); - wasm.setMemValue(pSql + sqlByteLen, 0); + wasm.poke(pSql + sqlByteLen, 0); metrics.strcpy = performance.now() - t; let breaker = 0; - while(pSql && wasm.getMemValue(pSql,'i8')){ - wasm.setPtrValue(ppStmt, 0); - wasm.setPtrValue(pzTail, 0); + while(pSql && wasm.peek(pSql,'i8')){ + wasm.pokePtr(ppStmt, 0); + wasm.pokePtr(pzTail, 0); t = performance.now(); let rc = capi.sqlite3_prepare_v3( db.handle, pSql, sqlByteLen, 0, ppStmt, pzTail ); metrics.prepTotal += performance.now() - t; checkSqliteRc(db.handle, rc); - pStmt = wasm.getPtrValue(ppStmt); - pSql = wasm.getPtrValue(pzTail); + pStmt = wasm.peekPtr(ppStmt); + pSql = wasm.peekPtr(pzTail); sqlByteLen = pSqlEnd - pSql; if(!pStmt) continue/*empty statement*/; ++metrics.stmtCount; @@ -495,7 +495,7 @@ const oFlags = capi.SQLITE_OPEN_CREATE | capi.SQLITE_OPEN_READWRITE; const ppDb = wasm.scopedAllocPtr(); const rc = capi.sqlite3_open_v2(d.filename, ppDb, oFlags, null); - pDb = wasm.getPtrValue(ppDb) + pDb = wasm.peekPtr(ppDb) if(rc) toss("sqlite3_open_v2() failed with code",rc); capi.sqlite3_exec(pDb, "PRAGMA cache_size="+cacheSize, 0, 0, 0); this.logHtml(dbId,"cache_size =",cacheSize); diff --git a/ext/wasm/common/whwasmutil.js b/ext/wasm/common/whwasmutil.js index 9724f03e47..5de1aad6c6 100644 --- a/ext/wasm/common/whwasmutil.js +++ b/ext/wasm/common/whwasmutil.js @@ -608,15 +608,15 @@ self.WhWasmUtilInstaller = function(target){ be a pointer type and is treated as the WASM numeric type appropriate for the pointer size (`i32`). - While likely not obvious, this routine and its setMemValue() + While likely not obvious, this routine and its poke() counterpart are how pointer-to-value _output_ parameters in WASM-compiled C code can be interacted with: ``` const ptr = alloc(4); - setMemValue(ptr, 0, 'i32'); // clear the ptr's value + poke(ptr, 0, 'i32'); // clear the ptr's value aCFuncWithOutputPtrToInt32Arg( ptr ); // e.g. void foo(int *x); - const result = getMemValue(ptr, 'i32'); // fetch ptr's value + const result = peek(ptr, 'i32'); // fetch ptr's value dealloc(ptr); ``` @@ -628,15 +628,15 @@ self.WhWasmUtilInstaller = function(target){ const scope = scopedAllocPush(); try{ const ptr = scopedAlloc(4); - setMemValue(ptr, 0, 'i32'); + poke(ptr, 0, 'i32'); aCFuncWithOutputPtrArg( ptr ); - result = getMemValue(ptr, 'i32'); + result = peek(ptr, 'i32'); }finally{ scopedAllocPop(scope); } ``` - As a rule setMemValue() must be called to set (typically zero + As a rule poke() must be called to set (typically zero out) the pointer's value, else it will contain an essentially random value. @@ -644,9 +644,9 @@ self.WhWasmUtilInstaller = function(target){ painful impact on performance. Rather than doing so, use heapForSize() to fetch the heap object and read directly from it. - See: setMemValue() + See: poke() */ - target.getMemValue = function f(ptr, type='i8'){ + target.peek = function f(ptr, type='i8'){ if(type.endsWith('*')) type = ptrIR; const c = (cache.memory && cache.heapSize === cache.memory.buffer.byteLength) ? cache : heapWrappers(); @@ -668,7 +668,7 @@ self.WhWasmUtilInstaller = function(target){ } /* fallthru */ default: - toss('Invalid type for getMemValue():',type); + toss('Invalid type for peek():',type); } if(list) list.push(rc); }while(list && arguments[0].length); @@ -676,10 +676,10 @@ self.WhWasmUtilInstaller = function(target){ }; /** - The counterpart of getMemValue(), this sets a numeric value at + The counterpart of peek(), this sets a numeric value at the given WASM heap address, using the type to define how many bytes are written. Throws if given an invalid type. See - getMemValue() for details about the type argument. If the 3rd + peek() for details about the type argument. If the 3rd argument ends with `*` then it is treated as a pointer type and this function behaves as if the 3rd argument were `i32`. @@ -693,7 +693,7 @@ self.WhWasmUtilInstaller = function(target){ heapForSize() to fetch the heap object and assign directly to it or use the heap's set() method. */ - target.setMemValue = function(ptr, value, type='i8'){ + target.poke = function(ptr, value, type='i8'){ if (type.endsWith('*')) type = ptrIR; const c = (cache.memory && cache.heapSize === cache.memory.buffer.byteLength) ? cache : heapWrappers(); @@ -712,30 +712,37 @@ self.WhWasmUtilInstaller = function(target){ } /* fallthru */ default: - toss('Invalid type for setMemValue(): ' + type); + toss('Invalid type for poke(): ' + type); } } return this; }; /** - Convenience form of getMemValue() intended for fetching + Convenience form of peek() intended for fetching pointer-to-pointer values. If passed a single non-array argument it returns the value of that one pointer address. If passed multiple arguments, or a single array of arguments, it returns an array of their values. */ - target.getPtrValue = function(...ptr){ - return target.getMemValue( (1===ptr.length ? ptr[0] : ptr), ptrIR ); - }; + target.peekPtr = (...ptr)=>target.peek( (1===ptr.length ? ptr[0] : ptr), ptrIR ); /** - A variant of setMemValue() intended for setting - pointer-to-pointer values. Its differences from setMemValue() are + A variant of poke() intended for setting + pointer-to-pointer values. Its differences from poke() are that (1) it defaults to a value of 0, (2) it always writes to the pointer-sized heap view, and (3) it returns `this`. */ - target.setPtrValue = (ptr, value=0)=>target.setMemValue(ptr, value, ptrIR); + target.pokePtr = (ptr, value=0)=>target.poke(ptr, value, ptrIR); + + /** Deprecated alias for getMemValue() */ + target.getMemValue = target.peek; + /** Deprecated alias for peekPtr() */ + target.getPtrValue = target.peekPtr; + /** Deprecated alias for poke() */ + target.setMemValue = target.poke; + /** Deprecated alias for pokePtr() */ + target.setPtrValue = target.pokePtr; /** Returns true if the given value appears to be legal for use as @@ -1129,12 +1136,12 @@ self.WhWasmUtilInstaller = function(target){ ]((list.length + 1) * target.ptrSizeof); let i = 0; list.forEach((e)=>{ - target.setPtrValue(pList + (target.ptrSizeof * i++), + target.pokePtr(pList + (target.ptrSizeof * i++), target[ isScoped ? 'scopedAllocCString' : 'allocCString' ](""+e)); }); - target.setPtrValue(pList + (target.ptrSizeof * i), 0); + target.pokePtr(pList + (target.ptrSizeof * i), 0); return pList; }; @@ -1179,7 +1186,7 @@ self.WhWasmUtilInstaller = function(target){ target.cArgvToJs = (argc, pArgv)=>{ const list = []; for(let i = 0; i < argc; ++i){ - const arg = target.getPtrValue(pArgv + (target.ptrSizeof * i)); + const arg = target.peekPtr(pArgv + (target.ptrSizeof * i)); list.push( arg ? target.cstrToJs(arg) : null ); } return list; @@ -1203,7 +1210,7 @@ self.WhWasmUtilInstaller = function(target){ __affirmAlloc(target, method); const pIr = safePtrSize ? 'i64' : ptrIR; let m = target[method](howMany * (safePtrSize ? 8 : ptrSizeof)); - target.setMemValue(m, 0, pIr) + target.poke(m, 0, pIr) if(1===howMany){ return m; } @@ -1211,7 +1218,7 @@ self.WhWasmUtilInstaller = function(target){ for(let i = 1; i < howMany; ++i){ m += (safePtrSize ? 8 : ptrSizeof); a[i] = m; - target.setMemValue(m, 0, pIr); + target.poke(m, 0, pIr); } return a; }; @@ -1242,7 +1249,7 @@ self.WhWasmUtilInstaller = function(target){ When one of the returned pointers will refer to a 64-bit value, e.g. a double or int64, an that value must be written or fetched, - e.g. using setMemValue() or getMemValue(), it is important that + e.g. using poke() or peek(), it is important that the pointer in question be aligned to an 8-byte boundary or else it will not be fetched or written properly and will corrupt or read neighboring memory. It is only safe to pass false when the @@ -1521,8 +1528,8 @@ self.WhWasmUtilInstaller = function(target){ - Figure out how/whether we can (semi-)transparently handle pointer-type _output_ arguments. Those currently require explicit handling by allocating pointers, assigning them before - the call using setMemValue(), and fetching them with - getMemValue() after the call. We may be able to automate some + the call using poke(), and fetching them with + peek() after the call. We may be able to automate some or all of that. - Figure out whether it makes sense to extend the arg adapter diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index a9b22adde9..ddf60def9c 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -472,13 +472,13 @@ self.sqlite3InitModule = sqlite3InitModule; m = w.allocFromTypedArray(u); for(let i = 0; i < u.length; ++i){ T.assert(u[i] === byteList[i]) - .assert(u[i] === w.getMemValue(m + i, 'i8')); + .assert(u[i] === w.peek(m + i, 'i8')); } w.dealloc(m); m = w.allocFromTypedArray(u.buffer); for(let i = 0; i < u.length; ++i){ T.assert(u[i] === byteList[i]) - .assert(u[i] === w.getMemValue(m + i, 'i8')); + .assert(u[i] === w.peek(m + i, 'i8')); } w.dealloc(m); T.mustThrowMatching( @@ -557,14 +557,14 @@ self.sqlite3InitModule = sqlite3InitModule; let rc = w.cstrncpy(cpy, cStr, n+10); T.assert(n+1 === rc). assert("hello" === w.cstrToJs(cpy)). - assert(chr('o') === w.getMemValue(cpy+n-1)). - assert(0 === w.getMemValue(cpy+n)); + assert(chr('o') === w.peek(cpy+n-1)). + assert(0 === w.peek(cpy+n)); let cStr2 = w.scopedAllocCString("HI!!!"); rc = w.cstrncpy(cpy, cStr2, 3); T.assert(3===rc). assert("HI!lo" === w.cstrToJs(cpy)). - assert(chr('!') === w.getMemValue(cpy+2)). - assert(chr('l') === w.getMemValue(cpy+3)); + assert(chr('!') === w.peek(cpy+2)). + assert(chr('l') === w.peek(cpy+3)); }finally{ w.scopedAllocPop(scope); } @@ -587,8 +587,8 @@ self.sqlite3InitModule = sqlite3InitModule; const jstr = "hällo, world!"; const [cstr, n] = w.allocCString(jstr, true); T.assert(14 === n) - .assert(0===w.getMemValue(cstr+n)) - .assert(chr('!')===w.getMemValue(cstr+n-1)); + .assert(0===w.peek(cstr+n)) + .assert(chr('!')===w.peek(cstr+n-1)); w.dealloc(cstr); } @@ -624,8 +624,8 @@ self.sqlite3InitModule = sqlite3InitModule; const [z1, z2, z3] = w.scopedAllocPtr(3); T.assert('number'===typeof z1).assert(z2>z1).assert(z3>z2) - .assert(0===w.getMemValue(z1,'i32'), 'allocPtr() must zero the targets') - .assert(0===w.getMemValue(z3,'i32')); + .assert(0===w.peek(z1,'i32'), 'allocPtr() must zero the targets') + .assert(0===w.peek(z3,'i32')); }finally{ // Pop them in "incorrect" order to make sure they behave: w.scopedAllocPop(asc); @@ -645,8 +645,8 @@ self.sqlite3InitModule = sqlite3InitModule; T.assert(1===w.scopedAlloc.level); const [cstr, n] = w.scopedAllocCString("hello, world", true); T.assert(12 === n) - .assert(0===w.getMemValue(cstr+n)) - .assert(chr('d')===w.getMemValue(cstr+n-1)); + .assert(0===w.peek(cstr+n)) + .assert(chr('d')===w.peek(cstr+n-1)); }); }/*scopedAlloc()*/ @@ -708,9 +708,9 @@ self.sqlite3InitModule = sqlite3InitModule; w.scopedAllocCall(function(){ const pI1 = w.scopedAlloc(8), pI2 = pI1+4; - w.setPtrValue([pI1, pI2], 0); + w.pokePtr([pI1, pI2], 0); const f = w.xWrap('sqlite3_wasm_test_int64_minmax',undefined,['i64*','i64*']); - const [r1, r2] = w.getMemValue([pI1, pI2], 'i64'); + const [r1, r2] = w.peek([pI1, pI2], 'i64'); T.assert(!Number.isSafeInteger(r1)).assert(!Number.isSafeInteger(r2)); }); } @@ -954,8 +954,8 @@ self.sqlite3InitModule = sqlite3InitModule; try{ const n = 520; const p = wasm.pstack.alloc(n); - T.assert(0===wasm.getMemValue(p)) - .assert(0===wasm.getMemValue(p+n-1)); + T.assert(0===wasm.peek(p)) + .assert(0===wasm.peek(p+n-1)); T.assert(undefined === capi.sqlite3_randomness(n - 10, p)); let j, check = 0; const heap = wasm.heap8u(); @@ -1070,7 +1070,7 @@ self.sqlite3InitModule = sqlite3InitModule; rc = capi.sqlite3_db_status(this.db, capi.SQLITE_DBSTATUS_LOOKASIDE_USED, pCur, pHi, 0); T.assert(0===rc); - if(wasm.getMemValue(pCur, 'i32')){ + if(wasm.peek(pCur, 'i32')){ warn("Cannot test db_config(SQLITE_DBCONFIG_LOOKASIDE)", "while lookaside memory is in use."); }else{ @@ -1078,22 +1078,22 @@ self.sqlite3InitModule = sqlite3InitModule; 0, 4096, 12); T.assert(0 === rc); } - wasm.setPtrValue([pCur, pHi], 0); - let [vCur, vHi] = wasm.getPtrValue(pCur, pHi); + wasm.pokePtr([pCur, pHi], 0); + let [vCur, vHi] = wasm.peekPtr(pCur, pHi); T.assert(0===vCur).assert(0===vHi); rc = capi.sqlite3_status(capi.SQLITE_STATUS_MEMORY_USED, pCur, pHi, 0); - [vCur, vHi] = wasm.getPtrValue([pCur, pHi]); + [vCur, vHi] = wasm.peekPtr([pCur, pHi]); //console.warn("i32 vCur,vHi",vCur,vHi); T.assert(0 === rc).assert(vCur > 0).assert(vHi >= vCur); if(wasm.bigIntEnabled){ // Again in 64-bit. Recall that pCur and pHi are allocated // large enough to account for this re-use. - wasm.setPtrValue([pCur, pHi], 0) - .setMemValue([vCur, vHi], 0, 'i64'); + wasm.pokePtr([pCur, pHi], 0) + .poke([vCur, vHi], 0, 'i64'); rc = capi.sqlite3_status64(capi.SQLITE_STATUS_MEMORY_USED, pCur, pHi, 0); - [vCur, vHi] = wasm.getMemValue([pCur, pHi], 'i64'); + [vCur, vHi] = wasm.peek([pCur, pHi], 'i64'); //console.warn("i64 vCur,vHi",vCur,vHi); T.assert(0 === rc).assert(vCur > 0).assert(vHi >= vCur); } @@ -1303,11 +1303,11 @@ self.sqlite3InitModule = sqlite3InitModule; pzDT, pzColl, pNotNull, pPK, pAuto ); T.assert(0===rc) - .assert("INTEGER"===wasm.cstrToJs(wasm.getPtrValue(pzDT))) - .assert("BINARY"===wasm.cstrToJs(wasm.getPtrValue(pzColl))) - .assert(0===wasm.getMemValue(pNotNull,'i32')) - .assert(1===wasm.getMemValue(pPK,'i32')) - .assert(0===wasm.getMemValue(pAuto,'i32')) + .assert("INTEGER"===wasm.cstrToJs(wasm.peekPtr(pzDT))) + .assert("BINARY"===wasm.cstrToJs(wasm.peekPtr(pzColl))) + .assert(0===wasm.peek(pNotNull,'i32')) + .assert(1===wasm.peek(pPK,'i32')) + .assert(0===wasm.peek(pAuto,'i32')) }finally{ wasm.pstack.restore(stack); } @@ -1449,11 +1449,11 @@ self.sqlite3InitModule = sqlite3InitModule; name: 'summer', xStep: (pCtx, n)=>{ const ac = sjac(pCtx, 4); - wasm.setMemValue(ac, wasm.getMemValue(ac,'i32') + Number(n), 'i32'); + wasm.poke(ac, wasm.peek(ac,'i32') + Number(n), 'i32'); }, xFinal: (pCtx)=>{ const ac = sjac(pCtx, 0); - return ac ? wasm.getMemValue(ac,'i32') : 0; + return ac ? wasm.peek(ac,'i32') : 0; } }); let v = db.selectValue([ @@ -1472,13 +1472,13 @@ self.sqlite3InitModule = sqlite3InitModule; arity: -1, xStep: (pCtx, ...args)=>{ const ac = sjac(pCtx, 4); - let sum = wasm.getMemValue(ac, 'i32'); + let sum = wasm.peek(ac, 'i32'); for(const v of args) sum += Number(v); - wasm.setMemValue(ac, sum, 'i32'); + wasm.poke(ac, sum, 'i32'); }, xFinal: (pCtx)=>{ const ac = sjac(pCtx, 0); - capi.sqlite3_result_int( pCtx, ac ? wasm.getMemValue(ac,'i32') : 0 ); + capi.sqlite3_result_int( pCtx, ac ? wasm.peek(ac,'i32') : 0 ); // xFinal() may either return its value directly or call // sqlite3_result_xyz() and return undefined. Both are // functionally equivalent. @@ -1519,11 +1519,11 @@ self.sqlite3InitModule = sqlite3InitModule; name: 'summer64', xStep: (pCtx, n)=>{ const ac = sjac(pCtx, 8); - wasm.setMemValue(ac, wasm.getMemValue(ac,'i64') + BigInt(n), 'i64'); + wasm.poke(ac, wasm.peek(ac,'i64') + BigInt(n), 'i64'); }, xFinal: (pCtx)=>{ const ac = sjac(pCtx, 0); - return ac ? wasm.getMemValue(ac,'i64') : 0n; + return ac ? wasm.peek(ac,'i64') : 0n; } }); let v = db.selectValue([ @@ -1545,11 +1545,11 @@ self.sqlite3InitModule = sqlite3InitModule; const sjac = (cx,n=4)=>capi.sqlite3_js_aggregate_context(cx,n); const xValueFinal = (pCtx)=>{ const ac = sjac(pCtx, 0); - return ac ? wasm.getMemValue(ac,'i32') : 0; + return ac ? wasm.peek(ac,'i32') : 0; }; const xStepInverse = (pCtx, n)=>{ const ac = sjac(pCtx); - wasm.setMemValue(ac, wasm.getMemValue(ac,'i32') + Number(n), 'i32'); + wasm.poke(ac, wasm.peek(ac,'i32') + Number(n), 'i32'); }; db.createFunction({ name: 'winsumint', @@ -1670,32 +1670,32 @@ self.sqlite3InitModule = sqlite3InitModule; const ptrValType = 'i32'; try{ ptrInt = w.scopedAlloc(4); - w.setMemValue(ptrInt,origValue, ptrValType); + w.poke(ptrInt,origValue, ptrValType); const cf = w.xGet('sqlite3_wasm_test_intptr'); const oldPtrInt = ptrInt; //log('ptrInt',ptrInt); - //log('getMemValue(ptrInt)',w.getMemValue(ptrInt)); - T.assert(origValue === w.getMemValue(ptrInt, ptrValType)); + //log('peek(ptrInt)',w.peek(ptrInt)); + T.assert(origValue === w.peek(ptrInt, ptrValType)); const rc = cf(ptrInt); //log('cf(ptrInt)',rc); //log('ptrInt',ptrInt); - //log('getMemValue(ptrInt)',w.getMemValue(ptrInt,ptrValType)); + //log('peek(ptrInt)',w.peek(ptrInt,ptrValType)); T.assert(2*origValue === rc). - assert(rc === w.getMemValue(ptrInt,ptrValType)). + assert(rc === w.peek(ptrInt,ptrValType)). assert(oldPtrInt === ptrInt); const pi64 = w.scopedAlloc(8)/*ptr to 64-bit integer*/; const o64 = 0x010203040506/*>32-bit integer*/; const ptrType64 = 'i64'; if(w.bigIntEnabled){ - w.setMemValue(pi64, o64, ptrType64); + w.poke(pi64, o64, ptrType64); //log("pi64 =",pi64, "o64 = 0x",o64.toString(16), o64); - const v64 = ()=>w.getMemValue(pi64,ptrType64) - //log("getMemValue(pi64)",v64()); + const v64 = ()=>w.peek(pi64,ptrType64) + //log("peek(pi64)",v64()); T.assert(v64() == o64); - //T.assert(o64 === w.getMemValue(pi64, ptrType64)); + //T.assert(o64 === w.peek(pi64, ptrType64)); const cf64w = w.xGet('sqlite3_wasm_test_int64ptr'); cf64w(pi64); - //log("getMemValue(pi64)",v64()); + //log("peek(pi64)",v64()); T.assert(v64() == BigInt(2 * o64)); cf64w(pi64); T.assert(v64() == BigInt(4 * o64)); @@ -1707,8 +1707,8 @@ self.sqlite3InitModule = sqlite3InitModule; const pMin = w.scopedAlloc(16); const pMax = pMin + 8; - const g64 = (p)=>w.getMemValue(p,ptrType64); - w.setMemValue([pMin, pMax], 0, ptrType64); + const g64 = (p)=>w.peek(p,ptrType64); + w.poke([pMin, pMax], 0, ptrType64); const minMaxI64 = [ w.xCall('sqlite3_wasm_test_int64_min'), w.xCall('sqlite3_wasm_test_int64_max') @@ -1720,7 +1720,7 @@ self.sqlite3InitModule = sqlite3InitModule; T.assert(g64(pMin) === minMaxI64[0], "int64 mismatch"). assert(g64(pMax) === minMaxI64[1], "int64 mismatch"); //log("pMin",g64(pMin), "pMax",g64(pMax)); - w.setMemValue(pMin, minMaxI64[0], ptrType64); + w.poke(pMin, minMaxI64[0], ptrType64); T.assert(g64(pMin) === minMaxI64[0]). assert(minMaxI64[0] === db.selectValue("select ?",g64(pMin))). assert(minMaxI64[1] === db.selectValue("select ?",g64(pMax))); @@ -1775,13 +1775,13 @@ self.sqlite3InitModule = sqlite3InitModule; ); if(0===rc){ const t = VT.xVtab.create(ppVtab); - T.assert(t === VT.xVtab.get(wasm.getPtrValue(ppVtab))); + T.assert(t === VT.xVtab.get(wasm.peekPtr(ppVtab))); } return rc; }catch(e){ if(!(e instanceof sqlite3.WasmAllocError)){ - wasm.dealloc(wasm.getPtrValue, pzErr); - wasm.setPtrValue(pzErr, wasm.allocCString(e.message)); + wasm.dealloc(wasm.peekPtr, pzErr); + wasm.pokePtr(pzErr, wasm.allocCString(e.message)); } return VT.xError('xConnect',e); } @@ -1986,7 +1986,7 @@ self.sqlite3InitModule = sqlite3InitModule; ); if(0===rc){ const t = VT.xVtab.create(ppVtab); - T.assert(t === VT.xVtab.get(wasm.getPtrValue(ppVtab))); + T.assert(t === VT.xVtab.get(wasm.peekPtr(ppVtab))); vtabTrace("xCreate",...arguments," ppVtab =",t.pointer); } return rc; diff --git a/manifest b/manifest index f30b31d761..8cd8536f26 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Micro-optimization\sin\sthe\soft-activated\sJS-to-WASM\sarguments\sconversion\sstep. -D 2022-12-09T08:44:22.095 +C Rename\sthe\soft-used,\sverbose\ssqlite3.wasm.get/setMemValue()\sand\sget/setPtrValue()\sto\speek/poke()\sand\speek/pokePtr().\sThe\sold\snames\sare\sretained\sas\saliases\sjust\sin\scase\sany\sclient\scode\sactually\suses\sthem,\sbut\sthey\sare\snow\sdeprecated. +D 2022-12-09T09:23:27.874 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -503,25 +503,25 @@ F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08 F ext/wasm/api/post-js-header.js 47b6b281f39ad59fa6e8b658308cd98ea292c286a68407b35ff3ed9cfd281a62 F ext/wasm/api/pre-js.c-pp.js b88499dc303c21fc3f55f2c364a0f814f587b60a95784303881169f9e91c1d5f F ext/wasm/api/sqlite3-api-cleanup.js 680d5ccfff54459db136a49b2199d9f879c8405d9c99af1dda0cc5e7c29056f4 -F ext/wasm/api/sqlite3-api-glue.js c1d0dac2b00a3341f1caf3f8422140b93d2f7c5196a6133d13409f678655babc -F ext/wasm/api/sqlite3-api-oo1.js 70747d6482c1dda91d43bacc9b807642200b3631c4be50c372cf4ea98e90976e -F ext/wasm/api/sqlite3-api-prologue.js b0e1ca687b4470f3ee409c3d5938c3be7ac0c854b1401e217f0d56ba96636346 +F ext/wasm/api/sqlite3-api-glue.js f687f921f10a52800228445d10c7f7f4f5dab6059097e93d7749629b5fe5fe88 +F ext/wasm/api/sqlite3-api-oo1.js 6d10849609231ccd46fa11b1d3fbbe0f45d9fe84c66a0b054601036540844300 +F ext/wasm/api/sqlite3-api-prologue.js 496a4158e9904265d75715c57830d34ce528c4578b741d6f47c037d1a86fbe0d F ext/wasm/api/sqlite3-api-worker1.js e94ba98e44afccfa482874cd9acb325883ade50ed1f9f9526beb9de1711f182f F ext/wasm/api/sqlite3-license-version-header.js a661182fc93fc2cf212dfd0b987f8e138a3ac98f850b1112e29b5fbdaecc87c3 F ext/wasm/api/sqlite3-opfs-async-proxy.js 7795b84b66a7a8dedc791340709b310bb497c3c72a80bef364fa2a58e2ddae3f -F ext/wasm/api/sqlite3-v-helper.js 181117ad4c604500599dc07f07314a75f111dd06aab756e77ac8db64dff59d1d -F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 78133d710bee4c48a1a30262b44a284bc017a3751caa7967bdc030f5d0178daa +F ext/wasm/api/sqlite3-v-helper.js 64bb3559446eb441ce87afe942f6f924ee135a9f069a82705ffefdcd55fc6481 +F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 66daf6fb6843bea615fe193109e1542efbeca24f560ee9da63375a910bb48115 F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9 F ext/wasm/api/sqlite3-wasm.c ecf7af7259c7db4b467b7a3fec2faaa766777f370f201f5e6533593911d4acde F ext/wasm/api/sqlite3-worker1-promiser.js 0c7a9826dbf82a5ed4e4f7bf7816e825a52aff253afbf3350431f5773faf0e4b F ext/wasm/api/sqlite3-worker1.js 1e54ea3d540161bcfb2100368a2fc0cad871a207b8336afee1c445715851ec54 F ext/wasm/batch-runner.html 4deeed44fe41496dc6898d9fb17938ea3291f40f4bfb977e29d0cef96fbbe4c8 -F ext/wasm/batch-runner.js 49609e89aaac9989d6c1ad3fae268e4878e1ad7bc5fd3e5c2f44959660780b2e +F ext/wasm/batch-runner.js 0dad6a02ad796f1003d3b7048947d275c4d6277f63767b8e685c27df8fdac93e F ext/wasm/c-pp.c 92285f7bce67ed7b7020b40fde8ed0982c442b63dc33df9dfd4b658d4a6c0779 F ext/wasm/common/SqliteTestUtil.js d8bf97ecb0705a2299765c8fc9e11b1a5ac7f10988bbf375a6558b7ca287067b F ext/wasm/common/emscripten.css 11bd104b6c0d597c67d40cc8ecc0a60dae2b965151e3b6a37fa5708bac3acd15 F ext/wasm/common/testing.css 0ff15602a3ab2bad8aef2c3bd120c7ee3fd1c2054ad2ace7e214187ae68d926f -F ext/wasm/common/whwasmutil.js 96085c3fb17e019ac8e92a1310d6c976acdbc3dc1caec056ae7288d60df0f1b6 +F ext/wasm/common/whwasmutil.js ab8da0ba4133f44694f5c26687d954af09ba9e2cfa536596f641cd5ac147aebc F ext/wasm/demo-123-worker.html a0b58d9caef098a626a1a1db567076fca4245e8d60ba94557ede8684350a81ed F ext/wasm/demo-123.html 8c70a412ce386bd3796534257935eb1e3ea5c581e5d5aea0490b8232e570a508 F ext/wasm/demo-123.js ebae30756585bca655b4ab2553ec9236a87c23ad24fc8652115dcedb06d28df6 @@ -555,7 +555,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555 F ext/wasm/test-opfs-vfs.js 44363db07b2a20e73b0eb1808de4400ca71b703af718d0fa6d962f15e73bf2ac F ext/wasm/tester1-worker.html d43f3c131d88f10d00aff3e328fed13c858d674ea2ff1ff90225506137f85aa9 F ext/wasm/tester1.c-pp.html d34bef3d48e5cbc1c7c06882ad240fec49bf88f5f65696cc2c72c416933aa406 -F ext/wasm/tester1.c-pp.js 323f83c0aee8ae44bfacfc2d7e77cf2f3f1f2b3475ae63bb90772d882741f4e2 +F ext/wasm/tester1.c-pp.js c5555f271bf10db2cda8550549178ec7b9a6f77236592f0a9c3132c46c4ca5cf F ext/wasm/tests/opfs/concurrency/index.html 86d8ac435074d1e7007b91105f4897f368c165e8cecb6a9aa3d81f5cf5dcbe70 F ext/wasm/tests/opfs/concurrency/test.js a98016113eaf71e81ddbf71655aa29b0fed9a8b79a3cdd3620d1658eb1cc9a5d F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 @@ -2067,8 +2067,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f07141b7500c36169c2c96e045acf37ec97a0d75c0a5f4d0ebed4dc1d2094ccf -R bbdb4e606f2496a8e678d46149d27e66 +P ee47e9b83ca668b37dc1d8e519048a635693cf33d9967a2d81ff0824b7eea4ba +R 51ad3b31f5be17cf2dd5876e95922a5a U stephan -Z a13be2222b1eb37b716fa4d706c4fcde +Z 8e66df1e6b7cf683557d1817b0c14d69 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 66e94c3dc5..7067f450cd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ee47e9b83ca668b37dc1d8e519048a635693cf33d9967a2d81ff0824b7eea4ba \ No newline at end of file +ad0a8139b0b025f8e9d2eca0c303557ef10fdfab8c8b65afb08c510a804073d5 \ No newline at end of file