Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 45b0bfa

Browse files
committedDec 12, 2019
Portability workaround for wasi/api.h errno constants
Uses UINT16_C for backing of errno constants (EPERM etc) as in previous versions, rather than casting them to __wasm_errno_t. This fixes some portable codebases that use the C preprocessor to compare the constant values like this: ``` #if EPERM > 0 #define DAV1D_ERR(e) (-(e)) #else #define DAV1D_ERR(e) (e) #endif ``` Adds a test case to catch regressions. Fixes emscripten-core#9996
1 parent e92546b commit 45b0bfa

File tree

2 files changed

+93
-81
lines changed

2 files changed

+93
-81
lines changed
 

‎system/include/wasi/api.h

+81-81
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,25 @@ typedef uint32_t __wasi_clockid_t;
6565
* The clock measuring real time. Time value zero corresponds with
6666
* 1970-01-01T00:00:00Z.
6767
*/
68-
#define __WASI_CLOCKID_REALTIME ((__wasi_clockid_t)0)
68+
#define __WASI_CLOCKID_REALTIME (UINT32_C(0))
6969

7070
/**
7171
* The store-wide monotonic clock, which is defined as a clock measuring
7272
* real time, whose value cannot be adjusted and which cannot have negative
7373
* clock jumps. The epoch of this clock is undefined. The absolute time
7474
* value of this clock therefore has no meaning.
7575
*/
76-
#define __WASI_CLOCKID_MONOTONIC ((__wasi_clockid_t)1)
76+
#define __WASI_CLOCKID_MONOTONIC (UINT32_C(1))
7777

7878
/**
7979
* The CPU-time clock associated with the current process.
8080
*/
81-
#define __WASI_CLOCKID_PROCESS_CPUTIME_ID ((__wasi_clockid_t)2)
81+
#define __WASI_CLOCKID_PROCESS_CPUTIME_ID (UINT32_C(2))
8282

8383
/**
8484
* The CPU-time clock associated with the current thread.
8585
*/
86-
#define __WASI_CLOCKID_THREAD_CPUTIME_ID ((__wasi_clockid_t)3)
86+
#define __WASI_CLOCKID_THREAD_CPUTIME_ID (UINT32_C(3))
8787

8888
/**
8989
* Error codes returned by functions.
@@ -96,387 +96,387 @@ typedef uint16_t __wasi_errno_t;
9696
/**
9797
* No error occurred. System call completed successfully.
9898
*/
99-
#define __WASI_ERRNO_SUCCESS ((__wasi_errno_t)0)
99+
#define __WASI_ERRNO_SUCCESS (UINT16_C(0))
100100

101101
/**
102102
* Argument list too long.
103103
*/
104-
#define __WASI_ERRNO_2BIG ((__wasi_errno_t)1)
104+
#define __WASI_ERRNO_2BIG (UINT16_C(1))
105105

106106
/**
107107
* Permission denied.
108108
*/
109-
#define __WASI_ERRNO_ACCES ((__wasi_errno_t)2)
109+
#define __WASI_ERRNO_ACCES (UINT16_C(2))
110110

111111
/**
112112
* Address in use.
113113
*/
114-
#define __WASI_ERRNO_ADDRINUSE ((__wasi_errno_t)3)
114+
#define __WASI_ERRNO_ADDRINUSE (UINT16_C(3))
115115

116116
/**
117117
* Address not available.
118118
*/
119-
#define __WASI_ERRNO_ADDRNOTAVAIL ((__wasi_errno_t)4)
119+
#define __WASI_ERRNO_ADDRNOTAVAIL (UINT16_C(4))
120120

121121
/**
122122
* Address family not supported.
123123
*/
124-
#define __WASI_ERRNO_AFNOSUPPORT ((__wasi_errno_t)5)
124+
#define __WASI_ERRNO_AFNOSUPPORT (UINT16_C(5))
125125

126126
/**
127127
* Resource unavailable, or operation would block.
128128
*/
129-
#define __WASI_ERRNO_AGAIN ((__wasi_errno_t)6)
129+
#define __WASI_ERRNO_AGAIN (UINT16_C(6))
130130

131131
/**
132132
* Connection already in progress.
133133
*/
134-
#define __WASI_ERRNO_ALREADY ((__wasi_errno_t)7)
134+
#define __WASI_ERRNO_ALREADY (UINT16_C(7))
135135

