Skip to content

Commit 2079a29

Browse files
committed
Add new simple export mechanism
This change adds a new `-sEXPORT` setting that can by used to export any type of symbols (see emscripten-core#8380) It also includes a new `-sMANGLED_SYMBOLS` setting which default to true in order to not break backwards compatibility. Both these new settings are currently experimental and using `-sEXPORT` currently disables `-sMANGLED_SYMBOLS` by default.
1 parent c4ecb13 commit 2079a29

File tree

105 files changed

+1280
-1122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+1280
-1122
lines changed

emcc.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,6 @@ def apply_user_settings():
293293

294294
setattr(settings, user_key, value)
295295

296-
if key == 'EXPORTED_FUNCTIONS':
297-
# used for warnings in emscripten.py
298-
settings.USER_EXPORTS = settings.EXPORTED_FUNCTIONS.copy()
299-
300296
# TODO(sbc): Remove this legacy way.
301297
if key == 'WASM_OBJECT_FILES':
302298
settings.LTO = 0 if value else 'full'
@@ -1539,7 +1535,7 @@ def in_directory(root, child):
15391535

15401536
def parse_symbol_list_file(contents):
15411537
"""Parse contents of one-symbol-per-line response file. This format can by used
1542-
with, for example, -sEXPORTED_FUNCTIONS=@filename and avoids the need for any
1538+
with, for example, -sEXPORTS=@filename and avoids the need for any
15431539
kind of quoting or escaping.
15441540
"""
15451541
values = contents.splitlines()

site/source/docs/getting_started/FAQ.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ Here is an example of how to use it:
350350
<script type="text/javascript">
351351
var Module = {
352352
onRuntimeInitialized: function() {
353-
Module._foobar(); // foobar was exported
353+
Module.foobar(); // foobar was exported
354354
}
355355
};
356356
</script>

site/source/docs/optimizing/Module-Splitting.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Here’s the function to write the profile and our new main function::
131131

132132
// Get the size of the profile and allocate a buffer for it.
133133
var len = __write_profile(0, 0);
134-
var ptr = _malloc(len);
134+
var ptr = malloc(len);
135135

136136
// Write the profile data to the buffer.
137137
__write_profile(ptr, len);
@@ -142,7 +142,7 @@ Here’s the function to write the profile and our new main function::
142142
fs.writeFileSync('profile.data', profile_data);
143143

144144
// Free the buffer.
145-
_free(ptr);
145+
free(ptr);
146146
});
147147

