Skip to content

Commit

Permalink
csize => csize_t for sysctl
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour authored and dom96 committed Jan 28, 2020
1 parent 2e20f56 commit 2ecef8f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
5 changes: 2 additions & 3 deletions lib/pure/concurrency/cpuinfo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ when defined(macosx) or defined(bsd):
HW_AVAILCPU = 25
HW_NCPU = 3
proc sysctl(x: ptr array[0..3, cint], y: cint, z: pointer,
a: var csize, b: pointer, c: int): cint {.
a: var csize_t, b: pointer, c: csize_t): cint {.
importc: "sysctl", nodecl.}

when defined(genode):
Expand Down Expand Up @@ -73,10 +73,9 @@ proc countProcessors*(): int {.rtl, extern: "ncpi$1".} =
var
mib: array[0..3, cint]
numCPU: int
len: csize
mib[0] = CTL_HW
mib[1] = HW_AVAILCPU
len = sizeof(numCPU)
var len = sizeof(numCPU).csize_t
discard sysctl(addr(mib), 2, addr(numCPU), len, nil, 0)
if numCPU < 1:
mib[1] = HW_NCPU
Expand Down
10 changes: 5 additions & 5 deletions lib/pure/ioselects/ioselectors_kqueue.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ when defined(macosx) or defined(freebsd) or defined(dragonfly):
const MAX_DESCRIPTORS_ID = 29 # KERN_MAXFILESPERPROC (MacOS)
else:
const MAX_DESCRIPTORS_ID = 27 # KERN_MAXFILESPERPROC (FreeBSD)
proc sysctl(name: ptr cint, namelen: cuint, oldp: pointer, oldplen: ptr csize,
newp: pointer, newplen: csize): cint
proc sysctl(name: ptr cint, namelen: cuint, oldp: pointer, oldplen: ptr csize_t,
newp: pointer, newplen: csize_t): cint
{.importc: "sysctl",header: """#include <sys/types.h>
#include <sys/sysctl.h>"""}
elif defined(netbsd) or defined(openbsd):
# OpenBSD and NetBSD don't have KERN_MAXFILESPERPROC, so we are using
# KERN_MAXFILES, because KERN_MAXFILES is always bigger,
# than KERN_MAXFILESPERPROC.
const MAX_DESCRIPTORS_ID = 7 # KERN_MAXFILES
proc sysctl(name: ptr cint, namelen: cuint, oldp: pointer, oldplen: ptr csize,
newp: pointer, newplen: csize): cint
proc sysctl(name: ptr cint, namelen: cuint, oldp: pointer, oldplen: ptr csize_t,
newp: pointer, newplen: csize_t): cint
{.importc: "sysctl",header: """#include <sys/param.h>
#include <sys/sysctl.h>"""}

Expand Down Expand Up @@ -82,7 +82,7 @@ proc getUnique[T](s: Selector[T]): int {.inline.} =

proc newSelector*[T](): owned(Selector[T]) =
var maxFD = 0.cint
var size = csize(sizeof(cint))
var size = csize_t(sizeof(cint))
var namearr = [1.cint, MAX_DESCRIPTORS_ID.cint]
# Obtain maximum number of opened file descriptors for process
if sysctl(addr(namearr[0]), 2, cast[pointer](addr maxFD), addr size,
Expand Down
6 changes: 3 additions & 3 deletions lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2725,8 +2725,8 @@ when declared(paramCount) or defined(nimdoc):
result.add(paramStr(i))

when not weirdTarget and (defined(freebsd) or defined(dragonfly)):
proc sysctl(name: ptr cint, namelen: cuint, oldp: pointer, oldplen: ptr csize,
newp: pointer, newplen: csize): cint
proc sysctl(name: ptr cint, namelen: cuint, oldp: pointer, oldplen: ptr csize_t,
newp: pointer, newplen: csize_t): cint
{.importc: "sysctl",header: """#include <sys/types.h>
#include <sys/sysctl.h>"""}
const
Expand All @@ -2740,7 +2740,7 @@ when not weirdTarget and (defined(freebsd) or defined(dragonfly)):
const KERN_PROC_PATHNAME = 9

proc getApplFreebsd(): string =
var pathLength = csize(MAX_PATH)
var pathLength = csize_t(MAX_PATH)
result = newString(pathLength)
var req = [CTL_KERN.cint, KERN_PROC.cint, KERN_PROC_PATHNAME.cint, -1.cint]
while true:
Expand Down

0 comments on commit 2ecef8f

Please sign in to comment.