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

Fix allocation

This commit is contained in:
A. R. Shajii 2023-03-23 11:27:53 -04:00
parent e484bbe5c2
commit fbd0105958
2 changed files with 8 additions and 3 deletions

View File

@ -2,7 +2,8 @@
from internal.gc import (
free, register_finalizer, seq_alloc,
seq_alloc_atomic, seq_gc_add_roots, alloc_uncollectable
seq_alloc_atomic, seq_gc_add_roots, alloc_uncollectable,
alloc_atomic_uncollectable, atomic
)
@pure

View File

@ -1897,8 +1897,12 @@ class _PyWrap:
return cobj()
def wrap_to_py(o) -> cobj:
pytype = _PyWrap.py_type(type(o))
obj = Ptr[PyWrapper[type(o)]](alloc_uncollectable(sizeof(type(o))))
O = type(o)
P = PyWrapper[O]
sz = sizeof(P)
pytype = _PyWrap.py_type(O)
mem = alloc_atomic_uncollectable(sz) if atomic(O) else alloc_uncollectable(sz)
obj = Ptr[P](mem.as_byte())
obj[0] = PyWrapper(PyObject(1, pytype), o)
return obj.as_byte()