Skip to content

Commit 4e73614

Browse files
authored
[wasm64] Fix emscripten_get_compiler_setting (#16938)
Although this changes the return type of `emscripten_get_compiler_setting` from `int` to `long` I don't think this will break many existing users (this API I also imagine has very few users). The test here needed an update because it tried to directly use the return value in a printf statement but most users will likely be assigning to an `int` which will continue to work. I thought about using `intptr_t` as the return type but that would mean adding `#include <inttypes.h>` to `emscripten.h` which seems like a slightly bigger change.
1 parent e5b7c6c commit 4e73614

File tree

8 files changed

+13
-8
lines changed

8 files changed

+13
-8
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ jobs:
381381
executor: bionic
382382
steps:
383383
- run-tests-linux:
384-
test_targets: "wasm64.test_hello_world wasm64.test_ccall wasm64l.test_hello_world wasm64l.test_mmap wasm64l.test_unistd_* skip:wasm64l.test_unistd_sysconf wasm64l.test_mmap_file wasm64l.test_ccall wasm64l.test_signals"
384+
test_targets: "wasm64.test_hello_world wasm64.test_ccall wasm64l.test_hello_world wasm64l.test_mmap wasm64l.test_unistd_* skip:wasm64l.test_unistd_sysconf wasm64l.test_mmap_file wasm64l.test_ccall wasm64l.test_signals wasm64l.test_emscripten_get_compiler_setting"
385385
test-other:
386386
executor: bionic
387387
steps:

ChangeLog.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.11
2222
------
23+
- The return value of `emscripten_get_compiler_setting` was changed from `int`
24+
to `long` so that it is compatible with `MEMORY64`. The return value of this
25+
function sometimes contains a pointer value so `int` is not sufficiently
26+
wide under `wasm64`. (#16938)
2327
- The `EM_BUILD_VERBOSE` environment variable only effects test code these days
24-
and therefore was renamed to `EMTEST_BUILD_VERBOSE`.
28+
and therefore was renamed to `EMTEST_BUILD_VERBOSE`. (#16904)
2529

2630
3.1.10 - 05/02/2022
2731
-------------------

site/source/docs/api_reference/emscripten.h.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,15 +1042,15 @@ Defines
10421042
Functions
10431043
---------
10441044
1045-
.. c:function:: int emscripten_get_compiler_setting(const char *name)
1045+
.. c:function:: long emscripten_get_compiler_setting(const char *name)
10461046
10471047
Returns the value of a compiler setting.
10481048
10491049
For example, to return the integer representing the value of ``INITIAL_MEMORY`` during compilation: ::
10501050
10511051
emscripten_get_compiler_setting("INITIAL_MEMORY")
10521052
1053-
For values containing anything other than an integer, a string is returned (you will need to cast the ``int`` return value to a ``char*``).
1053+
For values containing anything other than an integer, a string is returned (you will need to cast the ``long`` return value to a ``char*``).
10541054
10551055
Some useful things this can do is provide the version of Emscripten (“EMSCRIPTEN_VERSION”), the optimization level (“OPT_LEVEL”), debug level (“DEBUG_LEVEL”), etc.
10561056

src/library.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,6 +2572,7 @@ LibraryManager.library = {
25722572
// We never free the return values of this function so we need to allocate
25732573
// using builtin_malloc to avoid LSan reporting these as leaks.
25742574
emscripten_get_compiler_setting__deps: ['emscripten_builtin_malloc'],
2575+
emscripten_get_compiler_setting__sig: 'pp',
25752576
emscripten_get_compiler_setting: function(name) {
25762577
#if RETAIN_COMPILER_SETTINGS
25772578
name = UTF8ToString(name);

src/preamble.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ function instrumentWasmExportsForMemory64(exports) {
785785
(function(name) {
786786
var original = exports[name];
787787
var replacement = original;
788-
if (name === 'stackAlloc' || name === 'malloc') {
788+
if (name === 'stackAlloc' || name === 'malloc' || name === 'emscripten_builtin_malloc') {
789789
// get one i64, return an i64
790790
replacement = (x) => {
791791
var r = Number(original(BigInt(x)));

system/include/emscripten/emscripten.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ int emscripten_get_worker_queue_size(worker_handle worker);
136136

137137
// misc.
138138

139-
int emscripten_get_compiler_setting(const char *name);
139+
long emscripten_get_compiler_setting(const char *name);
140140
int emscripten_has_asyncify(void);
141141

142142
void emscripten_debugger(void);

tests/core/emscripten_get_compiler_setting.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <emscripten.h>
1111

1212
int main() {
13-
printf("INVOKE_RUN: %d\n", emscripten_get_compiler_setting("INVOKE_RUN"));
13+
printf("INVOKE_RUN: %ld\n", emscripten_get_compiler_setting("INVOKE_RUN"));
1414
assert((unsigned)emscripten_get_compiler_setting("OPT_LEVEL") <= 3);
1515
assert((unsigned)emscripten_get_compiler_setting("DEBUG_LEVEL") <= 4);
1616
printf("EMSCRIPTEN_VERSION: %s\n", (char*)emscripten_get_compiler_setting("EMSCRIPTEN_VERSION"));

tests/test_other.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9445,7 +9445,7 @@ def test_renamed_setting(self):
94459445
#include <emscripten.h>
94469446
94479447
int main() {
9448-
printf("%d %d\n",
9448+
printf("%ld %ld\n",
94499449
emscripten_get_compiler_setting("BINARYEN_ASYNC_COMPILATION"),
94509450
emscripten_get_compiler_setting("WASM_ASYNC_COMPILATION"));
94519451
return 0;

0 commit comments

Comments
 (0)