148148
int main() {

site/source/docs/porting/Debugging.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ Note that you need to emit HTML as in that example, as the memory profiler
287287
output is rendered onto the page. To view it, load ``page.html`` in your
288288
browser (remember to use a :ref:`local webserver <faq-local-webserver>`). The display
289289
auto-updates, so you can open the devtools console and run a command like
290-
``_malloc(1024 * 1024)``. That will allocate 1MB of memory, which will then show
290+
``malloc(1024 * 1024)``. That will allocate 1MB of memory, which will then show
291291
up on the memory profiler display.
292292

293293
.. _debugging-autodebugger:

site/source/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ The parameters you pass to and receive from functions need to be primitive value
238238
- JavaScript string ``someString`` can be converted to a ``char *`` using ``ptr = stringToNewUTF8(someString)``.
239239

240240
.. note:: The conversion to a pointer allocates memory, which needs to be
241-
freed up via a call to ``free(ptr)`` afterwards (``_free`` in JavaScript side) -
241+
freed up via a call to ``free(ptr)`` afterwards -
242242
- ``char *`` received from C/C++ can be converted to a JavaScript string using :js:func:`UTF8ToString`.
243243

244244
There are other convenience functions for converting strings and encodings
@@ -702,10 +702,10 @@ to process the data, and finally frees the buffer.
702702

703703
.. code-block:: javascript
704704
705-
var buf = Module._malloc(myTypedArray.length*myTypedArray.BYTES_PER_ELEMENT);
705+
var buf = Module.malloc(myTypedArray.length*myTypedArray.BYTES_PER_ELEMENT);
706706
Module.HEAPU8.set(myTypedArray, buf);
707707
Module.ccall('my_function', 'number', ['number'], [buf]);
708-
Module._free(buf);
708+
Module.free(buf);
709709
710710
Here ``my_function`` is a C function that receives a single integer parameter
711711
(or a pointer, they are both just 32-bit integers for us) and returns an

src/Fetch.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function fetchLoadCachedData(db, fetch, onsuccess, onerror) {
152152
#endif
153153
// The data pointer malloc()ed here has the same lifetime as the emscripten_fetch_t structure itself has, and is
154154
// freed when emscripten_fetch_close() is called.
155-
var ptr = _malloc(len);
155+
var ptr = malloc(len);
156156
HEAPU8.set(new Uint8Array(value), ptr);
157157
{{{ makeSetValue('fetch', C_STRUCTS.emscripten_fetch_t.data, 'ptr', '*') }}};
158158
writeI53ToI64(fetch + {{{ C_STRUCTS.emscripten_fetch_t.numBytes }}}, len);
@@ -329,7 +329,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
329329
#endif
330330
// The data pointer malloc()ed here has the same lifetime as the emscripten_fetch_t structure itself has, and is
331331
// freed when emscripten_fetch_close() is called.
332-
ptr = _malloc(ptrLen);
332+
ptr = malloc(ptrLen);
333333
HEAPU8.set(new Uint8Array(/** @type{Array<number>} */(xhr.response)), ptr);
334334
}
335335
{{{ makeSetValue('fetch', C_STRUCTS.emscripten_fetch_t.data, 'ptr', '*') }}}
@@ -401,7 +401,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
401401
assert(onprogress, 'When doing a streaming fetch, you should have an onprogress handler registered to receive the chunks!');
402402
#endif
403403
// Allocate byte data in Emscripten heap for the streamed memory block (freed immediately after onprogress call)
404-
ptr = _malloc(ptrLen);
404+
ptr = malloc(ptrLen);
405405
HEAPU8.set(new Uint8Array(/** @type{Array<number>} */(xhr.response)), ptr);
406406
}
407407
{{{ makeSetValue('fetch', C_STRUCTS.emscripten_fetch_t.data, 'ptr', '*') }}}
@@ -415,7 +415,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
415415
if (xhr.statusText) stringToUTF8(xhr.statusText, fetch + {{{ C_STRUCTS.emscripten_fetch_t.statusText }}}, 64);
416416
onprogress?.(fetch, xhr, e);
417417
if (ptr) {
418-
_free(ptr);
418+
free(ptr);
419419
}
420420
};
421421
xhr.onreadystatechange = (e) => {

src/compiler.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ if (!ALL_INCOMING_MODULE_JS_API.length) {
5050
ALL_INCOMING_MODULE_JS_API = INCOMING_MODULE_JS_API;
5151
}
5252

53-
EXPORTED_FUNCTIONS = new Set(EXPORTED_FUNCTIONS);
53+
EXPORTS = new Set(EXPORTS);
5454
WASM_EXPORTS = new Set(WASM_EXPORTS);
5555
SIDE_MODULE_EXPORTS = new Set(SIDE_MODULE_EXPORTS);
5656
INCOMING_MODULE_JS_API = new Set(INCOMING_MODULE_JS_API);

src/deterministic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Module['thisProgram'] = 'thisProgram'; // for consistency between different buil
2626

2727
function hashMemory(id) {
2828
var ret = 0;
29-
var len = _sbrk(0);
29+
var len = sbrk(0);
3030
for (var i = 0; i < len; i++) {
3131
ret = (ret*17 + HEAPU8[i])|0;
3232
}

src/embind/embind.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
/*global addToLibrary*/
77

88
/*global Module, asm*/
9-
/*global _malloc, _free, _memcpy*/
9+
/*global malloc, free, memcpy*/
1010
/*global FUNCTION_TABLE, HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64*/
1111
/*global readLatin1String*/
12-
/*global Emval, emval_handle_array, __emval_decref*/
12+
/*global Emval, emval_handle_array, _emval_decref*/
1313
/*jslint sub:true*/ /* The symbols 'fromWireType' and 'toWireType' must be accessed via array notation to be closure-safe since craftInvokerFunction crafts functions as strings that can't be closured. */
1414

1515
// -- jshint doesn't understand library syntax, so we need to specifically tell it about the symbols we define
@@ -46,7 +46,7 @@ var LibraryEmbind = {
4646
name: 'emscripten::val',
4747
'fromWireType': (handle) => {
4848
var rv = Emval.toValue(handle);
49-
__emval_decref(handle);
49+
_emval_decref(handle);
5050
return rv;
5151
},
5252
'toWireType': (destructors, value) => Emval.toHandle(value),
@@ -535,7 +535,7 @@ var LibraryEmbind = {
535535
str = a.join('');
536536
}
537537

538-
_free(value);
538+
free(value);
539539

540540
return str;
541541
},
@@ -557,7 +557,7 @@ var LibraryEmbind = {
557557
}
558558

559559
// assumes POINTER_SIZE alignment
560-
var base = _malloc({{{ POINTER_SIZE }}} + length + 1);
560+
var base = malloc({{{ POINTER_SIZE }}} + length + 1);
561561
var ptr = base + {{{ POINTER_SIZE }}};
562562
{{{ makeSetValue('base', '0', 'length', SIZE_TYPE) }}};
563563
if (stdStringIsUTF8 && valueIsOfTypeString) {
@@ -567,7 +567,7 @@ var LibraryEmbind = {
567567
for (var i = 0; i < length; ++i) {
568568
var charCode = value.charCodeAt(i);
569569
if (charCode > 255) {
570-
_free(ptr);
570+
free(ptr);
571571
throwBindingError('String has UTF-16 code units that do not fit in 8 bits');
572572
}
573573
HEAPU8[ptr + i] = charCode;
@@ -580,14 +580,14 @@ var LibraryEmbind = {
580580
}
581581

582582
if (destructors !== null) {
583-
destructors.push(_free, base);
583+
destructors.push(free, base);
584584
}
585585
return base;
586586
},
587587
argPackAdvance: GenericWireTypeSize,
588588
'readValueFromPointer': readPointer,
589589
destructorFunction(ptr) {
590-
_free(ptr);
590+
free(ptr);
591591
},
592592
});
593593
},
@@ -635,7 +635,7 @@ var LibraryEmbind = {
635635
}
636636
}
637637

