1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Remove two incorrect calls to structType.dipose() which prematurely freed objects in use by the virtual table test/demo code.

FossilOrigin-Name: 060eb2848975a24ff6683a8a9c4d7546ae36147323b0edae01fb42f52d9bb2d6
This commit is contained in:
stephan
2022-12-10 15:41:47 +00:00
parent 9cb6ff2792
commit 8c0041f5bf
4 changed files with 70 additions and 69 deletions

View File

@ -319,16 +319,6 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
return this; return this;
}; };
/**
Expects to be passed the (argc,argv) arguments of
sqlite3_module::xFilter(), or an equivalent API. This function
transforms the arguments (an array of (sqlite3_value*)) into a JS
array of equivalent JS values. It uses the same type conversions
as sqlite3_create_function_v2() and friends. Throws on error,
e.g. if it cannot figure out a sensible data conversion.
*/
vtab.sqlite3ValuesToJs = capi.sqlite3_create_function_v2.udfConvertArgs;
/** /**
Internal factory function for xVtab and xCursor impls. Internal factory function for xVtab and xCursor impls.
*/ */
@ -401,6 +391,9 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
sqlite3_vtab_cursor: to be called from any sqlite3_module methods sqlite3_vtab_cursor: to be called from any sqlite3_module methods
which take a `sqlite3_vtab_cursor*` argument except xClose(), which take a `sqlite3_vtab_cursor*` argument except xClose(),
in which case use unget() or dispose(). in which case use unget() or dispose().
Rule to remember: _never_ call dispose() on an instance
returned by this function.
*/ */
get: (pCObj)=>__xWrap(pCObj), get: (pCObj)=>__xWrap(pCObj),
/** /**
@ -416,6 +409,9 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
sqlite3_vtab_cursor: to be called from xClose() or during sqlite3_vtab_cursor: to be called from xClose() or during
cleanup in a failed xOpen(). cleanup in a failed xOpen().
Calling this method obligates the caller to call dispose() on
the returned object when they're done with it.
*/ */
unget: (pCObj)=>__xWrap(pCObj,true), unget: (pCObj)=>__xWrap(pCObj,true),
/** /**

View File

@ -1388,60 +1388,65 @@ self.sqlite3InitModule = sqlite3InitModule;
}/*sqlite3_js_vfs_create_file()*/) }/*sqlite3_js_vfs_create_file()*/)
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
.t('Scalar UDFs', function(sqlite3){ .t({
const db = this.db; name:'Scalar UDFs',
db.createFunction("foo",(pCx,a,b)=>a+b); //predicate: ()=>false,
T.assert(7===db.selectValue("select foo(3,4)")). test: function(sqlite3){
assert(5===db.selectValue("select foo(3,?)",2)). const db = this.db;
assert(5===db.selectValue("select foo(?,?2)",[1,4])). db.createFunction("foo",(pCx,a,b)=>a+b);
assert(5===db.selectValue("select foo($a,$b)",{$a:0,$b:5})); T.assert(7===db.selectValue("select foo(3,4)")).
db.createFunction("bar", { assert(5===db.selectValue("select foo(3,?)",2)).
arity: -1, assert(5===db.selectValue("select foo(?,?2)",[1,4])).
xFunc: (pCx,...args)=>{ assert(5===db.selectValue("select foo($a,$b)",{$a:0,$b:5}));
let rc = 0; db.createFunction("bar", {
for(const v of args) rc += v; arity: -1,
return rc; xFunc: (pCx,...args)=>{
} let rc = 0;
}).createFunction({ for(const v of args) rc += v;
name: "asis", return rc;
xFunc: (pCx,arg)=>arg }
}); }).createFunction({
T.assert(0===db.selectValue("select bar()")). name: "asis",
assert(1===db.selectValue("select bar(1)")). xFunc: (pCx,arg)=>arg
assert(3===db.selectValue("select bar(1,2)")). });
assert(-1===db.selectValue("select bar(1,2,-4)")). T.assert(0===db.selectValue("select bar()")).
assert('hi' === db.selectValue("select asis('hi')")). assert(1===db.selectValue("select bar(1)")).
assert('hi' === db.selectValue("select ?",'hi')). assert(3===db.selectValue("select bar(1,2)")).
assert(null === db.selectValue("select null")). assert(-1===db.selectValue("select bar(1,2,-4)")).
assert(null === db.selectValue("select asis(null)")). assert('hi' === db.selectValue("select asis('hi')")).
assert(1 === db.selectValue("select ?",1)). assert('hi' === db.selectValue("select ?",'hi')).
assert(2 === db.selectValue("select ?",[2])). assert(null === db.selectValue("select null")).
assert(3 === db.selectValue("select $a",{$a:3})). assert(null === db.selectValue("select asis(null)")).
assert(T.eqApprox(3.1,db.selectValue("select 3.0 + 0.1"))). assert(1 === db.selectValue("select ?",1)).
assert(T.eqApprox(1.3,db.selectValue("select asis(1 + 0.3)"))); assert(2 === db.selectValue("select ?",[2])).
assert(3 === db.selectValue("select $a",{$a:3})).
assert(T.eqApprox(3.1,db.selectValue("select 3.0 + 0.1"))).
assert(T.eqApprox(1.3,db.selectValue("select asis(1 + 0.3)")));
let blobArg = new Uint8Array([0x68, 0x69]); let blobArg = new Uint8Array([0x68, 0x69]);
let blobRc = db.selectValue("select asis(?1)", blobArg); let blobRc = db.selectValue("select asis(?1)", blobArg);
T.assert(blobRc instanceof Uint8Array). T.assert(blobRc instanceof Uint8Array).
assert(2 === blobRc.length). assert(2 === blobRc.length).
assert(0x68==blobRc[0] && 0x69==blobRc[1]); assert(0x68==blobRc[0] && 0x69==blobRc[1]);
blobRc = db.selectValue("select asis(X'6869')"); blobRc = db.selectValue("select asis(X'6869')");
T.assert(blobRc instanceof Uint8Array). T.assert(blobRc instanceof Uint8Array).
assert(2 === blobRc.length). assert(2 === blobRc.length).
assert(0x68==blobRc[0] && 0x69==blobRc[1]); assert(0x68==blobRc[0] && 0x69==blobRc[1]);
blobArg = new Int8Array([0x68, 0x69]); blobArg = new Int8Array([0x68, 0x69]);
//debug("blobArg=",blobArg); //debug("blobArg=",blobArg);
blobRc = db.selectValue("select asis(?1)", blobArg); blobRc = db.selectValue("select asis(?1)", blobArg);
T.assert(blobRc instanceof Uint8Array). T.assert(blobRc instanceof Uint8Array).
assert(2 === blobRc.length); assert(2 === blobRc.length);
//debug("blobRc=",blobRc); //debug("blobRc=",blobRc);
T.assert(0x68==blobRc[0] && 0x69==blobRc[1]); T.assert(0x68==blobRc[0] && 0x69==blobRc[1]);
}
}) })
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
.t({ .t({
name: 'Aggregate UDFs', name: 'Aggregate UDFs',
//predicate: ()=>false,
test: function(sqlite3){ test: function(sqlite3){
const db = this.db; const db = this.db;
const sjac = capi.sqlite3_js_aggregate_context; const sjac = capi.sqlite3_js_aggregate_context;
@ -1512,6 +1517,7 @@ self.sqlite3InitModule = sqlite3InitModule;
.t({ .t({
name: 'Aggregate UDFs (64-bit)', name: 'Aggregate UDFs (64-bit)',
predicate: ()=>wasm.bigIntEnabled, predicate: ()=>wasm.bigIntEnabled,
//predicate: ()=>false,
test: function(sqlite3){ test: function(sqlite3){
const db = this.db; const db = this.db;
const sjac = capi.sqlite3_js_aggregate_context; const sjac = capi.sqlite3_js_aggregate_context;
@ -1538,6 +1544,7 @@ self.sqlite3InitModule = sqlite3InitModule;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
.t({ .t({
name: 'Window UDFs', name: 'Window UDFs',
//predicate: ()=>false,
test: function(){ test: function(){
/* Example window function, table, and results taken from: /* Example window function, table, and results taken from:
https://sqlite.org/windowfunctions.html#udfwinfunc */ https://sqlite.org/windowfunctions.html#udfwinfunc */
@ -1856,7 +1863,6 @@ self.sqlite3InitModule = sqlite3InitModule;
xEof: function(pCursor){ xEof: function(pCursor){
const c = VT.xCursor.get(pCursor), const c = VT.xCursor.get(pCursor),
rc = c._rowId>=10; rc = c._rowId>=10;
c.dispose();
return rc; return rc;
}, },
xFilter: function(pCursor, idxNum, idxCStr, xFilter: function(pCursor, idxNum, idxCStr,
@ -1864,10 +1870,9 @@ self.sqlite3InitModule = sqlite3InitModule;
try{ try{
const c = VT.xCursor.get(pCursor); const c = VT.xCursor.get(pCursor);
c._rowId = 0; c._rowId = 0;
const list = VT.sqlite3ValuesToJs(argc, argv); const list = capi.sqlite3_values_to_js(argc, argv);
T.assert(argc === list.length); T.assert(argc === list.length);
//log(argc,"xFilter value(s):",list); //log(argc,"xFilter value(s):",list);
c.dispose();
return 0; return 0;
}catch(e){ }catch(e){
return VT.xError('xFilter',e); return VT.xError('xFilter',e);
@ -2044,7 +2049,7 @@ self.sqlite3InitModule = sqlite3InitModule;
vtabTrace("xFilter",...arguments); vtabTrace("xFilter",...arguments);
const c = VT.xCursor.get(pCursor); const c = VT.xCursor.get(pCursor);
c._rowId = 0; c._rowId = 0;
const list = VT.sqlite3ValuesToJs(argc, argv); const list = capi.sqlite3_values_to_js(argc, argv);
T.assert(argc === list.length); T.assert(argc === list.length);
}, },
xBestIndex: function(pVtab, pIdxInfo){ xBestIndex: function(pVtab, pIdxInfo){

View File

@ -1,5 +1,5 @@
C Expose\ssqlite3_column_value()\sto\sWASM\sand\sadd\ssqlite3_column_js(). C Remove\stwo\sincorrect\scalls\sto\sstructType.dipose()\swhich\sprematurely\sfreed\sobjects\sin\suse\sby\sthe\svirtual\stable\stest/demo\scode.
D 2022-12-10T15:13:29.279 D 2022-12-10T15:41:47.936
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -509,7 +509,7 @@ F ext/wasm/api/sqlite3-api-prologue.js 70ba9bfefacbf11727da6a8f404fccbe666353d09
F ext/wasm/api/sqlite3-api-worker1.js e94ba98e44afccfa482874cd9acb325883ade50ed1f9f9526beb9de1711f182f F ext/wasm/api/sqlite3-api-worker1.js e94ba98e44afccfa482874cd9acb325883ade50ed1f9f9526beb9de1711f182f
F ext/wasm/api/sqlite3-license-version-header.js a661182fc93fc2cf212dfd0b987f8e138a3ac98f850b1112e29b5fbdaecc87c3 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-opfs-async-proxy.js 7795b84b66a7a8dedc791340709b310bb497c3c72a80bef364fa2a58e2ddae3f
F ext/wasm/api/sqlite3-v-helper.js 64bb3559446eb441ce87afe942f6f924ee135a9f069a82705ffefdcd55fc6481 F ext/wasm/api/sqlite3-v-helper.js 6f6c3e390a72e08b0a5b16a0d567d7af3c04d172831853a29d72a6f1dd40ff24
F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 66daf6fb6843bea615fe193109e1542efbeca24f560ee9da63375a910bb48115 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 66daf6fb6843bea615fe193109e1542efbeca24f560ee9da63375a910bb48115
F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9 F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9
F ext/wasm/api/sqlite3-wasm.c daad00c6822facb6ceb506dadc2201c734e9128c457c93f9304df01542084216 F ext/wasm/api/sqlite3-wasm.c daad00c6822facb6ceb506dadc2201c734e9128c457c93f9304df01542084216
@ -555,7 +555,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555
F ext/wasm/test-opfs-vfs.js 44363db07b2a20e73b0eb1808de4400ca71b703af718d0fa6d962f15e73bf2ac F ext/wasm/test-opfs-vfs.js 44363db07b2a20e73b0eb1808de4400ca71b703af718d0fa6d962f15e73bf2ac
F ext/wasm/tester1-worker.html d43f3c131d88f10d00aff3e328fed13c858d674ea2ff1ff90225506137f85aa9 F ext/wasm/tester1-worker.html d43f3c131d88f10d00aff3e328fed13c858d674ea2ff1ff90225506137f85aa9
F ext/wasm/tester1.c-pp.html d34bef3d48e5cbc1c7c06882ad240fec49bf88f5f65696cc2c72c416933aa406 F ext/wasm/tester1.c-pp.html d34bef3d48e5cbc1c7c06882ad240fec49bf88f5f65696cc2c72c416933aa406
F ext/wasm/tester1.c-pp.js 88981420cd91fa134293fc15507b4c94923dab6b3d2e9fc9a4510fdb4f4c6368 F ext/wasm/tester1.c-pp.js 3e9f1d92d9f3464954553d0aa918cba8294451e32a38c229ce5964818f707702
F ext/wasm/tests/opfs/concurrency/index.html 86d8ac435074d1e7007b91105f4897f368c165e8cecb6a9aa3d81f5cf5dcbe70 F ext/wasm/tests/opfs/concurrency/index.html 86d8ac435074d1e7007b91105f4897f368c165e8cecb6a9aa3d81f5cf5dcbe70
F ext/wasm/tests/opfs/concurrency/test.js a98016113eaf71e81ddbf71655aa29b0fed9a8b79a3cdd3620d1658eb1cc9a5d F ext/wasm/tests/opfs/concurrency/test.js a98016113eaf71e81ddbf71655aa29b0fed9a8b79a3cdd3620d1658eb1cc9a5d
F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 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.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 35d1d63c7d60119b64341c561294890812837d5432d1d7bed3ed88d6212fbfa0 P 7783aa4af1331190fd1f42a71bb724041e2e82b51745f9740926e4ead83a97ed
R 74949983660f34694e10167d70549cc3 R 665d2c5db7dd22191a3e1edf86f2deb6
U stephan U stephan
Z 02a2b2f3f049d4f2376808efde37d6cf Z 3ceb2605e22c9be9046cc21f4a5a89d8
# Remove this line to create a well-formed Fossil manifest. # Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
7783aa4af1331190fd1f42a71bb724041e2e82b51745f9740926e4ead83a97ed 060eb2848975a24ff6683a8a9c4d7546ae36147323b0edae01fb42f52d9bb2d6