mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-20 14:25:23 +00:00
Fixes to support Dragonfly BSD. (#5552)
* Fix kqueue.nim and ansi_c.nim to support dragonfly. * Fix ioselectors.nim, threads.nim to support dragonfly. * Fix deprecated dealloc call in tioselectors.nim. * Fix tfsmonitor.nim test to run only on Linux. * Fix osproc.nim return wrong exit codes. * Fix getAppFilename() for dragonfly. * Fix proper exit code handling.
This commit is contained in:
committed by
Andreas Rumpf
parent
b938a5b884
commit
336a7c9b3f
@@ -11,7 +11,8 @@
|
||||
|
||||
from posix import Timespec
|
||||
|
||||
when defined(macosx) or defined(freebsd) or defined(openbsd):
|
||||
when defined(macosx) or defined(freebsd) or defined(openbsd) or
|
||||
defined(dragonfly):
|
||||
const
|
||||
EVFILT_READ* = -1
|
||||
EVFILT_WRITE* = -2
|
||||
@@ -40,6 +41,11 @@ elif defined(freebsd):
|
||||
EVFILT_FS* = -9 ## filesystem events
|
||||
EVFILT_LIO* = -10 ## attached to lio requests
|
||||
EVFILT_USER* = -11 ## user events
|
||||
elif defined(dragonfly):
|
||||
const
|
||||
EVFILT_EXCEPT* = -8 ## exceptional conditions
|
||||
EVFILT_USER* = -9 ## user events
|
||||
EVFILT_FS* = -10 ## filesystem events
|
||||
|
||||
# Actions:
|
||||
const
|
||||
@@ -64,9 +70,9 @@ const
|
||||
const
|
||||
EV_EOF* = 0x8000 ## EOF detected
|
||||
EV_ERROR* = 0x4000 ## Error, data contains errno
|
||||
EV_NODATA* = 0x1000 ## EOF and no more data
|
||||
|
||||
|
||||
when defined(macosx) or defined(freebsd):
|
||||
when defined(macosx) or defined(freebsd) or defined(dragonfly):
|
||||
# EVFILT_USER is not supported by OpenBSD and NetBSD
|
||||
#
|
||||
# data/hint flags/masks for EVFILT_USER, shared with userspace
|
||||
|
||||
@@ -33,12 +33,14 @@ const hasThreadSupport = compileOption("threads") and defined(threadsafe)
|
||||
|
||||
const ioselSupportedPlatform* = defined(macosx) or defined(freebsd) or
|
||||
defined(netbsd) or defined(openbsd) or
|
||||
defined(dragonfly) or
|
||||
(defined(linux) and not defined(android))
|
||||
## This constant is used to determine whether the destination platform is
|
||||
## fully supported by ``ioselectors`` module.
|
||||
|
||||
const bsdPlatform = defined(macosx) or defined(freebsd) or
|
||||
defined(netbsd) or defined(openbsd)
|
||||
defined(netbsd) or defined(openbsd) or
|
||||
defined(dragonfly)
|
||||
|
||||
when defined(nimdoc):
|
||||
type
|
||||
|
||||
@@ -22,7 +22,7 @@ const
|
||||
when defined(kqcache):
|
||||
const CACHE_EVENTS = true
|
||||
|
||||
when defined(macosx) or defined(freebsd):
|
||||
when defined(macosx) or defined(freebsd) or defined(dragonfly):
|
||||
when defined(macosx):
|
||||
const MAX_DESCRIPTORS_ID = 29 # KERN_MAXFILESPERPROC (MacOS)
|
||||
else:
|
||||
|
||||
@@ -1464,7 +1464,7 @@ when declared(paramCount) or defined(nimdoc):
|
||||
for i in 1..paramCount():
|
||||
result.add(paramStr(i))
|
||||
|
||||
when defined(freebsd):
|
||||
when defined(freebsd) or defined(dragonfly):
|
||||
proc sysctl(name: ptr cint, namelen: cuint, oldp: pointer, oldplen: ptr csize,
|
||||
newp: pointer, newplen: csize): cint
|
||||
{.importc: "sysctl",header: """#include <sys/types.h>
|
||||
@@ -1472,9 +1472,13 @@ when defined(freebsd):
|
||||
const
|
||||
CTL_KERN = 1
|
||||
KERN_PROC = 14
|
||||
KERN_PROC_PATHNAME = 12
|
||||
MAX_PATH = 1024
|
||||
|
||||
when defined(freebsd):
|
||||
const KERN_PROC_PATHNAME = 12
|
||||
else:
|
||||
const KERN_PROC_PATHNAME = 9
|
||||
|
||||
proc getApplFreebsd(): string =
|
||||
var pathLength = csize(MAX_PATH)
|
||||
result = newString(pathLength)
|
||||
@@ -1578,7 +1582,7 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect].} =
|
||||
result = getApplAux("/proc/self/exe")
|
||||
elif defined(solaris):
|
||||
result = getApplAux("/proc/" & $getpid() & "/path/a.out")
|
||||
elif defined(freebsd):
|
||||
elif defined(freebsd) or defined(dragonfly):
|
||||
result = getApplFreebsd()
|
||||
# little heuristic that may work on other POSIX-like systems:
|
||||
if result.len == 0:
|
||||
|
||||
@@ -990,7 +990,7 @@ elif not defined(useNimRtl):
|
||||
import kqueue, times
|
||||
|
||||
proc waitForExit(p: Process, timeout: int = -1): int =
|
||||
if p.exitStatus != -3: return int(p.exitStatus) shr 8
|
||||
if p.exitStatus != -3: return ((p.exitStatus and 0xFF00) shr 8)
|
||||
if timeout == -1:
|
||||
var status : cint = 1
|
||||
if waitpid(p.id, status, 0) < 0:
|
||||
@@ -1155,13 +1155,13 @@ elif not defined(useNimRtl):
|
||||
|
||||
proc peekExitCode(p: Process): int =
|
||||
var status : cint = 1
|
||||
if p.exitStatus != -3: return int(p.exitStatus) shr 8
|
||||
if p.exitStatus != -3: return ((p.exitStatus and 0xFF00) shr 8)
|
||||
var ret = waitpid(p.id, status, WNOHANG)
|
||||
var b = ret == int(p.id)
|
||||
if b: result = -1
|
||||
if WIFEXITED(status):
|
||||
p.exitStatus = status
|
||||
result = p.exitStatus.int shr 8
|
||||
result = (status and 0xFF00) shr 8
|
||||
else:
|
||||
result = -1
|
||||
|
||||
|
||||
@@ -38,7 +38,8 @@ when defined(windows):
|
||||
SIGSEGV = cint(11)
|
||||
SIGTERM = cint(15)
|
||||
elif defined(macosx) or defined(linux) or defined(freebsd) or
|
||||
defined(openbsd) or defined(netbsd) or defined(solaris):
|
||||
defined(openbsd) or defined(netbsd) or defined(solaris) or
|
||||
defined(dragonfly):
|
||||
const
|
||||
SIGABRT = cint(6)
|
||||
SIGFPE = cint(8)
|
||||
|
||||
@@ -204,7 +204,12 @@ else:
|
||||
proc getThreadId*(): int =
|
||||
## get the ID of the currently running thread.
|
||||
result = int(syscall(NR_gettid))
|
||||
elif defined(macosx) or defined(bsd):
|
||||
elif defined(dragonfly):
|
||||
proc lwp_gettid(): int32 {.importc, header: "unistd.h".}
|
||||
|
||||
proc getThreadId*(): int =
|
||||
result = int(lwp_gettid())
|
||||
elif defined(macosx) or defined(freebsd) or defined(openbsd) or defined(netbsd):
|
||||
proc pthread_threadid_np(y: pointer; x: var uint64): cint {.importc, header: "pthread.h".}
|
||||
|
||||
proc getThreadId*(): int =
|
||||
@@ -221,7 +226,6 @@ else:
|
||||
## get the ID of the currently running thread.
|
||||
result = int(thr_self())
|
||||
|
||||
|
||||
const
|
||||
emulatedThreadVars = compileOption("tlsEmulation")
|
||||
|
||||
|
||||
@@ -45,11 +45,11 @@ when not defined(windows):
|
||||
var aiList = getAddrInfo("0.0.0.0", Port(13337))
|
||||
if bindAddr(server_socket, aiList.ai_addr,
|
||||
aiList.ai_addrlen.Socklen) < 0'i32:
|
||||
dealloc(aiList)
|
||||
freeAddrInfo(aiList)
|
||||
raiseOSError(osLastError())
|
||||
if server_socket.listen() == -1:
|
||||
raiseOSError(osLastError())
|
||||
dealloc(aiList)
|
||||
freeAddrInfo(aiList)
|
||||
|
||||
aiList = getAddrInfo("127.0.0.1", Port(13337))
|
||||
discard posix.connect(client_socket, aiList.ai_addr,
|
||||
@@ -58,7 +58,7 @@ when not defined(windows):
|
||||
registerHandle(selector, server_socket, {Event.Read}, 0)
|
||||
registerHandle(selector, client_socket, {Event.Write}, 0)
|
||||
|
||||
dealloc(aiList)
|
||||
freeAddrInfo(aiList)
|
||||
discard selector.select(100)
|
||||
|
||||
var sockAddress: SockAddr
|
||||
@@ -497,15 +497,15 @@ else:
|
||||
var aiList = getAddrInfo("0.0.0.0", Port(13337))
|
||||
if bindAddr(server_socket, aiList.ai_addr,
|
||||
aiList.ai_addrlen.Socklen) < 0'i32:
|
||||
dealloc(aiList)
|
||||
freeAddrInfo(aiList)
|
||||
raiseOSError(osLastError())
|
||||
discard server_socket.listen()
|
||||
dealloc(aiList)
|
||||
freeAddrInfo(aiList)
|
||||
|
||||
aiList = getAddrInfo("127.0.0.1", Port(13337))
|
||||
discard connect(client_socket, aiList.ai_addr,
|
||||
aiList.ai_addrlen.Socklen)
|
||||
dealloc(aiList)
|
||||
freeAddrInfo(aiList)
|
||||
# for some reason Windows select doesn't return both
|
||||
# descriptors from first call, so we need to make 2 calls
|
||||
discard selector.select(100)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
discard """
|
||||
disabled: windows
|
||||
disabled: bsd
|
||||
disabled: macosx
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
Reference in New Issue
Block a user