fix(ffilib): runtime=True 时把 _ffilib 登记为导入模块,进入可达性扫描
Pass 0 的 _AddPending 只影响 viperbuild 的闭包 BFS,不影响 Phase1/Phase2 的 includes 可达性扫描(后者由 tr._imported_modules 驱动),所以 _ffilib 仍然没被收录、拿不到 SHA1。改为在 translate_import 里判断:若存在 runtime=True 的句柄(ViperBuild.HasRuntimeFfiHandle),则随 import ffilib 一并 NotePlainImport("_ffilib")。
This commit is contained in:
1 parent
796a2f5921
commit
2caf6f0795
2 files changed
+17
-1
No files matched your search
@@ -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
|
||||
|
||||
@@ -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 <lib> name(...) 的库路径(runtime=True 的 thunk 用它 LoadLibraryA)
|
||||
def FfiHandlePath(name: str) -> str:
|
||||
"""库路径;未登记返回 None"""
|
||||
|
||||
Reference in new issue
Block a user