diff options
author | Yeongjong Lee <yj34.lee@samsung.com> | 2020-01-28 14:46:10 +0900 |
---|---|---|
committer | WooHyun Jung <wh0705.jung@samsung.com> | 2020-01-28 14:46:10 +0900 |
commit | 581bec9598943cc9274dfe7db1a73a4c878c3cdd (patch) | |
tree | ae52675a45025659459dfb329e73538417dc625f /src/bindings | |
parent | b3c0da13d80456bcbf3954698413df5ee845b8c2 (diff) | |
download | efl-581bec9598943cc9274dfe7db1a73a4c878c3cdd.tar.gz |
eolian_mono: make struct immutable
Summary:
Immutable value type is recommeneded for struct type in cs world.
`DO NOT define mutable value types.`
(see, https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/struct)
Also, this patch include refactoring of generated struct types.
1. Change field type to property type that have only getter. it will fix CA1051(ref T8397).
2. Remove internal NativeStruct. there is private field for marshalling struct instead.
3. Fix some test cases that change value inside struct. because struct is immutable.
Test Plan: meson build -Dbindings=mono,cxx -Dmono-beta=true
Reviewers: woohyun, felipealmeida, Jaehyun_Cho
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Maniphest Tasks: T8397
Differential Revision: https://phab.enlightenment.org/D11146
Diffstat (limited to 'src/bindings')
-rw-r--r-- | src/bindings/mono/eo_mono/EoWrapper.cs | 8 | ||||
-rw-r--r-- | src/bindings/mono/eo_mono/workaround.cs | 61 |
2 files changed, 19 insertions, 50 deletions
diff --git a/src/bindings/mono/eo_mono/EoWrapper.cs b/src/bindings/mono/eo_mono/EoWrapper.cs index 99e60b1d2b..db618232c4 100644 --- a/src/bindings/mono/eo_mono/EoWrapper.cs +++ b/src/bindings/mono/eo_mono/EoWrapper.cs @@ -328,7 +328,7 @@ public abstract class EoWrapper : IWrapper, IDisposable internal Efl.EventCb GetInternalEventCallback<T>(EventHandler<T> handler, Func<IntPtr, T> createArgsInstance) where T:EventArgs { - return (IntPtr data, ref Efl.Event.NativeStruct evt) => + return (IntPtr data, ref Efl.Event evt) => { var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target; if (obj != null) @@ -348,7 +348,7 @@ public abstract class EoWrapper : IWrapper, IDisposable internal Efl.EventCb GetInternalEventCallback(EventHandler handler) { - return (IntPtr data, ref Efl.Event.NativeStruct evt) => + return (IntPtr data, ref Efl.Event evt) => { var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target; if (obj != null) @@ -383,13 +383,13 @@ public abstract class EoWrapper : IWrapper, IDisposable } } - private static void OwnershipUniqueCallback(IntPtr data, ref Efl.Event.NativeStruct evt) + private static void OwnershipUniqueCallback(IntPtr data, ref Efl.Event evt) { var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data); ws.MakeUnique(); } - private static void OwnershipSharedCallback(IntPtr data, ref Efl.Event.NativeStruct evt) + private static void OwnershipSharedCallback(IntPtr data, ref Efl.Event evt) { var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data); ws.MakeShared(); diff --git a/src/bindings/mono/eo_mono/workaround.cs b/src/bindings/mono/eo_mono/workaround.cs index 0afe95807b..3e6829feef 100644 --- a/src/bindings/mono/eo_mono/workaround.cs +++ b/src/bindings/mono/eo_mono/workaround.cs @@ -173,17 +173,24 @@ internal struct EventDescription [Efl.Eo.BindingEntity] internal struct Event { + /// <summary>Internal wrapper for field Object</summary> + private System.IntPtr obj; + /// <summary>Internal wrapper for field Desc</summary> + private System.IntPtr desc; + /// <summary>Internal wrapper for field Info</summary> + private System.IntPtr info; + /// <summary> /// The object the callback was called on. /// <para>Since EFL 1.22.</para> /// </summary> - public Efl.Object Object; + public Efl.Object Object { get => (Efl.Object) Efl.Eo.Globals.CreateWrapperFor(obj); } /// <summary> /// The event description. /// <para>Since EFL 1.22.</para> /// </summary> - public Efl.EventDescription Desc; + public Efl.EventDescription Desc { get => Eina.PrimitiveConversion.PointerToManaged<Efl.EventDescription>(desc); } /// <summary> /// Extra event information passed by the event caller. @@ -192,7 +199,7 @@ internal struct Event /// 2) Structs, built-in types and containers are passed as const pointers, with one level of indirection. /// <para>Since EFL 1.22.</para> /// </summary> - public System.IntPtr Info; + public System.IntPtr Info { get => info; } /// <summary>Constructor for Event.</summary> public Event( @@ -200,59 +207,21 @@ internal struct Event Efl.EventDescription desc = default(Efl.EventDescription), System.IntPtr info = default(System.IntPtr)) { - this.Object = obj; - this.Desc = desc; - this.Info = info; + this.obj = obj?.NativeHandle ?? System.IntPtr.Zero; + this.desc = Eina.PrimitiveConversion.ManagedToPointerAlloc(desc); + this.info = info; } /// <summary>Implicit conversion to the managed representation from a native pointer.</summary> /// <param name="ptr">Native pointer to be converted.</param> public static implicit operator Event(IntPtr ptr) { - var tmp = (Event.NativeStruct) Marshal.PtrToStructure(ptr, typeof(Event.NativeStruct)); + var tmp = (Event) Marshal.PtrToStructure(ptr, typeof(Event)); return tmp; } - - /// <summary>Internal wrapper for struct Event.</summary> - [StructLayout(LayoutKind.Sequential)] - public struct NativeStruct - { - /// <summary>Internal wrapper for field Object</summary> - public System.IntPtr Object; - - /// <summary>Internal wrapper for field Desc</summary> - public System.IntPtr Desc; - - /// <summary>Internal wrapper for field Info</summary> - public System.IntPtr Info; - - /// <summary>Implicit conversion to the internal/marshalling representation.</summary> - /// <param name="externalStruct">Managed struct to be converted.</param> - /// <returns>Native representation of the managed struct.</returns> - public static implicit operator Event.NativeStruct(Event externalStruct) - { - var internalStruct = new Event.NativeStruct(); - internalStruct.Object = externalStruct.Object?.NativeHandle ?? System.IntPtr.Zero; - internalStruct.Desc = Eina.PrimitiveConversion.ManagedToPointerAlloc(externalStruct.Desc); - internalStruct.Info = externalStruct.Info; - return internalStruct; - } - - /// <summary>Implicit conversion to the managed representation.</summary> - /// <param name="internalStruct">Native struct to be converted.</param> - /// <returns>Managed representation of the native struct.</returns> - public static implicit operator Event(Event.NativeStruct internalStruct) - { - var externalStruct = new Event(); - externalStruct.Object = (Efl.Object) Efl.Eo.Globals.CreateWrapperFor(internalStruct.Object); - externalStruct.Desc = Eina.PrimitiveConversion.PointerToManaged<Efl.EventDescription>(internalStruct.Desc); - externalStruct.Info = internalStruct.Info; - return externalStruct; - } - } } -internal delegate void EventCb(System.IntPtr data, ref Event.NativeStruct evt); +internal delegate void EventCb(System.IntPtr data, ref Event evt); internal delegate void FreeWrapperSupervisorCb(System.IntPtr obj); namespace Access |