mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-27 20:41:58 +03:00
Rename wasm.xWrap.resultAdapter() X:free entries to X:dealloc for consistency with wasm.dealloc(). Add an undocumented feature to replace wasm.alloc/dealloc/realloc() with the C-standard allocators (after an allocator misuse led down a several-hour rabbit hole trying to discover a mis-free() violation). Related test updates.
FossilOrigin-Name: d9807656f8a7c2a893d3f68ee5592f44826b8e999ae66f7d9000674b5c1b0207
This commit is contained in:
@ -112,12 +112,23 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
}
|
||||
return !!self.BigInt64Array;
|
||||
})(),
|
||||
allocExportName: 'sqlite3_malloc',
|
||||
deallocExportName: 'sqlite3_free',
|
||||
reallocExportName: 'sqlite3_realloc',
|
||||
wasmfsOpfsDir: '/opfs'
|
||||
wasmfsOpfsDir: '/opfs',
|
||||
/**
|
||||
useStdAlloc is just for testing an allocator discrepancy. The
|
||||
docs guarantee that this is false in the canonical builds. For
|
||||
99% of purposes it doesn't matter which allocators we use, but
|
||||
it becomes significant with, e.g., sqlite3_deserialize()
|
||||
and certain wasm.xWrap.resultAdapter()s.
|
||||
*/
|
||||
useStdAlloc: false
|
||||
}, apiConfig || {});
|
||||
|
||||
Object.assign(config, {
|
||||
allocExportName: config.useStdAlloc ? 'malloc' : 'sqlite3_malloc',
|
||||
deallocExportName: config.useStdAlloc ? 'free' : 'sqlite3_free',
|
||||
reallocExportName: config.useStdAlloc ? 'realloc' : 'sqlite3_realloc'
|
||||
}, config);
|
||||
|
||||
[
|
||||
// If any of these config options are functions, replace them with
|
||||
// the result of calling that function...
|
||||
@ -768,15 +779,12 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
}
|
||||
|
||||
wasm.alloc = function f(n){
|
||||
const m = f.impl(n);
|
||||
if(!m) throw new WasmAllocError("Failed to allocate",n," bytes.");
|
||||
return m;
|
||||
return f.impl(n) || WasmAllocError.toss("Failed to allocate",n," bytes.");
|
||||
};
|
||||
wasm.alloc.impl = wasm.exports[keyAlloc];
|
||||
wasm.realloc = function f(m,n){
|
||||
const m2 = f.impl(m,n);
|
||||
if(n && !m2) throw new WasmAllocError("Failed to reallocate",n," bytes.");
|
||||
return n ? m2 : 0;
|
||||
return n ? (m2 || WasmAllocError.toss("Failed to reallocate",n," bytes.")) : 0;
|
||||
};
|
||||
wasm.realloc.impl = wasm.exports[keyRealloc];
|
||||
wasm.dealloc = wasm.exports[keyDealloc];
|
||||
|
Reference in New Issue
Block a user