summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-12-26 22:48:34 +0100
committerAraq <rumpf_a@web.de>2012-12-26 22:48:34 +0100
commit81b718641c6a01581925423fa85be9b97d28bcdd (patch)
tree9672d5a09e38da1f0a86de485d2ce94bb5057020 /lib
parentb6c8e16b0f23b09fc4c35e3c2542b75c32152e62 (diff)
downloadNim-81b718641c6a01581925423fa85be9b97d28bcdd.tar.gz
small improvements for FFI
Diffstat (limited to 'lib')
-rwxr-xr-xlib/pure/dynlib.nim9
-rwxr-xr-xlib/system.nim13
2 files changed, 17 insertions, 5 deletions
diff --git a/lib/pure/dynlib.nim b/lib/pure/dynlib.nim
index 3ade1cbf9..a64b7f138 100755
--- a/lib/pure/dynlib.nim
+++ b/lib/pure/dynlib.nim
@@ -1,7 +1,7 @@
 #
 #
 #            Nimrod's Runtime Library
-#        (c) Copyright 2009 Andreas Rumpf
+#        (c) Copyright 2012 Andreas Rumpf
 #
 #    See the file "copying.txt", included in this
 #    distribution, for details about the copyright.
@@ -18,6 +18,10 @@ proc LoadLib*(path: string): TLibHandle
   ## loads a library from `path`. Returns nil if the library could not 
   ## be loaded.
 
+proc LoadLib*(): TLibHandle
+  ## gets the handle from the current executable. Returns nil if the 
+  ## library could not be loaded.
+
 proc UnloadLib*(lib: TLibHandle)
   ## unloads the library `lib`
 
@@ -57,6 +61,7 @@ when defined(posix):
       importc, header: "<dlfcn.h>".}
 
   proc LoadLib(path: string): TLibHandle = return dlopen(path, RTLD_NOW)
+  proc LoadLib(): TLibHandle = return dlopen(nil, RTLD_NOW)
   proc UnloadLib(lib: TLibHandle) = dlclose(lib)
   proc symAddr(lib: TLibHandle, name: cstring): pointer = 
     return dlsym(lib, name)
@@ -78,6 +83,8 @@ elif defined(windows) or defined(dos):
 
   proc LoadLib(path: string): TLibHandle =
     result = cast[TLibHandle](winLoadLibrary(path))
+  proc LoadLib(): TLibHandle =
+    result = cast[TLibHandle](winLoadLibrary(nil))
   proc UnloadLib(lib: TLibHandle) = FreeLibrary(cast[THINSTANCE](lib))
 
   proc symAddr(lib: TLibHandle, name: cstring): pointer =
diff --git a/lib/system.nim b/lib/system.nim
index e199d7611..cbca90a3b 100755
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -1716,8 +1716,8 @@ when not defined(EcmaScript) and not defined(NimrodVM):
 
   proc initStackBottom() {.inline, compilerproc.} =
     # WARNING: This is very fragile! An array size of 8 does not work on my
-    # Linux 64bit system. Very strange, but we are at the will of GCC's 
-    # optimizer...
+    # Linux 64bit system. -- That's because the stack direction is the other
+    # way round.
     when defined(setStackBottom):
       var locals {.volatile.}: pointer
       locals = addr(locals)
@@ -1754,7 +1754,6 @@ when not defined(EcmaScript) and not defined(NimrodVM):
     proc endbStep()
 
   # ----------------- IO Part ------------------------------------------------
-
   type
     CFile {.importc: "FILE", nodecl, final.} = object  # empty record for
                                                        # data hiding
@@ -1783,7 +1782,7 @@ when not defined(EcmaScript) and not defined(NimrodVM):
       ## The standard error stream.
       ##
       ## Note: In my opinion, this should not be used -- the concept of a
-      ## separate error stream is a design flaw of UNIX. A seperate *message
+      ## separate error stream is a design flaw of UNIX. A separate *message
       ## stream* is a good idea, but since it is named ``stderr`` there are few
       ## programs out there that distinguish properly between ``stdout`` and
       ## ``stderr``. So, that's what you get if you don't name your variables
@@ -2121,6 +2120,8 @@ when not defined(EcmaScript) and not defined(NimrodVM):
 
 elif defined(ecmaScript) or defined(NimrodVM):
   # Stubs:
+  proc nimGCvisit(d: pointer, op: int) {.compilerRtl.} = nil
+
   proc GC_disable() = nil
   proc GC_enable() = nil
   proc GC_fullCollect() = nil
@@ -2151,6 +2152,10 @@ elif defined(ecmaScript) or defined(NimrodVM):
       if x == y: return 0
       if x < y: return -1
       return 1
+  
+  when defined(nimffi):
+    include "system/sysio"
+
 
 proc quit*(errormsg: string, errorcode = QuitFailure) {.noReturn.} =
   ## a shorthand for ``echo(errormsg); quit(errorcode)``.