1
0
mirror of https://github.com/exaloop/codon.git synced 2025-06-03 15:03:52 +08:00
codon/stdlib/internal/gc.codon

48 lines
1.1 KiB
Plaintext
Raw Normal View History

2021-09-27 14:02:44 -04: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)
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)
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)