Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -3157,8 +3157,15 @@ mergeInto(LibraryManager.library, {
assert(('dynCall_' + sig) in Module, `bad function pointer type - dynCall function not found for sig '${sig}'`);
#endif
if (args && args.length) {
#if WASM_BIGINT
// j (64-bit integer) is fine, and is implemented as a BigInt. Without
// legalization, the number of parameters should match (j is not expanded
// into two i's).
assert(args.length === sig.length - 1);
#else
// j (64-bit integer) must be passed in as two numbers [low 32, high 32].
assert(args.length === sig.substring(1).replace(/j/g, '--').length);
#endif
} else {
assert(sig.length == 1);
}
Expand Down
52 changes: 45 additions & 7 deletions test/core/dyncall_specific.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,37 @@
* found in the LICENSE file.
*/

#include <assert.h>
#include <emscripten.h>
#include <stdint.h>
#include <stdio.h>

int waka(int w, long long xy, int z) {
#ifndef WASM_BIGINT
// xy should be 0xffff_ffff_0000_0004
int x = (int) xy; // should be 4
int y = xy >> 32; // should be -1
EM_ASM({
out('received ' + [$0, $1, $2, $3] + '.');
}, w, x, y, z);
int x = (int) xy;
int y = xy >> 32;
assert(w == 1);
assert(x == 4);
assert(y == -1);
assert(z == 9);
#else
// With WASM_BIGINT things are straightforward: the 64-bit value just arrives
// with the expected value of 4.
assert(w == 1);
assert(xy == 4);
assert(z == 9);
#endif
return 42;
}

EM_JS_DEPS(main, "$dynCall");

int main() {
EM_ASM({
// Note that these would need to use BigInts if the file were built with
// -sWASM_BIGINT

#ifndef WASM_BIGINT
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you flip the arms of the #if so this condition is in the positive?


#if DIRECT
console.log('Received ' + dynCall_iiji($0, 1, 4, 0xffffffff, 9));
return;
Expand All @@ -45,6 +56,33 @@ int main() {
eval("console.log('Received ' + Module['dynCall_iiji'](" + $0 + ", 1, 4, 0xffffffff, 9))");
return;
#endif

#else // WASM_BIGINT

#if DIRECT
console.log('Received ' + dynCall_iiji($0, 1, BigInt(4), 9));
return;
#endif
#if DYNAMIC_SIG
console.log('Received ' + dynCall('iiji', $0, [1, BigInt(4), 9]));
return;
#endif
#if EXPORTED
console.log('Received ' + Module['dynCall_iiji']($0, 1, BigInt(4), 9));
return;
#endif
#if EXPORTED_DYNAMIC_SIG
console.log('Received ' + Module['dynCall']('iiji', $0, [1, BigInt(4), 9]));
return;
#endif
#if FROM_OUTSIDE
eval("console.log('Received ' + Module['dynCall_iiji'](" + $0 + ", 1, BigInt(4), 9))");
return;
#endif

#endif

// We should have run the test and returned before we get here.
throw "no test mode";
}, &waka);
}
Expand Down
3 changes: 1 addition & 2 deletions test/core/dyncall_specific.out
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
received 1,4,-1,9.
Received 42
Received 42
9 changes: 7 additions & 2 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7209,8 +7209,13 @@ def test_EXPORTED_RUNTIME_METHODS(self):
'minimal_runtime': ['-sMINIMAL_RUNTIME=1']
})
def test_dyncall_specific(self, *args):
if self.get_setting('WASM_BIGINT') or self.get_setting('MEMORY64'):
self.skipTest('not compatible with WASM_BIGINT')
if self.get_setting('MEMORY64'):
self.skipTest('not compatible with MEMORY64')
if self.get_setting('WASM_BIGINT'):
# define DYNCALLS because this test does test calling them directly, and
# in WASM_BIGINT mode we do not enable them by default (since we can do
# more without them - we don't need to legalize)
args = list(args) + ['-sDYNCALLS=1', '-DWASM_BIGINT']
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can just do args += here

Copy link
Member Author

Choose a reason for hiding this comment

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

That modifies the input array, however, which can mean these accumulate, depending on how the test runner works? With the parallelism and all that I'd rather not make assumptions there.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But you are using *arg .. which mean python is creating an array based on the inputs.. and it will be fresh each time I believe.

At the very least you can do args = args + ['-sDYNCALLS=1', '-DWASM_BIGINT'] since that also makes a copy.

Copy link
Member Author

Choose a reason for hiding this comment

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

I checked now to make sure. It turns out that *args is always a tuple, not a list. So we do need the full syntax here, to turn the tuple into a list.

Instead, we could avoid *args, by replacing

    '': [],

with

    '': ([],),

and it is received as test_dyncall_specific(self, args), after which the code is simpler. Tradeoffs both ways, I don't feel strongly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Either way lgtm

Copy link
Collaborator

Choose a reason for hiding this comment

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

Drop the =1

cases = [
('DIRECT', []),
('DYNAMIC_SIG', ['-sDYNCALLS=1']),
Expand Down