@@ -110,19 +110,15 @@ if (ENVIRONMENT_IS_NODE) {
110
110
_malloc
111
111
_free
112
112
getValue
113
- intArrayFromString
114
113
setValue
115
114
stackAlloc
116
115
stackRestore
117
116
stackSave
118
117
UTF8ToString
119
- stringToUTF8
120
- lengthBytesUTF8
121
- allocate
122
- ALLOC_NORMAL
123
- allocateUTF8OnStack
118
+ stringToNewUTF8
124
119
removeFunction
125
120
addFunction
121
+ writeArrayToMemory
126
122
*/
127
123
128
124
"use strict";
@@ -650,14 +646,13 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
650
646
pos = this.pos;
651
647
this.pos += 1;
652
648
}
653
- var bytes = intArrayFromString(string);
654
- var strptr = allocate(bytes, ALLOC_NORMAL);
649
+ var strptr = stringToNewUTF8(string);
655
650
this.allocatedmem.push(strptr);
656
651
this.db.handleError(sqlite3_bind_text(
657
652
this.stmt,
658
653
pos,
659
654
strptr,
660
- bytes.length - 1,
655
+ - 1,
661
656
0
662
657
));
663
658
return true;
@@ -668,7 +663,8 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
668
663
pos = this.pos;
669
664
this.pos += 1;
670
665
}
671
- var blobptr = allocate(array, ALLOC_NORMAL);
666
+ var blobptr = _malloc(array.length);
667
+ writeArrayToMemory(array, blobptr);
672
668
this.allocatedmem.push(blobptr);
673
669
this.db.handleError(sqlite3_bind_blob(
674
670
this.stmt,
@@ -839,12 +835,10 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
839
835
*/
840
836
function StatementIterator(sql, db) {
841
837
this.db = db;
842
- var sz = lengthBytesUTF8(sql) + 1;
843
- this.sqlPtr = _malloc(sz);
838
+ this.sqlPtr = stringToNewUTF8(sql);
844
839
if (this.sqlPtr === null) {
845
840
throw new Error("Unable to allocate memory for the SQL string");
846
841
}
847
- stringToUTF8(sql, this.sqlPtr, sz);
848
842
this.nextSqlPtr = this.sqlPtr;
849
843
this.nextSqlString = null;
850
844
this.activeStatement = null;
@@ -1057,25 +1051,27 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
1057
1051
if (!this.db) {
1058
1052
throw "Database closed";
1059
1053
}
1060
- var stack = stackSave();
1061
1054
var stmt = null;
1055
+ var originalSqlPtr = null;
1056
+ var currentSqlPtr = null;
1062
1057
try {
1063
- var nextSqlPtr = allocateUTF8OnStack(sql);
1058
+ originalSqlPtr = stringToNewUTF8(sql);
1059
+ currentSqlPtr = originalSqlPtr;
1064
1060
var pzTail = stackAlloc(4);
1065
1061
var results = [];
1066
- while (getValue(nextSqlPtr , "i8") !== NULL) {
1062
+ while (getValue(currentSqlPtr , "i8") !== NULL) {
1067
1063
setValue(apiTemp, 0, "i32");
1068
1064
setValue(pzTail, 0, "i32");
1069
1065
this.handleError(sqlite3_prepare_v2_sqlptr(
1070
1066
this.db,
1071
- nextSqlPtr ,
1067
+ currentSqlPtr ,
1072
1068
-1,
1073
1069
apiTemp,
1074
1070
pzTail
1075
1071
));
1076
1072
// pointer to a statement, or null
1077
1073
var pStmt = getValue(apiTemp, "i32");
1078
- nextSqlPtr = getValue(pzTail, "i32");
1074
+ currentSqlPtr = getValue(pzTail, "i32");
1079
1075
// Empty statement
1080
1076
if (pStmt !== NULL) {
1081
1077
var curresult = null;
@@ -1101,7 +1097,7 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
1101
1097
if (stmt) stmt["free"]();
1102
1098
throw errCaught;
1103
1099
} finally {
1104
- stackRestore(stack );
1100
+ if (originalSqlPtr) _free(originalSqlPtr );
1105
1101
}
1106
1102
};
1107
1103
@@ -1309,7 +1305,8 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
1309
1305
if (result === null) {
1310
1306
sqlite3_result_null(cx);
1311
1307
} else if (result.length != null) {
1312
- var blobptr = allocate(result, ALLOC_NORMAL);
1308
+ var blobptr = _malloc(result.length);
1309
+ writeArrayToMemory(result, blobptr);
1313
1310
sqlite3_result_blob(cx, blobptr, result.length, -1);
1314
1311
_free(blobptr);
1315
1312
} else {
@@ -139922,34 +139919,16 @@ var tempI64;
139922
139919
139923
139920
139924
139921
139925
- var ALLOC_NORMAL = 0;
139926
-
139927
- var ALLOC_STACK = 1;
139928
-
139929
139922
139930
139923
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);
139946
139928
return ret;
139947
139929
};
139948
139930
139949
139931
139950
-
139951
- var allocateUTF8OnStack = stringToUTF8OnStack;
139952
-
139953
139932
var functionsInTableMap;
139954
139933
139955
139934
var freeTableIndexes = [];
@@ -140297,9 +140276,8 @@ Module['cwrap'] = cwrap;
140297
140276
Module['addFunction'] = addFunction;
140298
140277
Module['removeFunction'] = removeFunction;
140299
140278
Module['UTF8ToString'] = UTF8ToString;
140300
- Module['ALLOC_NORMAL'] = ALLOC_NORMAL;
140301
- Module['allocate'] = allocate;
140302
- Module['allocateUTF8OnStack'] = allocateUTF8OnStack;
140279
+ Module['stringToNewUTF8'] = stringToNewUTF8;
140280
+ Module['writeArrayToMemory'] = writeArrayToMemory;
140303
140281
var missingLibrarySymbols = [
140304
140282
'writeI53ToI64',
140305
140283
'writeI53ToI64Clamped',
@@ -140357,7 +140335,6 @@ var missingLibrarySymbols = [
140357
140335
'UTF32ToString',
140358
140336
'stringToUTF32',
140359
140337
'lengthBytesUTF32',
140360
- 'stringToNewUTF8',
140361
140338
'registerKeyEventCallback',
140362
140339
'maybeCStringToJsString',
140363
140340
'findEventTarget',
@@ -140446,6 +140423,9 @@ var missingLibrarySymbols = [
140446
140423
'writeGLArray',
140447
140424
'registerWebGlEventCallback',
140448
140425
'runAndAbortIfError',
140426
+ 'ALLOC_NORMAL',
140427
+ 'ALLOC_STACK',
140428
+ 'allocate',
140449
140429
'writeStringToMemory',
140450
140430
'writeAsciiToMemory',
140451
140431
'setErrNo',
@@ -140515,7 +140495,6 @@ var unexportedSymbols = [
140515
140495
'stringToAscii',
140516
140496
'UTF16Decoder',
140517
140497
'stringToUTF8OnStack',
140518
- 'writeArrayToMemory',
140519
140498
'JSEvents',
140520
140499
'specialHTMLTargets',
140521
140500
'findCanvasEventTarget',
@@ -140573,8 +140552,8 @@ var unexportedSymbols = [
140573
140552
'IDBStore',
140574
140553
'SDL',
140575
140554
'SDL_gfx',
140576
- 'ALLOC_STACK',
140577
140555
'allocateUTF8',
140556
+ 'allocateUTF8OnStack',
140578
140557
'print',
140579
140558
'printErr',
140580
140559
];
0 commit comments