This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efl.

View the commit online.

commit ea9f21885809bbd25dbb41cba8d6640c4263ad96
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 15 12:30:48 2026 -0600

    mono: an absent collection is an empty one, not an exception
    
    Every generated struct with an optional collection field hands each
    omitted field straight to IListToNativeList (or its siblings), which
    rejected null, so such a struct could not be constructed at its own
    defaults: new Eldbus.Introspection.Signal() threw ArgumentException.
    
    Making the write side answer IntPtr.Zero is what the caller needed, and
    then the same fault appeared on the way back out: NativeListToIList
    threw on the IntPtr.Zero that had just been stored, so a struct became
    constructible and unreadable in the same step. Both directions now treat
    absence as an empty collection, for lists, arrays, iterators and
    accessors.
    
    This also changes what a generated method does with a null collection
    argument: it reaches C as NULL instead of throwing ArgumentException,
    and what NULL means is then up to the C function.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/bindings/mono/eo_mono/iwrapper.cs | 36 +++++++++++++++++++++++++++--------
 src/tests/efl_mono/Structs.cs         | 19 ++++++++++++++++++
 2 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs
index 11040b57c1..43e6e8fe2b 100644
--- a/src/bindings/mono/eo_mono/iwrapper.cs
+++ b/src/bindings/mono/eo_mono/iwrapper.cs
@@ -759,10 +759,13 @@ internal static class Globals
         Monitor.Exit(Efl.All.InitLock);
     }
 
+    // IntPtr.Zero is an absent collection, which reads back as an empty one.
     internal static IEnumerable<T> AccessorToIEnumerable<T>(IntPtr accessor)
     {
         if (accessor == IntPtr.Zero)
-           throw new ArgumentException("accessor is null", nameof(accessor));
+        {
+            yield break;
+        }
 
         IntPtr data = ""
         uint position = 0;
@@ -774,11 +777,12 @@ internal static class Globals
         }
     }
 
+    // A null collection is absent, and goes to C as IntPtr.Zero.
     internal static IntPtr IEnumerableToAccessor<T>(IEnumerable<T> enumerable, bool isMoved)
     {
         if (enumerable == null)
         {
-            throw new ArgumentException("enumerable is null", nameof(enumerable));
+            return IntPtr.Zero;
         }
 
         // If we are a wrapper around an existing Eina.Accessor, we can just forward
@@ -830,10 +834,13 @@ internal static class Globals
         return nativeAccessor;
     }
 
+    // IntPtr.Zero is an absent collection, which reads back as an empty one.
     internal static IEnumerable<T> IteratorToIEnumerable<T>(IntPtr iterator)
     {
         if (iterator == IntPtr.Zero)
-           throw new ArgumentException("iterator is null", nameof(iterator));
+        {
+            yield break;
+        }
 
         while (Eina.IteratorNativeFunctions.eina_iterator_next(iterator, out IntPtr data))
         {
@@ -841,11 +848,12 @@ internal static class Globals
         }
     }
 
+    // A null collection is absent, and goes to C as IntPtr.Zero.
     internal static IntPtr IEnumerableToIterator<T>(IEnumerable<T> enumerable, bool isMoved)
     {
         if (enumerable == null)
         {
-            throw new ArgumentException("enumerable is null", nameof(enumerable));
+            return IntPtr.Zero;
         }
 
         // If we are a wrapper around an existing Eina.Iterator, we can just forward
@@ -875,10 +883,13 @@ internal static class Globals
         return ret;
     }
 
+    // IntPtr.Zero is an absent collection, which reads back as an empty one.
     internal static IList<T> NativeListToIList<T>(IntPtr nativeList)
     {
         if (nativeList == IntPtr.Zero)
-            throw new ArgumentException("nativeList is null", nameof(nativeList));
+        {
+            return new List<T>();
+        }
 
         IntPtr l;
         List<T> list = new List<T>();
@@ -889,10 +900,13 @@ internal static class Globals
         return list;
     }
 
+    // A null collection is absent, and goes to C as IntPtr.Zero.
     internal static IntPtr IListToNativeList<T>(IList<T> list, bool isMoved)
     {
         if (list == null)
-            throw new ArgumentException("list is null", nameof(list));
+        {
+            return IntPtr.Zero;
+        }
 
         // If we are a wrapper around an existing Eina.List, we can just forward
         // it and avoid unnecessary copying in non-owning transfers.
@@ -917,10 +931,13 @@ internal static class Globals
         return nativeList;
     }
 
+    // IntPtr.Zero is an absent collection, which reads back as an empty one.
     internal static IList<T> NativeArrayToIList<T>(IntPtr nativeArray)
     {
         if (nativeArray == IntPtr.Zero)
-            throw new ArgumentException("nativeArray is null", nameof(nativeArray));
+        {
+            return new List<T>();
+        }
 
         List<T> list = new List<T>();
         UpdateListFromNativeArray(list, nativeArray);
@@ -929,10 +946,13 @@ internal static class Globals
         return list;
     }
 
+    // A null collection is absent, and goes to C as IntPtr.Zero.
     internal static IntPtr IListToNativeArray<T>(IList<T> list, bool isMoved)
     {
         if (list == null)
-            throw new ArgumentException("list is null", nameof(list));
+        {
+            return IntPtr.Zero;
+        }
 
         // If we are a wrapper around an existing Eina.Array, we can just forward
         // it and avoid unnecessary copying in non-owning transfers.
diff --git a/src/tests/efl_mono/Structs.cs b/src/tests/efl_mono/Structs.cs
index 334057c907..c2fdc5135d 100644
--- a/src/tests/efl_mono/Structs.cs
+++ b/src/tests/efl_mono/Structs.cs
@@ -43,6 +43,25 @@ internal class TestStructs
     }
 #endif
 
+#if EFL_BETA
+    public static void complex_omitted_collections_read_back_empty()
+    {
+        var hash = new Eina.Hash<string, string>();
+        var value = new Eina.Value(Eina.ValueType.Int32);
+        var binbuf = new Eina.Binbuf();
+
+        var complex = new Dummy.StructComplex(fhash: hash, fanyValue: value, fbinbuf: binbuf);
+        Test.AssertEquals(0, complex.Farray.Count);
+        Test.AssertEquals(0, complex.Flist.Count);
+        Test.AssertEquals(0, complex.Fiterator.Count());
+        Test.AssertEquals(0, complex.Faccessor.Count());
+
+        binbuf.Dispose();
+        value.Dispose();
+        hash.Dispose();
+    }
+#endif
+
     public static void parameter_initialization()
     {
         var simple = new Dummy.StructSimple(0x1, 0x2, (char)0x3, 0x4, 0x5);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to