fix(imports): NoneType 异常静默 + struct_body 判空,减少 WARN 干扰输出

编译大量输出 "HandlesImports: 忽略异常 'NoneType' object has no attribute 'endswith'":注解/类型解析回退路径对 None 参与运算(数据缺失属正常兜底)——每文件每符号都打 WARN 淹没关键信息。

- 783/1166/1264 三处 except:AttributeError+NoneType 时静默不 WARN,其他异常保留
- 两处 is_packed 判断补 struct_body is not None 防护(源头防 None.startswith/endswith)
This commit is contained in:
TermiNexus committed 2026-08-17 20:07:35 +08:00
1 parent f66e119d1f
commit e5af28fa93
1 file changed
+9 -2
+9 -2
View File
@@ -777,6 +777,8 @@ class ImportHandle(BaseHandle):
self._LoadModuleDeclarationsFromFile(sha1_pyi, Gen, module_name=alias.name, register_module_name=register_module_name, reexport_package=module_name)
has_functions_or_classes = True
except Exception as e:
# NoneType 异常是数据缺失的正常兜底,静默不 WARN(干扰太多)
if not (isinstance(e, AttributeError) and "'NoneType'" in str(e)):
if module_name == 'pyzlib':
node_type = type(node).__name__
name = getattr(node, 'name', getattr(node, 'attr', '?'))
@@ -1163,6 +1165,9 @@ class ImportHandle(BaseHandle):
ReturnTypeInfo.BaseType = t.CInt()
IsPtr = ReturnTypeInfo.IsPtr
except Exception as e: # 回退:返回类型解析失败时使用默认 CInt
# NoneType 异常(如对 None 调 endswith)是数据缺失的正常兜底场景,
# 静默不输出 WARN(干扰太多);其他异常保留提示。
if not (isinstance(e, AttributeError) and "'NoneType'" in str(e)):
_vlog().warning(f"HandlesImports: 忽略异常 {e}", exc_info=e)
ReturnTypeInfo = CTypeInfo()
ReturnTypeInfo.BaseType = t.CInt()
@@ -1261,6 +1266,8 @@ class ImportHandle(BaseHandle):
ParamTypeInfo.PtrCount = max(ParamTypeInfo.PtrCount, 1)
ParamType = Gen._ctype_to_llvm(ParamTypeInfo)
except Exception as e: # 回退:参数类型解析失败时使用默认 i32
# NoneType 异常是数据缺失的正常兜底,静默不 WARN(干扰太多)
if not (isinstance(e, AttributeError) and "'NoneType'" in str(e)):
_vlog().warning(f"HandlesImports: 忽略异常 {e}", exc_info=e)
ParamType = ir.IntType(32)
if isinstance(ParamType, ir.VoidType) or (isinstance(ParamType, ir.PointerType) and isinstance(ParamType.pointee, ir.VoidType)):
@@ -2109,7 +2116,7 @@ class ImportHandle(BaseHandle):
if len(parts[0]) == 16 and all(c in '0123456789abcdef' for c in parts[0]):
actual_sha1 = parts[0]
is_packed = struct_body.startswith('<{') and struct_body.endswith('}>')
is_packed = struct_body is not None and struct_body.startswith('<{') and struct_body.endswith('}>')
if struct_body and struct_body != 'opaque':
elem_types = []
if is_packed:
@@ -2461,7 +2468,7 @@ class ImportHandle(BaseHandle):
struct_body = struct_def_match.group(3).strip()
if struct_body and struct_body != 'opaque':
elem_types = []
is_packed = struct_body.startswith('<{') and struct_body.endswith('}>')
is_packed = struct_body is not None and struct_body.startswith('<{') and struct_body.endswith('}>')
if is_packed:
inner = struct_body[2:-1].strip()
else: