Skip to content

Commit c9cdff6

Browse files
authored
Remove legacy library symbols: $ALLOC_NORMAL, $ALLOC_STACK, $allocate (emscripten-core#27378)
Remove `$ALLOC_NORMAL`, `$ALLOC_STACK`, and `$allocate` from `liblegacy.js` and `extraLibraryFuncs` in `libcore.js`. These symbols were moved to `library_legacy.js` when the file was first created in July 2022 (emscripten-core#17390). They have produced `-Wdeprecated` warnings on usage since February 2024 (emscripten-core#21357), over 2 years ago, giving external users plenty time to transition. The `test_legacy_exported_runtime_numbers` test in `test_core.py` is also removed since it specifically tested `$ALLOC_STACK`. The error messages checked by that test are covered elsewhere in `test_other.py`: - "was not exported" is covered by `test_warn_module_out_err` and `test_exported_runtime_methods_from_js_library`. - "is a library symbol and not included by default" is covered by `test_removed_runtime_function` and `test_legacy_runtime`.
1 parent cf1becd commit c9cdff6

11 files changed

Lines changed: 13 additions & 108 deletions

File tree

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ See docs/process.md for more on how version tagging works.
2222
----------------------
2323
- Legacy support for ancient vendor-prefixed DOM APIs was removed (#27341,
2424
#27339, #27338, #27340, #27347)
25+
- Removed legacy JS library symbols symbols: `$ALLOC_NORMAL`, `$ALLOC_STACK`,
26+
and `$allocate`. (#27378)
2527

2628
6.0.3 - 07/13/26
2729
----------------

site/source/docs/api_reference/preamble.js.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,17 +425,11 @@ types. The views for accessing different types of memory are listed below.
425425

426426

427427
.. COMMENT (not rendered) : The following methods are explicitly not part of the public API and not documented. Note that in some case referred to by function name, other cases by Module assignment.
428-
429-
function allocate(slab, types, allocator, ptr) — Internal and use is discouraged. Documentation can remain in source code but not here.
430-
associated constants ALLOC_NORMAL, ALLOC_STACK
431-
432428
function addOnPreRun
433429
function addOnInit
434430
function addOnPreMain
435431
function addOnExit
436432
function addOnPostRun
437-
Module['ALLOC_NORMAL'] = ALLOC_NORMAL;
438-
Module['ALLOC_STACK'] = ALLOC_STACK;
439433
Module['HEAP'] = HEAP;
440434
Module['IHEAP'] = IHEAP;
441435
function demangle(func)

src/lib/libcore.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2455,9 +2455,6 @@ function autoAddDeps(lib, name) {
24552455
extraLibraryFuncs.push(
24562456
'$addFunction',
24572457
'$removeFunction',
2458-
'$allocate',
2459-
'$ALLOC_NORMAL',
2460-
'$ALLOC_STACK',
24612458
'$AsciiToString',
24622459
'$stringToAscii',
24632460
'$UTF16ToString',

src/lib/liblegacy.js

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,6 @@
1515
*/
1616

1717
legacyFuncs = {
18-
$ALLOC_NORMAL: 0, // Tries to use _malloc()
19-
$ALLOC_STACK: 1, // Lives for the duration of the current function call
20-
21-
/**
22-
* allocate(): This function is no longer used by emscripten but is kept around to avoid
23-
* breaking external users.
24-
* You should normally not use allocate(), and instead allocate
25-
* memory using _malloc()/stackAlloc(), initialize it with
26-
* setValue(), and so forth.
27-
* @param {(Uint8Array|Array<number>)} slab: An array of data.
28-
* @param {number=} allocator : How to allocate memory, see ALLOC_*
29-
*/
30-
$allocate__deps: ['$ALLOC_STACK', 'malloc', '$stackAlloc'],
31-
$allocate: (slab, allocator) => {
32-
var ret;
33-
#if ASSERTIONS
34-
assert(typeof allocator == 'number', 'allocate no longer takes a type argument')
35-
assert(typeof slab != 'number', 'allocate no longer takes a number as arg0')
36-
#endif
37-
38-
if (allocator == ALLOC_STACK) {
39-
ret = stackAlloc(slab.length);
40-
} else {
41-
ret = _malloc(slab.length);
42-
}
43-
44-
if (!slab.subarray && !slab.slice) {
45-
slab = new Uint8Array(slab);
46-
}
47-
HEAPU8.set(slab, ret);
48-
return ret;
49-
},
5018

5119
// Deprecated: This function should not be called because it is unsafe and
5220
// does not provide a maximum length limit of how many bytes it is allowed to

system/include/emscripten/em_macros.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
* setting.
3232
*
3333
* For example, if your code contains an EM_ASM or EM_JS block that make use of
34-
* the allocate and stackSave JS library functions then you might write this in
34+
* the stringToNewUTF8 and stackSave JS library functions then you might write this in
3535
* your library source code:
3636
*
37-
* EM_JS_DEPS(mylib_dep, "$allocate,$stackSave");
37+
* EM_JS_DEPS(mylib_dep, "$stringToNewUTF8,$stackSave");
3838
*
3939
* The emscripten linker will then pick this up and make sure those symbols get
4040
* included in the JS support library.

test/codesize/test_codesize_hello_O0.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 23661,
3-
"a.out.js.gz": 8600,
2+
"a.out.js": 23627,
3+
"a.out.js.gz": 8586,
44
"a.out.nodebug.wasm": 15115,
55
"a.out.nodebug.wasm.gz": 7464,
6-
"total": 38776,
7-
"total_gz": 16064,
6+
"total": 38742,
7+
"total_gz": 16050,
88
"sent": [
99
"fd_write"
1010
],
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"hello_world.js": 56342,
3-
"hello_world.js.gz": 17727,
2+
"hello_world.js": 56293,
3+
"hello_world.js.gz": 17712,
44
"hello_world.wasm": 15115,
55
"hello_world.wasm.gz": 7464,
66
"no_asserts.js": 25511,
@@ -11,6 +11,6 @@
1111
"strict.js.gz": 16711,
1212
"strict.wasm": 15115,
1313
"strict.wasm.gz": 7461,
14-
"total": 177756,
15-
"total_gz": 64046
14+
"total": 177707,
15+
"total_gz": 64031
1616
}

test/core/legacy_exported_runtime_numbers.cpp

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/core/legacy_exported_runtime_numbers_assert.out

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/test_core.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7302,40 +7302,6 @@ def test(output_prefix='', args=None, assert_returncode=0):
73027302
self.set_setting('EXPORTED_RUNTIME_METHODS', ['FS_createDataFile'])
73037303
test(args=['-sFORCE_FILESYSTEM'])
73047304

7305-
@no_modularize_instance('uses Module object directly')
7306-
@no_strict('This test verifies legacy behavior that does not apply to -sSTRICT builds.')
7307-
def test_legacy_exported_runtime_numbers(self):
7308-
# these used to be exported, but no longer are by default
7309-
def test(expected, args=None, assert_returncode=0):
7310-
self.do_runf('core/legacy_exported_runtime_numbers.cpp', expected,
7311-
assert_returncode=assert_returncode, cflags=args)
7312-
7313-
# Without assertion indirect usages (via Module) result in `undefined` and direct usage
7314-
# generates a builtin (not very helpful) JS error.
7315-
self.set_setting('ASSERTIONS', 0)
7316-
self.set_setting('LEGACY_RUNTIME', 0)
7317-
test('|undefined|')
7318-
test('ALLOC_STACK is not defined', args=['-DDIRECT'], assert_returncode=NON_ZERO)
7319-
7320-
# When assertions are enabled direct and indirect usage both abort with a useful error message.
7321-
not_exported = "'ALLOC_STACK' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the Emscripten FAQ)"
7322-
not_included = "`ALLOC_STACK` is a library symbol and not included by default; add it to your library.js __deps or to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE on the command line (e.g. -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='$ALLOC_STACK')"
7323-
self.set_setting('ASSERTIONS')
7324-
test(not_exported, assert_returncode=NON_ZERO)
7325-
test(not_included, args=['-DDIRECT'])
7326-
7327-
# Adding the symbol to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE should allow direct usage, but
7328-
# Module usage should continue to fail.
7329-
self.cflags += ['-Wno-deprecated']
7330-
self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', ['$ALLOC_STACK'])
7331-
test(not_exported, assert_returncode=NON_ZERO)
7332-
test('1', args=['-DDIRECT'])
7333-
7334-
# Adding the symbols to EXPORTED_RUNTIME_METHODS should make both usage patterns work.
7335-
self.set_setting('EXPORTED_RUNTIME_METHODS', ['ALLOC_STACK'])
7336-
test('|1|')
7337-
test('|1|', args=['-DDIRECT'])
7338-
73397305
def test_linker_response_file(self):
73407306
objfile = 'response_file.o'
73417307
out_js = self.output_name('response_file')

0 commit comments

Comments
 (0)