Commit 0a8d5695 authored by Simon Feltman's avatar Simon Feltman
Browse files

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
parent 1469403e
......@@ -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;
......
......@@ -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 *
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment