summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2017-03-26 09:30:59 +0200
committerGitHub <noreply@github.com>2017-03-26 09:30:59 +0200
commit1268ca79e5436e33a9fca0999477adf8f3e937ae (patch)
treeca0e18f2a078a3856c98498d5941c01073b5762c /lib
parent21b03257ef62609c3ce29b2c61bebb5cc6b0a243 (diff)
downloadNim-1268ca79e5436e33a9fca0999477adf8f3e937ae.tar.gz
fixes #5599 (#5610)
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/segfaults.nim4
-rw-r--r--lib/system.nim8
-rw-r--r--lib/system/chcks.nim6
-rw-r--r--lib/system/jssys.nim4
4 files changed, 15 insertions, 7 deletions
diff --git a/lib/pure/segfaults.nim b/lib/pure/segfaults.nim
index 3823d037c..373508430 100644
--- a/lib/pure/segfaults.nim
+++ b/lib/pure/segfaults.nim
@@ -13,10 +13,6 @@
 ##
 ## Tested on these OSes: Linux, Windows, OSX
 
-type
-  NilAccessError* = object of SystemError ## \
-    ## Raised on dereferences of ``nil`` pointers.
-
 # do allocate memory upfront:
 var se: ref NilAccessError
 new(se)
diff --git a/lib/system.nim b/lib/system.nim
index 94e10d7df..371cf8544 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -558,6 +558,10 @@ type
     ## Raised if it is attempted to send a message to a dead thread.
     ##
     ## See the full `exception hierarchy <manual.html#exception-handling-exception-hierarchy>`_.
+  NilAccessError* = object of SystemError ## \
+    ## Raised on dereferences of ``nil`` pointers.
+    ##
+    ## This is only raised if the ``segfaults.nim`` module was imported!
 
 {.deprecated: [TObject: RootObj, PObject: RootRef, TEffect: RootEffect,
   FTime: TimeEffect, FIO: IOEffect, FReadIO: ReadIOEffect,
@@ -2467,8 +2471,8 @@ template accumulateResult*(iter: untyped) =
 const NimStackTrace = compileOption("stacktrace")
 
 template coroutinesSupportedPlatform(): bool =
-  when defined(sparc) or defined(ELATE) or compileOption("gc", "v2") or 
-    defined(boehmgc) or defined(gogc) or defined(nogc) or defined(gcStack) or 
+  when defined(sparc) or defined(ELATE) or compileOption("gc", "v2") or
+    defined(boehmgc) or defined(gogc) or defined(nogc) or defined(gcStack) or
     defined(gcMarkAndSweep):
     false
   else:
diff --git a/lib/system/chcks.nim b/lib/system/chcks.nim
index 27a3708ea..1520f231e 100644
--- a/lib/system/chcks.nim
+++ b/lib/system/chcks.nim
@@ -50,7 +50,11 @@ proc chckRangeF(x, a, b: float): float =
 
 proc chckNil(p: pointer) =
   if p == nil:
-    sysFatal(ValueError, "attempt to write to a nil address")
+    sysFatal(NilAccessError, "attempt to write to a nil address")
+
+proc chckNilDisp(p: pointer) {.compilerproc.} =
+  if p == nil:
+    sysFatal(NilAccessError, "cannot dispatch; dispatcher is nil")
 
 proc chckObj(obj, subclass: PNimType) {.compilerproc.} =
   # checks if obj is of type subclass:
diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim
index 39ce1183b..9ef4a02f2 100644
--- a/lib/system/jssys.nim
+++ b/lib/system/jssys.nim
@@ -642,6 +642,10 @@ proc toU32*(a: int64): int32 {.asmNoStackFrame, compilerproc.} =
 proc nimMin(a, b: int): int {.compilerproc.} = return if a <= b: a else: b
 proc nimMax(a, b: int): int {.compilerproc.} = return if a >= b: a else: b
 
+proc chckNilDisp(p: pointer) {.compilerproc.} =
+  if p == nil:
+    sysFatal(NilAccessError, "cannot dispatch; dispatcher is nil")
+
 type NimString = string # hack for hti.nim
 include "system/hti"