638-
_free(value);
638+
free(value);
639639

640640
return str;
641641
},
@@ -646,20 +646,20 @@ var LibraryEmbind = {
646646

647647
// assumes POINTER_SIZE alignment
648648
var length = lengthBytesUTF(value);
649-
var ptr = _malloc({{{ POINTER_SIZE }}} + length + charSize);
649+
var ptr = malloc({{{ POINTER_SIZE }}} + length + charSize);
650650
{{{ makeSetValue('ptr', '0', 'length / charSize', SIZE_TYPE) }}};
651651

652652
encodeString(value, ptr + {{{ POINTER_SIZE }}}, length + charSize);
653653

654654
if (destructors !== null) {
655-
destructors.push(_free, ptr);
655+
destructors.push(free, ptr);
656656
}
657657
return ptr;
658658
},
659659
argPackAdvance: GenericWireTypeSize,
660660
'readValueFromPointer': readPointer,
661661
destructorFunction(ptr) {
662-
_free(ptr);
662+
free(ptr);
663663
}
664664
});
665665
},
@@ -670,7 +670,7 @@ var LibraryEmbind = {
670670

671671
_embind_register_user_type__deps: ['_embind_register_emval'],
672672
_embind_register_user_type: (rawType, name) => {
673-
__embind_register_emval(rawType);
673+
_embind_register_emval(rawType);
674674
},
675675

676676
_embind_register_optional__deps: ['$registerType', '$EmValOptionalType'],

src/embind/embind_shared.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ var LibraryEmbindShared = {
117117
},
118118
$getTypeName__deps: ['$readLatin1String', '__getTypeName', 'free'],
119119
$getTypeName: (type) => {
120-
var ptr = ___getTypeName(type);
120+
var ptr = __getTypeName(type);
121121
var rv = readLatin1String(ptr);
122-
_free(ptr);
122+
free(ptr);
123123
return rv;
124124
},
125125
$getFunctionName__deps: [],

0 commit comments

Comments
 (0)