Skip to content

Commit cd4faa9

Browse files
committed
fixup: 'feat(Lib/os): chmod' errmap not compile on Termux
due to E* is not const there [skip ci]
1 parent 3da7e86 commit cd4faa9

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

src/pylib/pyerrors/oserr/errmap.nim

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ when defined(js):
1515
template decl_c_intImpl(variable, name, _; defval) =
1616
let variable = from_js_const(name, defval)
1717
{.pragma: ErrnoMapAttr.}
18-
template ifHasErr(name, body) =
18+
template ifHasErr(name: int; body) =
1919
if name != DEF_INT: body
2020
else:
2121
import ../../pyconfig/util
@@ -24,7 +24,7 @@ else:
2424
template decl_c_intImpl(variable, name, includeFile; defval) =
2525
const variable = from_c_int(name, includeFile, defval)
2626
{.pragma: ErrnoMapAttr, compileTime.}
27-
template ifHasErr(name, body) =
27+
template ifHasErr(name: int; body) =
2828
when name != DEF_INT: body
2929

3030
template decl_c_int*(name, includeFile; defval) =
@@ -38,20 +38,32 @@ var errnomap*{.ErrnoMapAttr.}: Table[cint, proc(): ref PyOSError{.OSErrorInitAtt
3838
proc default_oserror*(): ref PyOSError{.OSErrorInitAttrs.} =
3939
new PyOSError
4040

41-
template decl_err(err){.dirty.} =
42-
decl_c_int(err, "<errno.h>", DEF_INT)
41+
template decl_err(variable, err){.dirty.} =
42+
decl_c_intImpl(variable, err, "<errno.h>", DEF_INT)
4343

44-
template decl_err_cint(err){.dirty.} =
45-
when declared(err):
44+
template isConst(e): bool = compiles((const _=err))
45+
46+
template asgExp(err; nerr: int; doSth) =
47+
asgn_cint err, cast[cint](nerr)
48+
export err
49+
doSth
50+
51+
template decl_err_cint(err, doIfDefined){.dirty.} =
52+
## generate `const err*: cint = ...` if err defined in `<errno.h>`
53+
bind asgExp
54+
when isConst(err):
4655
export err
56+
doIfDefined
4757
else:
48-
decl_c_intImpl(`n err`, name, "<errno.h>", DEF_INT)
49-
template asgExp =
50-
asgn_cint err, cast[cint](`n err`)
51-
export err
52-
when defined(js): asgExp
58+
decl_err(`n err`, err)
59+
when defined(js): asgExp err, `n err`, doIfDefined
5360
else:
54-
ifHasErr `n err`: asgExp
61+
ifHasErr `n err`: asgExp err, `n err`, doIfDefined
62+
63+
template decl_err_cint(err) =
64+
## generate `const err*: cint = ...` if err defined in `<errno.h>`
65+
bind decl_err_cint
66+
decl_err_cint(err): discard
5567

5668
decl_err_cint E2BIG
5769
decl_err_cint ENOEXEC
@@ -66,12 +78,8 @@ decl_err_cint EINVAL
6678

6779
when true: # PyExc_InitState
6880
template ADD_ERRNO(exc, err){.dirty.} =
69-
when not declared(err):
70-
decl_err(err)
71-
else:
72-
export err
73-
ifHasErr err:
74-
errnomap[cast[cint](err)] = proc(): ref PyOSError = new exc
81+
decl_err_cint err:
82+
errnomap[err] = proc(): ref PyOSError = new exc
7583
# The following is just copied from CPython's PyExc_InitState AS-IS.
7684

7785
ADD_ERRNO(BlockingIOError, EAGAIN);

0 commit comments

Comments
 (0)