136136
/**
137137
* Bad file descriptor.
138138
*/
139-
#define __WASI_ERRNO_BADF ((__wasi_errno_t)8)
139+
#define __WASI_ERRNO_BADF (UINT16_C(8))
140140

141141
/**
142142
* Bad message.
143143
*/
144-
#define __WASI_ERRNO_BADMSG ((__wasi_errno_t)9)
144+
#define __WASI_ERRNO_BADMSG (UINT16_C(9))
145145

146146
/**
147147
* Device or resource busy.
148148
*/
149-
#define __WASI_ERRNO_BUSY ((__wasi_errno_t)10)
149+
#define __WASI_ERRNO_BUSY (UINT16_C(10))
150150

151151
/**
152152
* Operation canceled.
153153
*/
154-
#define __WASI_ERRNO_CANCELED ((__wasi_errno_t)11)
154+
#define __WASI_ERRNO_CANCELED (UINT16_C(11))
155155

156156
/**
157157
* No child processes.
158158
*/
159-
#define __WASI_ERRNO_CHILD ((__wasi_errno_t)12)
159+
#define __WASI_ERRNO_CHILD (UINT16_C(12))
160160

161161
/**
162162
* Connection aborted.
163163
*/
164-
#define __WASI_ERRNO_CONNABORTED ((__wasi_errno_t)13)
164+
#define __WASI_ERRNO_CONNABORTED (UINT16_C(13))
165165

166166
/**
167167
* Connection refused.
168168
*/
169-
#define __WASI_ERRNO_CONNREFUSED ((__wasi_errno_t)14)
169+
#define __WASI_ERRNO_CONNREFUSED (UINT16_C(14))
170170

171171
/**
172172
* Connection reset.
173173
*/
174-
#define __WASI_ERRNO_CONNRESET ((__wasi_errno_t)15)
174+
#define __WASI_ERRNO_CONNRESET (UINT16_C(15))
175175

176176
/**
177177
* Resource deadlock would occur.
178178
*/
179-
#define __WASI_ERRNO_DEADLK ((__wasi_errno_t)16)
179+
#define __WASI_ERRNO_DEADLK (UINT16_C(16))
180180

181181
/**
182182
* Destination address required.
183183
*/
184-
#define __WASI_ERRNO_DESTADDRREQ ((__wasi_errno_t)17)
184+
#define __WASI_ERRNO_DESTADDRREQ (UINT16_C(17))
185185

186186
/**
187187
* Mathematics argument out of domain of function.
188188
*/
189-
#define __WASI_ERRNO_DOM ((__wasi_errno_t)18)
189+
#define __WASI_ERRNO_DOM (UINT16_C(18))
190190

191191
/**
192192
* Reserved.
193193
*/
194-
#define __WASI_ERRNO_DQUOT ((__wasi_errno_t)19)
194+
#define __WASI_ERRNO_DQUOT (UINT16_C(19))
195195

196196
/**
197197
* File exists.
198198
*/
199-
#define __WASI_ERRNO_EXIST ((__wasi_errno_t)20)
199+
#define __WASI_ERRNO_EXIST (UINT16_C(20))
200200

201201
/**
202202
* Bad address.
203203
*/
204-
#define __WASI_ERRNO_FAULT ((__wasi_errno_t)21)
204+
#define __WASI_ERRNO_FAULT (UINT16_C(21))
205205

206206
/**
207207
* File too large.
208208
*/
209-
#define __WASI_ERRNO_FBIG ((__wasi_errno_t)22)
209+
#define __WASI_ERRNO_FBIG (UINT16_C(22))
210210

211211
/**
212212
* Host is unreachable.
213213
*/
214-
#define __WASI_ERRNO_HOSTUNREACH ((__wasi_errno_t)23)
214+
#define __WASI_ERRNO_HOSTUNREACH (UINT16_C(23))
215215

216216
/**
217217
* Identifier removed.
218218
*/
219-
#define __WASI_ERRNO_IDRM ((__wasi_errno_t)24)
219+
#define __WASI_ERRNO_IDRM (UINT16_C(24))
220220

221221
/**
222222
* Illegal byte sequence.
223223
*/
224-
#define __WASI_ERRNO_ILSEQ ((__wasi_errno_t)25)
224+
#define __WASI_ERRNO_ILSEQ (UINT16_C(25))
225225

