Skip to content

Commit 806e0cb

Browse files
committed
fix(py): resourse's in arg limit is now a concept
1 parent 4fd4be8 commit 806e0cb

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/pylib/Lib/resource_impl/funcs.nim

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,21 @@ type
1717
py_rlimit* = tuple
1818
rlim_cur: int
1919
rlim_max: int
20+
py_rlimit_abc = concept self
21+
self.len is int
22+
self[int] is int
2023

2124
# XXX: NIM-BUG: rlim_cur and rlim_max are int over unsigned in std/posix
2225

2326
proc py2rlimit(limits: py_rlimit, rl_out: var RLimit) =
2427
rl_out.rlim_cur = limits.rlim_cur
2528
rl_out.rlim_max = limits.rlim_max
2629

30+
proc py2rlimit(limits: py_rlimit_abc, rl_out: var RLimit) =
31+
assert limits.len == 2
32+
rl_out.rlim_cur = limits[0]
33+
rl_out.rlim_max = limits[1]
34+
2735
proc rlimit2py(rl_in: RLimit): py_rlimit = (rl_in.rlim_cur, rl_in.rlim_max)
2836

2937
let RLIM_NLIMITS{.importc, header: "<sys/resource.h>".}: cint
@@ -41,7 +49,7 @@ proc getrlimit*(resource: int): py_rlimit =
4149

4250
proc raise_inval =
4351
raise newException(ValueError, "current limit exceeds maximum limit")
44-
proc setrlimit*(resource: int, limits: py_rlimit) =
52+
proc setrlimit*(resource: int, limits: py_rlimit_abc) =
4553
var rl: RLimit
4654
py2rlimit(limits, rl)
4755
if setrlimit(checked_resource(resource), rl) == -1:
@@ -64,7 +72,7 @@ when HAVE_PRLIMIT:
6472
raiseErrno()
6573
rlimit2py(old_limit)
6674

67-
proc prlimit*(pid: int, resource: int, limits: py_rlimit): py_rlimit{.discardable.} =
75+
proc prlimit*(pid: int, resource: int, limits: py_rlimit_abc): py_rlimit{.discardable.} =
6876
let
6977
pid = Pid pid
7078
resource = checked_resource(resource)

0 commit comments

Comments
 (0)