summaryrefslogtreecommitdiff
path: root/src/bindings
diff options
context:
space:
mode:
authorYeongjong Lee <yj34.lee@samsung.com>2020-01-28 14:46:10 +0900
committerWooHyun Jung <wh0705.jung@samsung.com>2020-01-28 14:46:10 +0900
commit581bec9598943cc9274dfe7db1a73a4c878c3cdd (patch)
treeae52675a45025659459dfb329e73538417dc625f /src/bindings
parentb3c0da13d80456bcbf3954698413df5ee845b8c2 (diff)
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.cs8
-rw-r--r--src/bindings/mono/eo_mono/workaround.cs61
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
328 328
329 internal Efl.EventCb GetInternalEventCallback<T>(EventHandler<T> handler, Func<IntPtr, T> createArgsInstance) where T:EventArgs 329 internal Efl.EventCb GetInternalEventCallback<T>(EventHandler<T> handler, Func<IntPtr, T> createArgsInstance) where T:EventArgs
330 { 330 {
331 return (IntPtr data, ref Efl.Event.NativeStruct evt) => 331 return (IntPtr data, ref Efl.Event evt) =>
332 { 332 {
333 var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target; 333 var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target;
334 if (obj != null) 334 if (obj != null)
@@ -348,7 +348,7 @@ public abstract class EoWrapper : IWrapper, IDisposable
348 348
349 internal Efl.EventCb GetInternalEventCallback(EventHandler handler) 349 internal Efl.EventCb GetInternalEventCallback(EventHandler handler)
350 { 350 {
351 return (IntPtr data, ref Efl.Event.NativeStruct evt) => 351 return (IntPtr data, ref Efl.Event evt) =>
352 { 352 {
353 var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target; 353 var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target;
354 if (obj != null) 354 if (obj != null)
@@ -383,13 +383,13 @@ public abstract class EoWrapper : IWrapper, IDisposable
383 } 383 }
384 } 384 }
385 385
386 private static void OwnershipUniqueCallback(IntPtr data, ref Efl.Event.NativeStruct evt) 386 private static void OwnershipUniqueCallback(IntPtr data, ref Efl.Event evt)
387 { 387 {
388 var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data); 388 var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data);
389 ws.MakeUnique(); 389 ws.MakeUnique();
390 } 390 }
391 391
392 private static void OwnershipSharedCallback(IntPtr data, ref Efl.Event.NativeStruct evt) 392 private static void OwnershipSharedCallback(IntPtr data, ref Efl.Event evt)
393 { 393 {
394 var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data); 394 var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data);
395 ws.MakeShared(); 395 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
173[Efl.Eo.BindingEntity] 173[Efl.Eo.BindingEntity]
174internal struct Event 174internal struct Event
175{ 175{
176 /// <summary>Internal wrapper for field Object</summary>
177 private System.IntPtr obj;
178 /// <summary>Internal wrapper for field Desc</summary>
179 private System.IntPtr desc;
180 /// <summary>Internal wrapper for field Info</summary>
181 private System.IntPtr info;
182
176 /// <summary> 183 /// <summary>
177 /// The object the callback was called on. 184 /// The object the callback was called on.
178 /// <para>Since EFL 1.22.</para> 185 /// <para>Since EFL 1.22.</para>
179 /// </summary> 186 /// </summary>
180 public Efl.Object Object; 187 public Efl.Object Object { get => (Efl.Object) Efl.Eo.Globals.CreateWrapperFor(obj); }
181 188
182 /// <summary> 189 /// <summary>
183 /// The event description. 190 /// The event description.
184 /// <para>Since EFL 1.22.</para> 191 /// <para>Since EFL 1.22.</para>
185 /// </summary> 192 /// </summary>
186 public Efl.EventDescription Desc; 193 public Efl.EventDescription Desc { get => Eina.PrimitiveConversion.PointerToManaged<Efl.EventDescription>(desc); }
187 194
188 /// <summary> 195 /// <summary>
189 /// Extra event information passed by the event caller. 196 /// Extra event information passed by the event caller.
@@ -192,7 +199,7 @@ internal struct Event
192 /// 2) Structs, built-in types and containers are passed as const pointers, with one level of indirection. 199 /// 2) Structs, built-in types and containers are passed as const pointers, with one level of indirection.
193 /// <para>Since EFL 1.22.</para> 200 /// <para>Since EFL 1.22.</para>
194 /// </summary> 201 /// </summary>
195 public System.IntPtr Info; 202 public System.IntPtr Info { get => info; }
196 203
197 /// <summary>Constructor for Event.</summary> 204 /// <summary>Constructor for Event.</summary>
198 public Event( 205 public Event(
@@ -200,59 +207,21 @@ internal struct Event
200 Efl.EventDescription desc = default(Efl.EventDescription), 207 Efl.EventDescription desc = default(Efl.EventDescription),
201 System.IntPtr info = default(System.IntPtr)) 208 System.IntPtr info = default(System.IntPtr))
202 { 209 {
203 this.Object = obj; 210 this.obj = obj?.NativeHandle ?? System.IntPtr.Zero;
204 this.Desc = desc; 211 this.desc = Eina.PrimitiveConversion.ManagedToPointerAlloc(desc);
205 this.Info = info; 212 this.info = info;
206 } 213 }
207 214
208 /// <summary>Implicit conversion to the managed representation from a native pointer.</summary> 215 /// <summary>Implicit conversion to the managed representation from a native pointer.</summary>
209 /// <param name="ptr">Native pointer to be converted.</param> 216 /// <param name="ptr">Native pointer to be converted.</param>
210 public static implicit operator Event(IntPtr ptr) 217 public static implicit operator Event(IntPtr ptr)
211 { 218 {
212 var tmp = (Event.NativeStruct) Marshal.PtrToStructure(ptr, typeof(Event.NativeStruct)); 219 var tmp = (Event) Marshal.PtrToStructure(ptr, typeof(Event));
213 return tmp; 220 return tmp;
214 } 221 }
215
216 /// <summary>Internal wrapper for struct Event.</summary>
217 [StructLayout(LayoutKind.Sequential)]
218 public struct NativeStruct
219 {
220 /// <summary>Internal wrapper for field Object</summary>
221 public System.IntPtr Object;
222
223 /// <summary>Internal wrapper for field Desc</summary>
224 public System.IntPtr Desc;
225
226 /// <summary>Internal wrapper for field Info</summary>
227 public System.IntPtr Info;
228
229 /// <summary>Implicit conversion to the internal/marshalling representation.</summary>
230 /// <param name="externalStruct">Managed struct to be converted.</param>
231 /// <returns>Native representation of the managed struct.</returns>
232 public static implicit operator Event.NativeStruct(Event externalStruct)
233 {
234 var internalStruct = new Event.NativeStruct();
235 internalStruct.Object = externalStruct.Object?.NativeHandle ?? System.IntPtr.Zero;
236 internalStruct.Desc = Eina.PrimitiveConversion.ManagedToPointerAlloc(externalStruct.Desc);
237 internalStruct.Info = externalStruct.Info;
238 return internalStruct;
239 }
240
241 /// <summary>Implicit conversion to the managed representation.</summary>
242 /// <param name="internalStruct">Native struct to be converted.</param>
243 /// <returns>Managed representation of the native struct.</returns>
244 public static implicit operator Event(Event.NativeStruct internalStruct)
245 {
246 var externalStruct = new Event();
247 externalStruct.Object = (Efl.Object) Efl.Eo.Globals.CreateWrapperFor(internalStruct.Object);
248 externalStruct.Desc = Eina.PrimitiveConversion.PointerToManaged<Efl.EventDescription>(internalStruct.Desc);
249 externalStruct.Info = internalStruct.Info;
250 return externalStruct;
251 }
252 }
253} 222}
254 223
255internal delegate void EventCb(System.IntPtr data, ref Event.NativeStruct evt); 224internal delegate void EventCb(System.IntPtr data, ref Event evt);
256internal delegate void FreeWrapperSupervisorCb(System.IntPtr obj); 225internal delegate void FreeWrapperSupervisorCb(System.IntPtr obj);
257 226
258namespace Access 227namespace Access