226226
/**
227227
* Operation in progress.
228228
*/
229-
#define __WASI_ERRNO_INPROGRESS ((__wasi_errno_t)26)
229+
#define __WASI_ERRNO_INPROGRESS (UINT16_C(26))
230230

231231
/**
232232
* Interrupted function.
233233
*/
234-
#define __WASI_ERRNO_INTR ((__wasi_errno_t)27)
234+
#define __WASI_ERRNO_INTR (UINT16_C(27))
235235

236236
/**
237237
* Invalid argument.
238238
*/
239-
#define __WASI_ERRNO_INVAL ((__wasi_errno_t)28)
239+
#define __WASI_ERRNO_INVAL (UINT16_C(28))
240240

241241
/**
242242
* I/O error.
243243
*/
244-
#define __WASI_ERRNO_IO ((__wasi_errno_t)29)
244+
#define __WASI_ERRNO_IO (UINT16_C(29))
245245

246246
/**
247247
* Socket is connected.
248248
*/
249-
#define __WASI_ERRNO_ISCONN ((__wasi_errno_t)30)
249+
#define __WASI_ERRNO_ISCONN (UINT16_C(30))
250250

251251
/**
252252
* Is a directory.
253253
*/
254-
#define __WASI_ERRNO_ISDIR ((__wasi_errno_t)31)
254+
#define __WASI_ERRNO_ISDIR (UINT16_C(31))
255255

256256
/**
257257
* Too many levels of symbolic links.
258258
*/
259-
#define __WASI_ERRNO_LOOP ((__wasi_errno_t)32)
259+
#define __WASI_ERRNO_LOOP (UINT16_C(32))
260260

261261
/**
262262
* File descriptor value too large.
263263
*/
264-
#define __WASI_ERRNO_MFILE ((__wasi_errno_t)33)
264+
#define __WASI_ERRNO_MFILE (UINT16_C(33))
265265

266266
/**
267267
* Too many links.
268268
*/
269-
#define __WASI_ERRNO_MLINK ((__wasi_errno_t)34)
269+
#define __WASI_ERRNO_MLINK (UINT16_C(34))
270270

271271
/**
272272
* Message too large.
273273
*/
274-
#define __WASI_ERRNO_MSGSIZE ((__wasi_errno_t)35)
274+
#define __WASI_ERRNO_MSGSIZE (UINT16_C(35))
275275

276276
/**
277277
* Reserved.
278278
*/
279-
#define __WASI_ERRNO_MULTIHOP ((__wasi_errno_t)36)
279+
#define __WASI_ERRNO_MULTIHOP (UINT16_C(36))
280280

281281
/**
282282
* Filename too long.
283283
*/
284-
#define __WASI_ERRNO_NAMETOOLONG ((__wasi_errno_t)37)
284+
#define __WASI_ERRNO_NAMETOOLONG (UINT16_C(37))
285285

286286
/**
287287
* Network is down.
288288
*/
289-
#define __WASI_ERRNO_NETDOWN ((__wasi_errno_t)38)
289+
#define __WASI_ERRNO_NETDOWN (UINT16_C(38))
290290

291291
/**
292292
* Connection aborted by network.
293293
*/
294-
#define __WASI_ERRNO_NETRESET ((__wasi_errno_t)39)
294+
#define __WASI_ERRNO_NETRESET (UINT16_C(39))
295295

296296
/**
297297
* Network unreachable.
298298
*/
299-
#define __WASI_ERRNO_NETUNREACH ((__wasi_errno_t)40)
299+
#define __WASI_ERRNO_NETUNREACH (UINT16_C(40))
300300

301301
/**
302302
* Too many files open in system.
303303
*/
304-
#define __WASI_ERRNO_NFILE ((__wasi_errno_t)41)
304+
#define __WASI_ERRNO_NFILE (UINT16_C(41))
305305

306306
/**
307307
* No buffer space available.
308308
*/
309-
#define __WASI_ERRNO_NOBUFS ((__wasi_errno_t)42)
309+
#define __WASI_ERRNO_NOBUFS (UINT16_C(42))
310310

311311
/**
312312
* No such device.
313313
*/
314-
#define __WASI_ERRNO_NODEV ((__wasi_errno_t)43)
314+
#define __WASI_ERRNO_NODEV (UINT16_C(43))
315315

316316
/**
317317
* No such file or directory.
318318
*/
319-
#define __WASI_ERRNO_NOENT ((__wasi_errno_t)44)
319+
#define __WASI_ERRNO_NOENT (UINT16_C(44))
320320

