Expose public garbage collector API for C language
You can now do epic things like this:
puts(_gc(xasprintf("%d", 123)));
The _gc() API is shorthand for _defer() which works like Go's keyword:
const char *s = xasprintf("%d", 123);
_defer(free, s);
puts(s);
Be sure to always use -fno-omit-frame-pointer which makes code fast too.
Enjoy! See also #114
This commit is contained in:
@@ -137,18 +137,18 @@ TEST(mmap, mapPrivate_writesDontChangeFile) {
|
||||
}
|
||||
|
||||
TEST(isheap, nullPtr) {
|
||||
ASSERT_FALSE(isheap(NULL));
|
||||
ASSERT_FALSE(_isheap(NULL));
|
||||
}
|
||||
|
||||
TEST(isheap, malloc) {
|
||||
ASSERT_TRUE(isheap(gc(malloc(1))));
|
||||
ASSERT_TRUE(_isheap(gc(malloc(1))));
|
||||
}
|
||||
|
||||
TEST(isheap, emptyMalloc) {
|
||||
ASSERT_TRUE(isheap(gc(malloc(0))));
|
||||
ASSERT_TRUE(_isheap(gc(malloc(0))));
|
||||
}
|
||||
|
||||
TEST(isheap, mallocOffset) {
|
||||
char *p = gc(malloc(131072));
|
||||
ASSERT_TRUE(isheap(p + 100000));
|
||||
ASSERT_TRUE(_isheap(p + 100000));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user