From 5a06c2260ddb6ac614f3c62f44013965d9738a66 Mon Sep 17 00:00:00 2001 From: def Date: Sun, 6 Mar 2016 22:09:27 +0100 Subject: [PATCH 1/4] Support IOFBF and IONBF on all systems --- lib/system/sysio.nim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index e81219a704..78c7b1ca1f 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -82,12 +82,11 @@ when NoFakeVars: const IOFBF = cint(0) IONBF = cint(4) - elif defined(macosx) or defined(linux): + else: + # On all systems I could find, including Linux, Mac OS X, and the BSDs const IOFBF = cint(0) IONBF = cint(2) - else: - {.error: "IOFBF not ported to your platform".} else: var IOFBF {.importc: "_IOFBF", nodecl.}: cint From c398bdc534a80cbacc74d21329346ed7fedc1107 Mon Sep 17 00:00:00 2001 From: def Date: Sun, 6 Mar 2016 22:25:37 +0100 Subject: [PATCH 2/4] Fix KEvent header includes --- lib/posix/kqueue.nim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/posix/kqueue.nim b/lib/posix/kqueue.nim index 511ada9ace..d91da632bc 100644 --- a/lib/posix/kqueue.nim +++ b/lib/posix/kqueue.nim @@ -47,8 +47,9 @@ const EV_ERROR* = 0x4000 ## Error, data contains errno type - KEvent* {.importc: "struct kevent", - header: "", pure, final.} = object + KEvent* {.importc: "struct kevent", pure, final + header: """#include + #include """.} = object ident*: cuint ## identifier for this event (uintptr_t) filter*: cshort ## filter for event flags*: cushort ## general flags From 4b1e3f26a73a0f9bf773f5a5c70025ed70a038cc Mon Sep 17 00:00:00 2001 From: def Date: Mon, 7 Mar 2016 01:44:11 +0100 Subject: [PATCH 3/4] Better getAppFilename() heuristic for OpenBSD and NetBSD Using the environment variable _ is completely broken and makes it impossible to build even nimble. After calling `sh` (ksh) on OpenBSD, `_` is wrongly set to `/bin/sh` and all subprocess calls to Nim fail. --- lib/pure/os.nim | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 0173858253..64b270f0ca 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -1350,15 +1350,12 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect].} = ## Returns the filename of the application's executable. ## ## This procedure will resolve symlinks. - ## - ## **Note**: This does not work reliably on BSD. # Linux: /proc//exe # Solaris: # /proc//object/a.out (filename only) # /proc//path/a.out (complete pathname) - # *BSD (and maybe Darwin too): - # /proc//file + # FreeBSD: /proc//file when defined(windows): when useWinUnicode: var buf = newWideCString("", 256) @@ -1368,15 +1365,6 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect].} = result = newString(256) var len = getModuleFileNameA(0, result, 256) setlen(result, int(len)) - elif defined(linux) or defined(aix): - result = getApplAux("/proc/self/exe") - if result.len == 0: result = getApplHeuristic() - elif defined(solaris): - result = getApplAux("/proc/" & $getpid() & "/path/a.out") - if result.len == 0: result = getApplHeuristic() - elif defined(freebsd): - result = getApplAux("/proc/" & $getpid() & "/file") - if result.len == 0: result = getApplHeuristic() elif defined(macosx): var size: cuint32 getExecPath1(nil, size) @@ -1386,9 +1374,15 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect].} = if result.len > 0: result = result.expandFilename else: + when defined(linux) or defined(aix): + result = getApplAux("/proc/self/exe") + elif defined(solaris): + result = getApplAux("/proc/" & $getpid() & "/path/a.out") + elif defined(freebsd): + result = getApplAux("/proc/" & $getpid() & "/file") # little heuristic that may work on other POSIX-like systems: - result = string(getEnv("_")) - if result.len == 0: result = getApplHeuristic() + if result.len == 0: + result = getApplHeuristic() proc getApplicationFilename*(): string {.rtl, extern: "nos$1", deprecated.} = ## Returns the filename of the application's executable. @@ -1404,7 +1398,6 @@ proc getApplicationDir*(): string {.rtl, extern: "nos$1", deprecated.} = proc getAppDir*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect].} = ## Returns the directory of the application's executable. - ## **Note**: This does not work reliably on BSD. result = splitFile(getAppFilename()).dir proc sleep*(milsecs: int) {.rtl, extern: "nos$1", tags: [TimeEffect].} = From e6dfadf55dc205934d50cb94812063d7d1cf93b5 Mon Sep 17 00:00:00 2001 From: def Date: Mon, 7 Mar 2016 02:13:35 +0100 Subject: [PATCH 4/4] Use /proc/self/exe on NetBSD --- lib/pure/os.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 64b270f0ca..470559e173 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -1374,7 +1374,7 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect].} = if result.len > 0: result = result.expandFilename else: - when defined(linux) or defined(aix): + when defined(linux) or defined(aix) or defined(netbsd): result = getApplAux("/proc/self/exe") elif defined(solaris): result = getApplAux("/proc/" & $getpid() & "/path/a.out")