diff --git a/App/lib/core/BuildPipeline.vp b/App/lib/core/BuildPipeline.vp index c808f5d..682332f 100644 --- a/App/lib/core/BuildPipeline.vp +++ b/App/lib/core/BuildPipeline.vp @@ -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 diff --git a/App/lib/core/Gen/ExprGenMixin.vp b/App/lib/core/Gen/ExprGenMixin.vp index 262bd4f..f932342 100644 --- a/App/lib/core/Gen/ExprGenMixin.vp +++ b/App/lib/core/Gen/ExprGenMixin.vp @@ -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)