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
+15 -8
+15 -8
View File
@@ -777,10 +777,12 @@ class ImportHandle(BaseHandle):
self._LoadModuleDeclarationsFromFile(sha1_pyi, Gen, module_name=alias.name, register_module_name=register_module_name, reexport_package=module_name) self._LoadModuleDeclarationsFromFile(sha1_pyi, Gen, module_name=alias.name, register_module_name=register_module_name, reexport_package=module_name)
has_functions_or_classes = True has_functions_or_classes = True
except Exception as e: except Exception as e:
if module_name == 'pyzlib': # NoneType 异常是数据缺失的正常兜底,静默不 WARN(干扰太多)
node_type = type(node).__name__ if not (isinstance(e, AttributeError) and "'NoneType'" in str(e)):
name = getattr(node, 'name', getattr(node, 'attr', '?')) if module_name == 'pyzlib':
_vlog().warning(f"HandlesImports: 忽略异常 {e}", exc_info=e) node_type = type(node).__name__
name = getattr(node, 'name', getattr(node, 'attr', '?'))
_vlog().warning(f"HandlesImports: 忽略异常 {e}", exc_info=e)
continue continue
if not has_functions_or_classes and module_name: if not has_functions_or_classes and module_name:
self._LoadDeclarationsFromStubLlvm(module_name, Gen) self._LoadDeclarationsFromStubLlvm(module_name, Gen)
@@ -1163,7 +1165,10 @@ class ImportHandle(BaseHandle):
ReturnTypeInfo.BaseType = t.CInt() ReturnTypeInfo.BaseType = t.CInt()
IsPtr = ReturnTypeInfo.IsPtr IsPtr = ReturnTypeInfo.IsPtr
except Exception as e: # 回退:返回类型解析失败时使用默认 CInt except Exception as e: # 回退:返回类型解析失败时使用默认 CInt
_vlog().warning(f"HandlesImports: 忽略异常 {e}", exc_info=e) # 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 = CTypeInfo()
ReturnTypeInfo.BaseType = t.CInt() ReturnTypeInfo.BaseType = t.CInt()
else: else:
@@ -1261,7 +1266,9 @@ class ImportHandle(BaseHandle):
ParamTypeInfo.PtrCount = max(ParamTypeInfo.PtrCount, 1) ParamTypeInfo.PtrCount = max(ParamTypeInfo.PtrCount, 1)
ParamType = Gen._ctype_to_llvm(ParamTypeInfo) ParamType = Gen._ctype_to_llvm(ParamTypeInfo)
except Exception as e: # 回退:参数类型解析失败时使用默认 i32 except Exception as e: # 回退:参数类型解析失败时使用默认 i32
_vlog().warning(f"HandlesImports: 忽略异常 {e}", exc_info=e) # NoneType 异常是数据缺失的正常兜底,静默不 WARN(干扰太多)
if not (isinstance(e, AttributeError) and "'NoneType'" in str(e)):
_vlog().warning(f"HandlesImports: 忽略异常 {e}", exc_info=e)
ParamType = ir.IntType(32) ParamType = ir.IntType(32)
if isinstance(ParamType, ir.VoidType) or (isinstance(ParamType, ir.PointerType) and isinstance(ParamType.pointee, ir.VoidType)): if isinstance(ParamType, ir.VoidType) or (isinstance(ParamType, ir.PointerType) and isinstance(ParamType.pointee, ir.VoidType)):
AnnName = None AnnName = None
@@ -2109,7 +2116,7 @@ class ImportHandle(BaseHandle):
if len(parts[0]) == 16 and all(c in '0123456789abcdef' for c in parts[0]): if len(parts[0]) == 16 and all(c in '0123456789abcdef' for c in parts[0]):
actual_sha1 = 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': if struct_body and struct_body != 'opaque':
elem_types = [] elem_types = []
if is_packed: if is_packed:
@@ -2461,7 +2468,7 @@ class ImportHandle(BaseHandle):
struct_body = struct_def_match.group(3).strip() struct_body = struct_def_match.group(3).strip()
if struct_body and struct_body != 'opaque': if struct_body and struct_body != 'opaque':
elem_types = [] 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: if is_packed:
inner = struct_body[2:-1].strip() inner = struct_body[2:-1].strip()
else: else: