summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/posix/kqueue.nim12
-rw-r--r--lib/pure/ioselectors.nim4
-rw-r--r--lib/pure/ioselects/ioselectors_kqueue.nim2
-rw-r--r--lib/pure/os.nim10
-rw-r--r--lib/pure/osproc.nim6
-rw-r--r--lib/system/ansi_c.nim3
-rw-r--r--lib/system/threads.nim8
-rw-r--r--tests/async/tioselectors.nim12
-rw-r--r--tests/misc/tfsmonitor.nim2
9 files changed, 39 insertions, 20 deletions
diff --git a/lib/posix/kqueue.nim b/lib/posix/kqueue.nim
index 19d661490..730491a53 100644
--- a/lib/posix/kqueue.nim
+++ b/lib/posix/kqueue.nim
@@ -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
diff --git a/lib/pure/ioselectors.nim b/lib/pure/ioselectors.nim
index d61e9c3c7..cbef5ce0d 100644
--- a/lib/pure/ioselectors.nim
+++ b/lib/pure/ioselectors.nim
@@ -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
diff --git a/lib/pure/ioselects/ioselectors_kqueue.nim b/lib/pure/ioselects/ioselectors_kqueue.nim
index 01b1b9586..7786de46a 100644
--- a/lib/pure/ioselects/ioselectors_kqueue.nim
+++ b/lib/pure/ioselects/ioselectors_kqueue.nim
@@ -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:
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index 6bf776a44..07670c5da 100644
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -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:
diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim
index fbcea4042..9a2cea665 100644
--- a/lib/pure/osproc.nim
+++ b/lib/pure/osproc.nim
@@ -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
 
diff --git a/lib/system/ansi_c.nim b/lib/system/ansi_c.nim
index e3b2072b9..52065531b 100644
--- a/lib/system/ansi_c.nim
+++ b/lib/system/ansi_c.nim
@@ -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)
diff --git a/lib/system/threads.nim b/lib/system/threads.nim
index 003969a79..86af95a85 100644
--- a/lib/system/threads.nim
+++ b/lib/system/threads.nim
@@ -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")
 
diff --git a/tests/async/tioselectors.nim b/tests/async/tioselectors.nim
index a1290efe1..048111d03 100644
--- a/tests/async/tioselectors.nim
+++ b/tests/async/tioselectors.nim
@@ -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)
diff --git a/tests/misc/tfsmonitor.nim b/tests/misc/tfsmonitor.nim
index 35f93fb47..5276cc8d3 100644
--- a/tests/misc/tfsmonitor.nim
+++ b/tests/misc/tfsmonitor.nim
@@ -1,5 +1,7 @@
 discard """
   disabled: windows
+  disabled: bsd
+  disabled: macosx
 """
 
 import unittest