Skip to content

Commit b90ff0b

Browse files
authored
Merge pull request #418 from ethereum/emscripten-update
Update wrapper to support newer Emscripten (1.39.3)
2 parents 2480e79 + 4b3a359 commit b90ff0b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

wrapper.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,29 @@ function setupMethods (soljson) {
2828
};
2929
}
3030

31-
var copyString = function (str, ptr) {
31+
var copyToCString = function (str, ptr) {
3232
var length = soljson.lengthBytesUTF8(str);
33+
// This is allocating memory using solc's allocator.
34+
// Assuming copyToCString is only used in the context of wrapCallback, solc will free these pointers.
35+
// See https://github.com/ethereum/solidity/blob/v0.5.13/libsolc/libsolc.h#L37-L40
3336
var buffer = soljson._malloc(length + 1);
3437
soljson.stringToUTF8(str, buffer, length + 1);
3538
soljson.setValue(ptr, buffer, '*');
3639
};
3740

41+
// This is to support multiple versions of Emscripten.
42+
// Take a single `ptr` and returns a `str`.
43+
var copyFromCString = soljson.UTF8ToString || soljson.Pointer_stringify;
44+
3845
var wrapCallback = function (callback) {
3946
assert(typeof callback === 'function', 'Invalid callback specified.');
4047
return function (path, contents, error) {
41-
var result = callback(soljson.Pointer_stringify(path));
48+
var result = callback(copyFromCString(path));
4249
if (typeof result.contents === 'string') {
43-
copyString(result.contents, contents);
50+
copyToCString(result.contents, contents);
4451
}
4552
if (typeof result.error === 'string') {
46-
copyString(result.error, error);
53+
copyToCString(result.error, error);
4754
}
4855
};
4956
};

0 commit comments

Comments
 (0)