[pygi] fix NULL array unit tests and fix crasher when sending None as an array



commit ab1aaff108d23aabd28c3634edfb67236eb55460
Author: John (J5) Palmieri <johnp redhat com>
Date:   Sat May 22 13:09:48 2010 +0200

    fix NULL array unit tests and fix crasher when sending None as an array
    
    * Unit tests were wrong given the annotation for test_array_int_null_in and
      test_array_int_null_out:
    
      /**
       * test_array_int_null_in:
       * @arr: (array length=len) (allow-none):
       * @len: length
       */
    
     -- and --
    
      /**
       * test_array_int_null_out:
       * @arr: (out) (array length=len) (allow-none):
       * @len: (out) : length
       */
    
      The (array length=len) annotation meant we don't pass in or
      receive the len argument as this is handled under the hood
      (Python's representation of an array, the list type, encapsulates
       the length inside the type)
    
    * Fixing up the tests revealed a latent crasher bug when passing None to an
      interface that accepts an array.  The fix was to check for NULL and set
      the length argument to 0 when invoking the bound method.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=619235

 gi/pygi-invoke.c         |    6 +++++-
 tests/test_everything.py |    4 ++--
 2 files changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index 0373a0d..11c6f23 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -501,8 +501,12 @@ _prepare_invocation_state (struct invocation_state *state,
                     if (state->is_method)
                         length_arg_pos--; // length_arg_pos refers to C args
                     if (length_arg_pos >= 0) {
+                    	int len = 0;
                         /* Set the auxiliary argument holding the length. */
-                        state->args[length_arg_pos]->v_size = array->len;
+                    	if (array)
+                    		len = array->len;
+
+                        state->args[length_arg_pos]->v_size = len;
                     }
 
                     /* Get rid of the GArray. */
diff --git a/tests/test_everything.py b/tests/test_everything.py
index f376a2f..ab4bdc9 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -56,7 +56,7 @@ class TestNullableArgs(unittest.TestCase):
         Everything.test_glist_null_in(None)
 
     def test_in_nullable_array(self):
-        Everything.test_array_int_null_in(None, -1)
+        Everything.test_array_int_null_in(None)
 
     def test_in_nullable_string(self):
         Everything.test_utf8_null_in(None)
@@ -69,7 +69,7 @@ class TestNullableArgs(unittest.TestCase):
         self.assertEqual(None, Everything.test_glist_null_out())
 
     def test_out_nullable_array(self):
-        self.assertEqual((None, 0), Everything.test_array_int_null_out())
+        self.assertEqual(None, Everything.test_array_int_null_out())
 
     def test_out_nullable_string(self):
         self.assertEqual(None, Everything.test_utf8_null_out())



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]