Skip to content

Commit

Permalink
fixes #20694; the exit function now takes cint type (#20775)
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout authored Nov 7, 2022
1 parent 0b4f502 commit 66b0c84
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,8 @@ when not defined(js) and hostOS != "standalone":
## deprecated, prefer `quit` or `exitprocs.getProgramResult`, `exitprocs.setProgramResult`.

import std/private/since
import system/ctypes
export ctypes

proc align(address, alignment: int): int =
if alignment == 0: # Actually, this is illegal. This branch exists to actively
Expand Down Expand Up @@ -1109,7 +1111,7 @@ elif defined(js) and defined(nodejs) and not defined(nimscript):
importc: "process.exit", noreturn.}

else:
proc rawQuit(errorcode: int = QuitSuccess) {.
proc rawQuit(errorcode: cint) {.
magic: "Exit", importc: "exit", header: "<stdlib.h>", noreturn.}

template sysAssert(cond: bool, msg: string) =
Expand Down Expand Up @@ -1244,9 +1246,6 @@ when not defined(nimV2):
## echo repr(i) # => 0x1055ed050[1, 2, 3, 4, 5]
## ```

import system/ctypes
export ctypes

when not defined(nimPreviewSlimSystem):
type
csize* {.importc: "size_t", nodecl, deprecated: "use `csize_t` instead".} = int
Expand Down Expand Up @@ -2302,14 +2301,14 @@ else:
when defined(posix): # posix uses low 8 bits
type ExitCodeRange = int8
else: # win32 uses low 32 bits
type ExitCodeRange = int32
type ExitCodeRange = cint

if errorcode < low(ExitCodeRange):
rawQuit(low(ExitCodeRange).int)
rawQuit(low(ExitCodeRange).cint)
elif errorcode > high(ExitCodeRange):
rawQuit(high(ExitCodeRange).int)
rawQuit(high(ExitCodeRange).cint)
else:
rawQuit(errorcode)
rawQuit(errorcode.cint)

proc quit*(errormsg: string, errorcode = QuitFailure) {.noreturn.} =
## A shorthand for `echo(errormsg); quit(errorcode)`.
Expand Down

0 comments on commit 66b0c84

Please sign in to comment.