Skip to content

Fix emrun_file_dump() to work in multithreaded builds.#26698

Open
juj wants to merge 2 commits intoemscripten-core:mainfrom
juj:fix_emrun_file_dump_with_threads
Open

Fix emrun_file_dump() to work in multithreaded builds.#26698
juj wants to merge 2 commits intoemscripten-core:mainfrom
juj:fix_emrun_file_dump_with_threads

Conversation

@juj
Copy link
Copy Markdown
Collaborator

@juj juj commented Apr 16, 2026

No description provided.

Comment thread test/test_browser.py
self.assertContained('remember to add `--` between arguments', err)

@also_with_threads
def test_emrun(self):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC we are not actually running these tests in CI since they got disabled a while back.

See #26182

We should certain look into fixing that.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Tending to that is not urgent from my pov at least.

Comment thread src/emrun_postjs.js Outdated
http.open("POST", "stdio.html?file=" + filename, true);
http.send(data); // XXX this does not work in workers, for some odd reason (issue #2681)
if (ArrayBuffer.isView(data) && typeof SharedArrayBuffer !== "undefined" && data.buffer instanceof SharedArrayBuffer) {
http.send(new data.constructor(data)); // Make a clone of the typed array of the same type, since http.send() does not allow SharedArrayBuffer backing.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just always go this. Its such a rare opertaion?\

Or at least do

if (.. ) {
   data = new data.constructor(data);
}
http.send(data);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea with the second part.

Comment thread src/emrun_postjs.js
out(`Dumping out file "${filename}" with ${data.length} bytes of data.`);
http.open("POST", "stdio.html?file=" + filename, true);
http.send(data); // XXX this does not work in workers, for some odd reason (issue #2681)
if (ArrayBuffer.isView(data) && typeof SharedArrayBuffer !== "undefined" && data.buffer instanceof SharedArrayBuffer) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It you look at getUnsharedTextDecoderView I think we can replace this whole expression with just !(data.buffer instanceof ArrayBuffer)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In emrun_file_dump() hypothetically, data might be a regular array. Since it is invoked from the JS realm (and not C/C++), existing users might have been calling it by feeding a regular array or a typed array, or a typed array view. The comment had

// POSTs the given binary data represented as a (typed) array

so I don't want to change that. That is why the check here is conditional.

@sbc100
Copy link
Copy Markdown
Collaborator

sbc100 commented Apr 16, 2026

Re the code size failures, here was an update that happened overnight. If you rebase that should now be fixed.

@juj juj force-pushed the fix_emrun_file_dump_with_threads branch from dcc4cb0 to 504c5e8 Compare April 17, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants