mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-06 04:57:49 +00:00
This reverts commit 00c31e8766.
This commit is contained in:
@@ -79,7 +79,7 @@ proc countProcessors*(): int {.rtl, extern: "ncpi$1".} =
|
||||
len: csize
|
||||
mib[0] = CTL_HW
|
||||
mib[1] = HW_AVAILCPU
|
||||
len = csize sizeof(numCPU)
|
||||
len = sizeof(numCPU)
|
||||
discard sysctl(addr(mib), 2, addr(numCPU), len, nil, 0)
|
||||
if numCPU < 1:
|
||||
mib[1] = HW_NCPU
|
||||
|
||||
@@ -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, csize remaining)
|
||||
ending = c_memchr(ms.data, delim, remaining)
|
||||
if ending == nil: # unterminated final slice
|
||||
ms.size = remaining # Weird case..check eat?
|
||||
yield ms
|
||||
|
||||
@@ -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, csize L)
|
||||
let found = c_memchr(s[start].unsafeAddr, sub, L)
|
||||
if not found.isNil:
|
||||
return cast[ByteAddress](found) -% cast[ByteAddress](s.cstring)
|
||||
else:
|
||||
|
||||
@@ -2270,7 +2270,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.} = uint
|
||||
csize* {.importc: "size_t", nodecl.} = int
|
||||
## 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*.
|
||||
@@ -3634,7 +3634,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, csize size)
|
||||
c_memmove(dest, source, size)
|
||||
when declared(memTrackerOp):
|
||||
memTrackerOp("moveMem", dest, size)
|
||||
proc equalMem(a, b: pointer, size: Natural): bool =
|
||||
|
||||
@@ -17,24 +17,14 @@ 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 {.
|
||||
@@ -144,22 +134,16 @@ 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, csize s.len, f)
|
||||
discard c_fwrite(s, 1, s.len, f)
|
||||
|
||||
{.pop.}
|
||||
|
||||
@@ -85,14 +85,10 @@ 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 {.
|
||||
@@ -113,8 +109,6 @@ 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.}
|
||||
@@ -159,7 +153,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 = int c_fread(buffer, 1, csize len, f)
|
||||
result = c_fread(buffer, 1, len, f)
|
||||
if result != len: checkErr(f)
|
||||
|
||||
proc readBytes*(f: File, a: var openArray[int8|uint8], start, len: Natural): int {.
|
||||
@@ -191,7 +185,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, csize len, f)
|
||||
result = c_fwrite(buffer, 1, len, f)
|
||||
checkErr(f)
|
||||
|
||||
proc writeBytes*(f: File, a: openArray[int8|uint8], start, len: Natural): int {.
|
||||
@@ -304,8 +298,6 @@ 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
|
||||
|
||||
@@ -320,7 +312,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, csize sp)
|
||||
let m = c_memchr(addr line.string[pos], '\L'.ord, 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])
|
||||
|
||||
@@ -10,7 +10,7 @@ when useLibC:
|
||||
|
||||
proc nimCopyMem*(dest, source: pointer, size: Natural) {.nonReloadable, compilerproc, inline.} =
|
||||
when useLibC:
|
||||
c_memcpy(dest, source, csize size)
|
||||
c_memcpy(dest, source, 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, csize size)
|
||||
c_memset(a, v, 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, csize size)
|
||||
c_memcmp(a, b, size)
|
||||
else:
|
||||
let a = cast[ptr UncheckedArray[byte]](a)
|
||||
let b = cast[ptr UncheckedArray[byte]](b)
|
||||
|
||||
@@ -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.csize)
|
||||
let heap = memalign(PageSize, realSize)
|
||||
|
||||
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, csize size, PROT_READ or PROT_WRITE,
|
||||
result = mmap(nil, 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, csize size, PROT_READ or PROT_WRITE,
|
||||
result = mmap(nil, 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, csize size)
|
||||
when reallyOsDealloc: discard munmap(p, size)
|
||||
|
||||
elif defined(windows):
|
||||
const
|
||||
|
||||
@@ -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, csize bytes)
|
||||
discard md5_Update(ctx, buf[0].addr, 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, csize L)
|
||||
discard md5_Update(ctx, input[i].addr, L)
|
||||
i += L
|
||||
|
||||
discard md5_Final(addr res, ctx)
|
||||
|
||||
@@ -20,8 +20,9 @@ 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", "", false, "https://github.com/Clyybber/compactdict"
|
||||
pkg "compactdict"
|
||||
pkg "comprehension", "", false, "https://github.com/alehander42/comprehension"
|
||||
pkg "criterion"
|
||||
pkg "dashing", "nim c tests/functional.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), csize buffer.pos, flags)
|
||||
result = createPacket(cstring(buffer.data), buffer.pos, flags)
|
||||
|
||||
proc isDirty*(buffer: PBuffer): bool {.inline.} =
|
||||
result = (buffer.pos != 0)
|
||||
|
||||
Reference in New Issue
Block a user