Skip to content
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

Preprocessor error with SEEK #10483

Closed
Epse opened this issue Feb 16, 2020 · 7 comments · Fixed by #10501
Closed

Preprocessor error with SEEK #10483

Epse opened this issue Feb 16, 2020 · 7 comments · Fixed by #10501

Comments

@Epse
Copy link

Epse commented Feb 16, 2020

When compiling any code that uses SEEK_SET, SEEK_CUR or SEEK_END with a preprocessor conditional, the compiler will error.

I have included error output below. Please let me know if this should be asked upstream, I have searched the internet but could not find anything about this particular issue.

./Modules/_io/fileio.c:890:5: error: token is not a valid binary operator in a preprocessor subexpression
#if SEEK_SET != 0
    ^~~~~~~~
/home/e/install/emsdk/upstream/emscripten/system/include/libc/fcntl.h:80:18: note: expanded from macro 'SEEK_SET'
#define SEEK_SET __WASI_WHENCE_SET
                 ^~~~~~~~~~~~~~~~~
/home/e/install/emsdk/upstream/emscripten/system/include/wasi/api.h:693:45: note: expanded from macro '__WASI_WHENCE_SET'
#define __WASI_WHENCE_SET ((__wasi_whence_t)0)
                           ~~~~~~~~~~~~~~~~~^
./Modules/_io/fileio.c:893:5: error: token is not a valid binary operator in a preprocessor subexpression
#if SEEK_CUR != 1
    ^~~~~~~~
/home/e/install/emsdk/upstream/emscripten/system/include/libc/fcntl.h:81:18: note: expanded from macro 'SEEK_CUR'
#define SEEK_CUR __WASI_WHENCE_CUR
                 ^~~~~~~~~~~~~~~~~
/home/e/install/emsdk/upstream/emscripten/system/include/wasi/api.h:698:45: note: expanded from macro '__WASI_WHENCE_CUR'
#define __WASI_WHENCE_CUR ((__wasi_whence_t)1)
                           ~~~~~~~~~~~~~~~~~^
./Modules/_io/fileio.c:896:5: error: token is not a valid binary operator in a preprocessor subexpression
#if SEEK_END != 2
    ^~~~~~~~
/home/e/install/emsdk/upstream/emscripten/system/include/libc/fcntl.h:82:18: note: expanded from macro 'SEEK_END'
#define SEEK_END __WASI_WHENCE_END
                 ^~~~~~~~~~~~~~~~~
/home/e/install/emsdk/upstream/emscripten/system/include/wasi/api.h:703:45: note: expanded from macro '__WASI_WHENCE_END'
#define __WASI_WHENCE_END ((__wasi_whence_t)2)
@sbc100
Copy link
Collaborator

sbc100 commented Feb 16, 2020

It looks to my like the upstream code might be trying to do something it shouldn't by assuming it can use SEEK_SET in the pre-processor in this way. It probably is worth seeing if we can find out what the standard says about this. Can you point me to the upstream code in question (is it open source)?

@Epse
Copy link
Author

Epse commented Feb 16, 2020

It's Cython, though a simple example like the following triggers as well. Factor to note here is that Clang and GCC compile this without warnings to native code.

#include <stdio.h>

#if SEEK_SET != 0
#define didsomething
#endif

int main() {
    return 0;
}

@sbc100
Copy link
Collaborator

sbc100 commented Feb 16, 2020

I'm just wondering if that standard says that constants like SEEK_SET have to be usable in pre-processor expressions like this?

@sbc100
Copy link
Collaborator

sbc100 commented Feb 16, 2020

Oh.. I completely forgot. We already fixed this upstream in wasi-libc: WebAssembly/wasi-libc#148.

We just need to update the wasi headers.

@Epse
Copy link
Author

Epse commented Feb 17, 2020

Any idea when this might happen or how I might do this for myself until the headers get updated?

@sbc100
Copy link
Collaborator

sbc100 commented Feb 17, 2020

For a quick local fix you can probably just edit api.h and remove those cast operations from the macros.

sbc100 added a commit that referenced this issue Feb 19, 2020
This address more issues with using typedefs in macros. Otherwise
seems to be mostly a no-op, adding comments and some static asserts.

Fixes: #10483
sbc100 added a commit that referenced this issue Feb 19, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
This address more issues with using typedefs in macros. Otherwise
seems to be mostly a no-op, adding comments and some static asserts.

Fixes: #10483
@Epse
Copy link
Author

Epse commented Feb 19, 2020 via email

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 a pull request may close this issue.

2 participants