mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-12-22 19:45:34 +00:00
Merge pull request #261 from kant2002/kant/nativeaot-freidnly
Make Marshal.SizeOf AOT friendly
This commit is contained in:
commit
116762af89
|
@ -53,7 +53,7 @@ namespace Cairo {
|
|||
|
||||
static int native_glyph_size, c_compiler_long_size;
|
||||
|
||||
static Context ()
|
||||
static unsafe Context ()
|
||||
{
|
||||
//
|
||||
// This is used to determine what kind of structure
|
||||
|
@ -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 = sizeof(IntPtr);
|
||||
|
||||
PlatformID platform = Environment.OSVersion.Platform;
|
||||
if (platform == PlatformID.Win32NT ||
|
||||
|
@ -74,10 +74,10 @@ namespace Cairo {
|
|||
platform == PlatformID.WinCE ||
|
||||
ptr_size == 4){
|
||||
c_compiler_long_size = 4;
|
||||
native_glyph_size = Marshal.SizeOf (typeof (NativeGlyph_4byte_longs));
|
||||
native_glyph_size = Marshal.SizeOf<NativeGlyph_4byte_longs> ();
|
||||
} else {
|
||||
c_compiler_long_size = 8;
|
||||
native_glyph_size = Marshal.SizeOf (typeof (Glyph));
|
||||
native_glyph_size = Marshal.SizeOf<Glyph> ();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ namespace Cairo
|
|||
|
||||
internal static IntPtr GlyphsToIntPtr (Glyph[] glyphs)
|
||||
{
|
||||
int size = Marshal.SizeOf (glyphs[0]);
|
||||
int size = Marshal.SizeOf<Glyph> ();
|
||||
IntPtr dest = Marshal.AllocHGlobal (size * glyphs.Length);
|
||||
long pos = dest.ToInt64 ();
|
||||
for (int i = 0; i < glyphs.Length; i++, pos += size)
|
||||
|
|
|
@ -12,10 +12,10 @@ namespace GLib {
|
|||
public partial class HookList : GLib.Opaque {
|
||||
|
||||
// Internal representation of the wrapped ABI structure.
|
||||
static public AbiStruct abi_info = new AbiStruct(new List<AbiField> {
|
||||
static public unsafe AbiStruct abi_info = new AbiStruct(new List<AbiField> {
|
||||
new GLib.AbiField("seq_id"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(ulong)) // seq_id
|
||||
, (uint) 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) 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) 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) 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) 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) sizeof (IntPtr) * 2 // dummy
|
||||
, "finalize_hook"
|
||||
, null
|
||||
, (long) Marshal.OffsetOf(typeof(GHookList_dummyAlign), "dummy")
|
||||
|
|
|
@ -356,19 +356,19 @@ namespace GLib {
|
|||
while (current != IntPtr.Zero) {
|
||||
Marshal.PtrToStructure (current, currentStruct);
|
||||
res.Add (currentStruct);
|
||||
current = (IntPtr) ((long)current + Marshal.SizeOf (typeof (T)));
|
||||
current = (IntPtr) ((long)current + Marshal.SizeOf<T> ());
|
||||
}
|
||||
|
||||
return res.ToArray ();
|
||||
}
|
||||
|
||||
public static IntPtr StructArrayToNullTerminatedStructArrayIntPtr<T> (T[] InputArray)
|
||||
public static unsafe IntPtr StructArrayToNullTerminatedStructArrayIntPtr<T> (T[] InputArray)
|
||||
{
|
||||
int intPtrSize = Marshal.SizeOf (typeof (IntPtr));
|
||||
int intPtrSize = sizeof (IntPtr);
|
||||
IntPtr mem = Marshal.AllocHGlobal ((InputArray.Length + 1) * intPtrSize);
|
||||
|
||||
for (int i = 0; i < InputArray.Length; i++) {
|
||||
IntPtr structPtr = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (T)));
|
||||
IntPtr structPtr = Marshal.AllocHGlobal (Marshal.SizeOf<T> ());
|
||||
Marshal.StructureToPtr (InputArray[i], structPtr, false);
|
||||
// jump to next pointer
|
||||
Marshal.WriteIntPtr (mem, structPtr);
|
||||
|
|
|
@ -936,10 +936,10 @@ namespace GLib {
|
|||
}
|
||||
|
||||
// Internal representation of the wrapped ABI structure.
|
||||
static public AbiStruct abi_info = new AbiStruct(new List<AbiField> {
|
||||
static public unsafe AbiStruct abi_info = new AbiStruct(new List<AbiField> {
|
||||
new GLib.AbiField("g_type_instance"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) 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) 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) sizeof (IntPtr) // qdata
|
||||
, "ref_count"
|
||||
, null
|
||||
, (long) Marshal.OffsetOf(typeof(GObject_qdataAlign), "qdata")
|
||||
|
@ -965,149 +965,149 @@ namespace GLib {
|
|||
);
|
||||
//
|
||||
// Internal representation of the wrapped ABI structure.
|
||||
static public AbiStruct class_abi = new AbiStruct(new List<AbiField> {
|
||||
static public unsafe AbiStruct class_abi = new AbiStruct(new List<AbiField> {
|
||||
new GLib.AbiField("type_class"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, null
|
||||
, "construct_props"
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
new GLib.AbiField("construct_props"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, "type_class"
|
||||
, "constructor_cb"
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
new GLib.AbiField("constructor_cb"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, "construct_props"
|
||||
, "set_prop_cb"
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
new GLib.AbiField("set_prop_cb"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, "constructor_cb"
|
||||
, "get_prop_cb"
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
new GLib.AbiField("get_prop_cb"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, "set_prop_cb"
|
||||
, "dispose"
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
new GLib.AbiField("dispose"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, "get_prop_cb"
|
||||
, "finalize"
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
new GLib.AbiField("finalize"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, "dispose"
|
||||
, "dispatch_properties_changed"
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
new GLib.AbiField("dispatch_properties_changed"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, "finalize"
|
||||
, "notify"
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
new GLib.AbiField("notify"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, "dispatch_properties_changed"
|
||||
, "constructed"
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
new GLib.AbiField("constructed"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, "notify"
|
||||
, "dummy1"
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
new GLib.AbiField("dummy1"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, "constructed"
|
||||
, "dummy2"
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
new GLib.AbiField("dummy2"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, "dummy1"
|
||||
, "dummy3"
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
new GLib.AbiField("dummy3"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, "dummy2"
|
||||
, "dummy4"
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
new GLib.AbiField("dummy3"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, "dummy2"
|
||||
, "dummy4"
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
new GLib.AbiField("dummy4"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, "dummy3"
|
||||
, "dummy5"
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
new GLib.AbiField("dummy5"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, "dummy4"
|
||||
, "dummy6"
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
new GLib.AbiField("dummy6"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, "dummy5"
|
||||
, "dummy7"
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
new GLib.AbiField("dummy7"
|
||||
, 0
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, "dummy6"
|
||||
, null
|
||||
, (uint) Marshal.SizeOf(typeof(IntPtr)) // g_type_instance
|
||||
, (uint) sizeof (IntPtr) // g_type_instance
|
||||
, 0
|
||||
),
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace GLib {
|
|||
{
|
||||
object[] pvals = new object [n_pvals];
|
||||
for (int i = 0; i < n_pvals; i++) {
|
||||
IntPtr p = new IntPtr ((long) pvals_ptr + i * Marshal.SizeOf (typeof (Value)));
|
||||
IntPtr p = new IntPtr ((long) pvals_ptr + i * Marshal.SizeOf<Value> ());
|
||||
Value v = (Value) Marshal.PtrToStructure (p, typeof (Value));
|
||||
pvals [i] = v.Val;
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ namespace GLib {
|
|||
|
||||
bool NativeInvoker (InvocationHint ihint, object[] pvals)
|
||||
{
|
||||
int val_sz = Marshal.SizeOf (typeof (Value));
|
||||
int val_sz = Marshal.SizeOf<Value> ();
|
||||
IntPtr buf = Marshal.AllocHGlobal (pvals.Length * val_sz);
|
||||
Value[] vals = new Value [pvals.Length];
|
||||
for (int i = 0; i < pvals.Length; i++) {
|
||||
|
|
|
@ -72,7 +72,7 @@ namespace GLib {
|
|||
|
||||
public SignalClosure (IntPtr obj, string signal_name, System.Type args_type)
|
||||
{
|
||||
raw_closure = g_closure_new_simple (Marshal.SizeOf (typeof (GClosure)), IntPtr.Zero);
|
||||
raw_closure = g_closure_new_simple (Marshal.SizeOf<GClosure> (), IntPtr.Zero);
|
||||
g_closure_set_marshal (raw_closure, Marshaler);
|
||||
g_closure_add_finalize_notifier (raw_closure, IntPtr.Zero, Notify);
|
||||
closures [raw_closure] = this;
|
||||
|
@ -159,7 +159,7 @@ namespace GLib {
|
|||
args.Args = new object [n_param_vals - 1];
|
||||
GLib.Value[] vals = new GLib.Value [n_param_vals - 1];
|
||||
for (int i = 1; i < n_param_vals; i++) {
|
||||
IntPtr ptr = new IntPtr (param_values.ToInt64 () + i * Marshal.SizeOf (typeof (Value)));
|
||||
IntPtr ptr = new IntPtr (param_values.ToInt64 () + i * Marshal.SizeOf<Value> ());
|
||||
vals [i - 1] = (Value) Marshal.PtrToStructure (ptr, typeof (Value));
|
||||
args.Args [i - 1] = vals [i - 1].Val;
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ namespace GLib {
|
|||
closure.Invoke (ci_args);
|
||||
for (int i = 1; i < n_param_vals; i++) {
|
||||
vals [i - 1].Update (args.Args [i - 1]);
|
||||
IntPtr ptr = new IntPtr (param_values.ToInt64 () + i * Marshal.SizeOf (typeof (Value)));
|
||||
IntPtr ptr = new IntPtr (param_values.ToInt64 () + i * Marshal.SizeOf<Value> ());
|
||||
Marshal.StructureToPtr (vals [i - 1], ptr, false);
|
||||
}
|
||||
if (return_val == IntPtr.Zero || args.RetVal == null)
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace GLib {
|
|||
static d_g_time_val_add g_time_val_add = FuncLoader.LoadFunction<d_g_time_val_add>(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_time_val_add"));
|
||||
|
||||
public void Add(long microseconds) {
|
||||
IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
|
||||
IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf<TimeVal> ());
|
||||
System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
|
||||
g_time_val_add(this_as_native, new IntPtr (microseconds));
|
||||
ReadNative (this_as_native, ref this);
|
||||
|
@ -54,7 +54,7 @@ namespace GLib {
|
|||
static d_g_time_val_to_iso8601 g_time_val_to_iso8601 = FuncLoader.LoadFunction<d_g_time_val_to_iso8601>(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_time_val_to_iso8601"));
|
||||
|
||||
public string ToIso8601() {
|
||||
IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
|
||||
IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf<TimeVal> ());
|
||||
System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
|
||||
IntPtr raw_ret = g_time_val_to_iso8601(this_as_native);
|
||||
string ret = GLib.Marshaller.PtrToStringGFree(raw_ret);
|
||||
|
@ -68,7 +68,7 @@ namespace GLib {
|
|||
|
||||
public static bool FromIso8601(string iso_date, out GLib.TimeVal time_) {
|
||||
IntPtr native_iso_date = GLib.Marshaller.StringToPtrGStrdup (iso_date);
|
||||
IntPtr native_time_ = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (GLib.TimeVal)));
|
||||
IntPtr native_time_ = Marshal.AllocHGlobal (Marshal.SizeOf<GLib.TimeVal> ());
|
||||
bool raw_ret = g_time_val_from_iso8601(native_iso_date, native_time_);
|
||||
bool ret = raw_ret;
|
||||
GLib.Marshaller.Free (native_iso_date);
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace Gdk {
|
|||
int[] tmp = new int [count];
|
||||
Marshal.Copy (keyval_ptr, tmp, 0, count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
IntPtr ptr = new IntPtr ((long) key_ptr + i * Marshal.SizeOf (typeof (KeymapKey)));
|
||||
IntPtr ptr = new IntPtr ((long) key_ptr + i * Marshal.SizeOf<KeymapKey> ());
|
||||
keyvals [i] = (uint) tmp [i];
|
||||
keys [i] = KeymapKey.New (ptr);
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ namespace Gdk {
|
|||
if (gdk_keymap_get_entries_for_keyval(Handle, keyval, out key_ptr, out count)) {
|
||||
KeymapKey[] result = new KeymapKey [count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
IntPtr ptr = new IntPtr ((long) key_ptr + i * Marshal.SizeOf (typeof (KeymapKey)));
|
||||
IntPtr ptr = new IntPtr ((long) key_ptr + i * Marshal.SizeOf<KeymapKey> ());
|
||||
result [i] = KeymapKey.New (ptr);
|
||||
}
|
||||
GLib.Marshaller.Free (key_ptr);
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace Gtk {
|
|||
for (int i=0; i < n_colors; i++)
|
||||
{
|
||||
colors[i] = Gdk.Color.New(parsedColors);
|
||||
parsedColors = (IntPtr) ((int)parsedColors + Marshal.SizeOf(colors[i]));
|
||||
parsedColors = (IntPtr) ((int)parsedColors + Marshal.SizeOf<Gdk.Color> ());
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
|
|
@ -271,7 +271,7 @@ namespace Gtk {
|
|||
vals [2] = new GLib.Value (iter);
|
||||
inst_and_params.Append (vals [2]);
|
||||
int cnt = IterNChildren ();
|
||||
IntPtr new_order_ptr = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (int)) * cnt);
|
||||
IntPtr new_order_ptr = Marshal.AllocHGlobal (sizeof(int) * cnt);
|
||||
Marshal.Copy (new_order, 0, new_order_ptr, cnt);
|
||||
vals [3] = new GLib.Value (new_order_ptr);
|
||||
inst_and_params.Append (vals [3]);
|
||||
|
|
|
@ -90,7 +90,7 @@ namespace Gtk {
|
|||
public bool GetGeometry(out Gdk.Screen screen, out Gdk.Rectangle area, out Gtk.Orientation orientation)
|
||||
{
|
||||
IntPtr native_screen;
|
||||
IntPtr native_area = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (Gdk.Rectangle)));
|
||||
IntPtr native_area = Marshal.AllocHGlobal (Marshal.SizeOf<Gdk.Rectangle> ());
|
||||
int native_orientation;
|
||||
bool ret = gtk_status_icon_get_geometry(Handle, out native_screen, native_area, out native_orientation);
|
||||
if (ret) {
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace Gtk {
|
|||
IntPtr array_ptr = gtk_target_table_new_from_list (list.Handle, out n_targets);
|
||||
|
||||
Gtk.TargetEntry[] ret = new Gtk.TargetEntry [n_targets];
|
||||
int unmanaged_struct_size = Marshal.SizeOf (typeof (Gtk.TargetEntry));
|
||||
int unmanaged_struct_size = Marshal.SizeOf<Gtk.TargetEntry> ();
|
||||
for (int i = 0; i < n_targets; i++) {
|
||||
ret [i] = Gtk.TargetEntry.New (new IntPtr (array_ptr.ToInt64 () + i * unmanaged_struct_size));
|
||||
}
|
||||
|
|
|
@ -161,7 +161,7 @@ namespace Gtk {
|
|||
vals [2] = new GLib.Value (iter);
|
||||
inst_and_params.Append (vals [2]);
|
||||
int cnt = IterNChildren (iter);
|
||||
IntPtr new_order_ptr = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (int)) * cnt);
|
||||
IntPtr new_order_ptr = Marshal.AllocHGlobal (sizeof(int) * cnt);
|
||||
Marshal.Copy (new_order, 0, new_order_ptr, cnt);
|
||||
vals [3] = new GLib.Value (new_order_ptr);
|
||||
inst_and_params.Append (vals [3]);
|
||||
|
|
|
@ -185,7 +185,7 @@ namespace Gtk {
|
|||
vals [2] = new GLib.Value (iter);
|
||||
inst_and_params.Append (vals [2]);
|
||||
int cnt = IterNChildren (iter);
|
||||
IntPtr new_order_ptr = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (int)) * cnt);
|
||||
IntPtr new_order_ptr = Marshal.AllocHGlobal (sizeof(int) * cnt);
|
||||
Marshal.Copy (new_order, 0, new_order_ptr, cnt);
|
||||
vals [3] = new GLib.Value (new_order_ptr);
|
||||
inst_and_params.Append (vals [3]);
|
||||
|
|
|
@ -165,7 +165,7 @@ namespace Gtk {
|
|||
vals [2] = new GLib.Value (iter);
|
||||
inst_and_params.Append (vals [2]);
|
||||
int cnt = IterNChildren (iter);
|
||||
IntPtr new_order_ptr = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (int)) * cnt);
|
||||
IntPtr new_order_ptr = Marshal.AllocHGlobal (sizeof(int) * cnt);
|
||||
Marshal.Copy (new_order, 0, new_order_ptr, cnt);
|
||||
vals [3] = new GLib.Value (new_order_ptr);
|
||||
inst_and_params.Append (vals [3]);
|
||||
|
|
|
@ -382,7 +382,7 @@ namespace Gtk {
|
|||
vals [2] = new GLib.Value (iter);
|
||||
inst_and_params.Append (vals [2]);
|
||||
int cnt = IterNChildren (iter);
|
||||
IntPtr new_order_ptr = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (int)) * cnt);
|
||||
IntPtr new_order_ptr = Marshal.AllocHGlobal (sizeof(int) * cnt);
|
||||
Marshal.Copy (new_order, 0, new_order_ptr, cnt);
|
||||
vals [3] = new GLib.Value (new_order_ptr);
|
||||
inst_and_params.Append (vals [3]);
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace Gtk {
|
|||
static d_g_closure_set_marshal g_closure_set_marshal = FuncLoader.LoadFunction<d_g_closure_set_marshal>(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_closure_set_marshal"));
|
||||
|
||||
static IntPtr CreateClosure (ClosureMarshal marshaler) {
|
||||
IntPtr raw_closure = g_closure_new_simple (Marshal.SizeOf (typeof (GClosure)), IntPtr.Zero);
|
||||
IntPtr raw_closure = g_closure_new_simple (Marshal.SizeOf<GClosure> (), IntPtr.Zero);
|
||||
g_closure_set_marshal (raw_closure, marshaler);
|
||||
return raw_closure;
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ namespace Gtk {
|
|||
{
|
||||
try {
|
||||
GLib.Value[] inst_and_params = new GLib.Value [n_param_vals];
|
||||
int gvalue_size = Marshal.SizeOf (typeof (GLib.Value));
|
||||
int gvalue_size = Marshal.SizeOf<GLib.Value> ();
|
||||
for (int idx = 0; idx < n_param_vals; idx++)
|
||||
inst_and_params [idx] = (GLib.Value) Marshal.PtrToStructure (new IntPtr (param_values.ToInt64 () + idx * gvalue_size), typeof (GLib.Value));
|
||||
|
||||
|
|
|
@ -508,7 +508,7 @@
|
|||
</Docs>
|
||||
</Member>
|
||||
<Member MemberName="StructArrayToNullTerminatedStructArrayIntPtr<T>">
|
||||
<MemberSignature Language="C#" Value="public static IntPtr StructArrayToNullTerminatedStructArrayIntPtr<T> (T[] InputArray);" />
|
||||
<MemberSignature Language="C#" Value="public static IntPtr unsafe StructArrayToNullTerminatedStructArrayIntPtr<T> (T[] InputArray);" />
|
||||
<MemberSignature Language="ILAsm" Value=".method public static hidebysig native int StructArrayToNullTerminatedStructArrayIntPtr<T>(!!T[] InputArray) cil managed" />
|
||||
<MemberType>Method</MemberType>
|
||||
<ReturnValue>
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace GtkSharp.Generation {
|
|||
|
||||
public string AllocNative ()
|
||||
{
|
||||
return "Marshal.AllocHGlobal (Marshal.SizeOf (typeof (" + QualifiedName + ")))";
|
||||
return "Marshal.AllocHGlobal (" + GenerationInfo.GetSizeOfExpression(QualifiedName) + ")";
|
||||
}
|
||||
|
||||
public string AllocNative (string var_name)
|
||||
|
|
|
@ -227,7 +227,7 @@ namespace GtkSharp.Generation {
|
|||
sw.WriteLine ();
|
||||
sw.WriteLine ("\t\t// Internal representation of the wrapped structure ABI.");
|
||||
sw.WriteLine ("\t\tstatic GLib.AbiStruct _" + info_name + " = null;");
|
||||
sw.WriteLine ("\t\tstatic public " + _new + "GLib.AbiStruct " + info_name + " {");
|
||||
sw.WriteLine ("\t\tstatic public unsafe " + _new + "GLib.AbiStruct " + info_name + " {");
|
||||
sw.WriteLine ("\t\t\tget {");
|
||||
sw.WriteLine ("\t\t\t\tif (_" + info_name + " == null)");
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ namespace GtkSharp.Generation {
|
|||
if (p.PassAs == "ref")
|
||||
sw.WriteLine ("\t\t\tIntPtr " + p.Name + "_ptr = GLib.Marshaller.StructureToPtrAlloc (" + p.Generatable.CallByName (p.Name) + ");");
|
||||
else
|
||||
sw.WriteLine ("\t\t\tIntPtr " + p.Name + "_ptr = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (" + p.MarshalType + ")));");
|
||||
sw.WriteLine ("\t\t\tIntPtr " + p.Name + "_ptr = Marshal.AllocHGlobal (" + GenerationInfo.GetSizeOfExpression(p.MarshalType) + ");");
|
||||
|
||||
sw.WriteLine ("\t\t\tvals [" + (i + 1) + "] = new GLib.Value (" + p.Name + "_ptr);");
|
||||
cleanup += "\t\t\t" + p.Name + " = " + p.FromNative ("(" + p.MarshalType + ") Marshal.PtrToStructure (" + p.Name + "_ptr, typeof (" + p.MarshalType + "))") + ";\n";
|
||||
|
|
|
@ -234,6 +234,27 @@ namespace GtkSharp.Generation {
|
|||
|
||||
return sw;
|
||||
}
|
||||
|
||||
internal static string GetSizeOfExpression(string cstype)
|
||||
{
|
||||
// See https://docs.microsoft.com/en-us/dotnet/framework/interop/blittable-and-non-blittable-types
|
||||
bool isBlittable = cstype == "IntPtr"
|
||||
|| cstype == "UIntPtr"
|
||||
|| cstype == "ulong"
|
||||
|| cstype == "long"
|
||||
|| cstype == "uint"
|
||||
|| cstype == "int"
|
||||
|| cstype == "ushort"
|
||||
|| cstype == "short"
|
||||
|| cstype == "byte"
|
||||
|| cstype == "sbyte"
|
||||
|| cstype == "float"
|
||||
|| cstype == "double";
|
||||
if (isBlittable)
|
||||
return "sizeof( " + cstype + " )";
|
||||
|
||||
return "Marshal.SizeOf<" + cstype + ">()";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
|
||||
public override string GenerateGetSizeOf () {
|
||||
return "(uint) Marshal.SizeOf(typeof(" + abi_type + "))";
|
||||
return "(uint) " + GenerationInfo.GetSizeOfExpression(abi_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -394,7 +394,7 @@ namespace GtkSharp.Generation {
|
|||
public override string[] Prepare {
|
||||
get {
|
||||
if (PassAs == "out")
|
||||
return new string [] { "IntPtr native_" + CallName + " = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (" + Generatable.QualifiedName + ")));"};
|
||||
return new string [] { "IntPtr native_" + CallName + " = Marshal.AllocHGlobal (" + GenerationInfo.GetSizeOfExpression(Generatable.QualifiedName) + ");"};
|
||||
else
|
||||
return new string [] { "IntPtr native_" + CallName + " = " + (Generatable as IManualMarshaler).AllocNative (CallName) + ";"};
|
||||
}
|
||||
|
|
|
@ -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) sizeof(IntPtr)";
|
||||
|
||||
if (IsBitfield)
|
||||
min_align = "1";
|
||||
|
|
|
@ -298,7 +298,7 @@ namespace GtkSharp.Generation {
|
|||
|
||||
public override void Prepare (StreamWriter sw, string indent)
|
||||
{
|
||||
sw.WriteLine (indent + "IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));");
|
||||
sw.WriteLine (indent + "IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf<" + QualifiedName + ">());");
|
||||
sw.WriteLine (indent + "System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);");
|
||||
}
|
||||
|
||||
|
|
|
@ -142,9 +142,9 @@ namespace GtkSharp.Generation {
|
|||
|
||||
var _enum = gen as EnumGen;
|
||||
if (_enum != null && !is_pointer)
|
||||
res = "(uint) Marshal.SizeOf(System.Enum.GetUnderlyingType(typeof(" + cstype + ")))";
|
||||
res = "(uint) sizeof(" + cstype + ")";
|
||||
else
|
||||
res = "(uint) Marshal.SizeOf(typeof(" + cstype + "))";
|
||||
res = "(uint) " + GenerationInfo.GetSizeOfExpression(cstype);
|
||||
|
||||
if (IsFixedSizeArray())
|
||||
res += " * " + ArrayLength;
|
||||
|
|
|
@ -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) sizeof(IntPtr)"));
|
||||
AddType (new SimpleGen ("GThread", "GLib.Thread", "null"));
|
||||
AddType (new ManualGen ("GBytes", "GLib.Bytes"));
|
||||
AddType (new SimpleGen ("GHookList", "GLib.HookList", "null",
|
||||
|
|
Loading…
Reference in a new issue