summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2013-09-06 00:25:48 +0200
committerAraq <rumpf_a@web.de>2013-09-06 00:25:48 +0200
commit827dc054fb50b0ad575179e2d763e4b6ea25d0f8 (patch)
treeb3217dbfaaaf3df1c36f7de4d7205046fab2689f /lib/system
parent40b379859c1f0775718a873a0ba58d32510855aa (diff)
downloadNim-827dc054fb50b0ad575179e2d763e4b6ea25d0f8.tar.gz
bugfix: --gc:none -d:useMalloc works again
Diffstat (limited to 'lib/system')
-rw-r--r--lib/system/excpt.nim80
-rw-r--r--lib/system/repr.nim29
2 files changed, 55 insertions, 54 deletions
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
index 03200c8e2..7937d9738 100644
--- a/lib/system/excpt.nim
+++ b/lib/system/excpt.nim
@@ -27,8 +27,6 @@ else:
   proc writeToStdErr(msg: CString) =
     discard MessageBoxA(0, msg, nil, 0)
 
-proc registerSignalHandler()
-
 proc chckIndx(i, a, b: int): int {.inline, compilerproc.}
 proc chckRange(i, a, b: int): int {.inline, compilerproc.}
 proc chckRangeF(x, a, b: float): float {.inline, compilerproc.}
@@ -278,46 +276,46 @@ when defined(endb):
   var
     dbgAborting: bool # whether the debugger wants to abort
 
-proc signalHandler(sig: cint) {.exportc: "signalHandler", noconv.} =
-  template processSignal(s, action: expr) {.immediate.} =
-    if s == SIGINT: action("SIGINT: Interrupted by Ctrl-C.\n")
-    elif s == SIGSEGV: 
-      action("SIGSEGV: Illegal storage access. (Attempt to read from nil?)\n")
-    elif s == SIGABRT:
-      when defined(endb):
-        if dbgAborting: return # the debugger wants to abort
-      action("SIGABRT: Abnormal termination.\n")
-    elif s == SIGFPE: action("SIGFPE: Arithmetic error.\n")
-    elif s == SIGILL: action("SIGILL: Illegal operation.\n")
-    elif s == SIGBUS: 
-      action("SIGBUS: Illegal storage access. (Attempt to read from nil?)\n")
-    else: action("unknown signal\n")
-
-  # print stack trace and quit
-  when hasSomeStackTrace:
-    GC_disable()
-    var buf = newStringOfCap(2000)
-    rawWriteStackTrace(buf)
-    processSignal(sig, buf.add) # nice hu? currying a la nimrod :-)
-    writeToStdErr(buf)
-    GC_enable()
-  else:
-    var msg: cstring
-    template asgn(y: expr) = msg = y
-    processSignal(sig, asgn)
-    writeToStdErr(msg)
-  when defined(endb): dbgAborting = True
-  quit(1) # always quit when SIGABRT
-
-proc registerSignalHandler() =
-  c_signal(SIGINT, signalHandler)
-  c_signal(SIGSEGV, signalHandler)
-  c_signal(SIGABRT, signalHandler)
-  c_signal(SIGFPE, signalHandler)
-  c_signal(SIGILL, signalHandler)
-  c_signal(SIGBUS, signalHandler)
-
 when not defined(noSignalHandler):
+  proc signalHandler(sig: cint) {.exportc: "signalHandler", noconv.} =
+    template processSignal(s, action: expr) {.immediate.} =
+      if s == SIGINT: action("SIGINT: Interrupted by Ctrl-C.\n")
+      elif s == SIGSEGV: 
+        action("SIGSEGV: Illegal storage access. (Attempt to read from nil?)\n")
+      elif s == SIGABRT:
+        when defined(endb):
+          if dbgAborting: return # the debugger wants to abort
+        action("SIGABRT: Abnormal termination.\n")
+      elif s == SIGFPE: action("SIGFPE: Arithmetic error.\n")
+      elif s == SIGILL: action("SIGILL: Illegal operation.\n")
+      elif s == SIGBUS: 
+        action("SIGBUS: Illegal storage access. (Attempt to read from nil?)\n")
+      else: action("unknown signal\n")
+
+    # print stack trace and quit
+    when hasSomeStackTrace:
+      GC_disable()
+      var buf = newStringOfCap(2000)
+      rawWriteStackTrace(buf)
+      processSignal(sig, buf.add) # nice hu? currying a la nimrod :-)
+      writeToStdErr(buf)
+      GC_enable()
+    else:
+      var msg: cstring
+      template asgn(y: expr) = msg = y
+      processSignal(sig, asgn)
+      writeToStdErr(msg)
+    when defined(endb): dbgAborting = True
+    quit(1) # always quit when SIGABRT
+
+  proc registerSignalHandler() =
+    c_signal(SIGINT, signalHandler)
+    c_signal(SIGSEGV, signalHandler)
+    c_signal(SIGABRT, signalHandler)
+    c_signal(SIGFPE, signalHandler)
+    c_signal(SIGILL, signalHandler)
+    c_signal(SIGBUS, signalHandler)
+
   registerSignalHandler() # call it in initialization section
 
 proc setControlCHook(hook: proc () {.noconv.}) =
diff --git a/lib/system/repr.nim b/lib/system/repr.nim
index 3c9ce73ac..a51864ac2 100644
--- a/lib/system/repr.nim
+++ b/lib/system/repr.nim
@@ -117,7 +117,8 @@ proc reprSet(p: pointer, typ: PNimType): string {.compilerRtl.} =
 type
   TReprClosure {.final.} = object # we cannot use a global variable here
                                   # as this wouldn't be thread-safe
-    marked: TCellSet
+    when defined(TCellSet):
+      marked: TCellSet
     recdepth: int       # do not recurse endlessly
     indent: int         # indentation
 
@@ -127,12 +128,13 @@ when not defined(useNimRtl):
     # have to do it here ...
     when hasThreadSupport and hasSharedHeap and defined(heapLock):
       AcquireSys(HeapLock)
-    Init(cl.marked)
+    when defined(TCellSet):
+      Init(cl.marked)
     cl.recdepth = -1      # default is to display everything!
     cl.indent = 0
 
   proc deinitReprClosure(cl: var TReprClosure) =
-    Deinit(cl.marked)
+    when defined(TCellSet): Deinit(cl.marked)
     when hasThreadSupport and hasSharedHeap and defined(heapLock): 
       ReleaseSys(HeapLock)
 
@@ -195,16 +197,17 @@ when not defined(useNimRtl):
   proc reprRef(result: var string, p: pointer, typ: PNimType,
                cl: var TReprClosure) =
     # we know that p is not nil here:
-    when defined(boehmGC) or defined(nogc):
-      var cell = cast[PCell](p)
-    else:
-      var cell = usrToCell(p)
-    add result, "ref " & reprPointer(p)
-    if cell notin cl.marked:
-      # only the address is shown:
-      incl(cl.marked, cell)
-      add result, " --> "
-      reprAux(result, p, typ.base, cl)
+    when defined(TCellSet):
+      when defined(boehmGC) or defined(nogc):
+        var cell = cast[PCell](p)
+      else:
+        var cell = usrToCell(p)
+      add result, "ref " & reprPointer(p)
+      if cell notin cl.marked:
+        # only the address is shown:
+        incl(cl.marked, cell)
+        add result, " --> "
+        reprAux(result, p, typ.base, cl)
 
   proc reprAux(result: var string, p: pointer, typ: PNimType,
                cl: var TReprClosure) =