[pygobject] Remove support for allowing PyObjects as void pointers



commit 0a8d5695972601eaa9f7f463bac173d02b0380a0
Author: Simon Feltman <sfeltman src gnome org>
Date:   Wed Jul 24 01:14:29 2013 -0700

    Remove support for allowing PyObjects as void pointers
    
    Final removal of marshaling Python object addresses as
    void pointers. This ensures we can successfully pass
    integer values as the pointer without the Python object
    leaking or crashing due to invalid memory.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688081

 gi/pygi-marshal-from-py.c |   20 ++++++--------------
 gi/pygi-marshal-to-py.c   |   14 ++------------
 tests/test_signal.py      |    5 +----
 3 files changed, 9 insertions(+), 30 deletions(-)
---
diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c
index 57b4126..52c91d9 100644
--- a/gi/pygi-marshal-from-py.c
+++ b/gi/pygi-marshal-from-py.c
@@ -255,21 +255,13 @@ _pygi_marshal_from_py_void (PyGIInvokeState   *state,
         arg->v_pointer = NULL;
     } else if (PYGLIB_CPointer_Check(py_arg)) {
         arg->v_pointer = PYGLIB_CPointer_GetPointer (py_arg, NULL);
+    } else if (PYGLIB_PyLong_Check(py_arg) || PyLong_Check(py_arg)) {
+        arg->v_pointer = PyLong_AsVoidPtr (py_arg);
     } else {
-        /* NOTE: This will change to only allow integers and the deprecation
-         * warning will become a runtime exception. Using the following:
-         * arg->v_pointer = PyLong_AsVoidPtr (py_arg);
-         * See: https://bugzilla.gnome.org/show_bug.cgi?id=688081
-         */
-
-        if (!PYGLIB_PyLong_Check(py_arg) && !PyLong_Check(py_arg)) {
-            if (PyErr_WarnEx(PyGIDeprecationWarning,
-                             "Pointer arguments will be restricted to integers, capsules, and None. "
-                             "See: https://bugzilla.gnome.org/show_bug.cgi?id=683599";,
-                             1))
-                return FALSE;
-        }
-        arg->v_pointer = py_arg;
+        PyErr_SetString(PyExc_ValueError,
+                        "Pointer arguments are restricted to integers, capsules, and None. "
+                        "See: https://bugzilla.gnome.org/show_bug.cgi?id=683599";);
+        return FALSE;
     }
 
     return TRUE;
diff --git a/gi/pygi-marshal-to-py.c b/gi/pygi-marshal-to-py.c
index 7c260f7..d59e1e3 100644
--- a/gi/pygi-marshal-to-py.c
+++ b/gi/pygi-marshal-to-py.c
@@ -117,20 +117,10 @@ _pygi_marshal_to_py_void (PyGIInvokeState   *state,
                           PyGIArgCache      *arg_cache,
                           GIArgument        *arg)
 {
-    PyObject *py_obj = NULL;
     if (arg_cache->is_pointer) {
-        /* NOTE: This will change to interpret pointers as integer values
-         * by using the following:
-         * py_obj = PyLong_FromVoidPtr (arg->v_pointer);
-         * See: https://bugzilla.gnome.org/show_bug.cgi?id=688081
-         */
-        py_obj = arg->v_pointer;
-    } else {
-        py_obj = Py_None;
+        return PyLong_FromVoidPtr (arg->v_pointer);
     }
-
-    Py_XINCREF (py_obj);
-    return py_obj;
+    Py_RETURN_NONE;
 }
 
 static PyObject *
diff --git a/tests/test_signal.py b/tests/test_signal.py
index ec13896..e90264a 100644
--- a/tests/test_signal.py
+++ b/tests/test_signal.py
@@ -327,9 +327,6 @@ class TestMatching(unittest.TestCase):
         self.assertEqual(obj.status, 2)
 
     def test_signal_handler_find(self):
-        def dummy(*args):
-            "Hack to work around: "
-
         def foo(obj):
             obj.status += 1
 
@@ -340,7 +337,7 @@ class TestMatching(unittest.TestCase):
         found_id = GObject.signal_handler_find(obj,
                                                GObject.SignalMatchType.ID,
                                                signal_id=signal_id, detail=detail,
-                                               closure=None, func=dummy, data=dummy)
+                                               closure=None, func=0, data=0)
         self.assertEqual(handler_id, found_id)
 
 


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