Files
Nim/lib/system/memory.nim
Copilot 47d3fb28bd Resolve merge conflicts with devel branch refactoring (#25423)
The PR branch had merge conflicts with `devel` due to a major compiler
refactoring that extracted type definitions from `compiler/ast.nim` into
a new `compiler/astdef.nim` file.

## Changes

- Resolved conflict in `compiler/ast.nim` by accepting `devel`'s
refactored structure
- Merged 763 commits from `devel` branch (commit range:
`ce6a345..b3273e7`)
- Preserved original PR changes removing deprecated symbols from
`lib/core/macros.nim`

The core PR functionality (removal of deprecated macros API since
v0.18.1) remains intact while incorporating the upstream AST
refactoring.

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2026-01-09 20:06:36 +08:00

55 lines
1.4 KiB
Nim

{.push stack_trace: off.}
const useLibC = not defined(nimNoLibc)
import ansi_c
proc nimCopyMem*(dest, source: pointer, size: Natural) {.nonReloadable, inline, enforceNoRaises.} =
when useLibC:
c_memcpy(dest, source, cast[csize_t](size))
else:
let d = cast[ptr UncheckedArray[byte]](dest)
let s = cast[ptr UncheckedArray[byte]](source)
var i = 0
while i < size:
d[i] = s[i]
inc i
proc nimSetMem*(a: pointer, v: cint, size: Natural) {.nonReloadable, inline, enforceNoRaises.} =
when useLibC:
c_memset(a, v, cast[csize_t](size))
else:
let a = cast[ptr UncheckedArray[byte]](a)
var i = 0
let v = cast[byte](v)
while i < size:
a[i] = v
inc i
proc nimZeroMem*(p: pointer, size: Natural) {.nonReloadable, inline, enforceNoRaises.} =
nimSetMem(p, 0, size)
proc nimCmpMem*(a, b: pointer, size: Natural): cint {.nonReloadable, inline, enforceNoRaises.} =
when useLibC:
c_memcmp(a, b, cast[csize_t](size))
else:
let a = cast[ptr UncheckedArray[byte]](a)
let b = cast[ptr UncheckedArray[byte]](b)
var i = 0
while i < size:
let d = a[i].cint - b[i].cint
if d != 0: return d
inc i
proc nimCStrLen*(a: cstring): int {.nonReloadable, inline, enforceNoRaises.} =
if a.isNil: return 0
when useLibC:
cast[int](c_strlen(a))
else:
var a = cast[ptr byte](a)
while a[] != 0:
a = cast[ptr byte](cast[uint](a) + 1)
inc result
{.pop.}