Emscripten: Problem with arguments passed to function

Created on 18 Jan 2018  路  5Comments  路  Source: emscripten-core/emscripten

I am building https://github.com/warchant/ed25519.git with Emscripten
The project is built with cmake, so I do

emcmake cmake . -DTESTING=OFF
emmake make
emcc libed25519.so -s EXPORTED_FUNCTIONS='["_ed25519_create_keypair", "_ed25519_sign", "_ed25519_verify", "_ed25519_derive_public_key"]' -o ed25519.js

Since this is a library, I export 4 functions, described in here

But when I try to call those functions from javascript, turns out that _ed25519_sign and _ed25519_verify in JScode receive 1 more argument than it described in .h file.

In .h file ed25519_sign receives 5 args, but in js code it receives 6.
in .h file ed25519_verify receives 4 args, but in js code it receives 5.

Because of that, in my wrapper functions I need to pass 1 more argument like this
(There I pass 0, so function works correctly)

Other option for me was to change variable assignments in generated code like i did here. After changing assignments function started to work correctly. But I don't like idea of changing generated code so I will stick to my "hack" in wrapper.

For other 2 functions, _ed25519_create_keypair and _ed25519_derive_public_key everything is OK.

wontfix

Most helpful comment

Yeah, I think this might not be documented - would be great to fix that, thanks! :)

Probably the "interacting with code" page is a good location, but if you were looking for this somewhere else, that could be better.

All 5 comments

I believe that is because of the unsigned long long msglen - that's a 64-bit integer, which can't be represented in JavaScript. So the compiler emits 2 params, for the lower and higher 32 bits each separately.

Thank you for the answer! Seems like you are right. I've written a small test to check it and seems that if you call such function for example from main, javascript explicitly passes additional argument for higher 32 bits.
I guess this case should be noted in docs (if it is not done already, sorry, didn't check properly). @kripken I can write docs for this case, so no one will fall for it again :)

Yeah, I think this might not be documented - would be great to fix that, thanks! :)

Probably the "interacting with code" page is a good location, but if you were looking for this somewhere else, that could be better.

Tried to add some documentation. Not sure if I explained everything correctly, but please check it.

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

void4 picture void4  路  3Comments

hcomere picture hcomere  路  3Comments

nemequ picture nemequ  路  4Comments

answer1103 picture answer1103  路  4Comments

jcfr picture jcfr  路  4Comments