summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-02-19 23:37:37 +0100
committerAraq <rumpf_a@web.de>2012-02-19 23:37:37 +0100
commitb2746c465968a5d61f3e9b18fb952097db4afea9 (patch)
treeb77a0b46feb2735c397a20c6f3afe8af418536fa /lib
parentccd58fba2cbc329eb42cd65c80d66ca09acad505 (diff)
downloadNim-b2746c465968a5d61f3e9b18fb952097db4afea9.tar.gz
added system.setControlCHook, system.writeStackTrace
Diffstat (limited to 'lib')
-rwxr-xr-xlib/impure/db_sqlite.nim3
-rwxr-xr-xlib/pure/parseutils.nim3
-rwxr-xr-xlib/system.nim8
-rwxr-xr-xlib/system/excpt.nim5
4 files changed, 17 insertions, 2 deletions
diff --git a/lib/impure/db_sqlite.nim b/lib/impure/db_sqlite.nim
index f54049899..dbe34fd51 100755
--- a/lib/impure/db_sqlite.nim
+++ b/lib/impure/db_sqlite.nim
@@ -85,7 +85,8 @@ proc setRow(stmt: PStmt, r: var TRow, cols: int) =
   for col in 0..cols-1:
     setLen(r[col], column_bytes(stmt, col)) # set capacity
     setLen(r[col], 0)
-    add(r[col], column_text(stmt, col))
+    let x = column_text(stmt, col)
+    if not isNil(x): add(r[col], x)
   
 iterator FastRows*(db: TDbConn, query: TSqlQuery,
                    args: openarray[string]): TRow =
diff --git a/lib/pure/parseutils.nim b/lib/pure/parseutils.nim
index fd9e880c6..4f0d2e21f 100755
--- a/lib/pure/parseutils.nim
+++ b/lib/pure/parseutils.nim
@@ -196,7 +196,7 @@ proc parseBiggestInt*(s: string, number: var biggestInt, start = 0): int {.
   ## parses an integer starting at `start` and stores the value into `number`.
   ## Result is the number of processed chars or 0 if there is no integer.
   ## `EOverflow` is raised if an overflow occurs.
-  var res: biggestInt = number
+  var res: biggestInt
   # use 'res' for exception safety (don't write to 'number' in case of an
   # overflow exception:
   result = rawParseInt(s, res, start)
@@ -281,6 +281,7 @@ proc parseBiggestFloat*(s: string, number: var biggestFloat, start = 0): int {.
       while s[i] == '_': inc(i)
   # Calculate Exponent
   var hd = 1.0
+  # XXX: this loop is horrible for large exponents:
   for j in 1..exponent: hd = hd * 10.0
   if esign > 0.0: number = number * hd
   else:           number = number / hd
diff --git a/lib/system.nim b/lib/system.nim
index 9968cd49d..b75f9022d 100755
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -1871,6 +1871,14 @@ when not defined(EcmaScript) and not defined(NimrodVM):
   else:
     initStackBottom()
     initGC()
+
+  proc setControlCHook*(hook: proc () {.noconv.})
+    ## allows you to override the behaviour of your application when CTRL+C
+    ## is pressed. Only one such hook is supported.
+    
+  proc writeStackTrace*()
+    ## writes the current stack trace to ``stderr``. This is only works
+    ## for debug builds.
     
   {.push stack_trace: off.}
   include "system/excpt"
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
index e7dc88af2..8260ba725 100755
--- a/lib/system/excpt.nim
+++ b/lib/system/excpt.nim
@@ -292,6 +292,11 @@ proc registerSignalHandler() =
 when not defined(noSignalHandler):
   registerSignalHandler() # call it in initialization section
 
+proc setControlCHook(hook: proc () {.noconv.}) =
+  # ugly cast, but should work on all architectures:
+  type TSignalHandler = proc (sig: cint) {.noconv.}
+  c_signal(SIGINT, cast[TSignalHandler](hook))
+
 proc raiseRangeError(val: biggestInt) {.compilerproc, noreturn, noinline.} =
   raise newException(EOutOfRange, "value " & $val & " out of range")