diff options
author | Clyybber <darkmine956@gmail.com> | 2019-10-08 14:15:47 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-10-08 14:15:47 +0200 |
commit | 00c31e87660d9db813871f5aa23661bf6b9bbdcb (patch) | |
tree | 4d8e57bbfae60c0a21acc16934a257f57ee70eee /lib | |
parent | edb24b7ce0882faaaec406f20c70723ac653ca2e (diff) | |
download | Nim-00c31e87660d9db813871f5aa23661bf6b9bbdcb.tar.gz |
Fixes #12187 (#12321)
* Fixes #12187 * Point to fork of compactdict Since the original repo is now archived / read-only
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/concurrency/cpuinfo.nim | 2 | ||||
-rw-r--r-- | lib/pure/memfiles.nim | 2 | ||||
-rw-r--r-- | lib/pure/strutils.nim | 2 | ||||
-rw-r--r-- | lib/system.nim | 4 | ||||
-rw-r--r-- | lib/system/ansi_c.nim | 18 | ||||
-rw-r--r-- | lib/system/io.nim | 14 | ||||
-rw-r--r-- | lib/system/memory.nim | 6 | ||||
-rw-r--r-- | lib/system/osalloc.nim | 8 | ||||
-rw-r--r-- | lib/wrappers/openssl.nim | 4 |
9 files changed, 42 insertions, 18 deletions
diff --git a/lib/pure/concurrency/cpuinfo.nim b/lib/pure/concurrency/cpuinfo.nim index 415b9a787..5a72459a3 100644 --- a/lib/pure/concurrency/cpuinfo.nim +++ b/lib/pure/concurrency/cpuinfo.nim @@ -79,7 +79,7 @@ proc countProcessors*(): int {.rtl, extern: "ncpi$1".} = len: csize mib[0] = CTL_HW mib[1] = HW_AVAILCPU - len = sizeof(numCPU) + len = csize sizeof(numCPU) discard sysctl(addr(mib), 2, addr(numCPU), len, nil, 0) if numCPU < 1: mib[1] = HW_NCPU diff --git a/lib/pure/memfiles.nim b/lib/pure/memfiles.nim index 411df1456..7e0478877 100644 --- a/lib/pure/memfiles.nim +++ b/lib/pure/memfiles.nim @@ -416,7 +416,7 @@ iterator memSlices*(mfile: MemFile, delim = '\l', eat = '\r'): MemSlice {.inline ms.data = mfile.mem var remaining = mfile.size while remaining > 0: - ending = c_memchr(ms.data, delim, remaining) + ending = c_memchr(ms.data, delim, csize remaining) if ending == nil: # unterminated final slice ms.size = remaining # Weird case..check eat? yield ms diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 69cb1efd5..fd5dcf14c 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -1872,7 +1872,7 @@ proc find*(s: string, sub: char, start: Natural = 0, last = 0): int {.noSideEffe when hasCStringBuiltin: let L = last-start+1 if L > 0: - let found = c_memchr(s[start].unsafeAddr, sub, L) + let found = c_memchr(s[start].unsafeAddr, sub, csize L) if not found.isNil: return cast[ByteAddress](found) -% cast[ByteAddress](s.cstring) else: diff --git a/lib/system.nim b/lib/system.nim index 0edc869c2..9158b6153 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2233,7 +2233,7 @@ type # these work for most platforms: ## This is the same as the type ``short`` in *C*. cint* {.importc: "int", nodecl.} = int32 ## This is the same as the type ``int`` in *C*. - csize* {.importc: "size_t", nodecl.} = int + csize* {.importc: "size_t", nodecl.} = uint ## This is the same as the type ``size_t`` in *C*. clonglong* {.importc: "long long", nodecl.} = int64 ## This is the same as the type ``long long`` in *C*. @@ -3597,7 +3597,7 @@ when not defined(JS): #and not defined(nimscript): when declared(memTrackerOp): memTrackerOp("copyMem", dest, size) proc moveMem(dest, source: pointer, size: Natural) = - c_memmove(dest, source, size) + c_memmove(dest, source, csize size) when declared(memTrackerOp): memTrackerOp("moveMem", dest, size) proc equalMem(a, b: pointer, size: Natural): bool = diff --git a/lib/system/ansi_c.nim b/lib/system/ansi_c.nim index 16e7a14d6..89058ce4f 100644 --- a/lib/system/ansi_c.nim +++ b/lib/system/ansi_c.nim @@ -17,14 +17,24 @@ when not defined(nimHasHotCodeReloading): proc c_memchr*(s: pointer, c: cint, n: csize): pointer {. importc: "memchr", header: "<string.h>".} +proc c_memchr*(s: pointer, c: cint, n: int): pointer {. + importc: "memchr", header: "<string.h>", deprecated: "csize is now uint".} proc c_memcmp*(a, b: pointer, size: csize): cint {. importc: "memcmp", header: "<string.h>", noSideEffect.} +proc c_memcmp*(a, b: pointer, size: int): cint {. + importc: "memcmp", header: "<string.h>", noSideEffect, deprecated: "csize is now uint".} proc c_memcpy*(a, b: pointer, size: csize): pointer {. importc: "memcpy", header: "<string.h>", discardable.} +proc c_memcpy*(a, b: pointer, size: int): pointer {. + importc: "memcpy", header: "<string.h>", discardable, deprecated: "csize is now uint".} proc c_memmove*(a, b: pointer, size: csize): pointer {. importc: "memmove", header: "<string.h>",discardable.} +proc c_memmove*(a, b: pointer, size: int): pointer {. + importc: "memmove", header: "<string.h>",discardable, deprecated: "csize is now uint".} proc c_memset*(p: pointer, value: cint, size: csize): pointer {. importc: "memset", header: "<string.h>", discardable.} +proc c_memset*(p: pointer, value: cint, size: int): pointer {. + importc: "memset", header: "<string.h>", discardable, deprecated: "csize is now uint".} proc c_strcmp*(a, b: cstring): cint {. importc: "strcmp", header: "<string.h>", noSideEffect.} proc c_strlen*(a: cstring): csize {. @@ -134,16 +144,22 @@ proc c_sprintf*(buf, frmt: cstring): cint {. proc c_malloc*(size: csize): pointer {. importc: "malloc", header: "<stdlib.h>".} +proc c_malloc*(size: int): pointer {. + importc: "malloc", header: "<stdlib.h>", deprecated: "csize is now uint".} proc c_free*(p: pointer) {. importc: "free", header: "<stdlib.h>".} proc c_realloc*(p: pointer, newsize: csize): pointer {. importc: "realloc", header: "<stdlib.h>".} +proc c_realloc*(p: pointer, newsize: int): pointer {. + importc: "realloc", header: "<stdlib.h>", deprecated: "csize is now uint".} proc c_fwrite*(buf: pointer, size, n: csize, f: CFilePtr): cint {. importc: "fwrite", header: "<stdio.h>".} +proc c_fwrite*(buf: pointer, size, n: int, f: CFilePtr): cint {. + importc: "fwrite", header: "<stdio.h>", deprecated: "csize is now uint".} proc rawWrite*(f: CFilePtr, s: cstring) {.compilerproc, nonReloadable, inline.} = # we cannot throw an exception here! - discard c_fwrite(s, 1, s.len, f) + discard c_fwrite(s, 1, csize s.len, f) {.pop.} diff --git a/lib/system/io.nim b/lib/system/io.nim index 7ba36a30d..46863064b 100644 --- a/lib/system/io.nim +++ b/lib/system/io.nim @@ -85,10 +85,14 @@ proc c_feof(f: File): cint {. when not declared(c_fwrite): proc c_fwrite(buf: pointer, size, n: csize, f: File): cint {. importc: "fwrite", header: "<stdio.h>".} + proc c_fwrite(buf: pointer, size, n: int, f: File): cint {. + importc: "fwrite", header: "<stdio.h>", deprecated: "csize is now uint".} # C routine that is used here: proc c_fread(buf: pointer, size, n: csize, f: File): csize {. importc: "fread", header: "<stdio.h>", tags: [ReadIOEffect].} +proc c_fread(buf: pointer, size, n: int, f: File): int {. + importc: "fread", header: "<stdio.h>", tags: [ReadIOEffect], deprecated: "csize is now uint".} when defined(windows): when not defined(amd64): proc c_fseek(f: File, offset: int64, whence: cint): cint {. @@ -109,6 +113,8 @@ proc c_ferror(f: File): cint {. importc: "ferror", header: "<stdio.h>", tags: [].} proc c_setvbuf(f: File, buf: pointer, mode: cint, size: csize): cint {. importc: "setvbuf", header: "<stdio.h>", tags: [].} +proc c_setvbuf(f: File, buf: pointer, mode: cint, size: int): cint {. + importc: "setvbuf", header: "<stdio.h>", tags: [], deprecated: "csize is now uint".} proc c_fprintf(f: File, frmt: cstring): cint {. importc: "fprintf", header: "<stdio.h>", varargs, discardable.} @@ -151,7 +157,7 @@ proc readBuffer*(f: File, buffer: pointer, len: Natural): int {. ## reads `len` bytes into the buffer pointed to by `buffer`. Returns ## the actual number of bytes that have been read which may be less than ## `len` (if not as many bytes are remaining), but not greater. - result = c_fread(buffer, 1, len, f) + result = int c_fread(buffer, 1, csize len, f) if result != len: checkErr(f) proc readBytes*(f: File, a: var openArray[int8|uint8], start, len: Natural): int {. @@ -183,7 +189,7 @@ proc writeBuffer*(f: File, buffer: pointer, len: Natural): int {. ## writes the bytes of buffer pointed to by the parameter `buffer` to the ## file `f`. Returns the number of actual written bytes, which may be less ## than `len` in case of an error. - result = c_fwrite(buffer, 1, len, f) + result = c_fwrite(buffer, 1, csize len, f) checkErr(f) proc writeBytes*(f: File, a: openArray[int8|uint8], start, len: Natural): int {. @@ -292,6 +298,8 @@ proc readLine*(f: File, line: var TaintedString): bool {.tags: [ReadIOEffect], ## ``false`` is returned `line` contains no new data. proc c_memchr(s: pointer, c: cint, n: csize): pointer {. importc: "memchr", header: "<string.h>".} + proc c_memchr(s: pointer, c: cint, n: int): pointer {. + importc: "memchr", header: "<string.h>", deprecated: "csize is now uint".} var pos = 0 @@ -306,7 +314,7 @@ proc readLine*(f: File, line: var TaintedString): bool {.tags: [ReadIOEffect], var fgetsSuccess = c_fgets(addr line.string[pos], sp.cint, f) != nil if not fgetsSuccess: checkErr(f) - let m = c_memchr(addr line.string[pos], '\L'.ord, sp) + let m = c_memchr(addr line.string[pos], '\L'.ord, csize sp) if m != nil: # \l found: Could be our own or the one by fgets, in any case, we're done var last = cast[ByteAddress](m) - cast[ByteAddress](addr line.string[0]) diff --git a/lib/system/memory.nim b/lib/system/memory.nim index 13bddf211..53c9b1c3b 100644 --- a/lib/system/memory.nim +++ b/lib/system/memory.nim @@ -10,7 +10,7 @@ when useLibC: proc nimCopyMem*(dest, source: pointer, size: Natural) {.nonReloadable, compilerproc, inline.} = when useLibC: - c_memcpy(dest, source, size) + c_memcpy(dest, source, csize size) else: let d = cast[ptr UncheckedArray[byte]](dest) let s = cast[ptr UncheckedArray[byte]](source) @@ -21,7 +21,7 @@ proc nimCopyMem*(dest, source: pointer, size: Natural) {.nonReloadable, compiler proc nimSetMem*(a: pointer, v: cint, size: Natural) {.nonReloadable, inline.} = when useLibC: - c_memset(a, v, size) + c_memset(a, v, csize size) else: let a = cast[ptr UncheckedArray[byte]](a) var i = 0 @@ -35,7 +35,7 @@ proc nimZeroMem*(p: pointer, size: Natural) {.compilerproc, nonReloadable, inlin proc nimCmpMem*(a, b: pointer, size: Natural): cint {.compilerproc, nonReloadable, inline.} = when useLibC: - c_memcmp(a, b, size) + c_memcmp(a, b, csize size) else: let a = cast[ptr UncheckedArray[byte]](a) let b = cast[ptr UncheckedArray[byte]](b) diff --git a/lib/system/osalloc.nim b/lib/system/osalloc.nim index 06e89f130..e29f997d2 100644 --- a/lib/system/osalloc.nim +++ b/lib/system/osalloc.nim @@ -153,7 +153,7 @@ elif defined(nintendoswitch): # size, as well as space to store our structure let realSize = alignSize(size + sizeof(NSwitchBlock)) - let heap = memalign(PageSize, realSize) + let heap = memalign(PageSize, realSize.csize) if heap.isNil: outOfMemoryStmt @@ -221,18 +221,18 @@ elif defined(posix): proc munmap(adr: pointer, len: csize): cint {.header: "<sys/mman.h>".} proc osAllocPages(size: int): pointer {.inline.} = - result = mmap(nil, size, PROT_READ or PROT_WRITE, + result = mmap(nil, csize size, PROT_READ or PROT_WRITE, MAP_PRIVATE or MAP_ANONYMOUS, -1, 0) if result == nil or result == cast[pointer](-1): raiseOutOfMem() proc osTryAllocPages(size: int): pointer {.inline.} = - result = mmap(nil, size, PROT_READ or PROT_WRITE, + result = mmap(nil, csize size, PROT_READ or PROT_WRITE, MAP_PRIVATE or MAP_ANONYMOUS, -1, 0) if result == cast[pointer](-1): result = nil proc osDeallocPages(p: pointer, size: int) {.inline.} = - when reallyOsDealloc: discard munmap(p, size) + when reallyOsDealloc: discard munmap(p, csize size) elif defined(windows): const diff --git a/lib/wrappers/openssl.nim b/lib/wrappers/openssl.nim index 482062617..46c9d7bd8 100644 --- a/lib/wrappers/openssl.nim +++ b/lib/wrappers/openssl.nim @@ -712,7 +712,7 @@ proc md5_File*(file: string): string {.raises: [IOError,Exception].} = discard md5_Init(ctx) while(let bytes = f.readChars(buf, 0, sz); bytes > 0): - discard md5_Update(ctx, buf[0].addr, bytes) + discard md5_Update(ctx, buf[0].addr, csize bytes) discard md5_Final(buf[0].addr, ctx) f.close @@ -731,7 +731,7 @@ proc md5_Str*(str: string): string = var i = 0 while i < str.len: let L = min(str.len - i, 512) - discard md5_Update(ctx, input[i].addr, L) + discard md5_Update(ctx, input[i].addr, csize L) i += L discard md5_Final(addr res, ctx) |