[backport] run nimpretty on os-related stuff
This commit is contained in:
parent
dcf3181bd1
commit
34d0be2ec1
10 changed files with 191 additions and 182 deletions
|
|
@ -39,7 +39,8 @@ proc bitxor*[T: SomeInteger](x, y: T): T {.magic: "BitxorI", noSideEffect.}
|
||||||
|
|
||||||
const useBuiltins = not defined(noIntrinsicsBitOpts)
|
const useBuiltins = not defined(noIntrinsicsBitOpts)
|
||||||
const noUndefined = defined(noUndefinedBitOpts)
|
const noUndefined = defined(noUndefinedBitOpts)
|
||||||
const useGCC_builtins = (defined(gcc) or defined(llvm_gcc) or defined(clang)) and useBuiltins
|
const useGCC_builtins = (defined(gcc) or defined(llvm_gcc) or
|
||||||
|
defined(clang)) and useBuiltins
|
||||||
const useICC_builtins = defined(icc) and useBuiltins
|
const useICC_builtins = defined(icc) and useBuiltins
|
||||||
const useVCC_builtins = defined(vcc) and useBuiltins
|
const useVCC_builtins = defined(vcc) and useBuiltins
|
||||||
const arch64 = sizeof(int) == 8
|
const arch64 = sizeof(int) == 8
|
||||||
|
|
@ -196,7 +197,8 @@ template parityImpl[T](value: T): int =
|
||||||
when useGCC_builtins:
|
when useGCC_builtins:
|
||||||
# Returns the number of set 1-bits in value.
|
# Returns the number of set 1-bits in value.
|
||||||
proc builtin_popcount(x: cuint): cint {.importc: "__builtin_popcount", cdecl.}
|
proc builtin_popcount(x: cuint): cint {.importc: "__builtin_popcount", cdecl.}
|
||||||
proc builtin_popcountll(x: culonglong): cint {.importc: "__builtin_popcountll", cdecl.}
|
proc builtin_popcountll(x: culonglong): cint {.
|
||||||
|
importc: "__builtin_popcountll", cdecl.}
|
||||||
|
|
||||||
# Returns the bit parity in value
|
# Returns the bit parity in value
|
||||||
proc builtin_parity(x: cuint): cint {.importc: "__builtin_parity", cdecl.}
|
proc builtin_parity(x: cuint): cint {.importc: "__builtin_parity", cdecl.}
|
||||||
|
|
@ -216,17 +218,24 @@ when useGCC_builtins:
|
||||||
|
|
||||||
elif useVCC_builtins:
|
elif useVCC_builtins:
|
||||||
# Counts the number of one bits (population count) in a 16-, 32-, or 64-byte unsigned integer.
|
# Counts the number of one bits (population count) in a 16-, 32-, or 64-byte unsigned integer.
|
||||||
proc builtin_popcnt16(a2: uint16): uint16 {.importc: "__popcnt16" header: "<intrin.h>", noSideEffect.}
|
proc builtin_popcnt16(a2: uint16): uint16 {.
|
||||||
proc builtin_popcnt32(a2: uint32): uint32 {.importc: "__popcnt" header: "<intrin.h>", noSideEffect.}
|
importc: "__popcnt16"header: "<intrin.h>", noSideEffect.}
|
||||||
proc builtin_popcnt64(a2: uint64): uint64 {.importc: "__popcnt64" header: "<intrin.h>", noSideEffect.}
|
proc builtin_popcnt32(a2: uint32): uint32 {.
|
||||||
|
importc: "__popcnt"header: "<intrin.h>", noSideEffect.}
|
||||||
|
proc builtin_popcnt64(a2: uint64): uint64 {.
|
||||||
|
importc: "__popcnt64"header: "<intrin.h>", noSideEffect.}
|
||||||
|
|
||||||
# Search the mask data from most significant bit (MSB) to least significant bit (LSB) for a set bit (1).
|
# Search the mask data from most significant bit (MSB) to least significant bit (LSB) for a set bit (1).
|
||||||
proc bitScanReverse(index: ptr culong, mask: culong): cuchar {.importc: "_BitScanReverse", header: "<intrin.h>", noSideEffect.}
|
proc bitScanReverse(index: ptr culong, mask: culong): cuchar {.
|
||||||
proc bitScanReverse64(index: ptr culong, mask: uint64): cuchar {.importc: "_BitScanReverse64", header: "<intrin.h>", noSideEffect.}
|
importc: "_BitScanReverse", header: "<intrin.h>", noSideEffect.}
|
||||||
|
proc bitScanReverse64(index: ptr culong, mask: uint64): cuchar {.
|
||||||
|
importc: "_BitScanReverse64", header: "<intrin.h>", noSideEffect.}
|
||||||
|
|
||||||
# Search the mask data from least significant bit (LSB) to the most significant bit (MSB) for a set bit (1).
|
# Search the mask data from least significant bit (LSB) to the most significant bit (MSB) for a set bit (1).
|
||||||
proc bitScanForward(index: ptr culong, mask: culong): cuchar {.importc: "_BitScanForward", header: "<intrin.h>", noSideEffect.}
|
proc bitScanForward(index: ptr culong, mask: culong): cuchar {.
|
||||||
proc bitScanForward64(index: ptr culong, mask: uint64): cuchar {.importc: "_BitScanForward64", header: "<intrin.h>", noSideEffect.}
|
importc: "_BitScanForward", header: "<intrin.h>", noSideEffect.}
|
||||||
|
proc bitScanForward64(index: ptr culong, mask: uint64): cuchar {.
|
||||||
|
importc: "_BitScanForward64", header: "<intrin.h>", noSideEffect.}
|
||||||
|
|
||||||
template vcc_scan_impl(fnc: untyped; v: untyped): int =
|
template vcc_scan_impl(fnc: untyped; v: untyped): int =
|
||||||
var index: culong
|
var index: culong
|
||||||
|
|
@ -238,16 +247,22 @@ elif useICC_builtins:
|
||||||
# Intel compiler intrinsics: http://fulla.fnal.gov/intel/compiler_c/main_cls/intref_cls/common/intref_allia_misc.htm
|
# Intel compiler intrinsics: http://fulla.fnal.gov/intel/compiler_c/main_cls/intref_cls/common/intref_allia_misc.htm
|
||||||
# see also: https://software.intel.com/en-us/node/523362
|
# see also: https://software.intel.com/en-us/node/523362
|
||||||
# Count the number of bits set to 1 in an integer a, and return that count in dst.
|
# Count the number of bits set to 1 in an integer a, and return that count in dst.
|
||||||
proc builtin_popcnt32(a: cint): cint {.importc: "_popcnt" header: "<immintrin.h>", noSideEffect.}
|
proc builtin_popcnt32(a: cint): cint {.
|
||||||
proc builtin_popcnt64(a: uint64): cint {.importc: "_popcnt64" header: "<immintrin.h>", noSideEffect.}
|
importc: "_popcnt"header: "<immintrin.h>", noSideEffect.}
|
||||||
|
proc builtin_popcnt64(a: uint64): cint {.
|
||||||
|
importc: "_popcnt64"header: "<immintrin.h>", noSideEffect.}
|
||||||
|
|
||||||
# Returns the number of trailing 0-bits in x, starting at the least significant bit position. If x is 0, the result is undefined.
|
# Returns the number of trailing 0-bits in x, starting at the least significant bit position. If x is 0, the result is undefined.
|
||||||
proc bitScanForward(p: ptr uint32, b: uint32): cuchar {.importc: "_BitScanForward", header: "<immintrin.h>", noSideEffect.}
|
proc bitScanForward(p: ptr uint32, b: uint32): cuchar {.
|
||||||
proc bitScanForward64(p: ptr uint32, b: uint64): cuchar {.importc: "_BitScanForward64", header: "<immintrin.h>", noSideEffect.}
|
importc: "_BitScanForward", header: "<immintrin.h>", noSideEffect.}
|
||||||
|
proc bitScanForward64(p: ptr uint32, b: uint64): cuchar {.
|
||||||
|
importc: "_BitScanForward64", header: "<immintrin.h>", noSideEffect.}
|
||||||
|
|
||||||
# Returns the number of leading 0-bits in x, starting at the most significant bit position. If x is 0, the result is undefined.
|
# Returns the number of leading 0-bits in x, starting at the most significant bit position. If x is 0, the result is undefined.
|
||||||
proc bitScanReverse(p: ptr uint32, b: uint32): cuchar {.importc: "_BitScanReverse", header: "<immintrin.h>", noSideEffect.}
|
proc bitScanReverse(p: ptr uint32, b: uint32): cuchar {.
|
||||||
proc bitScanReverse64(p: ptr uint32, b: uint64): cuchar {.importc: "_BitScanReverse64", header: "<immintrin.h>", noSideEffect.}
|
importc: "_BitScanReverse", header: "<immintrin.h>", noSideEffect.}
|
||||||
|
proc bitScanReverse64(p: ptr uint32, b: uint64): cuchar {.
|
||||||
|
importc: "_BitScanReverse64", header: "<immintrin.h>", noSideEffect.}
|
||||||
|
|
||||||
template icc_scan_impl(fnc: untyped; v: untyped): int =
|
template icc_scan_impl(fnc: untyped; v: untyped): int =
|
||||||
var index: uint32
|
var index: uint32
|
||||||
|
|
|
||||||
|
|
@ -133,8 +133,9 @@ const
|
||||||
LacksDevPackages* = {Distribution.Gentoo, Distribution.Slackware,
|
LacksDevPackages* = {Distribution.Gentoo, Distribution.Slackware,
|
||||||
Distribution.ArchLinux}
|
Distribution.ArchLinux}
|
||||||
|
|
||||||
var unameRes, releaseRes, hostnamectlRes: string ## we cache the result of the 'uname -a'
|
# we cache the result of the 'uname -a'
|
||||||
## execution for faster platform detections.
|
# execution for faster platform detections.
|
||||||
|
var unameRes, releaseRes, hostnamectlRes: string
|
||||||
|
|
||||||
template unameRelease(cmd, cache): untyped =
|
template unameRelease(cmd, cache): untyped =
|
||||||
if cache.len == 0:
|
if cache.len == 0:
|
||||||
|
|
@ -173,7 +174,8 @@ proc detectOsImpl(d: Distribution): bool =
|
||||||
result = defined(haiku)
|
result = defined(haiku)
|
||||||
else:
|
else:
|
||||||
let dd = toLowerAscii($d)
|
let dd = toLowerAscii($d)
|
||||||
result = dd in toLowerAscii(uname()) or dd in toLowerAscii(release()) or ("operating system: " & dd) in toLowerAscii(hostnamectl())
|
result = dd in toLowerAscii(uname()) or dd in toLowerAscii(release()) or
|
||||||
|
("operating system: " & dd) in toLowerAscii(hostnamectl())
|
||||||
|
|
||||||
template detectOs*(d: untyped): bool =
|
template detectOs*(d: untyped): bool =
|
||||||
## Distro/OS detection. For convenience the
|
## Distro/OS detection. For convenience the
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,8 @@ proc open*(filename: string, mode: FileMode = fmRead,
|
||||||
if readonly: shareMode else: shareMode or FILE_SHARE_WRITE,
|
if readonly: shareMode else: shareMode or FILE_SHARE_WRITE,
|
||||||
nil,
|
nil,
|
||||||
if newFileSize != -1: CREATE_ALWAYS else: OPEN_EXISTING,
|
if newFileSize != -1: CREATE_ALWAYS else: OPEN_EXISTING,
|
||||||
if readonly: FILE_ATTRIBUTE_READONLY or flags else: FILE_ATTRIBUTE_NORMAL or flags,
|
if readonly: FILE_ATTRIBUTE_READONLY or flags
|
||||||
|
else: FILE_ATTRIBUTE_NORMAL or flags,
|
||||||
0)
|
0)
|
||||||
|
|
||||||
when useWinUnicode:
|
when useWinUnicode:
|
||||||
|
|
@ -312,8 +313,8 @@ when defined(posix) or defined(nimdoc):
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
when defined(linux): #Maybe NetBSD, too?
|
when defined(linux): #Maybe NetBSD, too?
|
||||||
#On Linux this can be over 100 times faster than a munmap,mmap cycle.
|
#On Linux this can be over 100 times faster than a munmap,mmap cycle.
|
||||||
proc mremap(old: pointer; oldSize,newSize: csize; flags: cint): pointer {.
|
proc mremap(old: pointer; oldSize, newSize: csize; flags: cint):
|
||||||
importc: "mremap", header: "<sys/mman.h>" .}
|
pointer {.importc: "mremap", header: "<sys/mman.h>".}
|
||||||
let newAddr = mremap(f.mem, csize(f.size), csize(newFileSize), cint(1))
|
let newAddr = mremap(f.mem, csize(f.size), csize(newFileSize), cint(1))
|
||||||
if newAddr == cast[pointer](MAP_FAILED):
|
if newAddr == cast[pointer](MAP_FAILED):
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
|
|
@ -427,7 +428,8 @@ iterator memSlices*(mfile: MemFile, delim='\l', eat='\r'): MemSlice {.inline.} =
|
||||||
ms.data = cast[pointer](cast[int](ending) +% 1) # skip delim
|
ms.data = cast[pointer](cast[int](ending) +% 1) # skip delim
|
||||||
remaining = mfile.size - (ms.data -! mfile.mem)
|
remaining = mfile.size - (ms.data -! mfile.mem)
|
||||||
|
|
||||||
iterator lines*(mfile: MemFile, buf: var TaintedString, delim='\l', eat='\r'): TaintedString {.inline.} =
|
iterator lines*(mfile: MemFile, buf: var TaintedString, delim = '\l',
|
||||||
|
eat = '\r'): TaintedString {.inline.} =
|
||||||
## Replace contents of passed buffer with each new line, like
|
## Replace contents of passed buffer with each new line, like
|
||||||
## `readLine(File) <system.html#readLine,File,TaintedString>`_.
|
## `readLine(File) <system.html#readLine,File,TaintedString>`_.
|
||||||
## `delim`, `eat`, and delimiting logic is exactly as for
|
## `delim`, `eat`, and delimiting logic is exactly as for
|
||||||
|
|
@ -507,8 +509,8 @@ proc mmsWriteData(s: Stream, buffer: pointer, bufLen: int) =
|
||||||
moveMem(cast[pointer](p), buffer, bufLen)
|
moveMem(cast[pointer](p), buffer, bufLen)
|
||||||
inc(MemMapFileStream(s).pos, bufLen)
|
inc(MemMapFileStream(s).pos, bufLen)
|
||||||
|
|
||||||
proc newMemMapFileStream*(filename: string, mode: FileMode = fmRead, fileSize: int = -1):
|
proc newMemMapFileStream*(filename: string, mode: FileMode = fmRead,
|
||||||
MemMapFileStream =
|
fileSize: int = -1): MemMapFileStream =
|
||||||
## creates a new stream from the file named `filename` with the mode `mode`.
|
## creates a new stream from the file named `filename` with the mode `mode`.
|
||||||
## Raises ## `OSError` if the file cannot be opened. See the `system
|
## Raises ## `OSError` if the file cannot be opened. See the `system
|
||||||
## <system.html>`_ module for a list of available FileMode enums.
|
## <system.html>`_ module for a list of available FileMode enums.
|
||||||
|
|
|
||||||
|
|
@ -71,16 +71,11 @@ const poDemon* {.deprecated.} = poDaemon ## Nim versions before 0.20
|
||||||
## and this is needed just for backward compatibility.
|
## and this is needed just for backward compatibility.
|
||||||
|
|
||||||
|
|
||||||
proc execProcess*(command: string,
|
proc execProcess*(command: string, workingDir: string = "",
|
||||||
workingDir: string = "",
|
args: openArray[string] = [], env: StringTableRef = nil,
|
||||||
args: openArray[string] = [],
|
options: set[ProcessOption] = {poStdErrToStdOut, poUsePath, poEvalCommand}):
|
||||||
env: StringTableRef = nil,
|
TaintedString {.rtl, extern: "nosp$1",
|
||||||
options: set[ProcessOption] = {poStdErrToStdOut,
|
tags: [ExecIOEffect, ReadIOEffect, RootEffect].}
|
||||||
poUsePath,
|
|
||||||
poEvalCommand}): TaintedString {.
|
|
||||||
rtl, extern: "nosp$1",
|
|
||||||
tags: [ExecIOEffect, ReadIOEffect,
|
|
||||||
RootEffect].}
|
|
||||||
## A convenience procedure that executes ``command`` with ``startProcess``
|
## A convenience procedure that executes ``command`` with ``startProcess``
|
||||||
## and returns its output as a string.
|
## and returns its output as a string.
|
||||||
##
|
##
|
||||||
|
|
@ -102,8 +97,8 @@ proc execProcess*(command: string,
|
||||||
## # Note: outp may have an interleave of text from the nim compile
|
## # Note: outp may have an interleave of text from the nim compile
|
||||||
## # and any output from mytestfile when it runs
|
## # and any output from mytestfile when it runs
|
||||||
|
|
||||||
proc execCmd*(command: string): int {.rtl, extern: "nosp$1", tags: [ExecIOEffect,
|
proc execCmd*(command: string): int {.rtl, extern: "nosp$1",
|
||||||
ReadIOEffect, RootEffect].}
|
tags: [ExecIOEffect, ReadIOEffect, RootEffect].}
|
||||||
## Executes ``command`` and returns its error code.
|
## Executes ``command`` and returns its error code.
|
||||||
##
|
##
|
||||||
## Standard input, output, error streams are inherited from the calling process.
|
## Standard input, output, error streams are inherited from the calling process.
|
||||||
|
|
@ -121,13 +116,11 @@ proc execCmd*(command: string): int {.rtl, extern: "nosp$1", tags: [ExecIOEffect
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
## let errC = execCmd("nim c -r mytestfile.nim")
|
## let errC = execCmd("nim c -r mytestfile.nim")
|
||||||
|
|
||||||
proc startProcess*(command: string,
|
proc startProcess*(command: string, workingDir: string = "",
|
||||||
workingDir: string = "",
|
args: openArray[string] = [], env: StringTableRef = nil,
|
||||||
args: openArray[string] = [],
|
|
||||||
env: StringTableRef = nil,
|
|
||||||
options: set[ProcessOption] = {poStdErrToStdOut}):
|
options: set[ProcessOption] = {poStdErrToStdOut}):
|
||||||
owned(Process) {.rtl, extern: "nosp$1", tags: [ExecIOEffect, ReadEnvEffect,
|
owned(Process) {.rtl, extern: "nosp$1",
|
||||||
RootEffect].}
|
tags: [ExecIOEffect, ReadEnvEffect, RootEffect].}
|
||||||
## Starts a process. `Command` is the executable file, `workingDir` is the
|
## Starts a process. `Command` is the executable file, `workingDir` is the
|
||||||
## process's working directory. If ``workingDir == ""`` the current directory
|
## process's working directory. If ``workingDir == ""`` the current directory
|
||||||
## is used (default). `args` are the command line arguments that are passed to the
|
## is used (default). `args` are the command line arguments that are passed to the
|
||||||
|
|
@ -303,11 +296,10 @@ proc countProcessors*(): int {.rtl, extern: "nosp$1".} =
|
||||||
result = cpuinfo.countProcessors()
|
result = cpuinfo.countProcessors()
|
||||||
|
|
||||||
proc execProcesses*(cmds: openArray[string],
|
proc execProcesses*(cmds: openArray[string],
|
||||||
options = {poStdErrToStdOut, poParentStreams},
|
options = {poStdErrToStdOut, poParentStreams}, n = countProcessors(),
|
||||||
n = countProcessors(),
|
|
||||||
beforeRunEvent: proc(idx: int) = nil,
|
beforeRunEvent: proc(idx: int) = nil,
|
||||||
afterRunEvent: proc(idx: int, p: Process) = nil): int
|
afterRunEvent: proc(idx: int, p: Process) = nil):
|
||||||
{.rtl, extern: "nosp$1",
|
int {.rtl, extern: "nosp$1",
|
||||||
tags: [ExecIOEffect, TimeEffect, ReadEnvEffect, RootEffect].} =
|
tags: [ExecIOEffect, TimeEffect, ReadEnvEffect, RootEffect].} =
|
||||||
## Executes the commands `cmds` in parallel.
|
## Executes the commands `cmds` in parallel.
|
||||||
## Creates `n` processes that execute in parallel.
|
## Creates `n` processes that execute in parallel.
|
||||||
|
|
@ -419,14 +411,14 @@ proc execProcesses*(cmds: openArray[string],
|
||||||
close(p)
|
close(p)
|
||||||
|
|
||||||
when not defined(useNimRtl):
|
when not defined(useNimRtl):
|
||||||
proc execProcess(command: string,
|
proc execProcess(command: string, workingDir: string = "",
|
||||||
workingDir: string = "",
|
args: openArray[string] = [], env: StringTableRef = nil,
|
||||||
args: openArray[string] = [],
|
options: set[ProcessOption] = {poStdErrToStdOut, poUsePath,
|
||||||
env: StringTableRef = nil,
|
poEvalCommand}):
|
||||||
options: set[ProcessOption] = {poStdErrToStdOut,
|
TaintedString =
|
||||||
poUsePath,
|
|
||||||
poEvalCommand}): TaintedString =
|
var p = startProcess(command, workingDir = workingDir, args = args,
|
||||||
var p = startProcess(command, workingDir=workingDir, args=args, env=env, options=options)
|
env = env, options = options)
|
||||||
var outp = outputStream(p)
|
var outp = outputStream(p)
|
||||||
result = TaintedString""
|
result = TaintedString""
|
||||||
var line = newStringOfCap(120).TaintedString
|
var line = newStringOfCap(120).TaintedString
|
||||||
|
|
@ -503,14 +495,12 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
# O_RDONLY {.importc: "_O_RDONLY", header: "<fcntl.h>".}: int
|
# O_RDONLY {.importc: "_O_RDONLY", header: "<fcntl.h>".}: int
|
||||||
proc myDup(h: Handle; inherit: WINBOOL = 1): Handle =
|
proc myDup(h: Handle; inherit: WINBOOL = 1): Handle =
|
||||||
let thisProc = getCurrentProcess()
|
let thisProc = getCurrentProcess()
|
||||||
if duplicateHandle(thisProc, h,
|
if duplicateHandle(thisProc, h, thisProc, addr result, 0, inherit,
|
||||||
thisProc, addr result,0,inherit,
|
|
||||||
DUPLICATE_SAME_ACCESS) == 0:
|
DUPLICATE_SAME_ACCESS) == 0:
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
|
|
||||||
proc createAllPipeHandles(si: var STARTUPINFO;
|
proc createAllPipeHandles(si: var STARTUPINFO;
|
||||||
stdin, stdout, stderr: var Handle;
|
stdin, stdout, stderr: var Handle; hash: int) =
|
||||||
hash: int) =
|
|
||||||
var sa: SECURITY_ATTRIBUTES
|
var sa: SECURITY_ATTRIBUTES
|
||||||
sa.nLength = sizeof(SECURITY_ATTRIBUTES).cint
|
sa.nLength = sizeof(SECURITY_ATTRIBUTES).cint
|
||||||
sa.lpSecurityDescriptor = nil
|
sa.lpSecurityDescriptor = nil
|
||||||
|
|
@ -569,11 +559,10 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
proc fileClose(h: Handle) {.inline.} =
|
proc fileClose(h: Handle) {.inline.} =
|
||||||
if h > 4: discard closeHandle(h)
|
if h > 4: discard closeHandle(h)
|
||||||
|
|
||||||
proc startProcess(command: string,
|
proc startProcess(command: string, workingDir: string = "",
|
||||||
workingDir: string = "",
|
args: openArray[string] = [], env: StringTableRef = nil,
|
||||||
args: openArray[string] = [],
|
options: set[ProcessOption] = {poStdErrToStdOut}):
|
||||||
env: StringTableRef = nil,
|
owned Process =
|
||||||
options: set[ProcessOption] = {poStdErrToStdOut}): owned Process =
|
|
||||||
var
|
var
|
||||||
si: STARTUPINFO
|
si: STARTUPINFO
|
||||||
procInfo: PROCESS_INFORMATION
|
procInfo: PROCESS_INFORMATION
|
||||||
|
|
@ -842,11 +831,10 @@ elif not defined(useNimRtl):
|
||||||
tags: [ExecIOEffect, ReadEnvEffect, ReadDirEffect, RootEffect], cdecl, gcsafe.}
|
tags: [ExecIOEffect, ReadEnvEffect, ReadDirEffect, RootEffect], cdecl, gcsafe.}
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
||||||
proc startProcess(command: string,
|
proc startProcess(command: string, workingDir: string = "",
|
||||||
workingDir: string = "",
|
args: openArray[string] = [], env: StringTableRef = nil,
|
||||||
args: openArray[string] = [],
|
options: set[ProcessOption] = {poStdErrToStdOut}):
|
||||||
env: StringTableRef = nil,
|
owned Process =
|
||||||
options: set[ProcessOption] = {poStdErrToStdOut}): owned Process =
|
|
||||||
var
|
var
|
||||||
pStdin, pStdout, pStderr: array[0..1, cint]
|
pStdin, pStdout, pStderr: array[0..1, cint]
|
||||||
new(result)
|
new(result)
|
||||||
|
|
@ -1066,7 +1054,7 @@ elif not defined(useNimRtl):
|
||||||
discard execve(data.sysCommand, data.sysArgs, data.sysEnv)
|
discard execve(data.sysCommand, data.sysArgs, data.sysEnv)
|
||||||
|
|
||||||
startProcessFail(data)
|
startProcessFail(data)
|
||||||
{.pop}
|
{.pop.}
|
||||||
|
|
||||||
proc close(p: Process) =
|
proc close(p: Process) =
|
||||||
if poParentStreams notin p.options:
|
if poParentStreams notin p.options:
|
||||||
|
|
|
||||||
|
|
@ -18,14 +18,15 @@ type
|
||||||
pcLinkToDir ## path refers to a symbolic link to a directory
|
pcLinkToDir ## path refers to a symbolic link to a directory
|
||||||
|
|
||||||
proc staticWalkDir(dir: string; relative: bool): seq[
|
proc staticWalkDir(dir: string; relative: bool): seq[
|
||||||
tuple[kind: PathComponent, path: string]] =
|
tuple[kind: PathComponent; path: string]] =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
iterator walkDir*(dir: string; relative=false): tuple[kind: PathComponent, path: string] =
|
iterator walkDir*(dir: string; relative = false): tuple[kind: PathComponent;
|
||||||
|
path: string] =
|
||||||
for k, v in items(staticWalkDir(dir, relative)):
|
for k, v in items(staticWalkDir(dir, relative)):
|
||||||
yield (k, v)
|
yield (k, v)
|
||||||
|
|
||||||
iterator walkDirRec*(dir: string, filter={pcFile, pcDir}): string =
|
iterator walkDirRec*(dir: string; filter = {pcFile, pcDir}): string =
|
||||||
var stack = @[dir]
|
var stack = @[dir]
|
||||||
while stack.len > 0:
|
while stack.len > 0:
|
||||||
for k, p in walkDir(stack.pop()):
|
for k, p in walkDir(stack.pop()):
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,8 @@ proc isDotDot(x: string; bounds: (int, int)): bool =
|
||||||
proc isSlash(x: string; bounds: (int, int)): bool =
|
proc isSlash(x: string; bounds: (int, int)): bool =
|
||||||
bounds[1] == bounds[0] and x[bounds[0]] in {DirSep, AltSep}
|
bounds[1] == bounds[0] and x[bounds[0]] in {DirSep, AltSep}
|
||||||
|
|
||||||
proc addNormalizePath*(x: string; result: var string; state: var int; dirSep = DirSep) =
|
proc addNormalizePath*(x: string; result: var string; state: var int;
|
||||||
|
dirSep = DirSep) =
|
||||||
## Low level proc. Undocumented.
|
## Low level proc. Undocumented.
|
||||||
|
|
||||||
# state: 0th bit set if isAbsolute path. Other bits count
|
# state: 0th bit set if isAbsolute path. Other bits count
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ when defined(windows):
|
||||||
VectoredHandler = proc (p: PEXCEPTION_POINTERS): LONG {.stdcall.}
|
VectoredHandler = proc (p: PEXCEPTION_POINTERS): LONG {.stdcall.}
|
||||||
proc addVectoredExceptionHandler(firstHandler: ULONG,
|
proc addVectoredExceptionHandler(firstHandler: ULONG,
|
||||||
handler: VectoredHandler): pointer {.
|
handler: VectoredHandler): pointer {.
|
||||||
importc: "AddVectoredExceptionHandler", stdcall, dynlib: "kernel32.dll"}
|
importc: "AddVectoredExceptionHandler", stdcall, dynlib: "kernel32.dll".}
|
||||||
|
|
||||||
{.push stackTrace: off.}
|
{.push stackTrace: off.}
|
||||||
proc segfaultHandler(p: PEXCEPTION_POINTERS): LONG {.stdcall.} =
|
proc segfaultHandler(p: PEXCEPTION_POINTERS): LONG {.stdcall.} =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue