[pygobject] Add deprecation warning for marshaling arbitrary objects as pointers



commit 6a29d9be14ec33d06816ade67a5ccf5c7a1cf398
Author: Simon Feltman <sfeltman src gnome org>
Date:   Sat Jul 6 13:32:39 2013 -0700

    Add deprecation warning for marshaling arbitrary objects as pointers
    
    Add deprecation warning for marshaling arbitrary objects to/from void
    pointers with the exception of integers, PyCapsules, and None.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688081

 gi/pygi-marshal-from-py.c |   17 ++++++++++++++++-
 gi/pygi-marshal-to-py.c   |   10 ++++++++--
 2 files changed, 24 insertions(+), 3 deletions(-)
---
diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c
index 8065d19..77020d1 100644
--- a/gi/pygi-marshal-from-py.c
+++ b/gi/pygi-marshal-from-py.c
@@ -251,9 +251,24 @@ _pygi_marshal_from_py_void (PyGIInvokeState   *state,
 {
     g_warn_if_fail (arg_cache->transfer == GI_TRANSFER_NOTHING);
 
-    if (PYGLIB_CPointer_Check(py_arg)) {
+    if (py_arg == Py_None) {
+        arg->v_pointer = NULL;
+    } else if (PYGLIB_CPointer_Check(py_arg)) {
         arg->v_pointer = PYGLIB_CPointer_GetPointer (py_arg, NULL);
     } 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;
     }
 
diff --git a/gi/pygi-marshal-to-py.c b/gi/pygi-marshal-to-py.c
index c34015b..20c6b7d 100644
--- a/gi/pygi-marshal-to-py.c
+++ b/gi/pygi-marshal-to-py.c
@@ -118,10 +118,16 @@ _pygi_marshal_to_py_void (PyGIInvokeState   *state,
                           GIArgument        *arg)
 {
     PyObject *py_obj = NULL;
-    if (arg_cache->is_pointer)
+    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
+    } else {
         py_obj = Py_None;
+    }
 
     Py_XINCREF (py_obj);
     return py_obj;


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