mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +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
|
@ -46,9 +46,9 @@ TEST(grow, testStackMemory_convertsToDynamic) {
|
|||
int A[] = {1, 2, 3};
|
||||
int *p = A;
|
||||
size_t capacity = ARRAYLEN(A);
|
||||
if (!isheap(p)) {
|
||||
if (!_isheap(p)) {
|
||||
EXPECT_TRUE(__grow(&p, &capacity, sizeof(int), 0));
|
||||
EXPECT_TRUE(isheap(p));
|
||||
EXPECT_TRUE(_isheap(p));
|
||||
EXPECT_GT(capacity, ARRAYLEN(A));
|
||||
EXPECT_EQ(1, p[0]);
|
||||
EXPECT_EQ(2, p[1]);
|
||||
|
@ -86,9 +86,9 @@ TEST(grow, testOverflow_returnsFalseAndDoesNotFree) {
|
|||
int A[] = {1, 2, 3};
|
||||
int *p = A;
|
||||
size_t capacity = ARRAYLEN(A);
|
||||
if (!isheap(p)) {
|
||||
if (!_isheap(p)) {
|
||||
EXPECT_FALSE(__grow(&p, &capacity, pushpop(SIZE_MAX), 0));
|
||||
EXPECT_FALSE(isheap(p));
|
||||
EXPECT_FALSE(_isheap(p));
|
||||
EXPECT_EQ(capacity, ARRAYLEN(A));
|
||||
EXPECT_EQ(1, p[0]);
|
||||
EXPECT_EQ(2, p[1]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue