1
2{.push stackTrace: off.}
3
4proc allocImpl(size: Natural): pointer =
5  c_malloc(size.csize_t)
6
7proc alloc0Impl(size: Natural): pointer =
8  c_calloc(size.csize_t, 1)
9
10proc reallocImpl(p: pointer, newSize: Natural): pointer =
11  c_realloc(p, newSize.csize_t)
12
13proc realloc0Impl(p: pointer, oldsize, newSize: Natural): pointer =
14  result = realloc(p, newSize.csize_t)
15  if newSize > oldSize:
16    zeroMem(cast[pointer](cast[int](result) + oldSize), newSize - oldSize)
17
18proc deallocImpl(p: pointer) =
19  c_free(p)
20
21
22# The shared allocators map on the regular ones
23
24proc allocSharedImpl(size: Natural): pointer =
25  allocImpl(size)
26
27proc allocShared0Impl(size: Natural): pointer =
28  alloc0Impl(size)
29
30proc reallocSharedImpl(p: pointer, newSize: Natural): pointer =
31  reallocImpl(p, newSize)
32
33proc reallocShared0Impl(p: pointer, oldsize, newSize: Natural): pointer =
34  realloc0Impl(p, oldSize, newSize)
35
36proc deallocSharedImpl(p: pointer) = deallocImpl(p)
37
38
39# Empty stubs for the GC
40
41proc GC_disable() = discard
42proc GC_enable() = discard
43
44when not defined(gcOrc):
45  proc GC_fullCollect() = discard
46  proc GC_enableMarkAndSweep() = discard
47  proc GC_disableMarkAndSweep() = discard
48
49proc GC_setStrategy(strategy: GC_Strategy) = discard
50
51proc getOccupiedMem(): int = discard
52proc getFreeMem(): int = discard
53proc getTotalMem(): int = discard
54
55proc nimGC_setStackBottom(theStackBottom: pointer) = discard
56
57proc initGC() = discard
58
59proc newObjNoInit(typ: PNimType, size: int): pointer =
60  result = alloc(size)
61
62proc growObj(old: pointer, newsize: int): pointer =
63  result = realloc(old, newsize)
64
65proc nimGCref(p: pointer) {.compilerproc, inline.} = discard
66proc nimGCunref(p: pointer) {.compilerproc, inline.} = discard
67
68when not defined(gcDestructors):
69  proc unsureAsgnRef(dest: PPointer, src: pointer) {.compilerproc, inline.} =
70    dest[] = src
71
72proc asgnRef(dest: PPointer, src: pointer) {.compilerproc, inline.} =
73  dest[] = src
74proc asgnRefNoCycle(dest: PPointer, src: pointer) {.compilerproc, inline,
75  deprecated: "old compiler compat".} = asgnRef(dest, src)
76
77type
78  MemRegion = object
79
80proc alloc(r: var MemRegion, size: int): pointer =
81  result = alloc(size)
82proc alloc0Impl(r: var MemRegion, size: int): pointer =
83  result = alloc0Impl(size)
84proc dealloc(r: var MemRegion, p: pointer) = dealloc(p)
85proc deallocOsPages(r: var MemRegion) = discard
86proc deallocOsPages() = discard
87
88{.pop.}
89