std/segfaults

Search:
Source   Edit  

This modules registers a signal handler that turns access violations / segfaults into a NilAccessDefect exception. To be able to catch a NilAccessDefect all you have to do is to import this module.

Tested on these OSes: Linux, Windows, OSX

Types

C_JmpBuf {.importc: "jmp_buf", header: "<setjmp.h>".} = object
Source   Edit  
CFilePtr = ptr CFile
The type representing a file handle. Source   Edit  

Vars

cstderr {.importc: "stderr", header: "<stdio.h>".}: CFilePtr
Source   Edit  
cstdin {.importc: "stdin", header: "<stdio.h>".}: CFilePtr
Source   Edit  
cstdout {.importc: "stdout", header: "<stdio.h>".}: CFilePtr
Source   Edit  

Consts

SIG_DFL = 0
Source   Edit  
SIGABRT = 22'i32
Source   Edit  
SIGFPE = 8'i32
Source   Edit  
SIGILL = 4'i32
Source   Edit  
SIGINT = 2'i32
Source   Edit  
SIGSEGV = 11'i32
Source   Edit  

Procs

proc c_abort() {.importc: "abort", header: "<stdlib.h>", noSideEffect, noreturn,
                 ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc c_calloc(nmemb, size: csize_t): pointer {.importc: "calloc",
    header: "<stdlib.h>", ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc c_fflush(f: CFilePtr): cint {.importc: "fflush", header: "<stdio.h>",
                                   ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc c_fprintf(f: CFilePtr; frmt: cstring): cint {.importc: "fprintf",
    header: "<stdio.h>", varargs, discardable, ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc c_fputc(c: char; f: CFilePtr): cint {.importc: "fputc",
    header: "<stdio.h>", discardable, ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc c_fputs(c: cstring; f: CFilePtr): cint {.importc: "fputs",
    header: "<stdio.h>", discardable, ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc c_free(p: pointer) {.importc: "free", header: "<stdlib.h>", ...raises: [],
                          tags: [], forbids: [].}
Source   Edit  
proc c_fwrite(buf: pointer; size, n: csize_t; f: CFilePtr): csize_t {.
    importc: "fwrite", header: "<stdio.h>", ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc c_longjmp(jmpb: C_JmpBuf; retval: cint) {.header: "<setjmp.h>",
    importc: "longjmp", ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc c_malloc(size: csize_t): pointer {.importc: "malloc", header: "<stdlib.h>",
                                        ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc c_memchr(s: pointer; c: cint; n: csize_t): pointer {.importc: "memchr",
    header: "<string.h>", ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc c_memcmp(a, b: pointer; size: csize_t): cint {.importc: "memcmp",
    header: "<string.h>", noSideEffect, ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc c_memcpy(a, b: pointer; size: csize_t): pointer {.importc: "memcpy",
    header: "<string.h>", discardable, ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc c_memmove(a, b: pointer; size: csize_t): pointer {.importc: "memmove",
    header: "<string.h>", discardable, ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc c_memset(p: pointer; value: cint; size: csize_t): pointer {.
    importc: "memset", header: "<string.h>", discardable, ...raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc c_printf(frmt: cstring): cint {.importc: "printf", header: "<stdio.h>",
                                     varargs, discardable, ...raises: [], tags: [],
                                     forbids: [].}
Source   Edit  
proc c_raise(sign: cint): cint {.importc: "raise", header: "<signal.h>",
                                 ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc c_realloc(p: pointer; newsize: csize_t): pointer {.importc: "realloc",
    header: "<stdlib.h>", ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc c_setjmp(jmpb: C_JmpBuf): cint {.header: "<setjmp.h>", importc: "setjmp",
                                      ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc c_signal(sign: cint; handler: CSighandlerT): CSighandlerT {.
    importc: "signal", header: "<signal.h>", discardable, ...raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc c_snprintf(buf: cstring; n: csize_t; frmt: cstring): cint {.
    importc: "snprintf", header: "<stdio.h>", varargs, noSideEffect, ...raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc c_sprintf(buf, frmt: cstring): cint {.importc: "sprintf",
    header: "<stdio.h>", varargs, noSideEffect, ...raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc c_strcmp(a, b: cstring): cint {.importc: "strcmp", header: "<string.h>",
                                     noSideEffect, ...raises: [], tags: [],
                                     forbids: [].}
Source   Edit  
proc c_strlen(a: cstring): csize_t {.importc: "strlen", header: "<string.h>",
                                     noSideEffect, ...raises: [], tags: [],
                                     forbids: [].}
Source   Edit  
proc rawWrite(f: CFilePtr; s: cstring) {.compilerproc, nonReloadable, inline,
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc rawWriteString(f: CFilePtr; s: cstring; length: int) {.compilerproc,
    nonReloadable, inline, ...raises: [], tags: [], forbids: [].}
Source   Edit