deinitializing locks at program exit (#19043)
* deinitializing locks at program exit * deinitLock shouldn't be called for js backend I guess... * I suppose this is the best way to detect the ewruntime option * I guess I need these guards here too... * fixing merge conflict
This commit is contained in:
parent
141b76e365
commit
582468da1c
2 changed files with 35 additions and 24 deletions
|
|
@ -44,6 +44,9 @@ proc callClosures() {.noconv.} =
|
|||
of kClosure: fun.fun1()
|
||||
of kNoconv: fun.fun2()
|
||||
|
||||
when not defined(js) and not defined(nimOwnedEnabled):
|
||||
deinitLock(gFunsLock)
|
||||
|
||||
template fun() =
|
||||
if gFuns.len == 0:
|
||||
addAtExit(callClosures)
|
||||
|
|
|
|||
|
|
@ -40,7 +40,8 @@ type
|
|||
# text file handling:
|
||||
when not defined(nimscript) and not defined(js):
|
||||
# duplicated between io and ansi_c
|
||||
const stdioUsesMacros = (defined(osx) or defined(freebsd) or defined(dragonfly)) and not defined(emscripten)
|
||||
const stdioUsesMacros = (defined(osx) or defined(freebsd) or defined(
|
||||
dragonfly)) and not defined(emscripten)
|
||||
const stderrName = when stdioUsesMacros: "__stderrp" else: "stderr"
|
||||
const stdoutName = when stdioUsesMacros: "__stdoutp" else: "stdout"
|
||||
const stdinName = when stdioUsesMacros: "__stdinp" else: "stdin"
|
||||
|
|
@ -167,7 +168,8 @@ proc readBuffer*(f: File, buffer: pointer, len: Natural): int {.
|
|||
result = cast[int](c_fread(buffer, 1, cast[csize_t](len), f))
|
||||
if result != len: checkErr(f)
|
||||
|
||||
proc readBytes*(f: File, a: var openArray[int8|uint8], start, len: Natural): int {.
|
||||
proc readBytes*(f: File, a: var openArray[int8|uint8], start,
|
||||
len: Natural): int {.
|
||||
tags: [ReadIOEffect], benign.} =
|
||||
## reads `len` bytes into the buffer `a` starting at `a[start]`. Returns
|
||||
## the actual number of bytes that have been read which may be less than
|
||||
|
|
@ -727,7 +729,8 @@ proc open*(f: var File, filehandle: FileHandle,
|
|||
##
|
||||
## The passed file handle will no longer be inheritable.
|
||||
when not defined(nimInheritHandles) and declared(setInheritable):
|
||||
let oshandle = when defined(windows): FileHandle getOsfhandle(filehandle) else: filehandle
|
||||
let oshandle = when defined(windows): FileHandle getOsfhandle(
|
||||
filehandle) else: filehandle
|
||||
if not setInheritable(oshandle, false):
|
||||
return false
|
||||
f = c_fdopen(filehandle, FormatOpen[mode])
|
||||
|
|
@ -780,6 +783,10 @@ when declared(stdout):
|
|||
var echoLock: SysLock
|
||||
initSysLock echoLock
|
||||
|
||||
when not defined(js) and not defined(nimOwnedEnabled):
|
||||
import std/exitprocs
|
||||
addExitProc(proc() {.noconv.} = deinitSys echoLock)
|
||||
|
||||
const stdOutLock = not defined(windows) and
|
||||
not defined(android) and
|
||||
not defined(nintendoswitch) and
|
||||
|
|
@ -898,7 +905,8 @@ proc readLines*(filename: string, n: Natural): seq[string] =
|
|||
else:
|
||||
sysFatal(IOError, "cannot open: " & filename)
|
||||
|
||||
template readLines*(filename: string): seq[string] {.deprecated: "use readLines with two arguments".} =
|
||||
template readLines*(filename: string): seq[
|
||||
string] {.deprecated: "use readLines with two arguments".} =
|
||||
readLines(filename, 1)
|
||||
|
||||
iterator lines*(filename: string): string {.tags: [ReadIOEffect].} =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue