vitorsousa pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=e7e1d777f1107940164246a9e3e5921ba37eb8cf

commit e7e1d777f1107940164246a9e3e5921ba37eb8cf
Author: Lauro Moura <lauromo...@expertisesolutions.com.br>
Date:   Tue Apr 9 16:23:03 2019 -0300

    csharp: Add some null checks.
    
    Summary:
    - Check for nullness when getting stuff from C# to C
    - We should return null when wrapping a NULL pointer instead of throwing
      an exception
    
    Reviewers: felipealmeida, vitor.sousa, woohyun
    
    Reviewed By: vitor.sousa
    
    Subscribers: cedric, #reviewers, #committers
    
    Tags: #efl
    
    Differential Revision: https://phab.enlightenment.org/D8580
---
 src/bin/eolian_mono/eolian/mono/struct_definition.hh | 4 ++--
 src/bindings/mono/eo_mono/iwrapper.cs                | 6 ++++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/bin/eolian_mono/eolian/mono/struct_definition.hh 
b/src/bin/eolian_mono/eolian/mono/struct_definition.hh
index c059dd9cbe..d8f03118e7 100644
--- a/src/bin/eolian_mono/eolian/mono/struct_definition.hh
+++ b/src/bin/eolian_mono/eolian/mono/struct_definition.hh
@@ -48,7 +48,7 @@ struct to_internal_field_convert_generator
       if (klass)
         {
            if (!as_generator(
-                 indent << scope_tab << scope_tab << "_internal_struct." << 
string << " = _external_struct." << string << ".NativeHandle;\n")
+                 indent << scope_tab << scope_tab << "_internal_struct." << 
string << " = _external_struct." << string << "?.NativeHandle ?? 
System.IntPtr.Zero;\n")
                .generate(sink, std::make_tuple(field_name, field_name), 
context))
              return false;
         }
@@ -112,7 +112,7 @@ struct to_internal_field_convert_generator
       else if (field.type.c_type == "Eina_Value *" || field.type.c_type == 
"const Eina_Value *")
         {
            if (!as_generator(
-                 indent << scope_tab << scope_tab << "_internal_struct." << 
string << " = _external_struct." << string << ".NativeHandle;\n"
+                 indent << scope_tab << scope_tab << "_internal_struct." << 
string << " = _external_struct." << string << "?.NativeHandle ?? 
System.IntPtr.Zero;\n"
                ).generate(sink, std::make_tuple(field_name, field_name), 
context))
              return false;
         }
diff --git a/src/bindings/mono/eo_mono/iwrapper.cs 
b/src/bindings/mono/eo_mono/iwrapper.cs
index f3696606d2..83d8fd53ca 100644
--- a/src/bindings/mono/eo_mono/iwrapper.cs
+++ b/src/bindings/mono/eo_mono/iwrapper.cs
@@ -589,6 +589,12 @@ public class Globals
     /// <returns>The C# wrapper for this instance.</returns>
     public static Efl.Eo.IWrapper CreateWrapperFor(System.IntPtr handle, bool 
shouldIncRef=true)
     {
+
+        if (handle == IntPtr.Zero)
+        {
+            return null;
+        }
+
         IntPtr eoKlass = efl_class_get(handle);
 
         if (eoKlass == IntPtr.Zero)

-- 


Reply via email to