From: stephan Date: Sat, 17 Sep 2022 23:47:20 +0000 (+0000) Subject: Correct OPFS xRead() and xWrite() impls and add a very basic sanity test for them. X-Git-Tag: version-3.40.0~169^2~104 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5f4ad926817650b919ef1a9a987b8b70f906e9d9;p=thirdparty%2Fsqlite.git Correct OPFS xRead() and xWrite() impls and add a very basic sanity test for them. FossilOrigin-Name: cd06cc670029763955cf60ffcf944b36d41cb005b859d9b9fd0eea1b6741d0e9 --- diff --git a/ext/wasm/sqlite3-opfs-async-proxy.js b/ext/wasm/sqlite3-opfs-async-proxy.js index 4a60e8aa1a..58498e006b 100644 --- a/ext/wasm/sqlite3-opfs-async-proxy.js +++ b/ext/wasm/sqlite3-opfs-async-proxy.js @@ -259,10 +259,10 @@ const vfsAsyncImpls = { let rc = 0; const fh = __openFiles[fid]; try{ - const aRead = new Uint8array(fh.sab, n); + const aRead = new Uint8Array(fh.sab, 0, n); const nRead = fh.accessHandle.read(aRead, {at: offset}); if(nRead < n){/* Zero-fill remaining bytes */ - new Uint8array(fh.sab).fill(0, nRead, n); + new Uint8Array(fh.sab).fill(0, nRead, n); rc = state.sq3Codes.SQLITE_IOERR_SHORT_READ; } }catch(e){ @@ -302,7 +302,7 @@ const vfsAsyncImpls = { const fh = __openFiles[fid]; try{ affirmNotRO('xWrite', fh); - const nOut = fh.accessHandle.write(new UInt8Array(fh.sab, 0, n), {at: offset}); + const nOut = fh.accessHandle.write(new Uint8Array(fh.sab, 0, n), {at: offset}); rc = (nOut===n) ? 0 : state.sq3Codes.SQLITE_IOERR_WRITE; }catch(e){ error("xWrite():",e,fh); diff --git a/ext/wasm/x-sync-async.js b/ext/wasm/x-sync-async.js index 250fde349f..d36dc1700f 100644 --- a/ext/wasm/x-sync-async.js +++ b/ext/wasm/x-sync-async.js @@ -76,7 +76,7 @@ const initOpfsVfs = function(sqlite3){ of data may be added to it. */ const state = Object.create(null); - state.verbose = 3; + state.verbose = 2; state.fileBufferSize = 1024 * 64 + 8 /* size of fileHandle.sab. 64k = max sqlite3 page size */; state.fbInt64Offset = state.fileBufferSize - 8 /*spot in fileHandle.sab to store an int64*/; state.opIds = Object.create(null); @@ -239,10 +239,11 @@ const initOpfsVfs = function(sqlite3){ }, xRead: function(pFile,pDest,n,offset){ /* int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst) */ - const f = __opfsHandles[pFile]; + const f = __openFiles[pFile]; + let rc; try { // FIXME(?): block until we finish copying the xRead result buffer. How? - let rc = opRun('xRead',{fid:pFile, n, offset}); + rc = opRun('xRead',{fid:pFile, n, offset}); if(0!==rc) return rc; let i = 0; for(; i < n; ++i) wasm.setMemValue(pDest + i, f.sabView[i]); @@ -265,7 +266,7 @@ const initOpfsVfs = function(sqlite3){ }, xWrite: function(pFile,pSrc,n,offset){ /* int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst) */ - const f = __opfsHandles[pFile]; + const f = __openFiles[pFile]; try { let i = 0; // FIXME(?): block from here until we finish the xWrite. How? @@ -429,6 +430,14 @@ const initOpfsVfs = function(sqlite3){ rc = ioSyncWrappers.xFileSize(sq3File.pointer, pOut); if(rc) toss('xFileSize failed w/ rc',rc); log("xFileSize says:",wasm.getMemValue(pOut, 'i64')); + rc = ioSyncWrappers.xWrite(sq3File.pointer, zDbFile, 10, 0); + if(rc) toss("xWrite() failed!"); + const readBuf = wasm.scopedAlloc(16); + rc = ioSyncWrappers.xRead(sq3File.pointer, readBuf, 6, 1); + wasm.setMemValue(readBuf+6,0); + let jRead = wasm.cstringToJs(readBuf); + log("xRead() got:",jRead); + if("sanity"!==jRead) toss("Unexpected xRead() value."); log("xSleep()ing before close()ing..."); opRun('xSleep',1000); rc = ioSyncWrappers.xClose(fid); diff --git a/manifest b/manifest index 503b895473..b288f12d6c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Implement\sOPFS\sxAccess(),\salbeit\swith\smore\slimited\ssemantics\sthan\sthe\sVFS\sAPI\scalls\sfor.\sAdd\sa\sway\sfor\sOPFS\sxDelete()\sto\soptionally\srecursively\sremove\sempty\sdirs\sleft\sover\safter\sdeleting\sa\sfile. -D 2022-09-17T23:29:27.832 +C Correct\sOPFS\sxRead()\sand\sxWrite()\simpls\sand\sadd\sa\svery\sbasic\ssanity\stest\sfor\sthem. +D 2022-09-17T23:47:20.619 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -523,7 +523,7 @@ F ext/wasm/speedtest1.html fbb8e4d1639028443f3687a683be660beca6927920545cf6b1fdf F ext/wasm/split-speedtest1-script.sh a3e271938d4d14ee49105eb05567c6a69ba4c1f1293583ad5af0cd3a3779e205 x F ext/wasm/sql/000-mandelbrot.sql 775337a4b80938ac8146aedf88808282f04d02d983d82675bd63d9c2d97a15f0 F ext/wasm/sql/001-sudoku.sql 35b7cb7239ba5d5f193bc05ec379bcf66891bce6f2a5b3879f2f78d0917299b5 -F ext/wasm/sqlite3-opfs-async-proxy.js c4be9e614abea5f237564757141e3e128f0cff4b4cd8350f68e17347230fd34e +F ext/wasm/sqlite3-opfs-async-proxy.js ef012be0a77d3e34dc699de2e430b6d26a58c69dbebdd75248d8f41540996c71 F ext/wasm/sqlite3-worker1-promiser.js 92b8da5f38439ffec459a8215775d30fa498bc0f1ab929ff341fc3dd479660b9 F ext/wasm/sqlite3-worker1.js 0c1e7626304543969c3846573e080c082bf43bcaa47e87d416458af84f340a9e F ext/wasm/testing-worker1-promiser.html 6eaec6e04a56cf24cf4fa8ef49d78ce8905dde1354235c9125dca6885f7ce893 @@ -534,7 +534,7 @@ F ext/wasm/testing2.html a66951c38137ff1d687df79466351f3c734fa9c6d9cce71d3cf97c2 F ext/wasm/testing2.js 25584bcc30f19673ce13a6f301f89f8820a59dfe044e0c4f2913941f4097fe3c F ext/wasm/wasmfs.make 21a5cf297954a689e0dc2a95299ae158f681cae5e90c10b99d986097815fd42d F ext/wasm/x-sync-async.html 717b0d3bee96e49cbd36731bead497ab27a8bf3a3b23dd11e40e61d4ac9e8b80 -F ext/wasm/x-sync-async.js a95e8acb04fd69526317ee63bf25fa478a20e223d5dc16f7526baf5d81e07d1e +F ext/wasm/x-sync-async.js 961eb6c268086babd20d7b5e07cad72dc3118f9c46954e9a73b8b826deb4f771 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 @@ -2030,8 +2030,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 f36bddbe54c3acbfaa958042e4d24724f130bdca551401033f9bc63f3da73492 -R 5aad77d6a3a0d677e9c84e63e20c4294 +P c342b5d745f301104c59851c753287ebbbe95a69a56cb522d376d0f3e352c30f +R 70b6b0622f3dd6730d580a81783f068d U stephan -Z 31fefe04f3f471aad99d738829acf9a8 +Z 5c4a37b98dc31ffc6cd63d317f5738d7 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 6035cd7f00..39390f941c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c342b5d745f301104c59851c753287ebbbe95a69a56cb522d376d0f3e352c30f \ No newline at end of file +cd06cc670029763955cf60ffcf944b36d41cb005b859d9b9fd0eea1b6741d0e9 \ No newline at end of file