summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2012-07-31 18:50:53 +0300
committerZahary Karadjov <zahary@gmail.com>2012-07-31 18:59:44 +0300
commit1d065b601cbf2d017fa946b64269cd0e7b5026fa (patch)
tree394d650959b81c29bb197b46f01d0fa218788a65
parent674c05f426d586deba1401270f78b74c22c540bc (diff)
downloadNim-1d065b601cbf2d017fa946b64269cd0e7b5026fa.tar.gz
DLL fixes for windows; fixes #175
-rwxr-xr-xcompiler/cgen.nim3
-rwxr-xr-xcompiler/pragmas.nim22
-rwxr-xr-xlib/system.nim1
-rwxr-xr-xlib/system/threads.nim1
4 files changed, 16 insertions, 11 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index 8d027b11c..06018fa99 100755
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -861,7 +861,8 @@ proc genMainProc(m: BModule) =
         CommonMainBody & "}$n"
     WinCDllMain = 
         "BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, $n" &
-        "                    LPVOID lpvReserved) {$n" & "\tNimMain();$n" &
+        "                    LPVOID lpvReserved) {$n" &
+          "\tif(fwdreason == DLL_PROCESS_ATTACH) NimMain();$n" &
         "\treturn 1;$n" & "}$n"
     PosixNimDllMain = WinNimDllMain
     PosixCDllMain = 
diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim
index 28f77d1b9..fd637f4c7 100755
--- a/compiler/pragmas.nim
+++ b/compiler/pragmas.nim
@@ -212,16 +212,22 @@ proc expectDynlibNode(c: PContext, n: PNode): PNode =
       result = newEmptyStrNode(n)
     
 proc processDynLib(c: PContext, n: PNode, sym: PSym) = 
-  if (sym == nil) or (sym.kind == skModule): 
+  if (sym == nil) or (sym.kind == skModule):
     POptionEntry(c.optionStack.tail).dynlib = getLib(c, libDynamic, 
         expectDynlibNode(c, n))
-  elif n.kind == nkExprColonExpr: 
-    var lib = getLib(c, libDynamic, expectDynlibNode(c, n))
-    addToLib(lib, sym)
-    incl(sym.loc.flags, lfDynamicLib)
-  else: 
-    incl(sym.loc.flags, lfExportLib)
-  
+  else:
+    if n.kind == nkExprColonExpr:
+      var lib = getLib(c, libDynamic, expectDynlibNode(c, n))
+      addToLib(lib, sym)
+      incl(sym.loc.flags, lfDynamicLib)
+    else:
+      incl(sym.loc.flags, lfExportLib)
+    # since we'll be loading the dynlib symbols dynamically, we must use
+    # a calling convention that doesn't introduce custom name mangling
+    # cdecl is the default - the use can override this explicitly
+    if sym.typ.callConv == ccDefault:
+      sym.typ.callConv = ccCDecl
+
 proc processNote(c: PContext, n: PNode) =
   if (n.kind == nkExprColonExpr) and (sonsLen(n) == 2) and
       (n.sons[0].kind == nkBracketExpr) and
diff --git a/lib/system.nim b/lib/system.nim
index 84a3034f0..64a70b61b 100755
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -1935,7 +1935,6 @@ when not defined(EcmaScript) and not defined(NimrodVM):
     include "system/syslocks"
     include "system/threads"
   elif not defined(nogc):
-    initStackBottom()
     initGC()
 
   proc setControlCHook*(hook: proc () {.noconv.})
diff --git a/lib/system/threads.nim b/lib/system/threads.nim
index 7a60404ac..6b1fd2178 100755
--- a/lib/system/threads.nim
+++ b/lib/system/threads.nim
@@ -203,7 +203,6 @@ when not defined(useNimRtl):
   when not useStackMaskHack:
     var mainThread: TGcThread
     ThreadVarSetValue(globalsSlot, addr(mainThread))
-    initStackBottom()
     initGC()
     
   when emulatedThreadVars: