From d02e6f21e3ff3f986e7b6022238c7b38185fb9e1 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Mon, 19 Oct 2026 18:34:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(traceback):=20=E4=BB=8E=20temp=5Fdir=20?= =?UTF-8?q?=E6=89=AB=E6=8F=8F=20.vpi=20=E5=AE=9A=E4=BD=8D=20traceback=20?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sig_files 可能不含 include 的 .vpi;改为直接扫描 temp_dir/*.vpi 匹配 'Module: traceback',确保 main 模块拿到 Install 符号。 --- lib/Projectrans/Phase2Translator.py | 35 +++++++++++++++++------------ 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/lib/Projectrans/Phase2Translator.py b/lib/Projectrans/Phase2Translator.py index 9793648..fc29e3e 100644 --- a/lib/Projectrans/Phase2Translator.py +++ b/lib/Projectrans/Phase2Translator.py @@ -2358,21 +2358,28 @@ class Phase2Translator: # 直接调用它(不依赖 .ctors/.init_array,避免 MinGW 下 .ctors.65534 不执行)。 if self.traceback_enabled: _tb_sha1: str | None = None - for _k, _p in self.sig_files.items(): - try: - if 'traceback' in os.path.basename(_p): - _tb_sha1 = _k - break - if 'Module: traceback' in _ReadTextCached(_p)[:512]: - _tb_sha1 = _k - break - except Exception: - continue + _temp_vpi: str = getattr(self, 'temp_dir', '') or '' + if _temp_vpi and os.path.isdir(_temp_vpi): + for _fn in os.listdir(_temp_vpi): + if not _fn.endswith('.vpi'): + continue + try: + if 'Module: traceback' in _ReadTextCached(os.path.join(_temp_vpi, _fn))[:512]: + _tb_sha1 = _fn[:-4] + break + except Exception: + continue if _tb_sha1 is None: - for _k, _p in getattr(self, '_shared_source_module_sig_files', {}).items(): - if 'traceback' in str(_p): - _tb_sha1 = _k - break + for _k, _p in self.sig_files.items(): + try: + if 'traceback' in os.path.basename(_p): + _tb_sha1 = _k + break + if 'Module: traceback' in _ReadTextCached(_p)[:512]: + _tb_sha1 = _k + break + except Exception: + continue trans.translator.TracebackEnabled = self.traceback_enabled if _tb_sha1 is not None: trans.translator.TracebackInstallSymbol = f'{_tb_sha1}.Install'