Skip to content

Commit be5332b

Browse files
committed
fixup! feat(pyconfig): util.from_c_int_expr,AC_CHECK_FUNC[S]
And fix '\n' used in emit (resulting in `10` over `\n`)
1 parent f576b68 commit be5332b

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/pylib/Lib/errno_impl/private/errorcodeInit.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ macro initErrorcodeMap*(K, V; res: untyped, initFunc: typed) =
3434
# so we use a proc.
3535
result.add quote do:
3636
proc `addErrnoId`(){.inline.} =
37-
{.emit: "\n#ifdef " & `errNameNode` & '\n'.}
37+
{.emit: "\n#ifdef " & `errNameNode` & "\n".}
3838
`res`[`errId`] = `errNameNode`
3939
{.emit: "\n#endif\n".}
4040
result.add newCall(addErrnoId)

src/pylib/pyconfig/util.nim

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from std/strutils import parseInt, strip, multiReplace
55
import std/macros
66

77
const weirdTarget = defined(js) or defined(nimscript)
8-
8+
const pylibDebug = defined(pylibDebugPyConfig)
99
const cacheDir = currentSourcePath()/../".cfgcache"
1010
when not weirdTarget:
1111
static:
@@ -24,13 +24,19 @@ template decl_ac_implAux(handle; subcmd; variable; defval; doWithExecRes; code):
2424
when fileExists fp: handle variable, fp.slurp
2525
else:
2626
const
27-
res = gorgeEx( nimExeQuotedPath & ' ' & subcmd & " --hints:off --eval:" & quoteShell(astToStr code) )
27+
scode = astToStr code
28+
res = gorgeEx( nimExeQuotedPath & ' ' & subcmd & " --hints:"&(when pylibDebug: "on" else: "off")&" --eval:" & quoteShell(scode) )
2829
resCodeS = doWithExecRes res
30+
when pylibDebug:
31+
static:echo scode
2932
fp.writeFile resCodeS
3033
handle variable, resCodeS
3134

3235
template decl_ac_implAux(handle; subcmd; variable; defval; code): untyped =
33-
template handle_exec_res(res): string{.genSym, used.} = $res.exitCode
36+
template handle_exec_res(res): string{.genSym, used.} =
37+
when pylibDebug:
38+
echo res.output
39+
$res.exitCode
3440
decl_ac_implAux(handle, subcmd, variable, defval, handle_exec_res, code)
3541

3642

@@ -64,7 +70,7 @@ proc from_c_int_expr(cacheName, cexpr: string; defval: NimNode): NimNode =
6470
let pureVarId = newLit cacheName
6571
result = quote do:
6672
from_c_int(`cexpr`, `defval`):
67-
{.emit: ["/*VARSECTION*/\n#define ", `pureVarId`, " ", `cexpr`, '\n'].}
73+
{.emit: ["/*VARSECTION*/\n#define ", `pureVarId`, " ", `cexpr`, "\n"].}
6874

6975
macro from_c_int_underlined*(variable: static[string]; defval: int): int =
7076
let pureVar = variable.strip(chars = {'_'})
@@ -167,18 +173,20 @@ template c_defined*(variable; c_macro: string; headers: openArray = []) =
167173
template AC_CHECK_FUNC*(res, function) =
168174
## export const HAVE_`function`
169175
AC_LINK_IFELSE res, false:
176+
const fname{.inject.} = astToStr(function)
170177
{.emit: [
171178
"/*INCLUDESECTION*/\n",
172-
"#undef " & astToStr(function) & '\n',
179+
"#include <limits.h>\n",
180+
"#undef ", fname, "\n",
173181
"""/* The GNU C library defines this for functions which it implements
174182
to always fail with ENOSYS. Some functions are actually named
175183
something starting with __ and the normal name is an alias. */
176-
#if defined __stub_`function` || defined __stub___`function`
184+
#if defined __stub_""", fname, " || defined __stub___", fname, "\n", """
177185
choke me
178186
#endif
179187
"""
180188
].} #""" <- for code lint
181-
proc function(): cchar{.importc, header: "<limits.h>".}
189+
proc function(): cchar{.importc, cdecl.}
182190
discard function()
183191

184192
template AC_CHECK_FUNC*(function) =

0 commit comments

Comments
 (0)