Skip to content

Commit c54fa07

Browse files
committed
fix(Lib/resource): not compile on Linux(lack RUSAGE_BOTH,RUSAGE_THREAD)
1 parent 04c32a1 commit c54fa07

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/pylib/Lib/resource_impl/consts.nim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from ./csyms import SIZEOF_RLIMIT_T
2+
from ./csyms import SIZEOF_RLIMIT_T, RUSAGE_BOTH, RUSAGE_THREAD
33

44
const RLIM_INFINITY* =
55
when SIZEOF_RLIMIT_T == 8:
@@ -13,6 +13,9 @@ template wrap(name){.dirty.} =
1313
template wrap(name, os){.dirty.} =
1414
when defined(os):
1515
wrap(name)
16+
template wrapIfE(name){.dirty.} =
17+
when declared(name) and name != low(int):
18+
const name* = int name
1619

1720
wrap(RLIMIT_CORE)
1821
wrap(RLIMIT_CPU)
@@ -40,5 +43,5 @@ when defined(freebsd):
4043

4144
wrap(RUSAGE_SELF)
4245
wrap(RUSAGE_CHILDREN)
43-
wrap(RUSAGE_BOTH)
44-
wrap(RUSAGE_THREAD)
46+
wrapIfE(RUSAGE_BOTH)
47+
wrapIfE(RUSAGE_THREAD)

src/pylib/pyconfig/resource.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

22
import ./util
33

4+
const
5+
RUSAGE_BOTH* = from_c_int(RUSAGE_BOTH, "<sys/resource.h>")
6+
RUSAGE_THREAD* = from_c_int(RUSAGE_THREAD, "<sys/resource.h>")
7+
48
const SIZEOF_RLIMIT_T* = from_c_int(SIZEOF_RLIMIT_T, 8):
59
{.emit: """/*INCLUDESECTION*/
610
#include <sys/resource.h>

0 commit comments

Comments
 (0)