diff --git a/App/lib/core/Gen/ImportsGenMixin.vp b/App/lib/core/Gen/ImportsGenMixin.vp index 64a7260..4408f3d 100644 --- a/App/lib/core/Gen/ImportsGenMixin.vp +++ b/App/lib/core/Gen/ImportsGenMixin.vp @@ -11,7 +11,8 @@ import sys import win32.fileio as fileio import lib.Stub.StubMerger as StubMerger import lib.core.CompilerFactory as CompilerFactory -import lib.core.Gen.Translator as HT +import lib.core.Gen.Translator as HT +import lib.core.builtin.ViperBuild as ViperBuild import lib.Stub.StubMerger.StubMergerStore as StubMergerStore import lib.core.VLogger as VLogger @@ -589,6 +590,10 @@ novirtual class ImportsGenMixin: # declare_only=1/2 is the pre-registration scan and would false-positive. if trans._declare_only == 0: self._check_import_sha1(node, alias.name) StubMergerStore.NotePlainImport(pool_val, ctx, alias.name, alias.asname) + # runtime CDLL 的 thunk 要调 _ffilib:只要存在 runtime=True 的句柄, + # 就把该运行时库登记成导入模块,让可达性扫描收录它并分配 SHA1。 + if string.strcmp(alias.name, "ffilib") == 0: + if ViperBuild.HasRuntimeFfiHandle() != 0: StubMergerStore.NotePlainImport(pool_val, ctx, "_ffilib", None) trans._imported_modules = ctx.ImportedModules trans._from_imports = ctx.FromImports return 0 diff --git a/App/lib/core/builtin/ViperBuild.vp b/App/lib/core/builtin/ViperBuild.vp index 5b09fb9..76bb816 100644 --- a/App/lib/core/builtin/ViperBuild.vp +++ b/App/lib/core/builtin/ViperBuild.vp @@ -1079,6 +1079,17 @@ def IsCdlLDeclCall(node: ast.AST*) -> int: return _IsCDLLCall(node) +# HasRuntimeFfiHandle - 是否存在 runtime=True 的 CDLL 句柄(决定是否要引入 _ffilib 依赖) +def HasRuntimeFfiHandle() -> int: + """至少一个句柄 runtime=1 时返回 1""" + global _ffi_handles_rt + if _ffi_handles_rt is None: return 0 + n: sizet = _ffi_handles_rt.__len__() + for i in range(int(n)): + if _ffi_handles_rt.get(i) != 0: return 1 + return 0 + + # FfiHandlePath - 查询 extern name(...) 的库路径(runtime=True 的 thunk 用它 LoadLibraryA) def FfiHandlePath(name: str) -> str: """库路径;未登记返回 None"""