321321
/**
322322
* Executable file format error.
323323
*/
324-
#define __WASI_ERRNO_NOEXEC ((__wasi_errno_t)45)
324+
#define __WASI_ERRNO_NOEXEC (UINT16_C(45))
325325

326326
/**
327327
* No locks available.
328328
*/
329-
#define __WASI_ERRNO_NOLCK ((__wasi_errno_t)46)
329+
#define __WASI_ERRNO_NOLCK (UINT16_C(46))
330330

331331
/**
332332
* Reserved.
333333
*/
334-
#define __WASI_ERRNO_NOLINK ((__wasi_errno_t)47)
334+
#define __WASI_ERRNO_NOLINK (UINT16_C(47))
335335

336336
/**
337337
* Not enough space.
338338
*/
339-
#define __WASI_ERRNO_NOMEM ((__wasi_errno_t)48)
339+
#define __WASI_ERRNO_NOMEM (UINT16_C(48))
340340

341341
/**
342342
* No message of the desired type.
343343
*/
344-
#define __WASI_ERRNO_NOMSG ((__wasi_errno_t)49)
344+
#define __WASI_ERRNO_NOMSG (UINT16_C(49))
345345

346346
/**
347347
* Protocol not available.
348348
*/
349-
#define __WASI_ERRNO_NOPROTOOPT ((__wasi_errno_t)50)
349+
#define __WASI_ERRNO_NOPROTOOPT (UINT16_C(50))
350350

351351
/**
352352
* No space left on device.
353353
*/
354-
#define __WASI_ERRNO_NOSPC ((__wasi_errno_t)51)
354+
#define __WASI_ERRNO_NOSPC (UINT16_C(51))
355355

356356
/**
357357
* Function not supported.
358358
*/
359-
#define __WASI_ERRNO_NOSYS ((__wasi_errno_t)52)
359+
#define __WASI_ERRNO_NOSYS (UINT16_C(52))
360360

361361
/**
362362
* The socket is not connected.
363363
*/
364-
#define __WASI_ERRNO_NOTCONN ((__wasi_errno_t)53)
364+
#define __WASI_ERRNO_NOTCONN (UINT16_C(53))
365365

366366
/**
367367
* Not a directory or a symbolic link to a directory.
368368
*/
369-
#define __WASI_ERRNO_NOTDIR ((__wasi_errno_t)54)
369+
#define __WASI_ERRNO_NOTDIR (UINT16_C(54))
370370

371371
/**
372372
* Directory not empty.
373373
*/
374-
#define __WASI_ERRNO_NOTEMPTY ((__wasi_errno_t)55)
374+
#define __WASI_ERRNO_NOTEMPTY (UINT16_C(55))
375375

376376
/**
377377
* State not recoverable.
378378
*/
379-
#define __WASI_ERRNO_NOTRECOVERABLE ((__wasi_errno_t)56)
379+
#define __WASI_ERRNO_NOTRECOVERABLE (UINT16_C(56))
380380

381381
/**
382382
* Not a socket.
383383
*/
384-
#define __WASI_ERRNO_NOTSOCK ((__wasi_errno_t)57)
384+
#define __WASI_ERRNO_NOTSOCK (UINT16_C(57))
385385

386386
/**
387387
* Not supported, or operation not supported on socket.
388388
*/
389-
#define __WASI_ERRNO_NOTSUP ((__wasi_errno_t)58)
389+
#define __WASI_ERRNO_NOTSUP (UINT16_C(58))
390390

391391
/**
392392
* Inappropriate I/O control operation.
393393
*/
394-
#define __WASI_ERRNO_NOTTY ((__wasi_errno_t)59)
394+
#define __WASI_ERRNO_NOTTY (UINT16_C(59))
395395

396396
/**
397397
* No such device or address.
398398
*/
399-
#define __WASI_ERRNO_NXIO ((__wasi_errno_t)60)
399+
#define __WASI_ERRNO_NXIO (UINT16_C(60))
400400

401401
/**
402402
* Value too large to be stored in data type.
403403
*/
404-
#define __WASI_ERRNO_OVERFLOW ((__wasi_errno_t)61)
404+
#define __WASI_ERRNO_OVERFLOW (UINT16_C(61))
405405

406406
/**
407407
* Previous owner died.
408408
*/
409-
#define __WASI_ERRNO_OWNERDEAD ((__wasi_errno_t)62)
409+
#define __WASI_ERRNO_OWNERDEAD (UINT16_C(62))
410410

