mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 23:13:34 +00:00
Renaming gc() to _gc() was a mistake since the better thing to do is put it behind the _COSMO_SOURCE macro. We need this change because I haven't wanted to use my amazing garbage collector ever since we renamed it. You now need to define _COSMO_SOURCE yourself when using amalgamation header and cosmocc users need to pass the -mcosmo flag to get the gc() function Some other issues relating to cancelation have been fixed along the way. We're also now putting cosmocc in a folder named `.cosmocc` so it can be more safely excluded by grep --exclude-dir=.cosmocc --exclude-dir=o etc.
23 lines
885 B
C
23 lines
885 B
C
#ifndef COSMOPOLITAN_LIBC_MEM_GC_H_
|
|
#define COSMOPOLITAN_LIBC_MEM_GC_H_
|
|
#ifdef _COSMO_SOURCE
|
|
COSMOPOLITAN_C_START_
|
|
|
|
void _gc_free(void *) libcesque;
|
|
void __defer(void *, void *, void *) libcesque;
|
|
void gclongjmp(void *, int) libcesque wontreturn;
|
|
#define gc(THING) defer((void *)_gc_free, (void *)(THING))
|
|
#define _gc(THING) defer((void *)_gc_free, (void *)(THING))
|
|
#define defer(FN, ARG) \
|
|
({ \
|
|
autotype(ARG) Arg = (ARG); \
|
|
/* prevent weird opts like tail call */ \
|
|
__asm__ volatile("" : "+g"(Arg) : : "memory"); \
|
|
__defer(__builtin_frame_address(0), FN, Arg); \
|
|
__asm__ volatile("" : "+g"(Arg) : : "memory"); \
|
|
Arg; \
|
|
})
|
|
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* _COSMO_SOURCE */
|
|
#endif /* COSMOPOLITAN_LIBC_MEM_GC_H_ */
|