fixes #20694; the exit function now takes cint type (#20775)

This commit is contained in:
ringabout 2022-11-07 19:17:52 +08:00 • committed by GitHub
commit 66b0c843c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1078,6 +1078,8 @@ when not defined(js) and hostOS != "standalone":
## deprecated, prefer `quit` or `exitprocs.getProgramResult`, `exitprocs.setProgramResult`. ## deprecated, prefer `quit` or `exitprocs.getProgramResult`, `exitprocs.setProgramResult`.
import std/private/since import std/private/since
import system/ctypes
export ctypes
proc align(address, alignment: int): int = proc align(address, alignment: int): int =
if alignment == 0: # Actually, this is illegal. This branch exists to actively if alignment == 0: # Actually, this is illegal. This branch exists to actively
@ -1109,7 +1111,7 @@ elif defined(js) and defined(nodejs) and not defined(nimscript):
importc: "process.exit", noreturn.} importc: "process.exit", noreturn.}
else: else:
proc rawQuit(errorcode: int = QuitSuccess) {. proc rawQuit(errorcode: cint) {.
magic: "Exit", importc: "exit", header: "<stdlib.h>", noreturn.} magic: "Exit", importc: "exit", header: "<stdlib.h>", noreturn.}
template sysAssert(cond: bool, msg: string) = template sysAssert(cond: bool, msg: string) =
@ -1244,9 +1246,6 @@ when not defined(nimV2):
## echo repr(i) # => 0x1055ed050[1, 2, 3, 4, 5] ## echo repr(i) # => 0x1055ed050[1, 2, 3, 4, 5]
## ``` ## ```
import system/ctypes
export ctypes
when not defined(nimPreviewSlimSystem): when not defined(nimPreviewSlimSystem):
type type
csize* {.importc: "size_t", nodecl, deprecated: "use `csize_t` instead".} = int csize* {.importc: "size_t", nodecl, deprecated: "use `csize_t` instead".} = int
@ -2302,14 +2301,14 @@ else:
when defined(posix): # posix uses low 8 bits when defined(posix): # posix uses low 8 bits
type ExitCodeRange = int8 type ExitCodeRange = int8
else: # win32 uses low 32 bits else: # win32 uses low 32 bits
type ExitCodeRange = int32 type ExitCodeRange = cint
if errorcode < low(ExitCodeRange): if errorcode < low(ExitCodeRange):
rawQuit(low(ExitCodeRange).int) rawQuit(low(ExitCodeRange).cint)
elif errorcode > high(ExitCodeRange): elif errorcode > high(ExitCodeRange):
rawQuit(high(ExitCodeRange).int) rawQuit(high(ExitCodeRange).cint)
else: else:
rawQuit(errorcode) rawQuit(errorcode.cint)
proc quit*(errormsg: string, errorcode = QuitFailure) {.noreturn.} = proc quit*(errormsg: string, errorcode = QuitFailure) {.noreturn.} =
## A shorthand for `echo(errormsg); quit(errorcode)`. ## A shorthand for `echo(errormsg); quit(errorcode)`.