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

Function __allocCStr

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

Source from the content-addressed store, hash-verified

8407 };
8408
8409 const __allocCStr = function(jstr, returnWithLength, allocator, funcName){
8410 __affirmAlloc(target, funcName);
8411 if('string'!==typeof jstr) return null;
8412 const u = cache.utf8Encoder.encode(jstr),
8413 ptr = allocator(u.length+1);
8414 let toFree = ptr;
8415 try{
8416 const heap = heapWrappers().HEAP8U;
8417 heap.set(u, Number(ptr));
8418 heap[__ptrAdd(ptr, u.length)] = 0;
8419 toFree = __NullPtr;
8420 return returnWithLength ? [ptr, u.length] : ptr;
8421 }finally{
8422 if( toFree ) target.dealloc(toFree);
8423 }
8424 };
8425
8426 /**
8427 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