fix(gi): 模块级类全局按值本位存储(仅 __new__ 类用指针) - 修 CAM: V3 被包成 Ptr 致悬垂误报
This commit is contained in:
1 parent
9d0a43d5e6
commit
5460d78ff1
2 files changed
+11
-4
No files matched your search
@@ -2885,10 +2885,10 @@ def _inject_global_variable_declare(pool: memhub.MemBuddy*, mod: mlirlite.LLVMMo
|
||||
gv_ty_v: mlirlite.LLVMType* = resolved_v
|
||||
match resolved_v:
|
||||
case mlirlite.LLVMType.Struct(_, _, _):
|
||||
# Object classes (@t.Object/@t.CVTable: object-as-pointer) -> Ptr(struct), matching
|
||||
# handle_module_level_var; plain t.CStruct value classes keep a value instance.
|
||||
# 与 handle_module_level_var 保持同一口径:只有 `__new__`(自定义分配)的类才以指针表示;
|
||||
# 仅"有方法 / 带 vtable"(IsOOP / HasVTable)的类,模块级全局同样按值本位存储。
|
||||
gv_entry_v: GenTypes.StructEntry* = GenApi.find_struct_by_type(resolved_v)
|
||||
if gv_entry_v is not None and (gv_entry_v.HasNew != 0 or gv_entry_v.HasVTable != 0 or gv_entry_v.IsOOP != 0): gv_ty_v = mlirlite.Ptr(pool, resolved_v)
|
||||
if gv_entry_v is not None and gv_entry_v.HasNew != 0: gv_ty_v = mlirlite.Ptr(pool, resolved_v)
|
||||
else: gv_ty_v = resolved_v
|
||||
case mlirlite.LLVMType.Array(aelem_v, acount_v):
|
||||
# Fixed-size arrays (CArray[T, N]) keep the full [N x T] type, matching
|
||||
|
||||
@@ -556,7 +556,14 @@ novirtual class TranslatorGenMixin:
|
||||
gv_hn = gv_entry.HasNew; gv_hv = gv_entry.HasVTable; gv_oo = gv_entry.IsOOP
|
||||
stdio.printf("[GVAR-DIAG] name=%s hasnew=%d hasvtable=%d isoop=%d\n",
|
||||
var_name, gv_hn, gv_hv, gv_oo)
|
||||
if gv_entry is not None and (gv_entry.HasNew != 0 or gv_entry.HasVTable != 0 or gv_entry.IsOOP != 0):
|
||||
if gv_entry is not None and gv_entry.HasNew != 0:
|
||||
# 只有定义了 `__new__`(自定义分配器,对象存储可能不在本帧)的类才**必须**
|
||||
# 以指针表示。仅"有方法 / 带 vtable"(IsOOP / HasVTable)的类,值本体内联
|
||||
# 存储同样可工作(方法调用把 &obj 作 self 传入,vptr 亦可内联在值里),
|
||||
# 因此模块级全局也按**值本位**存储,与局部变量(`alloca %T`)语义一致:
|
||||
# `CAM: V3` ⇒ `@CAM = global %V3`,`CAM = V3(...)` 即整块就地写入
|
||||
# (不再产生"把本帧对象地址存进全局"的悬垂,也不再让
|
||||
# check_return_frame_decl 误报 LifetimeError)。
|
||||
# Object-class global (object-as-pointer): remember the Struct value type
|
||||
# so a BSS storage global can hold the instance; otherwise @g is NULL.
|
||||
resolved_stg_ty = resolved
|
||||
|
||||
Reference in new issue
Block a user