added system.setControlCHook, system.writeStackTrace

This commit is contained in:
Araq 2012-02-19 23:37:37 +01:00
commit b2746c4659
4 changed files with 17 additions and 2 deletions

View file

@ -85,7 +85,8 @@ proc setRow(stmt: PStmt, r: var TRow, cols: int) =
for col in 0..cols-1: for col in 0..cols-1:
setLen(r[col], column_bytes(stmt, col)) # set capacity setLen(r[col], column_bytes(stmt, col)) # set capacity
setLen(r[col], 0) 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, iterator FastRows*(db: TDbConn, query: TSqlQuery,
args: openarray[string]): TRow = args: openarray[string]): TRow =

View file

@ -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`. ## 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. ## Result is the number of processed chars or 0 if there is no integer.
## `EOverflow` is raised if an overflow occurs. ## `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 # use 'res' for exception safety (don't write to 'number' in case of an
# overflow exception: # overflow exception:
result = rawParseInt(s, res, start) result = rawParseInt(s, res, start)
@ -281,6 +281,7 @@ proc parseBiggestFloat*(s: string, number: var biggestFloat, start = 0): int {.
while s[i] == '_': inc(i) while s[i] == '_': inc(i)
# Calculate Exponent # Calculate Exponent
var hd = 1.0 var hd = 1.0
# XXX: this loop is horrible for large exponents:
for j in 1..exponent: hd = hd * 10.0 for j in 1..exponent: hd = hd * 10.0
if esign > 0.0: number = number * hd if esign > 0.0: number = number * hd
else: number = number / hd else: number = number / hd

View file

@ -1871,6 +1871,14 @@ when not defined(EcmaScript) and not defined(NimrodVM):
else: else:
initStackBottom() initStackBottom()
initGC() 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.} {.push stack_trace: off.}
include "system/excpt" include "system/excpt"

View file

@ -292,6 +292,11 @@ proc registerSignalHandler() =
when not defined(noSignalHandler): when not defined(noSignalHandler):
registerSignalHandler() # call it in initialization section 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.} = proc raiseRangeError(val: biggestInt) {.compilerproc, noreturn, noinline.} =
raise newException(EOutOfRange, "value " & $val & " out of range") raise newException(EOutOfRange, "value " & $val & " out of range")