Skip to content

Commit a2618d9

Browse files
Merge branch 'main' into shared_memory
2 parents 1d48e33 + 9e37a10 commit a2618d9

File tree

82 files changed

+438
-151
lines changed

Some content is hidden

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

82 files changed

+438
-151
lines changed

ChangeLog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ See docs/process.md for more on how version tagging works.
2323
- The usage of `EM_BOOL` in the emscripten API has been replaced with C/C++
2424
bool. This change should not be observable since `EM_BOOL` has been
2525
equivalent to `bool` since #22157. (#22155)
26+
- Fix regression introduced in 3.1.67 (#22557) which broke webgpu / int64
27+
integration. (#22689)
28+
- SDL2 port updated from 2.28.4 to 2.30.8. (#22697)
29+
- embind no longer exports any library functions by default. Previously we
30+
would export getInheritedInstanceCount, getLiveInheritedInstances,
31+
flushPendingDeletes and setDelayFunction. If you need these library function
32+
exprted they can be added to `EXPORTED_RUNTIME_METHODS`. (#22705)
2633

2734
3.1.68 - 09/30/24
2835
-----------------

site/source/docs/api_reference/wasm_audio_worklets.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ which resumes the audio context when the user clicks on the DOM Canvas element t
126126
"noise-generator", &options, &GenerateNoise, 0);
127127
128128
// Connect it to audio context destination
129-
EM_ASM({emscriptenGetAudioObject($0).connect(emscriptenGetAudioObject($1).destination)},
130-
wasmAudioWorklet, audioContext);
129+
emscripten_audio_node_connect(wasmAudioWorklet, audioContext, 0, 0);
131130
132131
// Resume context on mouse click
133132
emscripten_set_click_callback("canvas", (void*)audioContext, 0, OnCanvasClick);

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

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -613,30 +613,63 @@ Calling JavaScript functions as function pointers from C
613613
========================================================
614614

615615
You can use ``addFunction`` to return an integer value that represents a
616-
function pointer. Passing that integer to C code then lets it call that value as
617-
a function pointer, and the JavaScript function you sent to ``addFunction`` will
618-
be called.
616+
function pointer. Passing that integer to C code then lets it call that value
617+
as a function pointer, and the JavaScript function you sent to ``addFunction``
618+
will be called.
619619

620620
See `test_add_function in test/test_core.py`_ for an example.
621621

622622
You should build with ``-sALLOW_TABLE_GROWTH`` to allow new functions to be
623623
added to the table. Otherwise by default the table has a fixed size.
624624

625-
.. note:: When using ``addFunction`` on LLVM Wasm backend, you need to provide
626-
an additional second argument, a Wasm function signature string. Each
627-
character within a signature string represents a type. The first character
628-
represents the return type of a function, and remaining characters are for
629-
parameter types.
625+
When using ``addFunction`` with a JavaScript function, you need to provide
626+
an additional second argument, a Wasm function signature string, explained
627+
below. See `test/interop/test_add_function_post.js <https://github.com/emscripten-core/emscripten/blob/main/test/interop/test_add_function_post.js>`_ for an example.
628+
629+
630+
.. _interacting-with-code-function-signatures:
631+
632+
Function Signatures
633+
===================
634+
635+
The LLVM Wasm backend requires a Wasm function signature string when using
636+
``addFunction`` and in JavaScript libraries. Each character within a signature
637+
string represents a type. The first character represents the return type of a
638+
function, and remaining characters are for parameter types.
630639

631640
- ``'v'``: void type
632641
- ``'i'``: 32-bit integer type
633-
- ``'j'``: 64-bit integer type (currently does not exist in JavaScript)
642+
- ``'j'``: 64-bit integer type (see note below)
634643
- ``'f'``: 32-bit float type
635644
- ``'d'``: 64-bit float type
645+
- ``'p'``: 32-bit or 64-bit pointer (MEMORY64)
646+
647+
For example, if you add a function that takes an integer and does not return
648+
anything, the signature is ``'vi'``.
649+
650+
When ``'j'`` is used there are several ways in which the parameter value will
651+
be passed to JavaScript. By default, the value will either be passed as a
652+
single BigInt or a pair of JavaScript numbers (double) depending on whether
653+
the ``WASM_BIGINT`` settings is enabled. In addition, if you only require 53
654+
bits of precision you can add the ``__i53abi`` decorator, which will ignore
655+
the upper bits and the value will be received as a single JavaScript number
656+
(double). It cannot be used with ``addFunction``. Here is an example of a
657+
library function that sets the size of a file using a 64-bit value passed as
658+
a 53 bit (double) and returns an integer error code:
659+
660+
.. code-block:: c
661+
662+
extern "C" int _set_file_size(int handle, uint64_t size);
663+
664+
.. code-block:: javascript
636665
637-
For example, if you add a function that takes an integer and does not return
638-
anything, you can do ``addFunction(your_function, 'vi');``. See
639-
`test/interop/test_add_function_post.js <https://github.com/emscripten-core/emscripten/blob/main/test/interop/test_add_function_post.js>`_ for an example.
666+
_set_file_size__i53abi: true, // Handle 64-bit
667+
_set_file_size__sig: 'iij', // Function signature
668+
_set_file_size: function(handle, size) { ... return error; }
669+
670+
Using ``-sWASM_BIGINT`` when linking is an alternative method of handling
671+
64-bit types in libraries. ```Number()``` may be needed on the JavaScript
672+
side to convert it to a useable value. See `settings reference <https://emscripten.org/docs/tools_reference/settings_reference.html?highlight=environment#wasm-bigint>`_.
640673

641674

642675
.. _interacting-with-code-access-memory:

site/source/docs/porting/connecting_cpp_and_javascript/embind.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ For convenience, *embind* provides factory functions to register
10781078
EMSCRIPTEN_BINDINGS(stl_wrappers) {
10791079
register_vector<int>("VectorInt");
10801080
register_map<int,int>("MapIntInt");
1081-
register_optional<std::string>("Optional");
1081+
register_optional<std::string>();
10821082
}
10831083
10841084
A full example is shown below:

src/closure-externs/node-externs.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,18 @@ Buffer.prototype.toString = function(encoding, start, end) {};
104104

105105
Worker.prototype.ref = function() {};
106106
Worker.prototype.unref = function() {};
107+
108+
/**
109+
* @type {number}
110+
*/
111+
fs.Stats.prototype.atimeMs;
112+
113+
/**
114+
* @type {number}
115+
*/
116+
fs.Stats.prototype.mtimeMs;
117+
118+
/**
119+
* @type {number}
120+
*/
121+
fs.Stats.prototype.ctimeMs;

src/embind/embind.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,6 @@ var LibraryEmbind = {
5959
}`,
6060
$EmValOptionalType__deps: ['$EmValType'],
6161
$EmValOptionalType: '=Object.assign({optional: true}, EmValType);',
62-
$init_embind__deps: [
63-
'$getInheritedInstanceCount', '$getLiveInheritedInstances',
64-
'$flushPendingDeletes', '$setDelayFunction'],
65-
$init_embind__postset: 'init_embind();',
66-
$init_embind: () => {
67-
Module['getInheritedInstanceCount'] = getInheritedInstanceCount;
68-
Module['getLiveInheritedInstances'] = getLiveInheritedInstances;
69-
Module['flushPendingDeletes'] = flushPendingDeletes;
70-
Module['setDelayFunction'] = setDelayFunction;
71-
},
7262

7363
$throwUnboundTypeError__deps: ['$registeredTypes', '$typeDependencies', '$UnboundTypeError', '$getTypeName'],
7464
$throwUnboundTypeError: (message, types) => {
@@ -219,7 +209,6 @@ var LibraryEmbind = {
219209
},
220210

221211
// raw pointer -> instance
222-
$registeredInstances__deps: ['$init_embind'],
223212
$registeredInstances: {},
224213

225214
$getBasestPointer__deps: ['$throwBindingError'],
@@ -1582,6 +1571,8 @@ var LibraryEmbind = {
15821571
'$releaseClassHandle',
15831572
'$throwBindingError',
15841573
'$detachFinalizer',
1574+
'$flushPendingDeletes',
1575+
'$delayFunction',
15851576
],
15861577
$init_ClassHandle: () => {
15871578
Object.assign(ClassHandle.prototype, {

src/library.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ addToLibrary({
15341534
emscripten_log__deps: ['$formatString', '$emscriptenLog'],
15351535
emscripten_log: (flags, format, varargs) => {
15361536
var result = formatString(format, varargs);
1537-
var str = UTF8ArrayToString(result, 0);
1537+
var str = UTF8ArrayToString(result);
15381538
emscriptenLog(flags, str);
15391539
},
15401540

src/library_fs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ FS.staticInit();
13031303
var buf = new Uint8Array(length);
13041304
FS.read(stream, buf, 0, length, 0);
13051305
if (opts.encoding === 'utf8') {
1306-
ret = UTF8ArrayToString(buf, 0);
1306+
ret = UTF8ArrayToString(buf);
13071307
} else if (opts.encoding === 'binary') {
13081308
ret = buf;
13091309
}

src/library_noderawfs.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,17 @@ addToLibrary({
9191
var stream = FS.getStreamChecked(fd);
9292
fs.ftruncateSync(stream.nfd, len);
9393
},
94-
utime(path, atime, mtime) { fs.utimesSync(path, atime/1000, mtime/1000); },
94+
utime(path, atime, mtime) {
95+
// -1 here for atime or mtime means UTIME_OMIT was passed. Since node
96+
// doesn't support this concept we need to first find the existing
97+
// timestamps in order to preserve them.
98+
if (atime == -1 || mtime == -1) {
99+
var st = fs.statSync(path);
100+
if (atime == -1) atime = st.atimeMs;
101+
if (mtime == -1) mtime = st.mtimeMs;
102+
}
103+
fs.utimesSync(path, atime/1000, mtime/1000);
104+
},
95105
open(path, flags, mode) {
96106
if (typeof flags == "string") {
97107
flags = FS_modeStringToFlags(flags)

src/library_pthread.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,11 @@ var LibraryPThread = {
405405
#if ENVIRONMENT_MAY_BE_WEB || ENVIRONMENT_MAY_BE_WORKER
406406
// This is the way that we signal to the Web Worker that it is hosting
407407
// a pthread.
408+
#if ASSERTIONS
409+
'name': 'em-pthread-' + PThread.nextWorkerID,
410+
#else
408411
'name': 'em-pthread',
412+
#endif
409413
#endif
410414
};
411415
#if EXPORT_ES6 && USE_ES6_IMPORT_META

0 commit comments

Comments
 (0)