big rename

This commit is contained in:
Araq 2014-08-28 00:24:52 +02:00
commit df172806ea
12 changed files with 108 additions and 103 deletions

View file

@ -1,6 +1,6 @@
# #
# #
# The Nimrod Compiler # The Nim Compiler
# (c) Copyright 2014 Andreas Rumpf # (c) Copyright 2014 Andreas Rumpf
# #
# See the file "copying.txt", included in this # See the file "copying.txt", included in this

View file

@ -29,7 +29,7 @@
{.deadCodeElim:on.} {.deadCodeElim:on.}
from times import TTime from times import Time
const const
hasSpawnH = not defined(haiku) # should exist for every Posix system nowadays hasSpawnH = not defined(haiku) # should exist for every Posix system nowadays
@ -83,8 +83,11 @@ else:
## A type representing a directory stream. ## A type representing a directory stream.
type type
TSocketHandle* = distinct cint # The type used to represent socket descriptors SocketHandle* = distinct cint # The type used to represent socket descriptors
{.deprecated: [TSocketHandle: SocketHandle].}
type
Tdirent* {.importc: "struct dirent", Tdirent* {.importc: "struct dirent",
header: "<dirent.h>", final, pure.} = object ## dirent_t struct header: "<dirent.h>", final, pure.} = object ## dirent_t struct
d_ino*: Tino ## File serial number. d_ino*: Tino ## File serial number.

View file

@ -149,11 +149,11 @@ proc contains*[A](s: TSet[A], key: A): bool =
var index = rawGet(s, key) var index = rawGet(s, key)
result = index >= 0 result = index >= 0
proc rawInsert[A](s: var TSet[A], data: var TKeyValuePairSeq[A], key: A) = proc rawInsert[A](s: var TSet[A], data: var KeyValuePairSeq[A], key: A) =
rawInsertImpl() rawInsertImpl()
proc enlarge[A](s: var TSet[A]) = proc enlarge[A](s: var TSet[A]) =
var n: TKeyValuePairSeq[A] var n: KeyValuePairSeq[A]
newSeq(n, len(s.data) * growthFactor) newSeq(n, len(s.data) * growthFactor)
for i in countup(0, high(s.data)): for i in countup(0, high(s.data)):
if s.data[i].slot == seFilled: rawInsert(s, n, s.data[i].key) if s.data[i].slot == seFilled: rawInsert(s, n, s.data[i].key)
@ -500,7 +500,7 @@ type
## ##
## Use `init() <#init,OrderedSet[A],int>`_ or `initOrderedSet[type]() ## Use `init() <#init,OrderedSet[A],int>`_ or `initOrderedSet[type]()
## <#initOrderedSet>`_ before calling other procs on it. ## <#initOrderedSet>`_ before calling other procs on it.
data: TOrderedKeyValuePairSeq[A] data: OrderedKeyValuePairSeq[A]
counter, first, last: int counter, first, last: int
{.deprecated: [TOrderedSet: OrderedSet].} {.deprecated: [TOrderedSet: OrderedSet].}
@ -588,7 +588,7 @@ proc contains*[A](s: TOrderedSet[A], key: A): bool =
result = index >= 0 result = index >= 0
proc rawInsert[A](s: var TOrderedSet[A], proc rawInsert[A](s: var TOrderedSet[A],
data: var TOrderedKeyValuePairSeq[A], key: A) = data: var OrderedKeyValuePairSeq[A], key: A) =
rawInsertImpl() rawInsertImpl()
data[h].next = -1 data[h].next = -1
if s.first < 0: s.first = h if s.first < 0: s.first = h
@ -596,7 +596,7 @@ proc rawInsert[A](s: var TOrderedSet[A],
s.last = h s.last = h
proc enlarge[A](s: var TOrderedSet[A]) = proc enlarge[A](s: var TOrderedSet[A]) =
var n: TOrderedKeyValuePairSeq[A] var n: OrderedKeyValuePairSeq[A]
newSeq(n, len(s.data) * growthFactor) newSeq(n, len(s.data) * growthFactor)
var h = s.first var h = s.first
s.first = -1 s.first = -1

View file

@ -422,7 +422,7 @@ proc hasKey*[A, B](t: TOrderedTable[A, B], key: A): bool =
result = rawGet(t, key) >= 0 result = rawGet(t, key) >= 0
proc rawInsert[A, B](t: var TOrderedTable[A, B], proc rawInsert[A, B](t: var TOrderedTable[A, B],
data: var TOrderedKeyValuePairSeq[A, B], data: var OrderedKeyValuePairSeq[A, B],
key: A, val: B) = key: A, val: B) =
rawInsertImpl() rawInsertImpl()
data[h].next = -1 data[h].next = -1
@ -431,7 +431,7 @@ proc rawInsert[A, B](t: var TOrderedTable[A, B],
t.last = h t.last = h
proc enlarge[A, B](t: var TOrderedTable[A, B]) = proc enlarge[A, B](t: var TOrderedTable[A, B]) =
var n: TOrderedKeyValuePairSeq[A, B] var n: OrderedKeyValuePairSeq[A, B]
newSeq(n, len(t.data) * growthFactor) newSeq(n, len(t.data) * growthFactor)
var h = t.first var h = t.first
t.first = -1 t.first = -1

View file

@ -25,8 +25,8 @@ const
# #
type type
TBaseLexer* = object of RootObj ## the base lexer. Inherit your lexer from BaseLexer* = object of RootObj ## the base lexer. Inherit your lexer from
## this object. ## this object.
bufpos*: int ## the current position within the buffer bufpos*: int ## the current position within the buffer
buf*: cstring ## the buffer itself buf*: cstring ## the buffer itself
bufLen*: int ## length of buffer in characters bufLen*: int ## length of buffer in characters

View file

@ -48,7 +48,7 @@ proc mapMem*(m: var MemFile, mode: FileMode = fmRead,
if mappedSize == -1: 0 else: mappedSize, if mappedSize == -1: 0 else: mappedSize,
nil) nil)
if result == nil: if result == nil:
osError(osLastError()) raiseOSError(osLastError())
else: else:
assert mappedSize > 0 assert mappedSize > 0
result = mmap( result = mmap(
@ -58,7 +58,7 @@ proc mapMem*(m: var MemFile, mode: FileMode = fmRead,
if readonly: (MAP_PRIVATE or MAP_POPULATE) else: (MAP_SHARED or MAP_POPULATE), if readonly: (MAP_PRIVATE or MAP_POPULATE) else: (MAP_SHARED or MAP_POPULATE),
m.handle, offset) m.handle, offset)
if result == cast[pointer](MAP_FAILED): if result == cast[pointer](MAP_FAILED):
osError(osLastError()) raiseOSError(osLastError())
proc unmapMem*(f: var MemFile, p: pointer, size: int) = proc unmapMem*(f: var MemFile, p: pointer, size: int) =

View file

@ -243,7 +243,7 @@ proc osErrorMsg*(errorCode: OSErrorCode): string =
## message. ## message.
result = "" result = ""
when defined(Windows): when defined(Windows):
if errorCode != TOSErrorCode(0'i32): if errorCode != OSErrorCode(0'i32):
when useWinUnicode: when useWinUnicode:
var msgbuf: WideCString var msgbuf: WideCString
if formatMessageW(0x00000100 or 0x00001000 or 0x00000200, if formatMessageW(0x00000100 or 0x00001000 or 0x00000200,
@ -291,7 +291,7 @@ proc osLastError*(): OSErrorCode =
## immediately after an OS call fails. On POSIX systems this is not a problem. ## immediately after an OS call fails. On POSIX systems this is not a problem.
when defined(windows): when defined(windows):
result = TOSErrorCode(getLastError()) result = OSErrorCode(getLastError())
else: else:
result = OSErrorCode(errno) result = OSErrorCode(errno)
{.pop.} {.pop.}
@ -429,44 +429,44 @@ proc dirExists*(dir: string): bool {.inline.} =
## Synonym for existsDir ## Synonym for existsDir
existsDir(dir) existsDir(dir)
proc getLastModificationTime*(file: string): TTime {.rtl, extern: "nos$1".} = proc getLastModificationTime*(file: string): Time {.rtl, extern: "nos$1".} =
## Returns the `file`'s last modification time. ## Returns the `file`'s last modification time.
when defined(posix): when defined(posix):
var res: TStat var res: TStat
if stat(file, res) < 0'i32: osError(osLastError()) if stat(file, res) < 0'i32: raiseOSError(osLastError())
return res.st_mtime return res.st_mtime
else: else:
var f: TWIN32_FIND_DATA var f: TWIN32_FIND_DATA
var h = findFirstFile(file, f) var h = findFirstFile(file, f)
if h == -1'i32: osError(osLastError()) if h == -1'i32: raiseOSError(osLastError())
result = winTimeToUnixTime(rdFileTime(f.ftLastWriteTime)) result = winTimeToUnixTime(rdFileTime(f.ftLastWriteTime))
findClose(h) findClose(h)
proc getLastAccessTime*(file: string): TTime {.rtl, extern: "nos$1".} = proc getLastAccessTime*(file: string): Time {.rtl, extern: "nos$1".} =
## Returns the `file`'s last read or write access time. ## Returns the `file`'s last read or write access time.
when defined(posix): when defined(posix):
var res: TStat var res: TStat
if stat(file, res) < 0'i32: osError(osLastError()) if stat(file, res) < 0'i32: raiseOSError(osLastError())
return res.st_atime return res.st_atime
else: else:
var f: TWIN32_FIND_DATA var f: TWIN32_FIND_DATA
var h = findFirstFile(file, f) var h = findFirstFile(file, f)
if h == -1'i32: osError(osLastError()) if h == -1'i32: raiseOSError(osLastError())
result = winTimeToUnixTime(rdFileTime(f.ftLastAccessTime)) result = winTimeToUnixTime(rdFileTime(f.ftLastAccessTime))
findClose(h) findClose(h)
proc getCreationTime*(file: string): TTime {.rtl, extern: "nos$1".} = proc getCreationTime*(file: string): Time {.rtl, extern: "nos$1".} =
## Returns the `file`'s creation time. ## Returns the `file`'s creation time.
## Note that under posix OS's, the returned time may actually be the time at ## Note that under posix OS's, the returned time may actually be the time at
## which the file's attribute's were last modified. ## which the file's attribute's were last modified.
when defined(posix): when defined(posix):
var res: TStat var res: TStat
if stat(file, res) < 0'i32: osError(osLastError()) if stat(file, res) < 0'i32: raiseOSError(osLastError())
return res.st_ctime return res.st_ctime
else: else:
var f: TWIN32_FIND_DATA var f: TWIN32_FIND_DATA
var h = findFirstFile(file, f) var h = findFirstFile(file, f)
if h == -1'i32: osError(osLastError()) if h == -1'i32: raiseOSError(osLastError())
result = winTimeToUnixTime(rdFileTime(f.ftCreationTime)) result = winTimeToUnixTime(rdFileTime(f.ftCreationTime))
findClose(h) findClose(h)
@ -482,19 +482,19 @@ proc getCurrentDir*(): string {.rtl, extern: "nos$1", tags: [].} =
when useWinUnicode: when useWinUnicode:
var res = newWideCString("", bufsize) var res = newWideCString("", bufsize)
var L = getCurrentDirectoryW(bufsize, res) var L = getCurrentDirectoryW(bufsize, res)
if L == 0'i32: osError(osLastError()) if L == 0'i32: raiseOSError(osLastError())
result = res$L result = res$L
else: else:
result = newString(bufsize) result = newString(bufsize)
var L = getCurrentDirectoryA(bufsize, result) var L = getCurrentDirectoryA(bufsize, result)
if L == 0'i32: osError(osLastError()) if L == 0'i32: raiseOSError(osLastError())
setLen(result, L) setLen(result, L)
else: else:
result = newString(bufsize) result = newString(bufsize)
if getcwd(result, bufsize) != nil: if getcwd(result, bufsize) != nil:
setLen(result, c_strlen(result)) setLen(result, c_strlen(result))
else: else:
osError(osLastError()) raiseOSError(osLastError())
proc setCurrentDir*(newDir: string) {.inline, tags: [].} = proc setCurrentDir*(newDir: string) {.inline, tags: [].} =
## Sets the `current working directory`:idx:; `EOS` is raised if ## Sets the `current working directory`:idx:; `EOS` is raised if
@ -502,11 +502,11 @@ proc setCurrentDir*(newDir: string) {.inline, tags: [].} =
when defined(Windows): when defined(Windows):
when useWinUnicode: when useWinUnicode:
if setCurrentDirectoryW(newWideCString(newDir)) == 0'i32: if setCurrentDirectoryW(newWideCString(newDir)) == 0'i32:
osError(osLastError()) raiseOSError(osLastError())
else: else:
if setCurrentDirectoryA(newDir) == 0'i32: osError(osLastError()) if setCurrentDirectoryA(newDir) == 0'i32: raiseOSError(osLastError())
else: else:
if chdir(newDir) != 0'i32: osError(osLastError()) if chdir(newDir) != 0'i32: raiseOSError(osLastError())
proc joinPath*(head, tail: string): string {. proc joinPath*(head, tail: string): string {.
noSideEffect, rtl, extern: "nos$1".} = noSideEffect, rtl, extern: "nos$1".} =
@ -718,19 +718,19 @@ proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
var res = newWideCString("", bufsize div 2) var res = newWideCString("", bufsize div 2)
var L = getFullPathNameW(newWideCString(filename), bufsize, res, unused) var L = getFullPathNameW(newWideCString(filename), bufsize, res, unused)
if L <= 0'i32 or L >= bufsize: if L <= 0'i32 or L >= bufsize:
osError(osLastError()) raiseOSError(osLastError())
result = res$L result = res$L
else: else:
var unused: cstring var unused: cstring
result = newString(bufsize) result = newString(bufsize)
var L = getFullPathNameA(filename, bufsize, result, unused) var L = getFullPathNameA(filename, bufsize, result, unused)
if L <= 0'i32 or L >= bufsize: osError(osLastError()) if L <= 0'i32 or L >= bufsize: raiseOSError(osLastError())
setLen(result, L) setLen(result, L)
else: else:
# careful, realpath needs to take an allocated buffer according to Posix: # careful, realpath needs to take an allocated buffer according to Posix:
result = newString(pathMax) result = newString(pathMax)
var r = realpath(filename, result) var r = realpath(filename, result)
if r.isNil: osError(osLastError()) if r.isNil: raiseOSError(osLastError())
setLen(result, c_strlen(result)) setLen(result, c_strlen(result))
proc changeFileExt*(filename, ext: string): string {. proc changeFileExt*(filename, ext: string): string {.
@ -820,7 +820,7 @@ proc sameFile*(path1, path2: string): bool {.rtl, extern: "nos$1",
var f1 = openHandle(path1) var f1 = openHandle(path1)
var f2 = openHandle(path2) var f2 = openHandle(path2)
var lastErr: TOSErrorCode var lastErr: OSErrorCode
if f1 != INVALID_HANDLE_VALUE and f2 != INVALID_HANDLE_VALUE: if f1 != INVALID_HANDLE_VALUE and f2 != INVALID_HANDLE_VALUE:
var fi1, fi2: TBY_HANDLE_FILE_INFORMATION var fi1, fi2: TBY_HANDLE_FILE_INFORMATION
@ -839,11 +839,11 @@ proc sameFile*(path1, path2: string): bool {.rtl, extern: "nos$1",
discard closeHandle(f1) discard closeHandle(f1)
discard closeHandle(f2) discard closeHandle(f2)
if not success: osError(lastErr) if not success: raiseOSError(lastErr)
else: else:
var a, b: TStat var a, b: TStat
if stat(path1, a) < 0'i32 or stat(path2, b) < 0'i32: if stat(path1, a) < 0'i32 or stat(path2, b) < 0'i32:
osError(osLastError()) raiseOSError(osLastError())
else: else:
result = a.st_dev == b.st_dev and a.st_ino == b.st_ino result = a.st_dev == b.st_dev and a.st_ino == b.st_ino
@ -897,7 +897,7 @@ proc getFilePermissions*(filename: string): set[TFilePermission] {.
## permission is available in any case. ## permission is available in any case.
when defined(posix): when defined(posix):
var a: TStat var a: TStat
if stat(filename, a) < 0'i32: osError(osLastError()) if stat(filename, a) < 0'i32: raiseOSError(osLastError())
result = {} result = {}
if (a.st_mode and S_IRUSR) != 0'i32: result.incl(fpUserRead) if (a.st_mode and S_IRUSR) != 0'i32: result.incl(fpUserRead)
if (a.st_mode and S_IWUSR) != 0'i32: result.incl(fpUserWrite) if (a.st_mode and S_IWUSR) != 0'i32: result.incl(fpUserWrite)
@ -915,7 +915,7 @@ proc getFilePermissions*(filename: string): set[TFilePermission] {.
wrapUnary(res, getFileAttributesW, filename) wrapUnary(res, getFileAttributesW, filename)
else: else:
var res = getFileAttributesA(filename) var res = getFileAttributesA(filename)
if res == -1'i32: osError(osLastError()) if res == -1'i32: raiseOSError(osLastError())
if (res and FILE_ATTRIBUTE_READONLY) != 0'i32: if (res and FILE_ATTRIBUTE_READONLY) != 0'i32:
result = {fpUserExec, fpUserRead, fpGroupExec, fpGroupRead, result = {fpUserExec, fpUserRead, fpGroupExec, fpGroupRead,
fpOthersExec, fpOthersRead} fpOthersExec, fpOthersRead}
@ -941,13 +941,13 @@ proc setFilePermissions*(filename: string, permissions: set[TFilePermission]) {.
if fpOthersWrite in permissions: p = p or S_IWOTH if fpOthersWrite in permissions: p = p or S_IWOTH
if fpOthersExec in permissions: p = p or S_IXOTH if fpOthersExec in permissions: p = p or S_IXOTH
if chmod(filename, p) != 0: osError(osLastError()) if chmod(filename, p) != 0: raiseOSError(osLastError())
else: else:
when useWinUnicode: when useWinUnicode:
wrapUnary(res, getFileAttributesW, filename) wrapUnary(res, getFileAttributesW, filename)
else: else:
var res = getFileAttributesA(filename) var res = getFileAttributesA(filename)
if res == -1'i32: osError(osLastError()) if res == -1'i32: raiseOSError(osLastError())
if fpUserWrite in permissions: if fpUserWrite in permissions:
res = res and not FILE_ATTRIBUTE_READONLY res = res and not FILE_ATTRIBUTE_READONLY
else: else:
@ -956,7 +956,7 @@ proc setFilePermissions*(filename: string, permissions: set[TFilePermission]) {.
wrapBinary(res2, setFileAttributesW, filename, res) wrapBinary(res2, setFileAttributesW, filename, res)
else: else:
var res2 = setFileAttributesA(filename, res) var res2 = setFileAttributesA(filename, res)
if res2 == - 1'i32: osError(osLastError()) if res2 == - 1'i32: raiseOSError(osLastError())
proc copyFile*(source, dest: string) {.rtl, extern: "nos$1", proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
tags: [ReadIOEffect, WriteIOEffect].} = tags: [ReadIOEffect, WriteIOEffect].} =
@ -974,17 +974,17 @@ proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
when useWinUnicode: when useWinUnicode:
let s = newWideCString(source) let s = newWideCString(source)
let d = newWideCString(dest) let d = newWideCString(dest)
if copyFileW(s, d, 0'i32) == 0'i32: osError(osLastError()) if copyFileW(s, d, 0'i32) == 0'i32: raiseOSError(osLastError())
else: else:
if copyFileA(source, dest, 0'i32) == 0'i32: osError(osLastError()) if copyFileA(source, dest, 0'i32) == 0'i32: raiseOSError(osLastError())
else: else:
# generic version of copyFile which works for any platform: # generic version of copyFile which works for any platform:
const bufSize = 8000 # better for memory manager const bufSize = 8000 # better for memory manager
var d, s: File var d, s: File
if not open(s, source): osError(osLastError()) if not open(s, source): raiseOSError(osLastError())
if not open(d, dest, fmWrite): if not open(d, dest, fmWrite):
close(s) close(s)
osError(osLastError()) raiseOSError(osLastError())
var buf = alloc(bufSize) var buf = alloc(bufSize)
while true: while true:
var bytesread = readBuffer(s, buf, bufSize) var bytesread = readBuffer(s, buf, bufSize)
@ -994,7 +994,7 @@ proc copyFile*(source, dest: string) {.rtl, extern: "nos$1",
dealloc(buf) dealloc(buf)
close(s) close(s)
close(d) close(d)
osError(osLastError()) raiseOSError(osLastError())
if bytesread != bufSize: break if bytesread != bufSize: break
dealloc(buf) dealloc(buf)
close(s) close(s)
@ -1034,9 +1034,9 @@ proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [WriteDirEffect].}
if deleteFile(f) == 0: if deleteFile(f) == 0:
if getLastError() == ERROR_ACCESS_DENIED: if getLastError() == ERROR_ACCESS_DENIED:
if setFileAttributes(f, FILE_ATTRIBUTE_NORMAL) == 0: if setFileAttributes(f, FILE_ATTRIBUTE_NORMAL) == 0:
osError(osLastError()) raiseOSError(osLastError())
if deleteFile(f) == 0: if deleteFile(f) == 0:
osError(osLastError()) raiseOSError(osLastError())
else: else:
if c_remove(file) != 0'i32 and errno != ENOENT: if c_remove(file) != 0'i32 and errno != ENOENT:
raise newException(OSError, $strerror(errno)) raise newException(OSError, $strerror(errno))
@ -1084,7 +1084,7 @@ when defined(windows):
while true: while true:
var eend = strEnd(e) var eend = strEnd(e)
add(environment, $e) add(environment, $e)
e = cast[WideCString](cast[TAddress](eend)+2) e = cast[WideCString](cast[ByteAddress](eend)+2)
if eend[1].int == 0: break if eend[1].int == 0: break
discard freeEnvironmentStringsW(env) discard freeEnvironmentStringsW(env)
else: else:
@ -1095,7 +1095,7 @@ when defined(windows):
while true: while true:
var eend = strEnd(e) var eend = strEnd(e)
add(environment, $e) add(environment, $e)
e = cast[cstring](cast[TAddress](eend)+1) e = cast[cstring](cast[ByteAddress](eend)+1)
if eend[1] == '\0': break if eend[1] == '\0': break
discard freeEnvironmentStringsA(env) discard freeEnvironmentStringsA(env)
envComputed = true envComputed = true
@ -1174,14 +1174,14 @@ proc putEnv*(key, val: string) {.tags: [WriteEnvEffect].} =
indx = high(environment) indx = high(environment)
when defined(unix): when defined(unix):
if c_putenv(environment[indx]) != 0'i32: if c_putenv(environment[indx]) != 0'i32:
osError(osLastError()) raiseOSError(osLastError())
else: else:
when useWinUnicode: when useWinUnicode:
var k = newWideCString(key) var k = newWideCString(key)
var v = newWideCString(val) var v = newWideCString(val)
if setEnvironmentVariableW(k, v) == 0'i32: osError(osLastError()) if setEnvironmentVariableW(k, v) == 0'i32: raiseOSError(osLastError())
else: else:
if setEnvironmentVariableA(key, val) == 0'i32: osError(osLastError()) if setEnvironmentVariableA(key, val) == 0'i32: raiseOSError(osLastError())
iterator envPairs*(): tuple[key, value: TaintedString] {.tags: [ReadEnvEffect].} = iterator envPairs*(): tuple[key, value: TaintedString] {.tags: [ReadEnvEffect].} =
## Iterate over all `environments variables`:idx:. In the first component ## Iterate over all `environments variables`:idx:. In the first component
@ -1321,9 +1321,9 @@ proc rawRemoveDir(dir: string) =
let lastError = osLastError() let lastError = osLastError()
if res == 0'i32 and lastError.int32 != 3'i32 and if res == 0'i32 and lastError.int32 != 3'i32 and
lastError.int32 != 18'i32 and lastError.int32 != 2'i32: lastError.int32 != 18'i32 and lastError.int32 != 2'i32:
osError(lastError) raiseOSError(lastError)
else: else:
if rmdir(dir) != 0'i32 and errno != ENOENT: osError(osLastError()) if rmdir(dir) != 0'i32 and errno != ENOENT: raiseOSError(osLastError())
proc removeDir*(dir: string) {.rtl, extern: "nos$1", tags: [ proc removeDir*(dir: string) {.rtl, extern: "nos$1", tags: [
WriteDirEffect, ReadDirEffect].} = WriteDirEffect, ReadDirEffect].} =
@ -1341,17 +1341,17 @@ proc removeDir*(dir: string) {.rtl, extern: "nos$1", tags: [
proc rawCreateDir(dir: string) = proc rawCreateDir(dir: string) =
when defined(solaris): when defined(solaris):
if mkdir(dir, 0o711) != 0'i32 and errno != EEXIST and errno != ENOSYS: if mkdir(dir, 0o711) != 0'i32 and errno != EEXIST and errno != ENOSYS:
osError(osLastError()) raiseOSError(osLastError())
elif defined(unix): elif defined(unix):
if mkdir(dir, 0o711) != 0'i32 and errno != EEXIST: if mkdir(dir, 0o711) != 0'i32 and errno != EEXIST:
osError(osLastError()) raiseOSError(osLastError())
else: else:
when useWinUnicode: when useWinUnicode:
wrapUnary(res, createDirectoryW, dir) wrapUnary(res, createDirectoryW, dir)
else: else:
var res = createDirectoryA(dir) var res = createDirectoryA(dir)
if res == 0'i32 and getLastError() != 183'i32: if res == 0'i32 and getLastError() != 183'i32:
osError(osLastError()) raiseOSError(osLastError())
proc createDir*(dir: string) {.rtl, extern: "nos$1", tags: [WriteDirEffect].} = proc createDir*(dir: string) {.rtl, extern: "nos$1", tags: [WriteDirEffect].} =
## Creates the `directory`:idx: `dir`. ## Creates the `directory`:idx: `dir`.
@ -1403,13 +1403,13 @@ proc createSymlink*(src, dest: string) =
var wSrc = newWideCString(src) var wSrc = newWideCString(src)
var wDst = newWideCString(dest) var wDst = newWideCString(dest)
if createSymbolicLinkW(wDst, wSrc, flag) == 0 or getLastError() != 0: if createSymbolicLinkW(wDst, wSrc, flag) == 0 or getLastError() != 0:
osError(osLastError()) raiseOSError(osLastError())
else: else:
if createSymbolicLinkA(dest, src, flag) == 0 or getLastError() != 0: if createSymbolicLinkA(dest, src, flag) == 0 or getLastError() != 0:
osError(osLastError()) raiseOSError(osLastError())
else: else:
if symlink(src, dest) != 0: if symlink(src, dest) != 0:
osError(osLastError()) raiseOSError(osLastError())
proc createHardlink*(src, dest: string) = proc createHardlink*(src, dest: string) =
## Create a hard link at `dest` which points to the item specified ## Create a hard link at `dest` which points to the item specified
@ -1422,13 +1422,13 @@ proc createHardlink*(src, dest: string) =
var wSrc = newWideCString(src) var wSrc = newWideCString(src)
var wDst = newWideCString(dest) var wDst = newWideCString(dest)
if createHardLinkW(wDst, wSrc, nil) == 0: if createHardLinkW(wDst, wSrc, nil) == 0:
osError(osLastError()) raiseOSError(osLastError())
else: else:
if createHardLinkA(dest, src, nil) == 0: if createHardLinkA(dest, src, nil) == 0:
osError(osLastError()) raiseOSError(osLastError())
else: else:
if link(src, dest) != 0: if link(src, dest) != 0:
osError(osLastError()) raiseOSError(osLastError())
proc parseCmdLine*(c: string): seq[string] {. proc parseCmdLine*(c: string): seq[string] {.
noSideEffect, rtl, extern: "nos$1".} = noSideEffect, rtl, extern: "nos$1".} =
@ -1824,7 +1824,7 @@ proc getFileSize*(file: string): BiggestInt {.rtl, extern: "nos$1",
when defined(windows): when defined(windows):
var a: TWIN32_FIND_DATA var a: TWIN32_FIND_DATA
var resA = findFirstFile(file, a) var resA = findFirstFile(file, a)
if resA == -1: osError(osLastError()) if resA == -1: raiseOSError(osLastError())
result = rdFileSize(a) result = rdFileSize(a)
findClose(resA) findClose(resA)
else: else:
@ -1832,7 +1832,7 @@ proc getFileSize*(file: string): BiggestInt {.rtl, extern: "nos$1",
if open(f, file): if open(f, file):
result = getFileSize(f) result = getFileSize(f)
close(f) close(f)
else: osError(osLastError()) else: raiseOSError(osLastError())
proc findExe*(exe: string): string {.tags: [ReadDirEffect, ReadEnvEffect].} = proc findExe*(exe: string): string {.tags: [ReadDirEffect, ReadEnvEffect].} =
## Searches for `exe` in the current working directory and then ## Searches for `exe` in the current working directory and then
@ -1884,9 +1884,9 @@ type
size*: BiggestInt # Size of file. size*: BiggestInt # Size of file.
permissions*: set[TFilePermission] # File permissions permissions*: set[TFilePermission] # File permissions
linkCount*: BiggestInt # Number of hard links the file object has. linkCount*: BiggestInt # Number of hard links the file object has.
lastAccessTime*: TTime # Time file was last accessed. lastAccessTime*: Time # Time file was last accessed.
lastWriteTime*: TTime # Time file was last modified/written to. lastWriteTime*: Time # Time file was last modified/written to.
creationTime*: TTime # Time file was created. Not supported on all systems! creationTime*: Time # Time file was created. Not supported on all systems!
template rawToFormalFileInfo(rawInfo, formalInfo): expr = template rawToFormalFileInfo(rawInfo, formalInfo): expr =
## Transforms the native file info structure into the one nimrod uses. ## Transforms the native file info structure into the one nimrod uses.
@ -1959,12 +1959,12 @@ proc getFileInfo*(handle: FileHandle): FileInfo =
# To transform the C file descripter to a native file handle. # To transform the C file descripter to a native file handle.
var realHandle = get_osfhandle(handle) var realHandle = get_osfhandle(handle)
if getFileInformationByHandle(realHandle, addr rawInfo) == 0: if getFileInformationByHandle(realHandle, addr rawInfo) == 0:
osError(osLastError()) raiseOSError(osLastError())
rawToFormalFileInfo(rawInfo, result) rawToFormalFileInfo(rawInfo, result)
else: else:
var rawInfo: TStat var rawInfo: TStat
if fstat(handle, rawInfo) < 0'i32: if fstat(handle, rawInfo) < 0'i32:
osError(osLastError()) raiseOSError(osLastError())
rawToFormalFileInfo(rawInfo, result) rawToFormalFileInfo(rawInfo, result)
proc getFileInfo*(file: File): FileInfo = proc getFileInfo*(file: File): FileInfo =
@ -1989,19 +1989,19 @@ proc getFileInfo*(path: string, followSymlink = true): FileInfo =
handle = openHandle(path, followSymlink) handle = openHandle(path, followSymlink)
rawInfo: TBY_HANDLE_FILE_INFORMATION rawInfo: TBY_HANDLE_FILE_INFORMATION
if handle == INVALID_HANDLE_VALUE: if handle == INVALID_HANDLE_VALUE:
osError(osLastError()) raiseOSError(osLastError())
if getFileInformationByHandle(handle, addr rawInfo) == 0: if getFileInformationByHandle(handle, addr rawInfo) == 0:
osError(osLastError()) raiseOSError(osLastError())
rawToFormalFileInfo(rawInfo, result) rawToFormalFileInfo(rawInfo, result)
discard closeHandle(handle) discard closeHandle(handle)
else: else:
var rawInfo: TStat var rawInfo: TStat
if followSymlink: if followSymlink:
if lstat(path, rawInfo) < 0'i32: if lstat(path, rawInfo) < 0'i32:
osError(osLastError()) raiseOSError(osLastError())
else: else:
if stat(path, rawInfo) < 0'i32: if stat(path, rawInfo) < 0'i32:
osError(osLastError()) raiseOSError(osLastError())
rawToFormalFileInfo(rawInfo, result) rawToFormalFileInfo(rawInfo, result)
proc isHidden*(path: string): bool = proc isHidden*(path: string): bool =

View file

@ -334,7 +334,7 @@ when defined(Windows) and not defined(useNimRtl):
# TRUE and zero bytes returned (EOF). # TRUE and zero bytes returned (EOF).
# TRUE and n (>0) bytes returned (good data). # TRUE and n (>0) bytes returned (good data).
# FALSE and bytes returned undefined (system error). # FALSE and bytes returned undefined (system error).
if a == 0 and br != 0: osError(osLastError()) if a == 0 and br != 0: raiseOSError(osLastError())
s.atTheEnd = br < bufLen s.atTheEnd = br < bufLen
result = br result = br
@ -342,7 +342,7 @@ when defined(Windows) and not defined(useNimRtl):
var s = PFileHandleStream(s) var s = PFileHandleStream(s)
var bytesWritten: int32 var bytesWritten: int32
var a = winlean.writeFile(s.handle, buffer, bufLen.cint, bytesWritten, nil) var a = winlean.writeFile(s.handle, buffer, bufLen.cint, bytesWritten, nil)
if a == 0: osError(osLastError()) if a == 0: raiseOSError(osLastError())
proc newFileHandleStream(handle: THandle): PFileHandleStream = proc newFileHandleStream(handle: THandle): PFileHandleStream =
new(result) new(result)
@ -383,7 +383,7 @@ when defined(Windows) and not defined(useNimRtl):
piInheritablePipe.lpSecurityDescriptor = nil piInheritablePipe.lpSecurityDescriptor = nil
piInheritablePipe.bInheritHandle = 1 piInheritablePipe.bInheritHandle = 1
if createPipe(rdHandle, wrHandle, piInheritablePipe, 1024) == 0'i32: if createPipe(rdHandle, wrHandle, piInheritablePipe, 1024) == 0'i32:
osError(osLastError()) raiseOSError(osLastError())
proc fileClose(h: THandle) {.inline.} = proc fileClose(h: THandle) {.inline.} =
if h > 4: discard closeHandle(h) if h > 4: discard closeHandle(h)
@ -450,7 +450,7 @@ when defined(Windows) and not defined(useNimRtl):
fileClose(si.hStdError) fileClose(si.hStdError)
if e != nil: dealloc(e) if e != nil: dealloc(e)
if success == 0: osError(lastError) if success == 0: raiseOSError(lastError)
# Close the handle now so anyone waiting is woken: # Close the handle now so anyone waiting is woken:
discard closeHandle(procInfo.hThread) discard closeHandle(procInfo.hThread)
result.fProcessHandle = procInfo.hProcess result.fProcessHandle = procInfo.hProcess
@ -521,7 +521,7 @@ when defined(Windows) and not defined(useNimRtl):
var res = winlean.createProcessA(nil, command, nil, nil, 0, var res = winlean.createProcessA(nil, command, nil, nil, 0,
NORMAL_PRIORITY_CLASS, nil, nil, si, procInfo) NORMAL_PRIORITY_CLASS, nil, nil, si, procInfo)
if res == 0: if res == 0:
osError(osLastError()) raiseOSError(osLastError())
else: else:
process = procInfo.hProcess process = procInfo.hProcess
discard closeHandle(procInfo.hThread) discard closeHandle(procInfo.hThread)
@ -544,7 +544,7 @@ when defined(Windows) and not defined(useNimRtl):
of WAIT_TIMEOUT: of WAIT_TIMEOUT:
return 0 return 0
of WAIT_FAILED: of WAIT_FAILED:
osError(osLastError()) raiseOSError(osLastError())
else: else:
var i = ret - WAIT_OBJECT_0 var i = ret - WAIT_OBJECT_0
readfds.del(i) readfds.del(i)
@ -607,7 +607,7 @@ elif not defined(useNimRtl):
if poParentStreams notin options: if poParentStreams notin options:
if pipe(pStdin) != 0'i32 or pipe(pStdout) != 0'i32 or if pipe(pStdin) != 0'i32 or pipe(pStdout) != 0'i32 or
pipe(pStderr) != 0'i32: pipe(pStderr) != 0'i32:
osError(osLastError()) raiseOSError(osLastError())
var sysCommand: string var sysCommand: string
var sysArgsRaw: seq[string] var sysArgsRaw: seq[string]
@ -683,7 +683,7 @@ elif not defined(useNimRtl):
var fops: Tposix_spawn_file_actions var fops: Tposix_spawn_file_actions
template chck(e: expr) = template chck(e: expr) =
if e != 0'i32: osError(osLastError()) if e != 0'i32: raiseOSError(osLastError())
chck posix_spawn_file_actions_init(fops) chck posix_spawn_file_actions_init(fops)
chck posix_spawnattr_init(attr) chck posix_spawnattr_init(attr)
@ -726,7 +726,7 @@ elif not defined(useNimRtl):
proc startProcessAuxFork(data: TStartProcessData): TPid = proc startProcessAuxFork(data: TStartProcessData): TPid =
if pipe(data.pErrorPipe) != 0: if pipe(data.pErrorPipe) != 0:
osError(osLastError()) raiseOSError(osLastError())
finally: finally:
discard close(data.pErrorPipe[readIdx]) discard close(data.pErrorPipe[readIdx])
@ -751,12 +751,12 @@ elif not defined(useNimRtl):
exitnow(1) exitnow(1)
discard close(data.pErrorPipe[writeIdx]) discard close(data.pErrorPipe[writeIdx])
if pid < 0: osError(osLastError()) if pid < 0: raiseOSError(osLastError())
var error: cint var error: cint
let sizeRead = read(data.pErrorPipe[readIdx], addr error, sizeof(error)) let sizeRead = read(data.pErrorPipe[readIdx], addr error, sizeof(error))
if sizeRead == sizeof(error): if sizeRead == sizeof(error):
osError($strerror(error)) raiseOSError($strerror(error))
return pid return pid
@ -818,10 +818,10 @@ elif not defined(useNimRtl):
discard close(p.errHandle) discard close(p.errHandle)
proc suspend(p: PProcess) = proc suspend(p: PProcess) =
if kill(-p.id, SIGSTOP) != 0'i32: osError(osLastError()) if kill(-p.id, SIGSTOP) != 0'i32: raiseOSError(osLastError())
proc resume(p: PProcess) = proc resume(p: PProcess) =
if kill(-p.id, SIGCONT) != 0'i32: osError(osLastError()) if kill(-p.id, SIGCONT) != 0'i32: raiseOSError(osLastError())
proc running(p: PProcess): bool = proc running(p: PProcess): bool =
var ret = waitpid(p.id, p.exitCode, WNOHANG) var ret = waitpid(p.id, p.exitCode, WNOHANG)
@ -831,8 +831,8 @@ elif not defined(useNimRtl):
proc terminate(p: PProcess) = proc terminate(p: PProcess) =
if kill(-p.id, SIGTERM) == 0'i32: if kill(-p.id, SIGTERM) == 0'i32:
if p.running(): if p.running():
if kill(-p.id, SIGKILL) != 0'i32: osError(osLastError()) if kill(-p.id, SIGKILL) != 0'i32: raiseOSError(osLastError())
else: osError(osLastError()) else: raiseOSError(osLastError())
proc waitForExit(p: PProcess, timeout: int = -1): int = proc waitForExit(p: PProcess, timeout: int = -1): int =
#if waitPid(p.id, p.exitCode, 0) == int(p.id): #if waitPid(p.id, p.exitCode, 0) == int(p.id):
@ -842,7 +842,7 @@ elif not defined(useNimRtl):
if p.exitCode != -3: return p.exitCode if p.exitCode != -3: return p.exitCode
if waitpid(p.id, p.exitCode, 0) < 0: if waitpid(p.id, p.exitCode, 0) < 0:
p.exitCode = -3 p.exitCode = -3
osError(osLastError()) raiseOSError(osLastError())
result = int(p.exitCode) shr 8 result = int(p.exitCode) shr 8
proc peekExitCode(p: PProcess): int = proc peekExitCode(p: PProcess): int =
@ -856,7 +856,7 @@ elif not defined(useNimRtl):
proc createStream(stream: var PStream, handle: var FileHandle, proc createStream(stream: var PStream, handle: var FileHandle,
fileMode: FileMode) = fileMode: FileMode) =
var f: File var f: File
if not open(f, handle, fileMode): osError(osLastError()) if not open(f, handle, fileMode): raiseOSError(osLastError())
stream = newFileStream(f) stream = newFileStream(f)
proc inputStream(p: PProcess): PStream = proc inputStream(p: PProcess): PStream =

View file

@ -121,7 +121,7 @@ proc hasKey*(t: PStringTable, key: string): bool {.rtl, extern: "nst$1".} =
## returns true iff `key` is in the table `t`. ## returns true iff `key` is in the table `t`.
result = rawGet(t, key) >= 0 result = rawGet(t, key) >= 0
proc rawInsert(t: PStringTable, data: var TKeyValuePairSeq, key, val: string) = proc rawInsert(t: PStringTable, data: var KeyValuePairSeq, key, val: string) =
var h: THash = myhash(t, key) and high(data) var h: THash = myhash(t, key) and high(data)
while not isNil(data[h].key): while not isNil(data[h].key):
h = nextTry(h, high(data)) h = nextTry(h, high(data))
@ -129,7 +129,7 @@ proc rawInsert(t: PStringTable, data: var TKeyValuePairSeq, key, val: string) =
data[h].val = val data[h].val = val
proc enlarge(t: PStringTable) = proc enlarge(t: PStringTable) =
var n: TKeyValuePairSeq var n: KeyValuePairSeq
newSeq(n, len(t.data) * growthFactor) newSeq(n, len(t.data) * growthFactor)
for i in countup(0, high(t.data)): for i in countup(0, high(t.data)):
if not isNil(t.data[i].key): rawInsert(t, n, t.data[i].key, t.data[i].val) if not isNil(t.data[i].key): rawInsert(t, n, t.data[i].key, t.data[i].val)
@ -182,7 +182,7 @@ proc newStringTable*(keyValuePairs: varargs[string],
inc(i, 2) inc(i, 2)
proc newStringTable*(keyValuePairs: varargs[tuple[key, val: string]], proc newStringTable*(keyValuePairs: varargs[tuple[key, val: string]],
mode: TStringTableMode = modeCaseSensitive): PStringTable {. mode: StringTableMode = modeCaseSensitive): PStringTable {.
rtl, extern: "nst$1WithTableConstr".} = rtl, extern: "nst$1WithTableConstr".} =
## creates a new string table with given key value pairs. ## creates a new string table with given key value pairs.
## Example:: ## Example::

View file

@ -766,7 +766,7 @@ proc find*(s, sub: string, start: int = 0): int {.noSideEffect,
## Searches for `sub` in `s` starting at position `start`. ## Searches for `sub` in `s` starting at position `start`.
## ##
## Searching is case-sensitive. If `sub` is not in `s`, -1 is returned. ## Searching is case-sensitive. If `sub` is not in `s`, -1 is returned.
var a {.noinit.}: TSkipTable var a {.noinit.}: SkipTable
preprocessSub(sub, a) preprocessSub(sub, a)
result = findAux(s, sub, start, a) result = findAux(s, sub, start, a)
@ -1158,7 +1158,7 @@ proc formatBiggestFloat*(f: BiggestFloat, format: FloatFormatMode = ffDefault,
## after the decimal point for Nimrod's ``biggestFloat`` type. ## after the decimal point for Nimrod's ``biggestFloat`` type.
## ##
## If ``precision == 0``, it tries to format it nicely. ## If ``precision == 0``, it tries to format it nicely.
const floatFormatToChar: array[TFloatFormat, char] = ['g', 'f', 'e'] const floatFormatToChar: array[FloatFormatMode, char] = ['g', 'f', 'e']
var var
frmtstr {.noinit.}: array[0..5, char] frmtstr {.noinit.}: array[0..5, char]
buf {.noinit.}: array[0..2500, char] buf {.noinit.}: array[0..2500, char]

View file

@ -136,7 +136,7 @@ type
months*: int ## The number of months months*: int ## The number of months
years*: int ## The number of years years*: int ## The number of years
{.deprecated: [TMonth: Month, TWeekDay: WeekDay, TTime: Time, TTimeval: Timeval, {.deprecated: [TMonth: Month, TWeekDay: WeekDay, TTime: Time,
TTimeInterval: TimeInterval, TTimeInfo: TimeInfo].} TTimeInterval: TimeInterval, TTimeInfo: TimeInfo].}
proc getTime*(): Time {.tags: [TimeEffect], gcsafe.} proc getTime*(): Time {.tags: [TimeEffect], gcsafe.}
@ -228,7 +228,7 @@ proc isLeapYear*(year: int): bool =
else: else:
return false return false
proc getDaysInMonth*(month: TMonth, year: int): int = proc getDaysInMonth*(month: Month, year: int): int =
## gets the amount of days in a ``month`` of a ``year`` ## gets the amount of days in a ``month`` of a ``year``
# http://www.dispersiondesign.com/articles/time/number_of_days_in_a_month # http://www.dispersiondesign.com/articles/time/number_of_days_in_a_month
@ -350,7 +350,7 @@ when not defined(JS):
minute: int(tm.minute), minute: int(tm.minute),
hour: int(tm.hour), hour: int(tm.hour),
monthday: int(tm.monthday), monthday: int(tm.monthday),
month: TMonth(tm.month), month: Month(tm.month),
year: tm.year + 1900'i32, year: tm.year + 1900'i32,
weekday: weekDays[int(tm.weekday)], weekday: weekDays[int(tm.weekday)],
yearday: int(tm.yearday), yearday: int(tm.yearday),
@ -455,7 +455,7 @@ when not defined(JS):
when not defined(useNimRtl): when not defined(useNimRtl):
proc epochTime(): float = proc epochTime(): float =
when defined(posix): when defined(posix):
var a: Ttimeval var a: Timeval
posix_gettimeofday(a) posix_gettimeofday(a)
result = toFloat(a.tv_sec) + toFloat(a.tv_usec)*0.00_0001 result = toFloat(a.tv_sec) + toFloat(a.tv_usec)*0.00_0001
elif defined(windows): elif defined(windows):

View file

@ -363,7 +363,9 @@ const
proc wsaGetLastError*(): cint {.importc: "WSAGetLastError", dynlib: ws2dll.} proc wsaGetLastError*(): cint {.importc: "WSAGetLastError", dynlib: ws2dll.}
type type
TSocketHandle* = distinct int SocketHandle* = distinct int
{.deprecated: [TSocketHandle: SocketHandle].}
type type
TWSAData* {.pure, final, importc: "WSADATA", header: "Winsock2.h".} = object TWSAData* {.pure, final, importc: "WSADATA", header: "Winsock2.h".} = object