[pygobject/pygobject-2-28] fetch size from an enum type
- From: Mike Gorse <mgorse src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/pygobject-2-28] fetch size from an enum type
- Date: Mon, 4 Apr 2011 22:01:05 +0000 (UTC)
commit b0e499744d337adc608e2aa8996469bca2df044a
Author: Mike Gorse <mgorse novell com>
Date: Sat Apr 2 18:45:40 2011 -0500
fetch size from an enum type
Do not assume that an enum is returned as a long; treat it as an int if
the type indicates that its size is that of an int.
http://bugzilla.gnome.org/show_bug.cgi?id=646581
gi/pygi-argument.c | 25 ++++++++++++++++++++++---
1 files changed, 22 insertions(+), 3 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 6519e5c..ee14b49 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -1316,6 +1316,23 @@ hash_table_release:
return arg;
}
+static glong
+_pygi_glong_from_argument (GIArgument *arg,
+ GITypeInfo *type_info)
+{
+ gsize item_size = _pygi_g_type_info_size (type_info);
+
+ if (item_size == sizeof (glong))
+ return arg->v_long;
+ else if (item_size == sizeof (gint))
+ return arg->v_int;
+ else
+ {
+ g_warning ("pygi: unsupported item size %ld", item_size);
+ return arg->v_long;
+ }
+}
+
PyObject *
_pygi_argument_to_object (GIArgument *arg,
GITypeInfo *type_info,
@@ -1621,24 +1638,26 @@ _pygi_argument_to_object (GIArgument *arg,
/* An enum with a GType of None is an enum without GType */
PyObject *py_type = _pygi_type_import_by_gi_info (info);
PyObject *py_args = NULL;
+ glong val = _pygi_glong_from_argument (arg, type_info);
if (!py_type)
return NULL;
py_args = PyTuple_New (1);
- if (PyTuple_SetItem (py_args, 0, PyLong_FromLong (arg->v_long)) != 0) {
+ if (PyTuple_SetItem (py_args, 0, PyLong_FromLong (val)) != 0) {
Py_DECREF (py_args);
Py_DECREF (py_type);
return NULL;
}
- object = PyObject_CallFunction (py_type, "l", arg->v_long);
+ object = PyObject_CallFunction (py_type, "l", val);
Py_DECREF (py_args);
Py_DECREF (py_type);
} else if (info_type == GI_INFO_TYPE_ENUM) {
- object = pyg_enum_from_gtype (type, arg->v_long);
+ glong val = _pygi_glong_from_argument (arg, type_info);
+ object = pyg_enum_from_gtype (type, val);
} else {
object = pyg_flags_from_gtype (type, arg->v_long);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]