修正了种子编译器的错误
This commit is contained in:
@@ -338,7 +338,7 @@ class MemBuddy(MemManager):
|
||||
return 1
|
||||
prev: t.CVoid | t.CPtr = head
|
||||
cur: t.CVoid | t.CPtr = t.CVoid(c.Deref(t.CUInt64T(head, t.CPtr)), t.CPtr)
|
||||
while cur is not None:
|
||||
while t.CUInt64T(cur) != 0:
|
||||
if t.CUInt64T(cur) == t.CUInt64T(target):
|
||||
next_ptr: t.CVoid | t.CPtr = t.CVoid(c.Deref(t.CUInt64T(cur, t.CPtr)), t.CPtr)
|
||||
c.DerefAs(prev, next_ptr)
|
||||
@@ -418,28 +418,17 @@ class MemBuddy(MemManager):
|
||||
# === 虚函数覆盖 ===
|
||||
|
||||
def alloc(self, size: t.CSizeT) -> t.CVoid | t.CPtr:
|
||||
stdio.printf("DBG MemBuddy.alloc: size=%lu\n", size)
|
||||
stdio.fflush(None)
|
||||
self._lock()
|
||||
result: t.CVoid | t.CPtr = None
|
||||
if self.usable is not None:
|
||||
stdio.printf("DBG MemBuddy.alloc: usable=%p\n", self.usable)
|
||||
stdio.fflush(None)
|
||||
if size != 0:
|
||||
needed: t.CSizeT = size + MEMBUDDY_HEADER_SIZE
|
||||
order: t.CInt = self._order_for_size(needed)
|
||||
stdio.printf("DBG MemBuddy.alloc: order=%d max_order=%d\n", order, self.max_order)
|
||||
stdio.fflush(None)
|
||||
if order <= self.max_order:
|
||||
block: t.CVoid | t.CPtr = self._split_to_order(order)
|
||||
stdio.printf("DBG MemBuddy.alloc: block=%p\n", block)
|
||||
stdio.fflush(None)
|
||||
if block is not None:
|
||||
c.DerefAs(block, t.CVoid(t.CUInt64T((order << 1) | 1), t.CPtr))
|
||||
result = t.CVoid(t.CUInt64T(block) + MEMBUDDY_HEADER_SIZE, t.CPtr)
|
||||
else:
|
||||
stdio.printf("DBG MemBuddy.alloc: usable is None!\n")
|
||||
stdio.fflush(None)
|
||||
self._unlock()
|
||||
return result
|
||||
|
||||
@@ -509,7 +498,7 @@ class MemBuddy(MemManager):
|
||||
for i in range(MEMBUDDY_MAX_ORDERS + 1):
|
||||
head_val: t.CUInt64T = self.free_lists[i]
|
||||
cur: t.CVoid | t.CPtr = t.CVoid(head_val, t.CPtr)
|
||||
while cur is not None:
|
||||
while t.CUInt64T(cur) != 0:
|
||||
count += 1
|
||||
cur = t.CVoid(c.Deref(t.CUInt64T(cur, t.CPtr)), t.CPtr)
|
||||
return count
|
||||
@@ -522,7 +511,7 @@ class MemBuddy(MemManager):
|
||||
for i in range(MEMBUDDY_MAX_ORDERS + 1):
|
||||
head_val: t.CUInt64T = self.free_lists[i]
|
||||
cur: t.CVoid | t.CPtr = t.CVoid(head_val, t.CPtr)
|
||||
while cur is not None:
|
||||
while t.CUInt64T(cur) != 0:
|
||||
# 检查指针在可用区内
|
||||
if t.CUInt64T(cur) < t.CUInt64T(self.usable):
|
||||
return 1
|
||||
|
||||
@@ -38,10 +38,11 @@ def strncpy(dest: str, src: str, n: t.CSizeT) -> str:
|
||||
dest[0] = s
|
||||
dest += 1
|
||||
i += 1
|
||||
# 填充剩余空间为 '\0'
|
||||
for i in range(n):
|
||||
# 填充剩余空间为 '\0'(只填充 n-i 个,避免缓冲区溢出)
|
||||
while i < n:
|
||||
dest[0] = 0
|
||||
dest += 1
|
||||
i += 1
|
||||
return original_dest
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user