aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/common/whwasmutil.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-12-05 05:30:03 +0000
committerstephan <stephan@noemail.net>2022-12-05 05:30:03 +0000
commite1774479727bd2093f7bfcf38fd52a28eca6ff04 (patch)
treeaa61dccee8bc22a89867d932c3186be315e5e707 /ext/wasm/common/whwasmutil.js
parent95ade3bdb90f2b2a5b8fb330d7307b534020cbaf (diff)
downloadsqlite-e1774479727bd2093f7bfcf38fd52a28eca6ff04.tar.gz
sqlite-e1774479727bd2093f7bfcf38fd52a28eca6ff04.zip
Initial infrastructure for adding virtual table/table-valued function support to WASM.
FossilOrigin-Name: c202d7a0398b9aabc2babba5c4c91a313f32bbf37549d419775642bb4aa3936a
Diffstat (limited to 'ext/wasm/common/whwasmutil.js')
-rw-r--r--ext/wasm/common/whwasmutil.js28
1 files changed, 17 insertions, 11 deletions
diff --git a/ext/wasm/common/whwasmutil.js b/ext/wasm/common/whwasmutil.js
index 8cb483324..84d829dab 100644
--- a/ext/wasm/common/whwasmutil.js
+++ b/ext/wasm/common/whwasmutil.js
@@ -1081,10 +1081,9 @@ self.WhWasmUtilInstaller = function(target){
// impl for allocMainArgv() and scopedAllocMainArgv().
const __allocMainArgv = function(isScoped, list){
- if(!list.length) toss("Cannot allocate empty array.");
const pList = target[
isScoped ? 'scopedAlloc' : 'alloc'
- ](list.length * target.ptrSizeof);
+ ]((list.length + 1) * target.ptrSizeof);
let i = 0;
list.forEach((e)=>{
target.setPtrValue(pList + (target.ptrSizeof * i++),
@@ -1092,26 +1091,33 @@ self.WhWasmUtilInstaller = function(target){
isScoped ? 'scopedAllocCString' : 'allocCString'
](""+e));
});
+ target.setPtrValue(pList + (target.ptrSizeof * i), 0);
return pList;
};
/**
Creates an array, using scopedAlloc(), suitable for passing to a
C-level main() routine. The input is a collection with a length
- property and a forEach() method. A block of memory list.length
- entries long is allocated and each pointer-sized block of that
- memory is populated with a scopedAllocCString() conversion of the
- (""+value) of each element. Returns a pointer to the start of the
- list, suitable for passing as the 2nd argument to a C-style
- main() function.
-
- Throws if list.length is falsy or scopedAllocPush() is not active.
+ property and a forEach() method. A block of memory
+ (list.length+1) entries long is allocated and each pointer-sized
+ block of that memory is populated with a scopedAllocCString()
+ conversion of the (""+value) of each element, with the exception
+ that the final entry is a NULL pointer. Returns a pointer to the
+ start of the list, suitable for passing as the 2nd argument to a
+ C-style main() function.
+
+ Throws if scopedAllocPush() is not active.
+
+ Design note: the returned array is allocated with an extra NULL
+ pointer entry to accommodate certain APIs, but client code which
+ does not need that functionality should treat the returned array
+ as list.length entries long.
*/
target.scopedAllocMainArgv = (list)=>__allocMainArgv(true, list);
/**
Identical to scopedAllocMainArgv() but uses alloc() instead of
- scopedAllocMainArgv
+ scopedAlloc().
*/
target.allocMainArgv = (list)=>__allocMainArgv(false, list);