mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
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:
parent
0ad609268f
commit
33e8fc8687
26 changed files with 192 additions and 182 deletions
|
@ -43,8 +43,8 @@ bool __grow(void *pp, size_t *capacity, size_t itemsize, size_t extra) {
|
|||
p = (void **)pp;
|
||||
assert(itemsize);
|
||||
assert((*p && *capacity) || (!*p && !*capacity));
|
||||
assert(!isheap(*p) || ((intptr_t)*p & 15) == 0);
|
||||
p1 = isheap(*p) ? *p : NULL;
|
||||
assert(!_isheap(*p) || ((intptr_t)*p & 15) == 0);
|
||||
p1 = _isheap(*p) ? *p : NULL;
|
||||
p2 = NULL;
|
||||
n1 = *capacity;
|
||||
n2 = (*p ? n1 + (n1 >> 1) : MAX(4, INITIAL_CAPACITY / itemsize)) + extra;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue