修复了大量存在的问题,增加了假鸭子类型等等机制

This commit is contained in:
2026-06-25 14:49:46 +08:00
parent 19f2787db0
commit d88d11b646
827 changed files with 32617 additions and 18316 deletions

View File

@@ -5,7 +5,7 @@ import string
MPOOL_ALIGN: t.CDefine = 8
MPOOL_TYPE_SLAB: t.CDefine = 0
MPOOL_TYPE_BUMP: t.CDefine = 2
MPOOL_TYPE_BUMP: t.CDefine = 1
def _align_up(val: t.CSizeT, align: t.CSizeT) -> t.CSizeT:
@@ -39,7 +39,6 @@ class MPool:
self.alloc_map = None
self.alloc_map_size = 0
if mem == None: return
if block_size > 0:
self._init_slab(mem, mem_size, block_size)
else:
@@ -113,9 +112,7 @@ class MPool:
def alloc(self, size: t.CSizeT) -> t.CVoid | t.CPtr:
if self.mtype == MPOOL_TYPE_SLAB:
return self._slab_alloc()
if self.mtype == MPOOL_TYPE_BUMP:
return self._bump_alloc(size)
return None
return self._bump_alloc(size)
def alloc_buf(self, capacity: t.CSizeT) -> viperio.Buf | t.CPtr:
ptr: t.CVoid | t.CPtr = self.alloc(capacity)