修正了 TPC 的一些错误,包括 Test 维护后 TPV 无法重新编译或重编译后越界的部分问题

This commit is contained in:
2026-07-20 11:12:30 +08:00
parent ab73420b4f
commit a277ded8d4
476 changed files with 4000 additions and 3439 deletions

View File

@@ -171,6 +171,7 @@ def compute_file_sha1(pool: memhub.MemBuddy | t.CPtr,
bytes_read: t.CInt64T = f.read_all(buf, BUF_SIZE)
f.close()
if bytes_read <= 0:
stdlib.free(buf)
return None
# 原地去除 \rCRLF → LF与 Projectrans.py 文本模式读取一致
@@ -189,17 +190,21 @@ def compute_file_sha1(pool: memhub.MemBuddy | t.CPtr,
# 计算 SHA1
ctx: hashlib.sha1 | t.CPtr = hashlib.sha1()
if ctx is None:
stdlib.free(buf)
return None
ctx.update(buf)
digest: bytes = stdlib.malloc(hashlib.SHA1_DIGEST_LEN)
if digest is None:
stdlib.free(buf)
return None
ctx.final(digest)
# 转为十六进制字符串(取前 8 字节 = 16 个十六进制字符)
hex_buf: str = stdlib.malloc(17)
if hex_buf is None:
stdlib.free(buf)
stdlib.free(digest)
return None
for i in range(8):
hi: int = (digest[i] >> 4) & 0xF
@@ -213,6 +218,9 @@ def compute_file_sha1(pool: memhub.MemBuddy | t.CPtr,
else:
hex_buf[i * 2 + 1] = 'a' + (lo - 10)
hex_buf[16] = '\0'
# 释放临时缓冲区hex_buf 由调用者负责释放)
stdlib.free(buf)
stdlib.free(digest)
return hex_buf
@@ -245,6 +253,8 @@ def scan_directory_recursive(pool: memhub.MemBuddy | t.CPtr,
handle: win32base.HANDLE = win32file.FindFirstFileA(pattern, find_data)
if handle == win32base.INVALID_HANDLE_VALUE:
stdlib.free(pattern)
stdlib.free(find_data)
return 1
# 遍历所有文件和子目录
@@ -284,6 +294,7 @@ def scan_directory_recursive(pool: memhub.MemBuddy | t.CPtr,
prefix_len = string.strlen(rel_prefix)
rel_path: bytes = stdlib.malloc(prefix_len + fname_len + 2)
if rel_path is None:
stdlib.free(full_path)
break
if rel_prefix is not None and prefix_len > 0:
viperlib.snprintf(rel_path, prefix_len + fname_len + 2, "%s/%s", rel_prefix, fname)
@@ -312,13 +323,21 @@ def scan_directory_recursive(pool: memhub.MemBuddy | t.CPtr,
sha1: str = compute_file_sha1(pool, full_path)
if sha1 is not None:
add_file_entry(result, pool, full_path, rel_path, sha1)
stdio.printf(" [scan] %s -> %s\n", rel_path, sha1)
# 释放 compute_file_sha1 返回的临时 hex_buf
stdlib.free(sha1)
# 释放本次迭代分配的路径缓冲区
stdlib.free(full_path)
stdlib.free(rel_path)
# 继续搜索下一个文件
if win32file.FindNextFileA(handle, find_data) == 0:
nxt: t.CInt = win32file.FindNextFileA(handle, find_data)
if nxt == 0:
break
win32file.FindClose(handle)
stdlib.free(pattern)
stdlib.free(find_data)
return 0
@@ -341,7 +360,8 @@ def scan_includes(pool: memhub.MemBuddy | t.CPtr,
scan_directory_recursive(pool, includes_dir, None, result)
stdio.printf("[Phase1] 扫描完成: %d 个 .py 文件\n", result.Count)
count: t.CInt = result.Count
stdio.printf("[Phase1] 扫描完成: %d 个 .py 文件\n", count)
return result