@@ -110,19 +110,15 @@ if (ENVIRONMENT_IS_NODE) {
110110 _malloc
111111 _free
112112 getValue
113- intArrayFromString
114113 setValue
115114 stackAlloc
116115 stackRestore
117116 stackSave
118117 UTF8ToString
119- stringToUTF8
120- lengthBytesUTF8
121- allocate
122- ALLOC_NORMAL
123- allocateUTF8OnStack
118+ stringToNewUTF8
124119 removeFunction
125120 addFunction
121+ writeArrayToMemory
126122*/
127123
128124"use strict";
@@ -650,14 +646,13 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
650646 pos = this.pos;
651647 this.pos += 1;
652648 }
653- var bytes = intArrayFromString(string);
654- var strptr = allocate(bytes, ALLOC_NORMAL);
649+ var strptr = stringToNewUTF8(string);
655650 this.allocatedmem.push(strptr);
656651 this.db.handleError(sqlite3_bind_text(
657652 this.stmt,
658653 pos,
659654 strptr,
660- bytes.length - 1,
655+ - 1,
661656 0
662657 ));
663658 return true;
@@ -668,7 +663,8 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
668663 pos = this.pos;
669664 this.pos += 1;
670665 }
671- var blobptr = allocate(array, ALLOC_NORMAL);
666+ var blobptr = _malloc(array.length);
667+ writeArrayToMemory(array, blobptr);
672668 this.allocatedmem.push(blobptr);
673669 this.db.handleError(sqlite3_bind_blob(
674670 this.stmt,
@@ -839,12 +835,10 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
839835 */
840836 function StatementIterator(sql, db) {
841837 this.db = db;
842- var sz = lengthBytesUTF8(sql) + 1;
843- this.sqlPtr = _malloc(sz);
838+ this.sqlPtr = stringToNewUTF8(sql);
844839 if (this.sqlPtr === null) {
845840 throw new Error("Unable to allocate memory for the SQL string");
846841 }
847- stringToUTF8(sql, this.sqlPtr, sz);
848842 this.nextSqlPtr = this.sqlPtr;
849843 this.nextSqlString = null;
850844 this.activeStatement = null;
@@ -1057,25 +1051,27 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
10571051 if (!this.db) {
10581052 throw "Database closed";
10591053 }
1060- var stack = stackSave();
10611054 var stmt = null;
1055+ var originalSqlPtr = null;
1056+ var currentSqlPtr = null;
10621057 try {
1063- var nextSqlPtr = allocateUTF8OnStack(sql);
1058+ originalSqlPtr = stringToNewUTF8(sql);
1059+ currentSqlPtr = originalSqlPtr;
10641060 var pzTail = stackAlloc(4);
10651061 var results = [];
1066- while (getValue(nextSqlPtr , "i8") !== NULL) {
1062+ while (getValue(currentSqlPtr , "i8") !== NULL) {
10671063 setValue(apiTemp, 0, "i32");
10681064 setValue(pzTail, 0, "i32");
10691065 this.handleError(sqlite3_prepare_v2_sqlptr(
10701066 this.db,
1071- nextSqlPtr ,
1067+ currentSqlPtr ,
10721068 -1,
10731069 apiTemp,
10741070 pzTail
10751071 ));
10761072 // pointer to a statement, or null
10771073 var pStmt = getValue(apiTemp, "i32");
1078- nextSqlPtr = getValue(pzTail, "i32");
1074+ currentSqlPtr = getValue(pzTail, "i32");
10791075 // Empty statement
10801076 if (pStmt !== NULL) {
10811077 var curresult = null;
@@ -1101,7 +1097,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
11011097 if (stmt) stmt["free"]();
11021098 throw errCaught;
11031099 } finally {
1104- stackRestore(stack );
1100+ if (originalSqlPtr) _free(originalSqlPtr );
11051101 }
11061102 };
11071103
@@ -1309,7 +1305,8 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
13091305 if (result === null) {
13101306 sqlite3_result_null(cx);
13111307 } else if (result.length != null) {
1312- var blobptr = allocate(result, ALLOC_NORMAL);
1308+ var blobptr = _malloc(result.length);
1309+ writeArrayToMemory(result, blobptr);
13131310 sqlite3_result_blob(cx, blobptr, result.length, -1);
13141311 _free(blobptr);
13151312 } else {
@@ -139922,34 +139919,16 @@ var tempI64;
139922139919
139923139920
139924139921
139925- var ALLOC_NORMAL = 0;
139926-
139927- var ALLOC_STACK = 1;
139928-
139929139922
139930139923
139931- var allocate = (slab, allocator) => {
139932- var ret;
139933- assert(typeof allocator == 'number', 'allocate no longer takes a type argument')
139934- assert(typeof slab != 'number', 'allocate no longer takes a number as arg0')
139935-
139936- if (allocator == ALLOC_STACK) {
139937- ret = stackAlloc(slab.length);
139938- } else {
139939- ret = _malloc(slab.length);
139940- }
139941-
139942- if (!slab.subarray && !slab.slice) {
139943- slab = new Uint8Array(slab);
139944- }
139945- HEAPU8.set(slab, ret);
139924+ var stringToNewUTF8 = (str) => {
139925+ var size = lengthBytesUTF8(str) + 1;
139926+ var ret = _malloc(size);
139927+ if (ret) stringToUTF8(str, ret, size);
139946139928 return ret;
139947139929 };
139948139930
139949139931
139950-
139951- var allocateUTF8OnStack = stringToUTF8OnStack;
139952-
139953139932 var functionsInTableMap;
139954139933
139955139934 var freeTableIndexes = [];
@@ -140297,9 +140276,8 @@ Module['cwrap'] = cwrap;
140297140276Module['addFunction'] = addFunction;
140298140277Module['removeFunction'] = removeFunction;
140299140278Module['UTF8ToString'] = UTF8ToString;
140300- Module['ALLOC_NORMAL'] = ALLOC_NORMAL;
140301- Module['allocate'] = allocate;
140302- Module['allocateUTF8OnStack'] = allocateUTF8OnStack;
140279+ Module['stringToNewUTF8'] = stringToNewUTF8;
140280+ Module['writeArrayToMemory'] = writeArrayToMemory;
140303140281var missingLibrarySymbols = [
140304140282 'writeI53ToI64',
140305140283 'writeI53ToI64Clamped',
@@ -140357,7 +140335,6 @@ var missingLibrarySymbols = [
140357140335 'UTF32ToString',
140358140336 'stringToUTF32',
140359140337 'lengthBytesUTF32',
140360- 'stringToNewUTF8',
140361140338 'registerKeyEventCallback',
140362140339 'maybeCStringToJsString',
140363140340 'findEventTarget',
@@ -140446,6 +140423,9 @@ var missingLibrarySymbols = [
140446140423 'writeGLArray',
140447140424 'registerWebGlEventCallback',
140448140425 'runAndAbortIfError',
140426+ 'ALLOC_NORMAL',
140427+ 'ALLOC_STACK',
140428+ 'allocate',
140449140429 'writeStringToMemory',
140450140430 'writeAsciiToMemory',
140451140431 'setErrNo',
@@ -140515,7 +140495,6 @@ var unexportedSymbols = [
140515140495 'stringToAscii',
140516140496 'UTF16Decoder',
140517140497 'stringToUTF8OnStack',
140518- 'writeArrayToMemory',
140519140498 'JSEvents',
140520140499 'specialHTMLTargets',
140521140500 'findCanvasEventTarget',
@@ -140573,8 +140552,8 @@ var unexportedSymbols = [
140573140552 'IDBStore',
140574140553 'SDL',
140575140554 'SDL_gfx',
140576- 'ALLOC_STACK',
140577140555 'allocateUTF8',
140556+ 'allocateUTF8OnStack',
140578140557 'print',
140579140558 'printErr',
140580140559];
0 commit comments