[pygobject] to_py_array: Properly handle enum array items



commit 1bf7d2cddcd24f619a268d0af85d7919d72bacba
Author: Christoph Reiter <creiter src gnome org>
Date:   Sun Oct 22 17:59:17 2017 +0200

    to_py_array: Properly handle enum array items
    
    It used the fallback path and copied pointers.
    Do the same thing we do for integer items instead.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788890

 gi/pygi-array.c                 |    3 +++
 tests/gimarshallingtestsextra.c |   21 +++++++++++++++++++++
 tests/gimarshallingtestsextra.h |    2 ++
 tests/test_gi.py                |    6 ++++++
 4 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/gi/pygi-array.c b/gi/pygi-array.c
index 8dfab12..e55f9f6 100644
--- a/gi/pygi-array.c
+++ b/gi/pygi-array.c
@@ -618,6 +618,9 @@ _pygi_marshal_to_py_array (PyGIInvokeState   *state,
                                 item_arg.v_pointer = array_->data + i * item_size;
                             }
                             break;
+                        case GI_INFO_TYPE_ENUM:
+                            memcpy (&item_arg, array_->data + i * item_size, item_size);
+                            break;
                         default:
                             item_arg.v_pointer = g_array_index (array_, gpointer, i);
                             break;
diff --git a/tests/gimarshallingtestsextra.c b/tests/gimarshallingtestsextra.c
index eee3a14..3f4dcac 100644
--- a/tests/gimarshallingtestsextra.c
+++ b/tests/gimarshallingtestsextra.c
@@ -104,3 +104,24 @@ gi_marshalling_tests_filename_exists (gchar *path)
 {
   return g_file_test (path, G_FILE_TEST_EXISTS);
 }
+
+
+/**
+ * gi_marshalling_tests_enum_array_return_type:
+ * @n_members: (out): The number of members
+ *
+ * Returns: (array length=n_members) (transfer full): An array of enum values
+ */
+GIMarshallingTestsExtraEnum *
+gi_marshalling_tests_enum_array_return_type (gsize *n_members)
+{
+  GIMarshallingTestsExtraEnum *res = g_new0(GIMarshallingTestsExtraEnum, 3);
+
+  *n_members = 3;
+
+  res[0] = GI_MARSHALLING_TESTS_EXTRA_ENUM_VALUE1;
+  res[1] = GI_MARSHALLING_TESTS_EXTRA_ENUM_VALUE2;
+  res[2] = GI_MARSHALLING_TESTS_EXTRA_ENUM_VALUE3;
+
+  return res;
+}
diff --git a/tests/gimarshallingtestsextra.h b/tests/gimarshallingtestsextra.h
index 5452688..70c2cfa 100644
--- a/tests/gimarshallingtestsextra.h
+++ b/tests/gimarshallingtestsextra.h
@@ -37,4 +37,6 @@ gchar * gi_marshalling_tests_filename_copy (gchar *path_in);
 gboolean gi_marshalling_tests_filename_exists (gchar *path);
 gchar * gi_marshalling_tests_filename_to_glib_repr (gchar *path_in, gsize *len);
 
+GIMarshallingTestsExtraEnum * gi_marshalling_tests_enum_array_return_type (gsize *n_members);
+
 #endif /* EXTRA_TESTS */
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 0890126..3072974 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1094,6 +1094,12 @@ class TestArray(unittest.TestCase):
         self.assertEqual((True, ['hello']),
                          GIMarshallingTests.init_function(['hello', 'world']))
 
+    def test_enum_array_return_type(self):
+        self.assertEqual(GIMarshallingTests.enum_array_return_type(),
+                         [GIMarshallingTests.ExtraEnum.VALUE1,
+                          GIMarshallingTests.ExtraEnum.VALUE2,
+                          GIMarshallingTests.ExtraEnum.VALUE3])
+
 
 class TestGStrv(unittest.TestCase):
 


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