Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Fixes nim-lang#12187
* Point to fork of compactdict
Since the original repo is now archived / read-only
  • Loading branch information
Clyybber authored and Araq committed Oct 8, 2019
1 parent edb24b7 commit 00c31e8
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/pure/concurrency/cpuinfo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/pure/memfiles.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/pure/strutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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*.
Expand Down Expand Up @@ -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 =
Expand Down
18 changes: 17 additions & 1 deletion lib/system/ansi_c.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 {.
Expand Down Expand Up @@ -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.}
14 changes: 11 additions & 3 deletions lib/system/io.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 {.
Expand All @@ -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.}
Expand Down Expand Up @@ -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 {.
Expand Down Expand Up @@ -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 {.
Expand Down Expand Up @@ -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

Expand All @@ -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])
Expand Down
6 changes: 3 additions & 3 deletions lib/system/memory.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions lib/system/osalloc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/wrappers/openssl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions testament/important_packages.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/manyloc/keineschweine/lib/estreams.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 00c31e8

Please sign in to comment.