summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2013-05-31 01:27:03 +0200
committerAraq <rumpf_a@web.de>2013-05-31 01:27:03 +0200
commit8c211113f26260896614b7385b94ed91a5b9f291 (patch)
tree184835f828a10ec0b177599f55da4e3d39e42ac8
parenta8ba628bcd2535bc55e3bf67737e93ae99906a63 (diff)
downloadNim-8c211113f26260896614b7385b94ed91a5b9f291.tar.gz
better error message for subtle nil errors
-rw-r--r--compiler/cgen.nim2
-rw-r--r--compiler/options.nim2
-rw-r--r--lib/system/excpt.nim6
-rw-r--r--todo.txt1
4 files changed, 8 insertions, 3 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index 92216d278..7e782fc12 100644
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -346,6 +346,8 @@ proc resetLoc(p: BProc, loc: var TLoc) =
     else:
       linefmt(p, cpsStmts, "$1 = 0;$n", rdLoc(loc))
   else:
+    if optNilCheck in p.options:
+      linefmt(p, cpsStmts, "#chckNil((void*)$1);$n", addrLoc(loc))
     if loc.s != OnStack:
       linefmt(p, cpsStmts, "#genericReset((void*)$1, $2);$n",
               addrLoc(loc), genTypeInfo(p.module, loc.t))
diff --git a/compiler/options.nim b/compiler/options.nim
index f67ded163..6d93048fe 100644
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -92,7 +92,7 @@ var
   gOptions*: TOptions = {optObjCheck, optFieldCheck, optRangeCheck, 
                          optBoundsCheck, optOverflowCheck, optAssert, optWarns, 
                          optHints, optStackTrace, optLineTrace,
-                         optPatterns}
+                         optPatterns, optNilCheck}
   gGlobalOptions*: TGlobalOptions = {optThreadAnalysis}
   gExitcode*: int8
   gCmd*: TCommands = cmdNone  # the command
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
index faaefe083..bf0fe4b72 100644
--- a/lib/system/excpt.nim
+++ b/lib/system/excpt.nim
@@ -32,7 +32,7 @@ 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.}
-proc chckNil(p: pointer) {.inline, compilerproc.}
+proc chckNil(p: pointer) {.noinline, compilerproc.}
 
 var
   framePtr {.rtlThreadVar.}: PFrame
@@ -359,7 +359,9 @@ proc chckRangeF(x, a, b: float): float =
     raise newException(EOutOfRange, "value " & $x & " out of range")
 
 proc chckNil(p: pointer) =
-  if p == nil: c_raise(SIGSEGV)
+  if p == nil:
+    raise newException(EInvalidValue, "attempt to write to a nil address")
+    #c_raise(SIGSEGV)
 
 proc chckObj(obj, subclass: PNimType) {.compilerproc.} =
   # checks if obj is of type subclass:
diff --git a/todo.txt b/todo.txt
index 5214245ae..b59f7502e 100644
--- a/todo.txt
+++ b/todo.txt
@@ -9,6 +9,7 @@ version 0.9.4
   - overloading of ``.``? Special case ``.=``?
 - built-in 'getImpl'
 - macros.gensym still missing?
+- optimize 'genericReset'; 'newException' leads to code bloat
 
 
 Bugs