respect -d:useMalloc everywhere; turn ansi_c and memory into proper Nim modules
This commit is contained in:
parent
9565b844dd
commit
6efa7ecf18
4 changed files with 83 additions and 66 deletions
|
|
@ -1,6 +1,9 @@
|
|||
const useLibC = not defined(nimNoLibc)
|
||||
|
||||
proc nimCopyMem(dest, source: pointer, size: Natural) {.compilerproc, inline.} =
|
||||
when useLibC:
|
||||
import ansi_c
|
||||
|
||||
proc nimCopyMem*(dest, source: pointer, size: Natural) {.compilerproc, inline.} =
|
||||
when useLibC:
|
||||
c_memcpy(dest, source, size)
|
||||
else:
|
||||
|
|
@ -11,7 +14,7 @@ proc nimCopyMem(dest, source: pointer, size: Natural) {.compilerproc, inline.} =
|
|||
d[i] = s[i]
|
||||
inc i
|
||||
|
||||
proc nimSetMem(a: pointer, v: cint, size: Natural) {.nonReloadable, inline.} =
|
||||
proc nimSetMem*(a: pointer, v: cint, size: Natural) {.nonReloadable, inline.} =
|
||||
when useLibC:
|
||||
c_memset(a, v, size)
|
||||
else:
|
||||
|
|
@ -22,10 +25,10 @@ proc nimSetMem(a: pointer, v: cint, size: Natural) {.nonReloadable, inline.} =
|
|||
a[i] = v
|
||||
inc i
|
||||
|
||||
proc nimZeroMem(p: pointer, size: Natural) {.compilerproc, nonReloadable, inline.} =
|
||||
proc nimZeroMem*(p: pointer, size: Natural) {.compilerproc, nonReloadable, inline.} =
|
||||
nimSetMem(p, 0, size)
|
||||
|
||||
proc nimCmpMem(a, b: pointer, size: Natural): cint {.compilerproc, inline.} =
|
||||
proc nimCmpMem*(a, b: pointer, size: Natural): cint {.compilerproc, inline.} =
|
||||
when useLibC:
|
||||
c_memcmp(a, b, size)
|
||||
else:
|
||||
|
|
@ -37,7 +40,7 @@ proc nimCmpMem(a, b: pointer, size: Natural): cint {.compilerproc, inline.} =
|
|||
if d != 0: return d
|
||||
inc i
|
||||
|
||||
proc nimCStrLen(a: cstring): csize {.compilerproc, nonReloadable, inline.} =
|
||||
proc nimCStrLen*(a: cstring): csize {.compilerproc, nonReloadable, inline.} =
|
||||
when useLibC:
|
||||
c_strlen(a)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue