[pygobject/pygobject-3-8] Change interpretation of NULL pointer field from None to 0



commit 2a1c09fea76b3a1e696d9bb82c46e6c64ec574f9
Author: Simon Feltman <sfeltman src gnome org>
Date:   Mon Apr 22 03:43:23 2013 -0700

    Change interpretation of NULL pointer field from None to 0
    
    The usage of 0 is needed because these fields should generally
    be used to store integer indices or hashes, not necessarily
    pointers to actual data.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=698366

 gi/pygi-argument.c       | 11 +----------
 tests/test_everything.py |  5 +++--
 2 files changed, 4 insertions(+), 12 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 6cb8417..7de90a2 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -1529,18 +1529,9 @@ _pygi_argument_to_object (GIArgument  *arg,
     switch (type_tag) {
         case GI_TYPE_TAG_VOID:
         {
-            if (g_type_info_is_pointer (type_info) &&
-                    (arg->v_pointer != NULL)) {
+            if (g_type_info_is_pointer (type_info)) {
                 g_warn_if_fail (transfer == GI_TRANSFER_NOTHING);
                 object = PyLong_FromVoidPtr (arg->v_pointer);
-            } else {
-                /* None is used instead of zero for parity with ctypes.
-                 * This is helpful in case the values are being used for
-                 * actual memory addressing, in which case None will
-                 * raise as opposed to 0 which will crash.
-                 */
-                object = Py_None;
-                Py_INCREF (object);
             }
             break;
         }
diff --git a/tests/test_everything.py b/tests/test_everything.py
index 3c820d7..c5f9ac9 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -505,7 +505,8 @@ class TestEverything(unittest.TestCase):
         glist = GLib.List()
         raw = RawGList.from_wrapped(glist)
 
-        self.assertEqual(glist.data, None)
+        # Note that pointer fields use 0 for NULL in PyGObject and None in ctypes
+        self.assertEqual(glist.data, 0)
         self.assertEqual(raw.contents.data, None)
 
         glist.data = 123
@@ -513,7 +514,7 @@ class TestEverything(unittest.TestCase):
         self.assertEqual(raw.contents.data, 123)
 
         glist.data = None
-        self.assertEqual(glist.data, None)
+        self.assertEqual(glist.data, 0)
         self.assertEqual(raw.contents.data, None)
 
         # Setting to anything other than an int should raise


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