411411
/**
412412
* Operation not permitted.
413413
*/
414-
#define __WASI_ERRNO_PERM ((__wasi_errno_t)63)
414+
#define __WASI_ERRNO_PERM (UINT16_C(63))
415415

416416
/**
417417
* Broken pipe.
418418
*/
419-
#define __WASI_ERRNO_PIPE ((__wasi_errno_t)64)
419+
#define __WASI_ERRNO_PIPE (UINT16_C(64))
420420

421421
/**
422422
* Protocol error.
423423
*/
424-
#define __WASI_ERRNO_PROTO ((__wasi_errno_t)65)
424+
#define __WASI_ERRNO_PROTO (UINT16_C(65))
425425

426426
/**
427427
* Protocol not supported.
428428
*/
429-
#define __WASI_ERRNO_PROTONOSUPPORT ((__wasi_errno_t)66)
429+
#define __WASI_ERRNO_PROTONOSUPPORT (UINT16_C(66))
430430

431431
/**
432432
* Protocol wrong type for socket.
433433
*/
434-
#define __WASI_ERRNO_PROTOTYPE ((__wasi_errno_t)67)
434+
#define __WASI_ERRNO_PROTOTYPE (UINT16_C(67))
435435

436436
/**
437437
* Result too large.
438438
*/
439-
#define __WASI_ERRNO_RANGE ((__wasi_errno_t)68)
439+
#define __WASI_ERRNO_RANGE (UINT16_C(68))
440440

441441
/**
442442
* Read-only file system.
443443
*/
444-
#define __WASI_ERRNO_ROFS ((__wasi_errno_t)69)
444+
#define __WASI_ERRNO_ROFS (UINT16_C(69))
445445

446446
/**
447447
* Invalid seek.
448448
*/
449-
#define __WASI_ERRNO_SPIPE ((__wasi_errno_t)70)
449+
#define __WASI_ERRNO_SPIPE (UINT16_C(70))
450450

451451
/**
452452
* No such process.
453453
*/
454-
#define __WASI_ERRNO_SRCH ((__wasi_errno_t)71)
454+
#define __WASI_ERRNO_SRCH (UINT16_C(71))
455455

456456
/**
457457
* Reserved.
458458
*/
459-
#define __WASI_ERRNO_STALE ((__wasi_errno_t)72)
459+
#define __WASI_ERRNO_STALE (UINT16_C(72))
460460

461461
/**
462462
* Connection timed out.
463463
*/
464-
#define __WASI_ERRNO_TIMEDOUT ((__wasi_errno_t)73)
464+
#define __WASI_ERRNO_TIMEDOUT (UINT16_C(73))
465465

466466
/**
467467
* Text file busy.
468468
*/
469-
#define __WASI_ERRNO_TXTBSY ((__wasi_errno_t)74)
469+
#define __WASI_ERRNO_TXTBSY (UINT16_C(74))
470470

471471
/**
472472
* Cross-device link.
473473
*/
474-
#define __WASI_ERRNO_XDEV ((__wasi_errno_t)75)
474+
#define __WASI_ERRNO_XDEV (UINT16_C(75))
475475

476476
/**
477477
* Extension: Capabilities insufficient.
478478
*/
479-
#define __WASI_ERRNO_NOTCAPABLE ((__wasi_errno_t)76)
479+
#define __WASI_ERRNO_NOTCAPABLE (UINT16_C(76))
480480

481481
/**
482482
* File descriptor rights, determining which actions may be performed.

‎tests/test_core.py

+12
Original file line numberDiff line numberDiff line change
@@ -8456,6 +8456,18 @@ def test():
84568456
self.emcc_args += ['-DPOOL']
84578457
test()
84588458

8459+
def test_errno_type(self):
8460+
src = '''
8461+
#include <errno.h>
8462+
8463+
// Use of these constants in C preprocessor comparisons should work.
8464+
#if EPERM > 0
8465+
#define DAV1D_ERR(e) (-(e))
8466+
#else
8467+
#define DAV1D_ERR(e) (e)
8468+
#endif
8469+
'''
8470+
self.build(src, self.get_dir(), 'errno_type.c')
84598471

84608472
# Generate tests for everything
84618473
def make_run(name, emcc_args, settings=None, env=None):

0 commit comments

Comments
 (0)
Please sign in to comment.