diff --git a/App/lib/core/Gen/StructGenMixin.vp b/App/lib/core/Gen/StructGenMixin.vp index bb78dd1..f542f26 100644 --- a/App/lib/core/Gen/StructGenMixin.vp +++ b/App/lib/core/Gen/StructGenMixin.vp @@ -927,10 +927,24 @@ class StructGenMixin: # 也直接比较类名(struct_ty 的 Name 可能无 SHA1 前缀) if string.strcmp(entry2.Name, ty_name) == 0: return entry2.Name - # 最后回退: strstr 检查包含关系 - # ty_name 可能是 "SHA1.Counter",entry2.Name 是 "Counter" - if string.strstr(ty_name, entry2.Name) is not None: - return entry2.Name + # 最后回退: 后缀匹配("SHA1.ClassName" 尾部)——比 strstr 子串 + # 匹配安全:特化名 "SHA1.GSList[Param]" 会被基础名 "GSList" 错误 + # 命中(子串),导致链式方法调用 class_name 解析错(如 + # func.Params.append → GSList.append 查找失败 → 兄弟 Mixin 兜底 + # 误匹配 LinkedNode.append,this 前移 sizeof(LinkedNode) 写穿 + # 容器前 48 字节,LLvmLiteTest Test 3 崩溃根因)。 + if entry2.Name is not None and string.strlen(entry2.Name) > 0: + _tlen_cn: t.CSizeT = string.strlen(ty_name) + _nlen_cn: t.CSizeT = string.strlen(entry2.Name) + if _tlen_cn > _nlen_cn and ty_name[_tlen_cn - _nlen_cn - 1] == '.': + _tail_ok_cn: int = 1 + _ti_cn: t.CSizeT + for _ti_cn in range(_nlen_cn): + if ty_name[_tlen_cn - _nlen_cn + _ti_cn] != entry2.Name[_ti_cn]: + _tail_ok_cn = 0 + break + if _tail_ok_cn == 1: + return entry2.Name return None def _extract_struct_name(self, ty: llvmlite.LLVMType | t.CPtr) -> str: