From 1508563f1c53a8212e292be75cb2d7ddae0cbdd7 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sat, 24 Oct 2026 22:51:31 +0800 Subject: [PATCH] =?UTF-8?q?chore(ffilib):=20=E4=B8=B4=E6=97=B6=E6=8E=A2?= =?UTF-8?q?=E9=92=88=EF=BC=88CDLL=20=E6=8A=BD=E5=8F=96=20+=20extern=20?= =?UTF-8?q?=E5=88=86=E6=94=AF=E7=9A=84=20ffi=5Flib/runtime=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现象与"exe 已含最新提交"矛盾:add_c2 仍生成全局、@add 无 thunk、无 _ffilib 引用。加两处 printf 定位断点:_HandleCDLL 入口打印句柄名;translate_function_def 的 extern 分支打印 fd.ffi_lib 与 FfiHandleRuntime 结果。定位后立即移除。 --- App/lib/core/Gen/Func/FuncGenDef.vp | 4 ++++ App/lib/core/builtin/ViperBuild.vp | 2 ++ 2 files changed, 6 insertions(+) diff --git a/App/lib/core/Gen/Func/FuncGenDef.vp b/App/lib/core/Gen/Func/FuncGenDef.vp index d313c3c..2e9cb84 100644 --- a/App/lib/core/Gen/Func/FuncGenDef.vp +++ b/App/lib/core/Gen/Func/FuncGenDef.vp @@ -767,10 +767,14 @@ novirtual class FuncGenDef(CallGenBase.CallGenBase): if (has_export != 0 or has_state != 0) and trans.ModuleSha1 is not None: self.Gen.CallGenBase.register_cexport_func(trans.ModuleSha1, fd.name) if is_extern_decl != 0: + stdio.printf("[ffiprobe] extern branch '%s' ffi_lib=%s\n", fd.name, "nil" if fd.ffi_lib is None else fd.ffi_lib) + stdio.fflush(None) # extern name(...):runtime=True 在这里也生成 thunk(Phase A 的 extern 往往不走 # forward_declare_functions,两处都挂才覆盖全部路径;另一处靠 find_func_in_module 去重)。 if fd.ffi_lib is not None: ffi_rt_d: int = ViperBuild.FfiHandleRuntime(fd.ffi_lib) + stdio.printf("[ffiprobe] extern '%s' rt=%d\n", fd.name, ffi_rt_d) + stdio.fflush(None) if ffi_rt_d < 0: self.Gen.TypeGenErr.fatal_error(fd, f"extern library handle '{fd.ffi_lib}' is not a ffilib.CDLL binding (declare it with ffilib.CDLL(...) first)", "NameError") return 0 diff --git a/App/lib/core/builtin/ViperBuild.vp b/App/lib/core/builtin/ViperBuild.vp index 3703cdc..1953980 100644 --- a/App/lib/core/builtin/ViperBuild.vp +++ b/App/lib/core/builtin/ViperBuild.vp @@ -988,6 +988,8 @@ def _AssignTargetName(asn: ast.Assign*) -> str: # _HandleCDLL - 按实参形态写入静态/动态库表;list 回退形式本期 fail-fast def _HandleCDLL(node: ast.AST*, handle: str) -> int: """抽取 ffilib.CDLL(...):0=成功""" + stdio.printf("[ffiprobe] _HandleCDLL enter handle=%s\n", "?" if handle is None else handle) + stdio.fflush(None) if node is None or node.kind() != ast.ASTKind.Call: return 0 call: ast.Call* = ast.Call*(node) args: list[ast.AST*]* = call.args