codon/stdlib/internal/gc.codon

52 lines
1.3 KiB
Python
Raw Normal View History

2021-09-28 02:02:44 +08:00
# Primarily for internal use. Regular users should not use this module.
@pure
@C
def seq_alloc(a: int) -> cobj: pass
@pure
@C
def seq_alloc_atomic(a: int) -> cobj: pass
from C import seq_realloc(cobj, int) -> cobj
from C import seq_free(cobj)
2021-10-21 03:02:34 +08:00
from C import seq_register_finalizer(cobj, cobj)
2021-09-28 02:02:44 +08:00
from C import seq_gc_add_roots(cobj, cobj)
from C import seq_gc_remove_roots(cobj, cobj)
from C import seq_gc_clear_roots()
from C import seq_gc_exclude_static_roots(cobj, cobj)
def sizeof(T: type):
return T.__elemsize__
def atomic(T: type):
return T.__atomic__
def alloc(sz: int):
return seq_alloc(sz)
# Allocates a block of memory via GC, where the
# caller guarantees that this block will not store
# pointers to other GC-allocated data.
def alloc_atomic(sz: int):
return seq_alloc_atomic(sz)
def realloc(p: cobj, sz: int):
return seq_realloc(p, sz)
def free(p: cobj):
seq_free(p)
2021-10-21 03:02:34 +08:00
def register_finalizer(p: cobj, f: Function[[cobj, cobj], void]):
seq_register_finalizer(p, f.__raw__())
2021-09-28 02:02:44 +08:00
def add_roots(start: cobj, end: cobj):
seq_gc_add_roots(start, end)
def remove_roots(start: cobj, end: cobj):
seq_gc_remove_roots(start, end)
def clear_roots():
seq_gc_clear_roots()
def exclude_static_roots(start: cobj, end: cobj):
seq_gc_exclude_static_roots(start, end)