[fix] 修复WebGL平台未正确处理空struct类型的桥接函数签名的bug

main
walon 2023-02-09 20:11:15 +08:00
parent ff93f30a69
commit d67a11b384
5 changed files with 47 additions and 8 deletions

View File

@ -35,5 +35,9 @@ namespace HybridCLR.Editor.ABI
STRUCTURE_ALIGN2, STRUCTURE_ALIGN2,
STRUCTURE_ALIGN4, STRUCTURE_ALIGN4,
STRUCTURE_ALIGN8, STRUCTURE_ALIGN8,
SPECIAL_STRUCTURE_ALIGN1,
SPECIAL_STRUCTURE_ALIGN2,
SPECIAL_STRUCTURE_ALIGN4,
SPECIAL_STRUCTURE_ALIGN8,
} }
} }

View File

@ -15,7 +15,7 @@ namespace HybridCLR.Editor.ABI
public virtual bool IsSupportHFA => false; public virtual bool IsSupportHFA => false;
public virtual bool IsSupportSingletonStruct => false; public virtual bool IsSupportWebGLSpecialValueType => false;
public TypeInfo GetNativeIntTypeInfo() => IsArch32 ? TypeInfo.s_i4 : TypeInfo.s_i8; public TypeInfo GetNativeIntTypeInfo() => IsArch32 ? TypeInfo.s_i4 : TypeInfo.s_i8;
@ -249,6 +249,21 @@ namespace HybridCLR.Editor.ABI
return true; return true;
} }
public static bool IsWebGLSpeicalValueType(TypeSig type)
{
TypeDef typeDef = type.ToTypeDefOrRef().ResolveTypeDefThrow();
if (typeDef.IsEnum)
{
return false;
}
var fields = typeDef.Fields;// typeDef.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (fields.Count == 0)
{
return true;
}
return fields.All(f => f.IsStatic);
}
protected static TypeInfo CreateGeneralValueType(TypeSig type, int size, int aligment) protected static TypeInfo CreateGeneralValueType(TypeSig type, int size, int aligment)
{ {
System.Diagnostics.Debug.Assert(size % aligment == 0); System.Diagnostics.Debug.Assert(size % aligment == 0);
@ -276,10 +291,17 @@ namespace HybridCLR.Editor.ABI
default: throw new NotSupportedException(); default: throw new NotSupportedException();
} }
} }
//else if(IsSupportSingletonStruct && TryComputSingletonStruct(type, out var ssTypeInfo)) if (IsSupportWebGLSpecialValueType && IsWebGLSpeicalValueType(type))
//{ {
// return CreateTypeInfo(ssTypeInfo.Type); switch (typeAligment)
//} {
case 1: return new TypeInfo(ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN1, typeSize);
case 2: return new TypeInfo(ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN2, typeSize);
case 4: return new TypeInfo(ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN4, typeSize);
case 8: return new TypeInfo(ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN8, typeSize);
default: throw new NotSupportedException();
}
}
else else
{ {
// 64位下结构体内存对齐规则是一样的 // 64位下结构体内存对齐规则是一样的

View File

@ -19,7 +19,7 @@ namespace HybridCLR.Editor.ABI
public override bool IsSupportHFA => false; public override bool IsSupportHFA => false;
public override bool IsSupportSingletonStruct => true; public override bool IsSupportWebGLSpecialValueType => true;
protected override TypeInfo OptimizeSigType(TypeInfo type, bool returnType) protected override TypeInfo OptimizeSigType(TypeInfo type, bool returnType)

View File

@ -90,6 +90,10 @@ namespace HybridCLR.Editor.ABI
case ParamOrReturnType.STRUCTURE_ALIGN2: return "A" + Size; case ParamOrReturnType.STRUCTURE_ALIGN2: return "A" + Size;
case ParamOrReturnType.STRUCTURE_ALIGN4: return "B" + Size; case ParamOrReturnType.STRUCTURE_ALIGN4: return "B" + Size;
case ParamOrReturnType.STRUCTURE_ALIGN8: return "C" + Size; case ParamOrReturnType.STRUCTURE_ALIGN8: return "C" + Size;
case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN1: return "X" + Size;
case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN2: return "Y" + Size;
case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN4: return "Z" + Size;
case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN8: return "W" + Size;
default: throw new NotSupportedException(PorType.ToString()); default: throw new NotSupportedException(PorType.ToString());
}; };
} }
@ -121,6 +125,10 @@ namespace HybridCLR.Editor.ABI
case ParamOrReturnType.STRUCTURE_ALIGN2: return $"ValueTypeSizeAlign2<{Size}>"; case ParamOrReturnType.STRUCTURE_ALIGN2: return $"ValueTypeSizeAlign2<{Size}>";
case ParamOrReturnType.STRUCTURE_ALIGN4: return $"ValueTypeSizeAlign4<{Size}>"; case ParamOrReturnType.STRUCTURE_ALIGN4: return $"ValueTypeSizeAlign4<{Size}>";
case ParamOrReturnType.STRUCTURE_ALIGN8: return $"ValueTypeSizeAlign8<{Size}>"; case ParamOrReturnType.STRUCTURE_ALIGN8: return $"ValueTypeSizeAlign8<{Size}>";
case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN1: return $"WebGLSpeicalValueType<{Size}>";
case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN2: return $"WebGLSpeicalValueTypeAlign2<{Size}>";
case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN4: return $"WebGLSpeicalValueTypeAlign4<{Size}>";
case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN8: return $"WebGLSpeicalValueTypeAlign8<{Size}>";
default: throw new NotImplementedException(PorType.ToString()); default: throw new NotImplementedException(PorType.ToString());
}; };
} }
@ -141,7 +149,12 @@ namespace HybridCLR.Editor.ABI
case ParamOrReturnType.STRUCTURE_ALIGN1: case ParamOrReturnType.STRUCTURE_ALIGN1:
case ParamOrReturnType.STRUCTURE_ALIGN2: case ParamOrReturnType.STRUCTURE_ALIGN2:
case ParamOrReturnType.STRUCTURE_ALIGN4: case ParamOrReturnType.STRUCTURE_ALIGN4:
case ParamOrReturnType.STRUCTURE_ALIGN8: return (Size + 7) / 8; case ParamOrReturnType.STRUCTURE_ALIGN8:
case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN1:
case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN2:
case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN4:
case ParamOrReturnType.SPECIAL_STRUCTURE_ALIGN8:
return (Size + 7) / 8;
default: default:
{ {
Debug.Assert(PorType < ParamOrReturnType.STRUCT_NOT_PASS_AS_VALUE); Debug.Assert(PorType < ParamOrReturnType.STRUCT_NOT_PASS_AS_VALUE);

View File

@ -1,6 +1,6 @@
{ {
"name": "com.focus-creative-games.hybridclr_unity", "name": "com.focus-creative-games.hybridclr_unity",
"version": "2.0.3", "version": "2.0.4",
"displayName": "HybridCLR", "displayName": "HybridCLR",
"description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR", "description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR",
"category": "Runtime", "category": "Runtime",