mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 05:50:30 +00:00
newruntime: progress
This commit is contained in:
@@ -72,10 +72,7 @@ proc unloadLib*(lib: LibHandle) {.gcsafe.}
|
||||
|
||||
proc raiseInvalidLibrary*(name: cstring) {.noinline, noreturn.} =
|
||||
## raises an `EInvalidLibrary` exception.
|
||||
var e: ref LibraryError
|
||||
new(e)
|
||||
e.msg = "could not find symbol: " & $name
|
||||
raise e
|
||||
raise newException(LibraryError, "could not find symbol: " & $name)
|
||||
|
||||
proc symAddr*(lib: LibHandle, name: cstring): pointer {.gcsafe.}
|
||||
## retrieves the address of a procedure/variable from `lib`. Returns nil
|
||||
|
||||
@@ -73,7 +73,7 @@ proc raiseOSError*(errorCode: OSErrorCode; additionalInfo = "") {.noinline.} =
|
||||
## See also:
|
||||
## * `osErrorMsg proc <#osErrorMsg,OSErrorCode>`_
|
||||
## * `osLastError proc <#osLastError>`_
|
||||
var e: ref OSError; new(e)
|
||||
var e: owned(ref OSError); new(e)
|
||||
e.errorCode = errorCode.int32
|
||||
e.msg = osErrorMsg(errorCode)
|
||||
if additionalInfo.len > 0:
|
||||
|
||||
@@ -126,7 +126,7 @@ proc startProcess*(command: string,
|
||||
args: openArray[string] = [],
|
||||
env: StringTableRef = nil,
|
||||
options: set[ProcessOption] = {poStdErrToStdOut}):
|
||||
Process {.rtl, extern: "nosp$1", tags: [ExecIOEffect, ReadEnvEffect,
|
||||
owned Process {.rtl, extern: "nosp$1", tags: [ExecIOEffect, ReadEnvEffect,
|
||||
RootEffect].}
|
||||
## Starts a process. `Command` is the executable file, `workingDir` is the
|
||||
## process's working directory. If ``workingDir == ""`` the current directory
|
||||
@@ -470,7 +470,7 @@ when defined(Windows) and not defined(useNimRtl):
|
||||
addr bytesWritten, nil)
|
||||
if a == 0: raiseOSError(osLastError())
|
||||
|
||||
proc newFileHandleStream(handle: Handle): FileHandleStream =
|
||||
proc newFileHandleStream(handle: Handle): owned FileHandleStream =
|
||||
new(result)
|
||||
result.handle = handle
|
||||
result.closeImpl = hsClose
|
||||
@@ -573,7 +573,7 @@ when defined(Windows) and not defined(useNimRtl):
|
||||
workingDir: string = "",
|
||||
args: openArray[string] = [],
|
||||
env: StringTableRef = nil,
|
||||
options: set[ProcessOption] = {poStdErrToStdOut}): Process =
|
||||
options: set[ProcessOption] = {poStdErrToStdOut}): owned Process =
|
||||
var
|
||||
si: STARTUPINFO
|
||||
procInfo: PROCESS_INFORMATION
|
||||
@@ -840,7 +840,7 @@ elif not defined(useNimRtl):
|
||||
workingDir: string = "",
|
||||
args: openArray[string] = [],
|
||||
env: StringTableRef = nil,
|
||||
options: set[ProcessOption] = {poStdErrToStdOut}): Process =
|
||||
options: set[ProcessOption] = {poStdErrToStdOut}): owned Process =
|
||||
var
|
||||
pStdin, pStdout, pStderr: array[0..1, cint]
|
||||
new(result)
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
include "system/inclrtl"
|
||||
|
||||
proc newEIO(msg: string): ref IOError =
|
||||
proc newEIO(msg: string): owned(ref IOError) =
|
||||
new(result)
|
||||
result.msg = msg
|
||||
|
||||
@@ -403,7 +403,7 @@ when not defined(js):
|
||||
else:
|
||||
s.data = nil
|
||||
|
||||
proc newStringStream*(s: string = ""): StringStream =
|
||||
proc newStringStream*(s: string = ""): owned StringStream =
|
||||
## creates a new stream from the string `s`.
|
||||
new(result)
|
||||
result.data = s
|
||||
@@ -446,7 +446,7 @@ when not defined(js):
|
||||
if writeBuffer(FileStream(s).f, buffer, bufLen) != bufLen:
|
||||
raise newEIO("cannot write to stream")
|
||||
|
||||
proc newFileStream*(f: File): FileStream =
|
||||
proc newFileStream*(f: File): owned FileStream =
|
||||
## creates a new stream from the file `f`.
|
||||
new(result)
|
||||
result.f = f
|
||||
@@ -460,7 +460,7 @@ when not defined(js):
|
||||
result.writeDataImpl = fsWriteData
|
||||
result.flushImpl = fsFlush
|
||||
|
||||
proc newFileStream*(filename: string, mode: FileMode = fmRead, bufSize: int = -1): FileStream =
|
||||
proc newFileStream*(filename: string, mode: FileMode = fmRead, bufSize: int = -1): owned FileStream =
|
||||
## creates a new stream from the file named `filename` with the mode `mode`.
|
||||
## If the file cannot be opened, nil is returned. See the `system
|
||||
## <system.html>`_ module for a list of available FileMode enums.
|
||||
@@ -469,7 +469,7 @@ when not defined(js):
|
||||
var f: File
|
||||
if open(f, filename, mode, bufSize): result = newFileStream(f)
|
||||
|
||||
proc openFileStream*(filename: string, mode: FileMode = fmRead, bufSize: int = -1): FileStream =
|
||||
proc openFileStream*(filename: string, mode: FileMode = fmRead, bufSize: int = -1): owned FileStream =
|
||||
## creates a new stream from the file named `filename` with the mode `mode`.
|
||||
## If the file cannot be opened, an IO exception is raised.
|
||||
var f: File
|
||||
@@ -522,7 +522,7 @@ else:
|
||||
raise newEIO("cannot write to stream")
|
||||
inc(s.pos, bufLen)
|
||||
|
||||
proc newFileHandleStream*(handle: FileHandle): FileHandleStream =
|
||||
proc newFileHandleStream*(handle: FileHandle): owned FileHandleStream =
|
||||
new(result)
|
||||
result.handle = handle
|
||||
result.pos = 0
|
||||
@@ -535,7 +535,7 @@ else:
|
||||
result.writeData = hsWriteData
|
||||
|
||||
proc newFileHandleStream*(filename: string,
|
||||
mode: FileMode): FileHandleStream =
|
||||
mode: FileMode): owned FileHandleStream =
|
||||
when defined(windows):
|
||||
discard
|
||||
else:
|
||||
|
||||
@@ -247,7 +247,7 @@ proc `[]=`*(t: StringTableRef, key, val: string) {.
|
||||
rawInsert(t, t.data, key, val)
|
||||
inc(t.counter)
|
||||
|
||||
proc newStringTable*(mode: StringTableMode): StringTableRef {.
|
||||
proc newStringTable*(mode: StringTableMode): owned StringTableRef {.
|
||||
rtlFunc, extern: "nst$1".} =
|
||||
## Creates a new empty string table.
|
||||
##
|
||||
@@ -260,7 +260,7 @@ proc newStringTable*(mode: StringTableMode): StringTableRef {.
|
||||
newSeq(result.data, startSize)
|
||||
|
||||
proc newStringTable*(keyValuePairs: varargs[string],
|
||||
mode: StringTableMode): StringTableRef {.
|
||||
mode: StringTableMode): owned StringTableRef {.
|
||||
rtlFunc, extern: "nst$1WithPairs".} =
|
||||
## Creates a new string table with given `key, value` string pairs.
|
||||
##
|
||||
@@ -290,10 +290,7 @@ proc newStringTable*(keyValuePairs: varargs[tuple[key, val: string]],
|
||||
for key, val in items(keyValuePairs): result[key] = val
|
||||
|
||||
proc raiseFormatException(s: string) =
|
||||
var e: ref ValueError
|
||||
new(e)
|
||||
e.msg = "format string: key not found: " & s
|
||||
raise e
|
||||
raise newException(ValueError, "format string: key not found: " & s)
|
||||
|
||||
proc getValue(t: StringTableRef, flags: set[FormatFlag], key: string): string =
|
||||
if hasKey(t, key): return t.getOrDefault(key)
|
||||
|
||||
@@ -959,7 +959,7 @@ proc newTimezone*(
|
||||
{.tags: [], raises: [], benign.},
|
||||
zonedTimeFromAdjTimeImpl: proc (adjTime: Time): ZonedTime
|
||||
{.tags: [], raises: [], benign.}
|
||||
): Timezone =
|
||||
): owned Timezone =
|
||||
## Create a new ``Timezone``.
|
||||
##
|
||||
## ``zonedTimeFromTimeImpl`` and ``zonedTimeFromAdjTimeImpl`` is used
|
||||
|
||||
@@ -1638,6 +1638,8 @@ when defined(nimV2) and not defined(nimscript):
|
||||
new(r)
|
||||
return r
|
||||
else:
|
||||
template owned*(t: typeDesc): typedesc = t
|
||||
|
||||
proc new*[T](a: var ref T) {.magic: "New", noSideEffect.}
|
||||
## Creates a new object of type ``T`` and returns a safe (traced)
|
||||
## reference to it in ``a``.
|
||||
|
||||
Reference in New Issue
Block a user