summaryrefslogtreecommitdiff
path: root/gi/pygi-argument.c
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:48:07 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:48:11 +0900
commit3b5dc6176476d5ed2313cd7185d985f47e225165 (patch)
treeaee8e1d1c516bf7528eceae708baecfe484baddc /gi/pygi-argument.c
parentd80fc1d31f28c6bcf9ea34b253e8765321616c3c (diff)
downloadpygobject2-3b5dc6176476d5ed2313cd7185d985f47e225165.tar.gz
pygobject2-3b5dc6176476d5ed2313cd7185d985f47e225165.tar.bz2
pygobject2-3b5dc6176476d5ed2313cd7185d985f47e225165.zip
Imported Upstream version 3.7.2
Change-Id: I6fbadd2c5d032a44b4b424160cdbd0f097320457 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'gi/pygi-argument.c')
-rw-r--r--gi/pygi-argument.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index bffe9c4..61453e0 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -879,7 +879,15 @@ _pygi_argument_from_object (PyObject *object,
switch (type_tag) {
case GI_TYPE_TAG_VOID:
g_warn_if_fail (transfer == GI_TRANSFER_NOTHING);
- arg.v_pointer = object == Py_None ? NULL : object;
+ if (object == Py_None) {
+ arg.v_pointer = NULL;
+ } else if (!PYGLIB_PyLong_Check(object) && !PyLong_Check(object)) {
+ PyErr_SetString(PyExc_TypeError,
+ "Pointer assignment is restricted to integer values. "
+ "See: https://bugzilla.gnome.org/show_bug.cgi?id=683599");
+ } else {
+ arg.v_pointer = PyLong_AsVoidPtr (object);
+ }
break;
case GI_TYPE_TAG_BOOLEAN:
{
@@ -1285,7 +1293,12 @@ array_success:
} else if (g_type_is_a (type, G_TYPE_POINTER) ||
g_type_is_a (type, G_TYPE_VARIANT) ||
type == G_TYPE_NONE) {
- g_warn_if_fail (g_type_is_a (type, G_TYPE_VARIANT) || !g_type_info_is_pointer (type_info) || transfer == GI_TRANSFER_NOTHING);
+ g_warn_if_fail (g_type_is_a (type, G_TYPE_VARIANT) || !g_type_info_is_pointer (type_info) || transfer == GI_TRANSFER_NOTHING);
+
+ if (g_type_is_a (type, G_TYPE_VARIANT) && pyg_type_from_object (object) != G_TYPE_VARIANT) {
+ PyErr_SetString (PyExc_TypeError, "expected GLib.Variant");
+ break;
+ }
arg.v_pointer = pyg_pointer_get (object, void);
} else {
PyErr_Format (PyExc_NotImplementedError, "structure type '%s' is not supported yet", g_type_name (type));
@@ -1531,15 +1544,22 @@ _pygi_argument_to_object (GIArgument *arg,
type_tag = g_type_info_get_tag (type_info);
switch (type_tag) {
case GI_TYPE_TAG_VOID:
+ {
if (g_type_info_is_pointer (type_info) &&
(arg->v_pointer != NULL)) {
- /* Raw Python objects are passed to void* args */
g_warn_if_fail (transfer == GI_TRANSFER_NOTHING);
- object = arg->v_pointer;
- } else
+ 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_XINCREF (object);
+ Py_INCREF (object);
+ }
break;
+ }
case GI_TYPE_TAG_BOOLEAN:
{
object = PyBool_FromLong (arg->v_boolean);