MCPcopy Create free account
hub / github.com/GoogleChrome/samples / __allocCStr

Function __allocCStr

sqlite-wasm-cos/sqlite3-node.mjs:8288–8303  ·  view source on GitHub ↗
(jstr, returnWithLength, allocator, funcName)

Source from the content-addressed store, hash-verified

8286 };
8287
8288 const __allocCStr = function(jstr, returnWithLength, allocator, funcName){
8289 __affirmAlloc(target, funcName);
8290 if('string'!==typeof jstr) return null;
8291 const u = cache.utf8Encoder.encode(jstr),
8292 ptr = allocator(u.length+1);
8293 let toFree = ptr;
8294 try{
8295 const heap = heapWrappers().HEAP8U;
8296 heap.set(u, Number(ptr));
8297 heap[__ptrAdd(ptr, u.length)] = 0;
8298 toFree = __NullPtr;
8299 return returnWithLength ? [ptr, u.length] : ptr;
8300 }finally{
8301 if( toFree ) target.dealloc(toFree);
8302 }
8303 };
8304
8305 /**
8306 Uses target.alloc() to allocate enough memory for jstrlen(jstr)+1

Callers 1

sqlite3InitModuleFunction · 0.70

Calls 5

encodeMethod · 0.80
setMethod · 0.80
__affirmAllocFunction · 0.70
heapWrappersFunction · 0.70
__ptrAddFunction · 0.70

Tested by

no test coverage detected