Make Marshal.SizeOf AOT friendly

See https://github.com/dotnet/corert/issues/5374#issuecomment-455706335
Current state in NativeAOT experiment is the same.
This commit is contained in:
Andrii Kurdiumov 2021-06-13 22:24:09 +06:00
parent f77efced1a
commit 238b98b631
8 changed files with 52 additions and 52 deletions

View file

@ -65,7 +65,7 @@ namespace Cairo {
// except in the case of Win64 where sizeof(long)
// is 32 bits
//
int ptr_size = Marshal.SizeOf (typeof (IntPtr));
int ptr_size = Marshal.SizeOf<IntPtr>();
PlatformID platform = Environment.OSVersion.Platform;
if (platform == PlatformID.Win32NT ||

View file

@ -15,7 +15,7 @@ namespace GLib {
static public AbiStruct abi_info = new AbiStruct(new List<AbiField> {
new GLib.AbiField("seq_id"
, 0
, (uint) Marshal.SizeOf(typeof(ulong)) // seq_id
, (uint) Marshal.SizeOf<ulong>() // seq_id
, null
, "hook_size"
, (long) Marshal.OffsetOf(typeof(GHookList_seq_idAlign), "seq_id")
@ -23,7 +23,7 @@ namespace GLib {
),
new GLib.AbiField("hook_size"
, -1
, (uint) Marshal.SizeOf(typeof(uint)) // hook_size
, (uint) Marshal.SizeOf<uint>() // hook_size
, "seq_id"
, "is_setup"
, 1
@ -31,7 +31,7 @@ namespace GLib {
),
new GLib.AbiField("is_setup"
, -1
, (uint) Marshal.SizeOf(typeof(bool)) // is_setup
, (uint) Marshal.SizeOf<bool>() // is_setup
, "hook_size"
, "hooks"
, 1
@ -39,7 +39,7 @@ namespace GLib {
),
new GLib.AbiField("hooks"
, -1
, (uint) Marshal.SizeOf(typeof(IntPtr)) // hooks
, (uint) Marshal.SizeOf<IntPtr>() // hooks
, "is_setup"
, "dummy3"
, (long) Marshal.OffsetOf(typeof(GHookList_hooksAlign), "hooks")
@ -47,7 +47,7 @@ namespace GLib {
),
new GLib.AbiField("dummy3"
, -1
, (uint) Marshal.SizeOf(typeof(IntPtr)) // dummy3
, (uint) Marshal.SizeOf<IntPtr>() // dummy3
, "hooks"
, "finalize_hook"
, (long) Marshal.OffsetOf(typeof(GHookList_dummy3Align), "dummy3")
@ -55,7 +55,7 @@ namespace GLib {
),
new GLib.AbiField("finalize_hook"
, -1
, (uint) Marshal.SizeOf(typeof(IntPtr)) // finalize_hook
, (uint) Marshal.SizeOf<IntPtr>() // finalize_hook
, "dummy3"
, "dummy"
, (long) Marshal.OffsetOf(typeof(GHookList_finalize_hookAlign), "finalize_hook")
@ -63,7 +63,7 @@ namespace GLib {
),
new GLib.AbiField("dummy"
, -1
, (uint) Marshal.SizeOf(typeof(IntPtr)) * 2 // dummy
, (uint) Marshal.SizeOf<IntPtr>() * 2 // dummy
, "finalize_hook"
, null
, (long) Marshal.OffsetOf(typeof(GHookList_dummyAlign), "dummy")

View file

@ -364,7 +364,7 @@ namespace GLib {
public static IntPtr StructArrayToNullTerminatedStructArrayIntPtr<T> (T[] InputArray)
{
int intPtrSize = Marshal.SizeOf (typeof (IntPtr));
int intPtrSize = Marshal.SizeOf<IntPtr>();
IntPtr mem = Marshal.AllocHGlobal ((InputArray.Length + 1) * intPtrSize);
for (int i = 0; i < InputArray.Length; i++) {

View file

@ -939,7 +939,7 @@ namespace GLib {
static public AbiStruct abi_info = new AbiStruct(new List<AbiField> {
new GLib.AbiField("g_type_instance"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, null
, "ref_count"
, (long) Marshal.OffsetOf(typeof(GObject_g_type_instanceAlign), "g_type_instance")
@ -947,7 +947,7 @@ namespace GLib {
),
new GLib.AbiField("ref_count"
, -1
, (uint) Marshal.SizeOf(typeof(uint)) // ref_count
, (uint) Marshal.SizeOf<uint>() // ref_count
, "g_type_instance"
, "qdata"
, (long) Marshal.OffsetOf(typeof(GObject_ref_countAlign), "ref_count")
@ -955,7 +955,7 @@ namespace GLib {
),
new GLib.AbiField("qdata"
, -1
, (uint) Marshal.SizeOf(typeof(IntPtr)) // qdata
, (uint) Marshal.SizeOf<IntPtr>() // qdata
, "ref_count"
, null
, (long) Marshal.OffsetOf(typeof(GObject_qdataAlign), "qdata")
@ -968,146 +968,146 @@ namespace GLib {
static public AbiStruct class_abi = new AbiStruct(new List<AbiField> {
new GLib.AbiField("type_class"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, null
, "construct_props"
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
new GLib.AbiField("construct_props"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, "type_class"
, "constructor_cb"
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
new GLib.AbiField("constructor_cb"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, "construct_props"
, "set_prop_cb"
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
new GLib.AbiField("set_prop_cb"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, "constructor_cb"
, "get_prop_cb"
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
new GLib.AbiField("get_prop_cb"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, "set_prop_cb"
, "dispose"
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
new GLib.AbiField("dispose"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, "get_prop_cb"
, "finalize"
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
new GLib.AbiField("finalize"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, "dispose"
, "dispatch_properties_changed"
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
new GLib.AbiField("dispatch_properties_changed"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, "finalize"
, "notify"
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
new GLib.AbiField("notify"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, "dispatch_properties_changed"
, "constructed"
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
new GLib.AbiField("constructed"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, "notify"
, "dummy1"
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
new GLib.AbiField("dummy1"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, "constructed"
, "dummy2"
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
new GLib.AbiField("dummy2"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, "dummy1"
, "dummy3"
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
new GLib.AbiField("dummy3"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, "dummy2"
, "dummy4"
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
new GLib.AbiField("dummy3"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, "dummy2"
, "dummy4"
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
new GLib.AbiField("dummy4"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, "dummy3"
, "dummy5"
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
new GLib.AbiField("dummy5"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, "dummy4"
, "dummy6"
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
new GLib.AbiField("dummy6"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, "dummy5"
, "dummy7"
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
new GLib.AbiField("dummy7"
, 0
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, "dummy6"
, null
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
, (uint) Marshal.SizeOf<IntPtr>() // g_type_instance
, 0
),
}

View file

@ -68,7 +68,7 @@ namespace GtkSharp.Generation {
}
public override string GenerateGetSizeOf () {
return "(uint) Marshal.SizeOf(typeof(" + abi_type + "))";
return "(uint) Marshal.SizeOf<" + abi_type + ">()";
}
}
}

View file

@ -104,7 +104,7 @@ namespace GtkSharp.Generation {
// Do not generate structs if the type is a simple pointer.
if (IsCPointer())
min_align = "(uint) Marshal.SizeOf(typeof(IntPtr))";
min_align = "(uint) Marshal.SizeOf<IntPtr>()";
if (IsBitfield)
min_align = "1";

View file

@ -144,7 +144,7 @@ namespace GtkSharp.Generation {
if (_enum != null && !is_pointer)
res = "(uint) Marshal.SizeOf(System.Enum.GetUnderlyingType(typeof(" + cstype + ")))";
else
res = "(uint) Marshal.SizeOf(typeof(" + cstype + "))";
res = "(uint) Marshal.SizeOf<" + cstype + ">()";
if (IsFixedSizeArray())
res += " * " + ArrayLength;

View file

@ -150,7 +150,7 @@ namespace GtkSharp.Generation {
AddType (new MarshalGen ("GType", "GLib.GType", "IntPtr", "{0}.Val", "new GLib.GType({0})", "GLib.GType.None"));
AddType (new ByRefGen ("GValue", "GLib.Value"));
AddType (new SimpleGen ("GDestroyNotify", "GLib.DestroyNotify", "null",
"(uint) Marshal.SizeOf(typeof(IntPtr))"));
"(uint) Marshal.SizeOf<IntPtr>()"));
AddType (new SimpleGen ("GThread", "GLib.Thread", "null"));
AddType (new ManualGen ("GBytes", "GLib.Bytes"));
AddType (new SimpleGen ("GHookList", "GLib.HookList", "null",