diff --git a/lib/pure/concurrency/cpuinfo.nim b/lib/pure/concurrency/cpuinfo.nim index 415b9a78725a3..5a72459a30579 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 411df1456471e..7e0478877fdd7 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 69cb1efd58453..fd5dcf14cc7a1 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 0edc869c2fbc9..9158b615361ff 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 16e7a14d606e1..89058ce4f2ba2 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: "".} +proc c_memchr*(s: pointer, c: cint, n: int): pointer {. + importc: "memchr", header: "", deprecated: "csize is now uint".} proc c_memcmp*(a, b: pointer, size: csize): cint {. importc: "memcmp", header: "", noSideEffect.} +proc c_memcmp*(a, b: pointer, size: int): cint {. + importc: "memcmp", header: "", noSideEffect, deprecated: "csize is now uint".} proc c_memcpy*(a, b: pointer, size: csize): pointer {. importc: "memcpy", header: "", discardable.} +proc c_memcpy*(a, b: pointer, size: int): pointer {. + importc: "memcpy", header: "", discardable, deprecated: "csize is now uint".} proc c_memmove*(a, b: pointer, size: csize): pointer {. importc: "memmove", header: "",discardable.} +proc c_memmove*(a, b: pointer, size: int): pointer {. + importc: "memmove", header: "",discardable, deprecated: "csize is now uint".} proc c_memset*(p: pointer, value: cint, size: csize): pointer {. importc: "memset", header: "", discardable.} +proc c_memset*(p: pointer, value: cint, size: int): pointer {. + importc: "memset", header: "", discardable, deprecated: "csize is now uint".} proc c_strcmp*(a, b: cstring): cint {. importc: "strcmp", header: "", 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: "".} +proc c_malloc*(size: int): pointer {. + importc: "malloc", header: "", deprecated: "csize is now uint".} proc c_free*(p: pointer) {. importc: "free", header: "".} proc c_realloc*(p: pointer, newsize: csize): pointer {. importc: "realloc", header: "".} +proc c_realloc*(p: pointer, newsize: int): pointer {. + importc: "realloc", header: "", deprecated: "csize is now uint".} proc c_fwrite*(buf: pointer, size, n: csize, f: CFilePtr): cint {. importc: "fwrite", header: "".} +proc c_fwrite*(buf: pointer, size, n: int, f: CFilePtr): cint {. + importc: "fwrite", header: "", 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 7ba36a30d35c6..46863064be4dd 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: "".} + proc c_fwrite(buf: pointer, size, n: int, f: File): cint {. + importc: "fwrite", header: "", 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: "", tags: [ReadIOEffect].} +proc c_fread(buf: pointer, size, n: int, f: File): int {. + importc: "fread", header: "", 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: "", tags: [].} proc c_setvbuf(f: File, buf: pointer, mode: cint, size: csize): cint {. importc: "setvbuf", header: "", tags: [].} +proc c_setvbuf(f: File, buf: pointer, mode: cint, size: int): cint {. + importc: "setvbuf", header: "", tags: [], deprecated: "csize is now uint".} proc c_fprintf(f: File, frmt: cstring): cint {. importc: "fprintf", header: "", 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: "".} + proc c_memchr(s: pointer, c: cint, n: int): pointer {. + importc: "memchr", header: "", 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 13bddf211ec30..53c9b1c3bd3e2 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 06e89f1305c82..e29f997d233a2 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: "".} 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 482062617b25e..46c9d7bd8d31d 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) diff --git a/testament/important_packages.nim b/testament/important_packages.nim index 6fd135fd19a85..dfa448c95561f 100644 --- a/testament/important_packages.nim +++ b/testament/important_packages.nim @@ -20,9 +20,8 @@ pkg "chroma" pkg "chronicles", "nim c -o:chr -r chronicles.nim", true pkg "chronos" pkg "cligen", "nim c -o:cligenn -r cligen.nim" -pkg "coco", "", true pkg "combparser" -pkg "compactdict" +pkg "compactdict", "", false, "https://github.com/Clyybber/compactdict" pkg "comprehension", "", false, "https://github.com/alehander42/comprehension" pkg "criterion" pkg "dashing", "nim c tests/functional.nim" diff --git a/tests/manyloc/keineschweine/lib/estreams.nim b/tests/manyloc/keineschweine/lib/estreams.nim index 99cbb63d1846a..e8a036f03c93a 100644 --- a/tests/manyloc/keineschweine/lib/estreams.nim +++ b/tests/manyloc/keineschweine/lib/estreams.nim @@ -26,7 +26,7 @@ proc newBuffer*(pkt: PPacket): PBuffer = copyMem(addr result.data[0], pkt.data, pkt.dataLength) proc toPacket*(buffer: PBuffer; flags: TPacketFlag): PPacket = buffer.data.setLen buffer.pos - result = createPacket(cstring(buffer.data), buffer.pos, flags) + result = createPacket(cstring(buffer.data), csize buffer.pos, flags) proc isDirty*(buffer: PBuffer): bool {.inline.} = result = (buffer.pos != 0)