fix(gen): extract_module_docstrings 用 children 而非不存在的 body 字段

- FunctionDef/ClassDef 无 body 字段(函数体在 AST.children),fd.body 被编译为基类 parent 字段,bitcast 父节点当 list 调用 __len__ 导致 ASan 读 0xffffffffffffffff 崩溃
- 4 处 .body 改为 .children(与全库一致)
- BuildPipeline: docstring 提取提前到 tr.translate 之前(避免 translate 期间 mb 池复用 AST 池块)
This commit is contained in:
TermiNexus committed 2026-08-12 21:45:32 +08:00
1 parent 98ddf7977e
commit 8f484f6860
2 files changed
+11 -8

No files matched your search

+7 -4
View File
@@ -207,13 +207,16 @@ def TranslateFileGetTrans(mb: memhub.MemBuddy | t.CPtr, file_path: str,
if string.strstr(file_path, "includes") is not None:
strict_mode = 0
HandlesStruct.reset_visible_structs(mb, strict_mode)
# 提取 docstring(预注册阶段所有 App/includes 文件都被翻译,
# 保证跨模块 __doc__ 在正式翻译前已登记;查重幂等)
# 注意:必须在 tr.translate 之前扫描——translate 期间 mb 池大量分配
# IR 节点,AST 节点所在池块可能被复用覆盖(ASan 下遍历 tree 读
# 0xffffffffffffffff 崩溃),docstring 提取与翻译状态无关,提前安全。
if gen is not None:
gen.extract_module_docstrings(tree, sha1_val)
ret: int = tr.translate(tree)
if ret != 0:
return None
# 提取 docstring(预注册阶段所有 App/includes 文件都被翻译,
# 保证跨模块 __doc__ 在正式翻译前已登记;查重幂等)
if gen is not None:
gen.extract_module_docstrings(tree, sha1_val)
return tr
+4 -4
View File
@@ -3854,7 +3854,7 @@ class ExprGenMixin:
if kd == ast.ASTKind.FunctionDef:
fd: ast.FunctionDef | t.CPtr = (ast.FunctionDef | t.CPtr)(child)
if fd is not None and fd.name is not None:
fd_body: list[ast.AST | t.CPtr] | t.CPtr = fd.body
fd_body: list[ast.AST | t.CPtr] | t.CPtr = fd.children
fdoc: str = self._extract_docstring_from_body(fd_body)
if fdoc is not None:
self.register_docstring(module_sha1, fd.name, fdoc)
@@ -3862,12 +3862,12 @@ class ExprGenMixin:
cd: ast.ClassDef | t.CPtr = (ast.ClassDef | t.CPtr)(child)
if cd is None or cd.name is None:
continue
cd_body0: list[ast.AST | t.CPtr] | t.CPtr = cd.body
cd_body0: list[ast.AST | t.CPtr] | t.CPtr = cd.children
cdoc: str = self._extract_docstring_from_body(cd_body0)
if cdoc is not None:
self.register_docstring(module_sha1, cd.name, cdoc)
# 类方法 docstring(key="{ClassName}.{method}")
cd_body: list[ast.AST | t.CPtr] | t.CPtr = cd.body
cd_body: list[ast.AST | t.CPtr] | t.CPtr = cd.children
if cd_body is not None:
cbn: t.CSizeT = len(cd_body)
for mi in range(cbn):
@@ -3877,7 +3877,7 @@ class ExprGenMixin:
mfd: ast.FunctionDef | t.CPtr = (ast.FunctionDef | t.CPtr)(m)
if mfd is None or mfd.name is None:
continue
mdoc: str = self._extract_docstring_from_body(mfd.body)
mdoc: str = self._extract_docstring_from_body(mfd.children)
if mdoc is not None:
cl_nl: t.CSizeT = string.strlen(cd.name)
mt_nl: t.CSizeT = string.strlen(mfd.name)