mirror of https://github.com/exaloop/codon.git
55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
# 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_register_finalizer(cobj, 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)
|
|
|
|
def register_finalizer(p):
|
|
if hasattr(p, '__del__'):
|
|
def f(x: cobj, data: cobj, T: type):
|
|
Ptr[T](__ptr__(x).as_byte())[0].__del__()
|
|
seq_register_finalizer(p.__raw__(), f(T=type(p), ...).__raw__())
|