-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Change definition of true and false macros to be js friendly #24255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change definition of true and false macros to be js friendly #24255
Conversation
@sbc100 I added a test but curiously it does not pass because |
But you've seen this fail locally for you? |
Yes, I've been using this in Pyodide for years: I just had to copy paste it into another project and figured it would be nice to upstream. |
So when you see it fail I assume that failure is also coming from the clang version this header? If so, I guess this fix needs to happen upstream in clang instead? |
Another solution would be to using |
Yeah, I guess the system search path looks like:
so the clang include files are preferred over the emscripten files. |
We could potentially inject a fix like your into our |
6eadd5c
to
f7cdabe
Compare
Makes sense to me, I did that. |
Okay I added the comments you suggested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if its worth adding this without also adding something like EM_JS_MACROS
.
I would imagine the best place for something like this would be alongside something like EM_JS_MACROS
.
Is the idea that there could be other users out there who try to write EM_JS_MACROS
and this will help them avoid the pain you went through trying to debug stuff?
Yeah. A few months ago, someone was asking how to make struct MyStruct {
void* field1;
void* field2;
}
#define MyStruct_field1_offset 0
#define MyStruct_field2_offset 4
_Static_assert(offsetof(MyStruct, field1) == MyStruct_field1_offset);
_Static_assert(offsetof(MyStruct, field2) == MyStruct_field2_offset);
#define MyStruct_field1(x) HEAPU32[x/4 + MyStruct_field1_offset]
#define MyStruct_field2(x) HEAPU32[x/4 + MyStruct_field2_offset]
EM_JS_MACROS(void, f, (MyStruct* arg), {
const field1 = MyStruct_field1(x);
const field2 = MyStruct_field2(x);
}); Another common use case is for sharing bitflags between C and JS: #define FLAG1 (1 << 0)
#define FLAG2 (1 << 1)
...
EMSCRIPTEN_KEEPALIVE int get_flags() {
return FLAG1 | FLAG2;
}
EM_JS_MACROS(void, process_flags, (int flags), {
if (flags & FLAG1) {
// handle FLAG1
}
if (flags & FLAG2) {
// handle FLAG2
}
}); But the biggest reason for me is to inject standard error handling everywhere so that it's easier to implement a C calling convention in JS: #define EM_JS_REF(ret, func_name, args, body...) \
EM_JS_MACROS(ret WARN_UNUSED, func_name, args, { \
try /* intentionally no braces, body already has them */ \
body /* <== body of func */ \
catch (e) { \
LOG_EM_JS_ERROR(func_name, e); \
Module.handle_js_error(e); \
return 0; \
} \
errNoRet(); \
}) |
Opened #24272. |
No description provided.