mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Minor cleanups and additions in sqlite3.capi.wasm.pstack.
FossilOrigin-Name: 97bd670d3859bd3f2e62c15065b238b85ef614f26479e56a14be42c5784aedf4
This commit is contained in:
@ -560,56 +560,6 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
};
|
||||
}/*sqlite3_prepare_v2/v3()*/;
|
||||
|
||||
if(1){// Extend wasm.pstack, now that the wasm utils are installed
|
||||
/**
|
||||
Allocates n chunks, each sz bytes, as a single memory block and
|
||||
returns the addresses as an array of n element, each holding
|
||||
the address of one chunk.
|
||||
|
||||
Throws a WasmAllocError if allocation fails.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
const [p1, p2, p3] = wasm.pstack.allocChunks(3,4);
|
||||
```
|
||||
*/
|
||||
wasm.pstack.allocChunks = (n,sz)=>{
|
||||
const mem = wasm.pstack.alloc(n * sz);
|
||||
const rc = [];
|
||||
let i = 0, offset = 0;
|
||||
for(; i < n; offset = (sz * ++i)){
|
||||
rc.push(mem + offset);
|
||||
}
|
||||
return rc;
|
||||
};
|
||||
|
||||
/**
|
||||
A convenience wrapper for allocChunks() which sizes each chunks
|
||||
as either 8 bytes (safePtrSize is truthy) or wasm.ptrSizeof (if
|
||||
safePtrSize is falsy).
|
||||
|
||||
How it returns its result differs depending on its first
|
||||
argument: if it's 1, it returns a single pointer value. If it's
|
||||
more than 1, it returns the same as allocChunks().
|
||||
|
||||
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
|
||||
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.
|
||||
|
||||
However, when all pointers involved point to "small" data, it
|
||||
is safe to pass a falsy value to save to memory.
|
||||
*/
|
||||
wasm.pstack.allocPtr = (n=1,safePtrSize=true) =>{
|
||||
return 1===n
|
||||
? wasm.pstack.alloc(safePtrSize ? 8 : wasm.ptrSizeof)
|
||||
: wasm.pstack.allocChunks(n, safePtrSize ? 8 : wasm.ptrSizeof);
|
||||
};
|
||||
}/*wasm.pstack filler*/
|
||||
|
||||
{/* Import C-level constants and structs... */
|
||||
const cJson = wasm.xCall('sqlite3_wasm_enum_json');
|
||||
if(!cJson){
|
||||
|
Reference in New Issue
Block a user