As we need to use more libraries it became less practical to maintain our
own set of bindings, and since the GC only works with Tango, it makes
sense to just use Tango bindings.
-import libc = rt.gc.cdgc.libc;
+import cstdlib = tango.stdc.stdlib;
+import cstring = tango.stdc.string;
private extern (C) void onOutOfMemoryError();
private extern (C) void onOutOfMemoryError();
{
this.nbits = nbits;
nwords = (nbits + (BITS_PER_WORD - 1)) >> BITS_SHIFT;
{
this.nbits = nbits;
nwords = (nbits + (BITS_PER_WORD - 1)) >> BITS_SHIFT;
- data = cast(uint*)libc.calloc(nwords + 2, uint.sizeof);
+ data = cast(uint*)cstdlib.calloc(nwords + 2, uint.sizeof);
if (!data)
onOutOfMemoryError();
}
if (!data)
onOutOfMemoryError();
}
for (;d1!=dEnd;++d1)
*d1=0u;
} else {
for (;d1!=dEnd;++d1)
*d1=0u;
} else {
- libc.memset(data + 1, 0, nwords * uint.sizeof);
+ cstring.memset(data + 1, 0, nwords * uint.sizeof);
for (;d1!=dEnd;++d1,++d2)
*d1=*d2;
} else {
for (;d1!=dEnd;++d1,++d2)
*d1=*d2;
} else {
- libc.memcpy(data + 1, f.data + 1, nwords * uint.sizeof);
+ cstring.memcpy(data + 1, f.data + 1, nwords * uint.sizeof);
import rt.gc.cdgc.bits: GCBits;
import rt.gc.cdgc.stats: GCStats;
import alloc = rt.gc.cdgc.alloc;
import rt.gc.cdgc.bits: GCBits;
import rt.gc.cdgc.stats: GCStats;
import alloc = rt.gc.cdgc.alloc;
-import libc = rt.gc.cdgc.libc;
+
+import cstdlib = tango.stdc.stdlib;
+import cstring = tango.stdc.string;
assert(dim + nentries <= allocdim);
if (!data)
{
assert(dim + nentries <= allocdim);
if (!data)
{
- data = cast(Log*) libc.malloc(allocdim * Log.sizeof);
+ data = cast(Log*) cstdlib.malloc(allocdim * Log.sizeof);
if (!data && allocdim)
onOutOfMemoryError();
}
else
{
if (!data && allocdim)
onOutOfMemoryError();
}
else
{
- Log *newdata = cast(Log*) libc.malloc(
+ Log *newdata = cast(Log*) cstdlib.malloc(
allocdim * Log.sizeof);
if (!newdata && allocdim)
onOutOfMemoryError();
allocdim * Log.sizeof);
if (!newdata && allocdim)
onOutOfMemoryError();
- libc.memcpy(newdata, data, dim * Log.sizeof);
- libc.free(data);
+ cstring.memcpy(newdata, data, dim * Log.sizeof);
+ cstdlib.free(data);
- libc.memmove(data + i, data + i + 1, (dim - i) * Log.sizeof);
+ cstring.memmove(data + i, data + i + 1, (dim - i) * Log.sizeof);
{
reserve(from.dim - dim);
assert(from.dim <= allocdim);
{
reserve(from.dim - dim);
assert(from.dim <= allocdim);
- libc.memcpy(data, from.data, from.dim * Log.sizeof);
+ cstring.memcpy(data, from.data, from.dim * Log.sizeof);
void initialize()
{
gcLock = GCLock.classinfo;
void initialize()
{
gcLock = GCLock.classinfo;
- gcx = cast(Gcx*) libc.calloc(1, Gcx.sizeof);
+ gcx = cast(Gcx*) cstdlib.calloc(1, Gcx.sizeof);
if (!gcx)
onOutOfMemoryError();
gcx.initialize();
if (!gcx)
onOutOfMemoryError();
gcx.initialize();
// Return next item from free list
gcx.bucket[bin] = (cast(List*)p).next;
if( !(bits & BlkAttr.NO_SCAN) )
// Return next item from free list
gcx.bucket[bin] = (cast(List*)p).next;
if( !(bits & BlkAttr.NO_SCAN) )
- libc.memset(p + size, 0, binsize[bin] - size);
- debug (MEMSTOMP) libc.memset(p, 0xF0, size);
+ cstring.memset(p + size, 0, binsize[bin] - size);
+ debug (MEMSTOMP) cstring.memset(p, 0xF0, size);
assert(size != 0);
void *p = mallocNoSync(size, bits);
assert(size != 0);
void *p = mallocNoSync(size, bits);
- libc.memset(p, 0, size);
+ cstring.memset(p, 0, size);
p2 = mallocNoSync(size, bits);
if (psize < size)
size = psize;
p2 = mallocNoSync(size, bits);
if (psize < size)
size = psize;
- libc.memcpy(p2, p, size);
+ cstring.memcpy(p2, p, size);
synchronized (gcLock)
{
debug (MEMSTOMP)
synchronized (gcLock)
{
debug (MEMSTOMP)
- libc.memset(p + size, 0xF2, psize - size);
+ cstring.memset(p + size, 0xF2, psize - size);
pool.freePages(pagenum + newsz, psz - newsz);
}
return p;
pool.freePages(pagenum + newsz, psz - newsz);
}
return p;
if (i == pagenum + newsz)
{
debug (MEMSTOMP)
if (i == pagenum + newsz)
{
debug (MEMSTOMP)
- libc.memset(p + psize, 0xF0,
+ cstring.memset(p + psize, 0xF0,
- libc.memset(&pool.pagetable[pagenum + psz],
- B_PAGEPLUS, newsz - psz);
+ cstring.memset(pool.pagetable + pagenum +
+ psz, B_PAGEPLUS, newsz - psz);
return p;
}
if (i == pool.npages)
return p;
}
if (i == pool.npages)
p2 = mallocNoSync(size, bits);
if (psize < size)
size = psize;
p2 = mallocNoSync(size, bits);
if (psize < size)
size = psize;
- libc.memcpy(p2, p, size);
+ cstring.memcpy(p2, p, size);
if (sz < minsz)
return 0;
debug (MEMSTOMP)
if (sz < minsz)
return 0;
debug (MEMSTOMP)
- libc.memset(p + psize, 0xF0, (psz + sz) * PAGESIZE - psize);
- libc.memset(pool.pagetable + pagenum + psz, B_PAGEPLUS, sz);
+ cstring.memset(p + psize, 0xF0, (psz + sz) * PAGESIZE - psize);
+ cstring.memset(pool.pagetable + pagenum + psz, B_PAGEPLUS, sz);
gcx.p_cache = null;
gcx.size_cache = 0;
return (psz + sz) * PAGESIZE;
gcx.p_cache = null;
gcx.size_cache = 0;
return (psz + sz) * PAGESIZE;
size_t n = pagenum;
while (++n < pool.npages && pool.pagetable[n] == B_PAGEPLUS)
npages++;
size_t n = pagenum;
while (++n < pool.npages && pool.pagetable[n] == B_PAGEPLUS)
npages++;
- debug (MEMSTOMP) libc.memset(p, 0xF2, npages * PAGESIZE);
+ debug (MEMSTOMP) cstring.memset(p, 0xF2, npages * PAGESIZE);
pool.freePages(pagenum, npages);
}
else
pool.freePages(pagenum, npages);
}
else
// Add to free list
List *list = cast(List*)p;
// Add to free list
List *list = cast(List*)p;
- debug (MEMSTOMP) libc.memset(p, 0xF2, binsize[bin]);
+ debug (MEMSTOMP) cstring.memset(p, 0xF2, binsize[bin]);
list.next = gcx.bucket[bin];
gcx.bucket[bin] = list;
list.next = gcx.bucket[bin];
gcx.bucket[bin] = list;
size_t n;
size_t bsize = 0;
size_t n;
size_t bsize = 0;
- libc.memset(&stats, 0, GCStats.sizeof);
+ cstring.memset(&stats, 0, GCStats.sizeof);
for (n = 0; n < gcx.npools; n++)
{
for (n = 0; n < gcx.npools; n++)
{
// 1. to hide the reference from the GC
// 2. the GC doesn't scan delegates added by rt_attachDisposeEvent
// for references
// 1. to hide the reference from the GC
// 2. the GC doesn't scan delegates added by rt_attachDisposeEvent
// for references
- auto wp = cast(WeakPointer*)(libc.malloc(WeakPointer.sizeof));
+ auto wp = cast(WeakPointer*)(cstdlib.malloc(WeakPointer.sizeof));
if (!wp)
onOutOfMemoryError();
wp.reference = r;
if (!wp)
onOutOfMemoryError();
wp.reference = r;
if (wp.reference)
rt_detachDisposeEvent(wp.reference, &wp.ondestroy);
});
if (wp.reference)
rt_detachDisposeEvent(wp.reference, &wp.ondestroy);
});
{
Pool *pool = pooltable[i];
pool.Dtor();
{
Pool *pool = pooltable[i];
pool.Dtor();
+ cstdlib.free(pooltable);
size_t newdim = rootdim * 2 + 16;
void** newroots;
size_t newdim = rootdim * 2 + 16;
void** newroots;
- newroots = cast(void**) libc.malloc(newdim * newroots[0].sizeof);
+ newroots = cast(void**) cstdlib.malloc(newdim * newroots[0].sizeof);
if (!newroots)
onOutOfMemoryError();
if (roots)
{
if (!newroots)
onOutOfMemoryError();
if (roots)
{
- libc.memcpy(newroots, roots, nroots * newroots[0].sizeof);
- libc.free(roots);
+ cstring.memcpy(newroots, roots, nroots * newroots[0].sizeof);
+ cstdlib.free(roots);
}
roots = newroots;
rootdim = newdim;
}
roots = newroots;
rootdim = newdim;
if (roots[i] == p)
{
nroots--;
if (roots[i] == p)
{
nroots--;
- libc.memmove(roots + i, roots + i + 1,
+ cstring.memmove(roots + i, roots + i + 1,
(nroots - i) * roots[0].sizeof);
return;
}
(nroots - i) * roots[0].sizeof);
return;
}
size_t newdim = rangedim * 2 + 16;
Range *newranges;
size_t newdim = rangedim * 2 + 16;
Range *newranges;
- newranges = cast(Range*) libc.malloc(newdim * newranges[0].sizeof);
+ newranges = cast(Range*) cstdlib.malloc(newdim * Range.sizeof);
if (!newranges)
onOutOfMemoryError();
if (ranges)
{
if (!newranges)
onOutOfMemoryError();
if (ranges)
{
- libc.memcpy(newranges, ranges, nranges * newranges[0].sizeof);
- libc.free(ranges);
+ cstring.memcpy(newranges, ranges, nranges * Range.sizeof);
+ cstdlib.free(ranges);
}
ranges = newranges;
rangedim = newdim;
}
ranges = newranges;
rangedim = newdim;
if (ranges[i].pbot == pbot)
{
nranges--;
if (ranges[i].pbot == pbot)
{
nranges--;
- libc.memmove(ranges + i, ranges + i + 1,
+ cstring.memmove(ranges + i, ranges + i + 1,
(nranges - i) * ranges[0].sizeof);
return;
}
(nranges - i) * ranges[0].sizeof);
return;
}
- libc.free(pool);
- libc.memmove(pooltable + n,
+ cstdlib.free(pool);
+ cstring.memmove(pooltable + n,
pooltable + n + 1,
(--npools - n) * (Pool*).sizeof);
minAddr = pooltable[0].baseAddr;
pooltable + n + 1,
(--npools - n) * (Pool*).sizeof);
minAddr = pooltable[0].baseAddr;
L1:
pool.pagetable[pn] = B_PAGE;
if (npages > 1)
L1:
pool.pagetable[pn] = B_PAGE;
if (npages > 1)
- libc.memset(&pool.pagetable[pn + 1], B_PAGEPLUS, npages - 1);
+ cstring.memset(&pool.pagetable[pn + 1], B_PAGEPLUS, npages - 1);
p = pool.baseAddr + pn * PAGESIZE;
p = pool.baseAddr + pn * PAGESIZE;
- libc.memset(cast(char *)p + size, 0, npages * PAGESIZE - size);
- debug (MEMSTOMP) libc.memset(p, 0xF1, size);
+ cstring.memset(cast(char *)p + size, 0, npages * PAGESIZE - size);
+ debug (MEMSTOMP) cstring.memset(p, 0xF1, size);
- pool = cast(Pool *) libc.calloc(1, Pool.sizeof);
+ pool = cast(Pool *) cstdlib.calloc(1, Pool.sizeof);
if (pool)
{
pool.initialize(npages);
if (pool)
{
pool.initialize(npages);
goto Lerr;
newnpools = npools + 1;
goto Lerr;
newnpools = npools + 1;
- newpooltable = cast(Pool **) libc.realloc(pooltable,
+ newpooltable = cast(Pool **) cstdlib.realloc(pooltable,
newnpools * (Pool *).sizeof);
if (!newpooltable)
goto Lerr;
newnpools * (Pool *).sizeof);
if (!newpooltable)
goto Lerr;
if (pool.opCmp(newpooltable[i]) < 0)
break;
}
if (pool.opCmp(newpooltable[i]) < 0)
break;
}
- libc.memmove(newpooltable + i + 1, newpooltable + i,
+ cstring.memmove(newpooltable + i + 1, newpooltable + i,
(npools - i) * (Pool *).sizeof);
newpooltable[i] = pool;
(npools - i) * (Pool *).sizeof);
newpooltable[i] = pool;
List *list = cast(List *)p;
log_free(sentinel_add(list));
List *list = cast(List *)p;
log_free(sentinel_add(list));
- debug (MEMSTOMP) libc.memset(p, 0xF3, size);
+ debug (MEMSTOMP) cstring.memset(p, 0xF3, size);
}
pool.pagetable[pn] = B_FREE;
freed += PAGESIZE;
}
pool.pagetable[pn] = B_FREE;
freed += PAGESIZE;
List *list = cast(List *)p;
log_free(sentinel_add(list));
List *list = cast(List *)p;
log_free(sentinel_add(list));
- debug (MEMSTOMP) libc.memset(p, 0xF3, size);
+ debug (MEMSTOMP) cstring.memset(p, 0xF3, size);
log_free(sentinel_add(p));
pool.pagetable[pn] = B_FREE;
freedpages++;
log_free(sentinel_add(p));
pool.pagetable[pn] = B_FREE;
freedpages++;
- debug (MEMSTOMP) libc.memset(p, 0xF3, PAGESIZE);
+ debug (MEMSTOMP) cstring.memset(p, 0xF3, PAGESIZE);
while (pn + 1 < pool.npages && pool.pagetable[pn + 1] == B_PAGEPLUS)
{
pn++;
while (pn + 1 < pool.npages && pool.pagetable[pn + 1] == B_PAGEPLUS)
{
pn++;
debug (MEMSTOMP)
{
p += PAGESIZE;
debug (MEMSTOMP)
{
p += PAGESIZE;
- libc.memset(p, 0xF3, PAGESIZE);
+ cstring.memset(p, 0xF3, PAGESIZE);
freebits.alloc(cast(size_t)poolsize / 16);
noscan.alloc(cast(size_t)poolsize / 16);
freebits.alloc(cast(size_t)poolsize / 16);
noscan.alloc(cast(size_t)poolsize / 16);
- pagetable = cast(ubyte*) libc.malloc(npages);
+ pagetable = cast(ubyte*) cstdlib.malloc(npages);
if (!pagetable)
onOutOfMemoryError();
if (!pagetable)
onOutOfMemoryError();
- libc.memset(pagetable, B_FREE, npages);
+ cstring.memset(pagetable, B_FREE, npages);
topAddr = null;
}
if (pagetable)
topAddr = null;
}
if (pagetable)
+ cstdlib.free(pagetable);
mark.Dtor();
scan.Dtor();
mark.Dtor();
scan.Dtor();
*/
void freePages(size_t pagenum, size_t npages)
{
*/
void freePages(size_t pagenum, size_t npages)
{
- libc.memset(&pagetable[pagenum], B_FREE, npages);
+ cstring.memset(&pagetable[pagenum], B_FREE, npages);
import rt.gc.cdgc.gc: GC, BlkInfo;
import rt.gc.cdgc.stats: GCStats;
import rt.gc.cdgc.gc: GC, BlkInfo;
import rt.gc.cdgc.stats: GCStats;
-import libc = rt.gc.cdgc.libc;
+
+import cstdlib = tango.stdc.stdlib;
version (GCCLASS)
{
ClassInfo ci = GC.classinfo;
version (GCCLASS)
{
ClassInfo ci = GC.classinfo;
- void* p = libc.malloc(ci.init.length);
+ void* p = cstdlib.malloc(ci.init.length);
(cast(byte*)p)[0 .. ci.init.length] = ci.init[];
_gc = cast(GC)p;
}
else
{
(cast(byte*)p)[0 .. ci.init.length] = ci.init[];
_gc = cast(GC)p;
}
else
{
- _gc = cast(GC*) libc.calloc(1, GC.sizeof);
+ _gc = cast(GC*) cstdlib.calloc(1, GC.sizeof);
}
_gc.initialize();
version (DigitalMars) version(OSX) {
}
_gc.initialize();
version (DigitalMars) version(OSX) {
+++ /dev/null
-
-module rt.gc.cdgc.libc;
-
-version (Windows) {
- alias int c_long;
- alias uint c_ulong;
-}
-else {
- static if ((void*).sizeof > int.sizeof) {
- alias long c_long;
- alias ulong c_ulong;
- }
- else {
- alias int c_long;
- alias uint c_ulong;
- }
-}
-
-// C standard library
-extern (C):
-void* realloc(void*, size_t);
-void* malloc(size_t);
-void* calloc(size_t, size_t);
-void free(void*);
-void* memset(void*, int, size_t);
-void* memcpy(void*, void*, size_t);
-void* memmove(void*, void*, size_t);
-void printf(char* fmt, ...);
-