Add sqlite3.wasm.irSizeof() and extend certain allocation functions to make use of it.
FossilOrigin-Name: 1cbc7b1875e8611b9db7a747b4c9499501450deaf90c929d212511837d6f72b6
This commit is contained in:
parent
031ee6b9da
commit
7d59d90a5b
@ -1020,12 +1020,20 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
to the memory. On error, returns throws a WasmAllocError. The
|
||||
memory must eventually be released using restore().
|
||||
|
||||
If n is a string, it must be a WASM "IR" value in the set
|
||||
accepted by wasm.irSizeof(), which is mapped to the size of
|
||||
that data type. If passed a string not in that set, it throws a
|
||||
WasmAllocError.
|
||||
|
||||
This method always adjusts the given value to be a multiple
|
||||
of 8 bytes because failing to do so can lead to incorrect
|
||||
results when reading and writing 64-bit values from/to the WASM
|
||||
heap. Similarly, the returned address is always 8-byte aligned.
|
||||
*/
|
||||
alloc: (n)=>{
|
||||
alloc: function(n){
|
||||
if('string'===typeof n && !(n = wasm.irSizeof(n))){
|
||||
WasmAllocError.toss("Invalid value for pstack.alloc(",arguments[0],")");
|
||||
}
|
||||
return wasm.exports.sqlite3_wasm_pstack_alloc(n)
|
||||
|| WasmAllocError.toss("Could not allocate",n,
|
||||
"bytes from the pstack.");
|
||||
@ -1035,6 +1043,8 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
returns the addresses as an array of n element, each holding
|
||||
the address of one chunk.
|
||||
|
||||
sz may optionally be an IR string accepted by wasm.irSizeof().
|
||||
|
||||
Throws a WasmAllocError if allocation fails.
|
||||
|
||||
Example:
|
||||
@ -1043,7 +1053,10 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
const [p1, p2, p3] = wasm.pstack.allocChunks(3,4);
|
||||
```
|
||||
*/
|
||||
allocChunks: (n,sz)=>{
|
||||
allocChunks: function(n,sz){
|
||||
if('string'===typeof sz && !(sz = wasm.irSizeof(sz))){
|
||||
WasmAllocError.toss("Invalid size value for allocChunks(",arguments[1],")");
|
||||
}
|
||||
const mem = wasm.pstack.alloc(n * sz);
|
||||
const rc = [];
|
||||
let i = 0, offset = 0;
|
||||
|
@ -246,6 +246,25 @@ self.WhWasmUtilInstaller = function(target){
|
||||
cache.utf8Decoder = new TextDecoder();
|
||||
cache.utf8Encoder = new TextEncoder('utf-8');
|
||||
|
||||
/**
|
||||
For the given IR-like string in the set ('i8', 'i16', 'i32',
|
||||
'f32', 'float', 'i64', 'f64', 'double', '*'), or any string value
|
||||
ending in '*', returns the sizeof for that value
|
||||
(target.ptrSizeof in the latter case). For any other value, it
|
||||
returns the undefined value.
|
||||
*/
|
||||
target.irSizeof = (n)=>{
|
||||
switch(n){
|
||||
case 'i8': return 1;
|
||||
case 'i16': return 2;
|
||||
case 'i32': case 'f32': case 'float': return 4;
|
||||
case 'i64': case 'f64': case 'double': return 8;
|
||||
case '*': return ptrSizeof;
|
||||
default:
|
||||
return (''+n).endsWith('*') ? ptrSizeof : undefined;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
If (cache.heapSize !== cache.memory.buffer.byteLength), i.e. if
|
||||
the heap has grown since the last call, updates cache.HEAPxyz.
|
||||
|
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
||||
C Remove\sduplicated\sJS\sbinding\sof\ssqlite3changeset_apply_v2().
|
||||
D 2022-12-25T16:20:05.864
|
||||
C Add\ssqlite3.wasm.irSizeof()\sand\sextend\scertain\sallocation\sfunctions\sto\smake\suse\sof\sit.
|
||||
D 2022-12-25T20:05:11.134
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -505,7 +505,7 @@ F ext/wasm/api/pre-js.c-pp.js b88499dc303c21fc3f55f2c364a0f814f587b60a9578430388
|
||||
F ext/wasm/api/sqlite3-api-cleanup.js 680d5ccfff54459db136a49b2199d9f879c8405d9c99af1dda0cc5e7c29056f4
|
||||
F ext/wasm/api/sqlite3-api-glue.js fe8a0c30d906e4f14be26a2abdad5d84aa901eeb594f76c8050cb4df4f746a5d
|
||||
F ext/wasm/api/sqlite3-api-oo1.js ae4f6950913b4703b767f640a533675b45e9e6c462bf01e357cec16bc68943e2
|
||||
F ext/wasm/api/sqlite3-api-prologue.js 4ffe2b80742e2fcf44de6174bfb2981ff26ea0d1fe505bb511ffe0d9ac8fe6d0
|
||||
F ext/wasm/api/sqlite3-api-prologue.js 72e2b66daf1f5ea7b6a8477c4fe86493925a067cfa0b156a339589e653446920
|
||||
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
|
||||
@ -521,7 +521,7 @@ F ext/wasm/c-pp.c 92285f7bce67ed7b7020b40fde8ed0982c442b63dc33df9dfd4b658d4a6c07
|
||||
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 495cdffe8a6107608412ee57cdad79267f14a56e6b7825b9dc30c8ccfb02c87b
|
||||
F ext/wasm/common/whwasmutil.js a94f776bd3afcfc73283aad2bb0821ddf8e77f687a0d7ee84d14d2a138d78636
|
||||
F ext/wasm/demo-123-worker.html a0b58d9caef098a626a1a1db567076fca4245e8d60ba94557ede8684350a81ed
|
||||
F ext/wasm/demo-123.html 8c70a412ce386bd3796534257935eb1e3ea5c581e5d5aea0490b8232e570a508
|
||||
F ext/wasm/demo-123.js ebae30756585bca655b4ab2553ec9236a87c23ad24fc8652115dcedb06d28df6
|
||||
@ -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 0a36568c5a3db56a8ad23fd8abc672c5a7f1abed55984d902842ffd3ebb816e8
|
||||
R 7b14429320eea0000f7897f56a599155
|
||||
P 2e8336b6e1cba89dbcc11d6316e39c929bf8b018a18b92efc232abd47e0a5cc6
|
||||
R 63f0c28ba499a3e86a80a83d5b02806d
|
||||
U stephan
|
||||
Z c6f737ca9a33ea9873dd8c76d61cfde2
|
||||
Z e2479a6e1c7cf91263ea3378ad83cfc4
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@ -1 +1 @@
|
||||
2e8336b6e1cba89dbcc11d6316e39c929bf8b018a18b92efc232abd47e0a5cc6
|
||||
1cbc7b1875e8611b9db7a747b4c9499501450deaf90c929d212511837d6f72b6
|
Loading…
Reference in New Issue
Block a user