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

Parse error with WASI errno types #10018

Closed
juj opened this issue Dec 12, 2019 · 3 comments
Closed

Parse error with WASI errno types #10018

juj opened this issue Dec 12, 2019 · 3 comments

Comments

@juj
Copy link
Collaborator

juj commented Dec 12, 2019

Updating our codebases to new Wasm backend... Here is a silly issue.

On some platforms, the C errno defines EAGAIN and EWOULDBLOCK can have the same value. Hence, portable code in our codebase does

switch(errno) {
   case EAGAIN:
#if EAGAIN != EWOULDBLOCK
   case EWOULDBLOCK:
#endif
      // handle EAGAIN/EWOULDBLOCK here
}

But attempting to compile such code with new Emscripten code gives an error

os\Posix\Error.cpp:30:9: error: token is not a valid binary operator in a preprocessor subexpression
    #if EAGAIN != EWOULDBLOCK
        ^~~~~~
C:\code\emsdk\emscripten\incoming\system\lib\libc\musl\arch\emscripten\bits\errno.h:13:28: note: expanded from macro 'EAGAIN'
#define EAGAIN             __WASI_ERRNO_AGAIN
                           ^~~~~~~~~~~~~~~~~~
C:\code\emsdk\emscripten\incoming\system\include\wasi\api.h:129:45: note: expanded from macro '__WASI_ERRNO_AGAIN'
#define __WASI_ERRNO_AGAIN ((__wasi_errno_t)6)
                            ~~~~~~~~~~~~~~~~^

Changing

diff --git a/system/include/wasi/api.h b/system/include/wasi/api.h
index 137fc264d..7a928aa9f 100644
--- a/system/include/wasi/api.h
+++ b/system/include/wasi/api.h
@@ -126,7 +126,7 @@ typedef uint16_t __wasi_errno_t;
 /**
  * Resource unavailable, or operation would block.
  */
-#define __WASI_ERRNO_AGAIN ((__wasi_errno_t)6)
+#define __WASI_ERRNO_AGAIN 6

 /**
  * Connection already in progress.

resolves the build error, but not sure if that makes sense.

I don't know if spec mandates that testing #if EAGAIN != EWOULDBLOCK should be safe or not, but that line has not caused issues on any other platform (and Unity builds to a ton of platforms), so I'm wondering if Emscripten can change here? Is the (__wasi_errno_t) cast somehow important?

@kripken
Copy link
Member

kripken commented Dec 12, 2019

This looks like #9996, and overall I am starting to think we should just modify the wasi headers locally in emscripten... what do you think @sbc100 @Brion ?

@bvibber
Copy link
Collaborator

bvibber commented Dec 12, 2019

A local change should be an easy fix, but will be a maintenance burden later. I'd recommend seeing if wasi would be ok with changing the #defines in their upstream headers to improve portability.

@sbc100
Copy link
Collaborator

sbc100 commented Dec 12, 2019

Closing this as dup of #9996.

@sbc100 sbc100 closed this as completed Dec 12, 2019
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

No branches or pull requests

4 participants