mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-25 08:43:58 +00:00
added system.setControlCHook, system.writeStackTrace
This commit is contained in:
@@ -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 =
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user