mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-09 14:32:53 +00:00
Winlean and threads case sensitivity fixes.
This commit is contained in:
@@ -13,9 +13,9 @@
|
||||
##
|
||||
## **Note:** The current implementation of message passing is slow and does
|
||||
## not work with cyclic data structures.
|
||||
|
||||
when not declared(NimString):
|
||||
{.error: "You must not import this module explicitly".}
|
||||
|
||||
when not declared(NimString):
|
||||
{.error: "You must not import this module explicitly".}
|
||||
|
||||
type
|
||||
pbytes = ptr array[0.. 0xffff, byte]
|
||||
@@ -73,11 +73,11 @@ proc storeAux(dest, src: pointer, mt: PNimType, t: PRawChannel,
|
||||
d = cast[TAddress](dest)
|
||||
s = cast[TAddress](src)
|
||||
sysAssert(mt != nil, "mt == nil")
|
||||
case mt.Kind
|
||||
case mt.kind
|
||||
of tyString:
|
||||
if mode == mStore:
|
||||
var x = cast[ppointer](dest)
|
||||
var s2 = cast[ppointer](s)[]
|
||||
var x = cast[PPointer](dest)
|
||||
var s2 = cast[PPointer](s)[]
|
||||
if s2 == nil:
|
||||
x[] = nil
|
||||
else:
|
||||
@@ -86,17 +86,17 @@ proc storeAux(dest, src: pointer, mt: PNimType, t: PRawChannel,
|
||||
copyMem(ns, ss, ss.len+1 + GenericSeqSize)
|
||||
x[] = ns
|
||||
else:
|
||||
var x = cast[ppointer](dest)
|
||||
var s2 = cast[ppointer](s)[]
|
||||
var x = cast[PPointer](dest)
|
||||
var s2 = cast[PPointer](s)[]
|
||||
if s2 == nil:
|
||||
unsureAsgnRef(x, s2)
|
||||
else:
|
||||
unsureAsgnRef(x, copyString(cast[NimString](s2)))
|
||||
dealloc(t.region, s2)
|
||||
of tySequence:
|
||||
var s2 = cast[ppointer](src)[]
|
||||
var s2 = cast[PPointer](src)[]
|
||||
var seq = cast[PGenericSeq](s2)
|
||||
var x = cast[ppointer](dest)
|
||||
var x = cast[PPointer](dest)
|
||||
if s2 == nil:
|
||||
if mode == mStore:
|
||||
x[] = nil
|
||||
@@ -108,13 +108,13 @@ proc storeAux(dest, src: pointer, mt: PNimType, t: PRawChannel,
|
||||
x[] = alloc(t.region, seq.len *% mt.base.size +% GenericSeqSize)
|
||||
else:
|
||||
unsureAsgnRef(x, newObj(mt, seq.len * mt.base.size + GenericSeqSize))
|
||||
var dst = cast[taddress](cast[ppointer](dest)[])
|
||||
var dst = cast[TAddress](cast[PPointer](dest)[])
|
||||
for i in 0..seq.len-1:
|
||||
storeAux(
|
||||
cast[pointer](dst +% i*% mt.base.size +% GenericSeqSize),
|
||||
cast[pointer](cast[TAddress](s2) +% i *% mt.base.size +%
|
||||
GenericSeqSize),
|
||||
mt.Base, t, mode)
|
||||
mt.base, t, mode)
|
||||
var dstseq = cast[PGenericSeq](dst)
|
||||
dstseq.len = seq.len
|
||||
dstseq.reserved = seq.len
|
||||
@@ -123,8 +123,8 @@ proc storeAux(dest, src: pointer, mt: PNimType, t: PRawChannel,
|
||||
# copy type field:
|
||||
var pint = cast[ptr PNimType](dest)
|
||||
# XXX use dynamic type here!
|
||||
pint[] = mt
|
||||
if mt.base != nil:
|
||||
pint[] = mt
|
||||
if mt.base != nil:
|
||||
storeAux(dest, src, mt.base, t, mode)
|
||||
storeAux(dest, src, mt.node, t, mode)
|
||||
of tyTuple:
|
||||
@@ -134,8 +134,8 @@ proc storeAux(dest, src: pointer, mt: PNimType, t: PRawChannel,
|
||||
storeAux(cast[pointer](d +% i*% mt.base.size),
|
||||
cast[pointer](s +% i*% mt.base.size), mt.base, t, mode)
|
||||
of tyRef:
|
||||
var s = cast[ppointer](src)[]
|
||||
var x = cast[ppointer](dest)
|
||||
var s = cast[PPointer](src)[]
|
||||
var x = cast[PPointer](dest)
|
||||
if s == nil:
|
||||
if mode == mStore:
|
||||
x[] = nil
|
||||
@@ -225,20 +225,20 @@ proc recv*[TMsg](c: var TChannel[TMsg]): TMsg =
|
||||
acquireSys(q.lock)
|
||||
llRecv(q, addr(result), cast[PNimType](getTypeInfo(result)))
|
||||
releaseSys(q.lock)
|
||||
|
||||
proc tryRecv*[TMsg](c: var TChannel[TMsg]): tuple[dataAvaliable: bool,
|
||||
msg: TMsg] =
|
||||
## try to receives a message from the channel `c` if available. Otherwise
|
||||
## it returns ``(false, default(msg))``.
|
||||
|
||||
proc tryRecv*[TMsg](c: var TChannel[TMsg]): tuple[dataAvaliable: bool,
|
||||
msg: TMsg] =
|
||||
## try to receives a message from the channel `c` if available. Otherwise
|
||||
## it returns ``(false, default(msg))``.
|
||||
var q = cast[PRawChannel](addr(c))
|
||||
if q.mask != ChannelDeadMask:
|
||||
lockChannel(q):
|
||||
llRecv(q, addr(result.msg), cast[PNimType](getTypeInfo(result.msg)))
|
||||
llRecv(q, addr(result.msg), cast[PNimType](getTypeInfo(result.msg)))
|
||||
result.dataAvaliable = true
|
||||
|
||||
proc peek*[TMsg](c: var TChannel[TMsg]): int =
|
||||
## returns the current number of messages in the channel `c`. Returns -1
|
||||
## if the channel has been closed. **Note**: This is dangerous to use
|
||||
## if the channel has been closed. **Note**: This is dangerous to use
|
||||
## as it encourages races. It's much better to use ``tryRecv`` instead.
|
||||
var q = cast[PRawChannel](addr(c))
|
||||
if q.mask != ChannelDeadMask:
|
||||
|
||||
@@ -31,7 +31,7 @@ when defined(Windows):
|
||||
## Tries to acquire the lock `L`.
|
||||
|
||||
proc tryAcquireSys(L: var TSysLock): bool {.inline.} =
|
||||
result = TryAcquireSysAux(L) != 0'i32
|
||||
result = tryAcquireSysAux(L) != 0'i32
|
||||
|
||||
proc acquireSys(L: var TSysLock) {.stdcall, noSideEffect,
|
||||
dynlib: "kernel32", importc: "EnterCriticalSection".}
|
||||
|
||||
@@ -190,7 +190,7 @@ var globalsSlot = threadVarAlloc()
|
||||
|
||||
when emulatedThreadVars:
|
||||
proc GetThreadLocalVars(): pointer {.compilerRtl, inl.} =
|
||||
result = addr(cast[PGcThread](ThreadVarGetValue(globalsSlot)).tls)
|
||||
result = addr(cast[PGcThread](threadVarGetValue(globalsSlot)).tls)
|
||||
|
||||
when useStackMaskHack:
|
||||
proc maskStackPointer(offset: int): pointer {.compilerRtl, inl.} =
|
||||
@@ -210,7 +210,7 @@ when not defined(useNimRtl):
|
||||
initGC()
|
||||
|
||||
when emulatedThreadVars:
|
||||
if NimThreadVarsSize() > sizeof(TThreadLocalStorage):
|
||||
if nimThreadVarsSize() > sizeof(TThreadLocalStorage):
|
||||
echo "too large thread local storage size requested"
|
||||
quit 1
|
||||
|
||||
@@ -267,7 +267,7 @@ when not defined(boehmgc) and not hasSharedHeap:
|
||||
proc deallocOsPages()
|
||||
|
||||
template threadProcWrapperBody(closure: expr) {.immediate.} =
|
||||
when declared(globalsSlot): ThreadVarSetValue(globalsSlot, closure)
|
||||
when declared(globalsSlot): threadVarSetValue(globalsSlot, closure)
|
||||
var t = cast[ptr TThread[TArg]](closure)
|
||||
when useStackMaskHack:
|
||||
var tls: TThreadLocalStorage
|
||||
@@ -364,7 +364,7 @@ proc threadId*[TArg](t: var TThread[TArg]): TThreadId[TArg] {.inline.} =
|
||||
proc myThreadId*[TArg](): TThreadId[TArg] =
|
||||
## returns the thread ID of the thread that calls this proc. This is unsafe
|
||||
## because the type ``TArg`` is not checked for consistency!
|
||||
result = cast[TThreadId[TArg]](ThreadVarGetValue(globalsSlot))
|
||||
result = cast[TThreadId[TArg]](threadVarGetValue(globalsSlot))
|
||||
|
||||
when false:
|
||||
proc mainThreadId*[TArg](): TThreadId[TArg] =
|
||||
|
||||
@@ -199,14 +199,14 @@ else:
|
||||
importc: "GetCurrentDirectoryA", dynlib: "kernel32", stdcall.}
|
||||
proc setCurrentDirectoryA*(lpPathName: cstring): int32 {.
|
||||
importc: "SetCurrentDirectoryA", dynlib: "kernel32", stdcall.}
|
||||
proc createDirectoryA*(pathName: cstring, security: Pointer=nil): int32 {.
|
||||
proc createDirectoryA*(pathName: cstring, security: pointer=nil): int32 {.
|
||||
importc: "CreateDirectoryA", dynlib: "kernel32", stdcall.}
|
||||
proc removeDirectoryA*(lpPathName: cstring): int32 {.
|
||||
importc: "RemoveDirectoryA", dynlib: "kernel32", stdcall.}
|
||||
proc setEnvironmentVariableA*(lpName, lpValue: cstring): int32 {.
|
||||
stdcall, dynlib: "kernel32", importc: "SetEnvironmentVariableA".}
|
||||
|
||||
proc getModuleFileNameA*(handle: THandle, buf: CString, size: int32): int32 {.
|
||||
proc getModuleFileNameA*(handle: THandle, buf: cstring, size: int32): int32 {.
|
||||
importc: "GetModuleFileNameA", dynlib: "kernel32", stdcall.}
|
||||
|
||||
when useWinUnicode:
|
||||
@@ -304,7 +304,7 @@ else:
|
||||
dwFileAttributes: int32): WINBOOL {.
|
||||
stdcall, dynlib: "kernel32", importc: "SetFileAttributesA".}
|
||||
|
||||
proc copyFileA*(lpExistingFileName, lpNewFileName: CString,
|
||||
proc copyFileA*(lpExistingFileName, lpNewFileName: cstring,
|
||||
bFailIfExists: cint): cint {.
|
||||
importc: "CopyFileA", stdcall, dynlib: "kernel32".}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user