summaryrefslogtreecommitdiff
path: root/gi
diff options
context:
space:
mode:
Diffstat (limited to 'gi')
-rw-r--r--gi/Makefile.in6
-rw-r--r--gi/_glib/Makefile.in6
-rw-r--r--gi/_glib/pyglib-python-compat.h8
-rw-r--r--gi/_gobject/Makefile.in6
-rw-r--r--gi/_gobject/gobjectmodule.c59
-rw-r--r--gi/_gobject/pygflags.c57
-rw-r--r--gi/_gobject/pygobject-private.h12
-rw-r--r--gi/_gobject/pygobject.h4
-rw-r--r--gi/_gobject/pygtype.c6
-rw-r--r--gi/gimodule.c2
-rw-r--r--gi/overrides/GLib.py4
-rw-r--r--gi/overrides/GObject.py256
-rw-r--r--gi/overrides/Gdk.py28
-rw-r--r--gi/overrides/Gtk.py157
-rw-r--r--gi/overrides/Makefile.in6
-rw-r--r--gi/overrides/__init__.py22
-rw-r--r--gi/pygi-argument.c39
-rw-r--r--gi/pygi-argument.h1
-rw-r--r--gi/pygi-boxed.c14
-rw-r--r--gi/pygi-boxed.h3
-rw-r--r--gi/pygi-cache.c14
-rw-r--r--gi/pygi-closure.c6
-rw-r--r--gi/pygi-info.c4
-rw-r--r--gi/pygi-invoke.c2
-rw-r--r--gi/pygi-marshal-cleanup.c19
-rw-r--r--gi/pygi-marshal-from-py.c33
-rw-r--r--gi/pygi-marshal-to-py.c11
-rw-r--r--gi/pygi-private.h1
-rw-r--r--gi/pygi-property.c21
-rw-r--r--gi/pygi-signal-closure.c3
-rw-r--r--gi/pygi-source.c3
-rw-r--r--gi/pygtkcompat.py2
-rw-r--r--gi/repository/Makefile.in6
33 files changed, 450 insertions, 371 deletions
diff --git a/gi/Makefile.in b/gi/Makefile.in
index 1e845ce..7d17d1b 100644
--- a/gi/Makefile.in
+++ b/gi/Makefile.in
@@ -61,8 +61,10 @@ DIST_COMMON = $(pygi_PYTHON) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/as-ac-expand.m4 \
- $(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/python.m4 \
- $(top_srcdir)/configure.ac
+ $(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/libtool.m4 \
+ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
+ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
+ $(top_srcdir)/m4/python.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
diff --git a/gi/_glib/Makefile.in b/gi/_glib/Makefile.in
index dac2bfd..5a05798 100644
--- a/gi/_glib/Makefile.in
+++ b/gi/_glib/Makefile.in
@@ -61,8 +61,10 @@ DIST_COMMON = $(pyglib_PYTHON) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/as-ac-expand.m4 \
- $(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/python.m4 \
- $(top_srcdir)/configure.ac
+ $(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/libtool.m4 \
+ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
+ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
+ $(top_srcdir)/m4/python.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
diff --git a/gi/_glib/pyglib-python-compat.h b/gi/_glib/pyglib-python-compat.h
index 96a20c0..9ba68f7 100644
--- a/gi/_glib/pyglib-python-compat.h
+++ b/gi/_glib/pyglib-python-compat.h
@@ -137,6 +137,11 @@ static int _pyglib_init_##modname(PyObject *module)
#define PYGLIB_PyLong_AS_LONG PyInt_AS_LONG
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
+/* Python 2.7 lacks a PyInt_FromUnsignedLong function; use signed longs, and
+ * rely on PyInt_AsUnsignedLong() to interpret them correctly */
+#define PYGLIB_PyLong_FromUnsignedLong PyInt_FromLong
+#define PYGLIB_PyLong_AsUnsignedLong(o) PyInt_AsUnsignedLongMask((PyObject*)(o))
+
#define PYGLIB_PyNumber_Long PyNumber_Int
#ifndef PyVarObject_HEAD_INIT
@@ -225,6 +230,9 @@ PyTypeObject symbol = { \
#define PYGLIB_PyLongObject PyLongObject
#define PYGLIB_PyLong_Type PyLong_Type
+#define PYGLIB_PyLong_FromUnsignedLong PyLong_FromUnsignedLong
+#define PYGLIB_PyLong_AsUnsignedLong(o) PyLong_AsUnsignedLongMask((PyObject*)(o))
+
#define PYGLIB_PyBytes_FromString PyBytes_FromString
#define PYGLIB_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
#define PYGLIB_PyBytes_Resize(o, len) _PyBytes_Resize(o, len)
diff --git a/gi/_gobject/Makefile.in b/gi/_gobject/Makefile.in
index e6369f5..402a145 100644
--- a/gi/_gobject/Makefile.in
+++ b/gi/_gobject/Makefile.in
@@ -60,8 +60,10 @@ DIST_COMMON = $(pkginclude_HEADERS) $(pygobject_PYTHON) \
$(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/as-ac-expand.m4 \
- $(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/python.m4 \
- $(top_srcdir)/configure.ac
+ $(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/libtool.m4 \
+ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
+ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
+ $(top_srcdir)/m4/python.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
diff --git a/gi/_gobject/gobjectmodule.c b/gi/_gobject/gobjectmodule.c
index fda21e7..c49b412 100644
--- a/gi/_gobject/gobjectmodule.c
+++ b/gi/_gobject/gobjectmodule.c
@@ -37,7 +37,6 @@
#include "pygpointer.h"
#include "pygtype.h"
-static PyObject *_pyg_signal_accumulator_true_handled_func;
static GHashTable *log_handlers = NULL;
static gboolean log_handlers_disabled = FALSE;
@@ -340,17 +339,13 @@ create_signal (GType instance_type, const gchar *signal_name, PyObject *tuple)
Py_DECREF(item);
}
- if (py_accum == _pyg_signal_accumulator_true_handled_func)
- accumulator = g_signal_accumulator_true_handled;
- else {
- if (py_accum != NULL && py_accum != Py_None) {
- accum_data = g_new(PyGSignalAccumulatorData, 1);
- accum_data->callable = py_accum;
- Py_INCREF(py_accum);
- accum_data->user_data = py_accum_data;
- Py_XINCREF(py_accum_data);
- accumulator = _pyg_signal_accumulator;
- }
+ if (py_accum != NULL && py_accum != Py_None) {
+ accum_data = g_new(PyGSignalAccumulatorData, 1);
+ accum_data->callable = py_accum;
+ Py_INCREF(py_accum);
+ accum_data->user_data = py_accum_data;
+ Py_XINCREF(py_accum_data);
+ accumulator = _pyg_signal_accumulator;
}
signal_id = g_signal_newv(signal_name, instance_type, signal_flags,
@@ -577,7 +572,7 @@ create_property (const gchar *prop_name,
return NULL;
if (pyg_flags_get_value(prop_type, pydefault,
- (gint *)&default_value))
+ &default_value))
return NULL;
pspec = g_param_spec_flags (prop_name, nick, blurb,
@@ -1671,38 +1666,6 @@ pyg_add_emission_hook(PyGObject *self, PyObject *args)
}
static PyObject *
-pyg_remove_emission_hook(PyGObject *self, PyObject *args)
-{
- PyObject *pygtype, *repr;
- char *name;
- guint signal_id;
- gulong hook_id;
- GType gtype;
-
- if (!PyArg_ParseTuple(args, "Osk:gobject.remove_emission_hook",
- &pygtype, &name, &hook_id))
- return NULL;
-
- if ((gtype = pyg_type_from_object(pygtype)) == 0) {
- return NULL;
- }
-
- if (!g_signal_parse_name(name, gtype, &signal_id, NULL, TRUE)) {
- repr = PyObject_Repr((PyObject*)self);
- PyErr_Format(PyExc_TypeError, "%s: unknown signal name: %s",
- PYGLIB_PyUnicode_AsString(repr),
- name);
- Py_DECREF(repr);
- return NULL;
- }
-
- g_signal_remove_emission_hook(signal_id, hook_id);
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
pyg__install_metaclass(PyObject *dummy, PyTypeObject *metaclass)
{
Py_INCREF(metaclass);
@@ -1733,8 +1696,6 @@ static PyMethodDef _gobject_functions[] = {
(PyCFunction)pyg_signal_accumulator_true_handled, METH_VARARGS },
{ "add_emission_hook",
(PyCFunction)pyg_add_emission_hook, METH_VARARGS },
- { "remove_emission_hook",
- (PyCFunction)pyg_remove_emission_hook, METH_VARARGS },
{ "_install_metaclass",
(PyCFunction)pyg__install_metaclass, METH_O },
@@ -2233,10 +2194,6 @@ PYGLIB_MODULE_START(_gobject, "_gobject")
pygobject_enum_register_types(d);
pygobject_flags_register_types(d);
- /* signal registration recognizes this special accumulator 'constant' */
- _pyg_signal_accumulator_true_handled_func = \
- PyDict_GetItemString(d, "signal_accumulator_true_handled");
-
pygobject_api_functions.threads_enabled = pyglib_threads_enabled();
_pyglib_notify_on_enabling_threads(pyg_note_threads_enabled);
}
diff --git a/gi/_gobject/pygflags.c b/gi/_gobject/pygflags.c
index bad32c6..83aa4dc 100644
--- a/gi/_gobject/pygflags.c
+++ b/gi/_gobject/pygflags.c
@@ -3,7 +3,7 @@
* Copyright (C) 1998-2003 James Henstridge
* Copyright (C) 2004 Johan Dahlin
*
- * pygenum.c: GFlags wrapper
+ * pygflags.c: GFlags wrapper
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -40,11 +40,12 @@ pyg_flags_val_new(PyObject* subclass, GType gtype, PyObject *intval)
{
PyObject *args, *item;
args = Py_BuildValue("(O)", intval);
- item = (&PYGLIB_PyLong_Type)->tp_new((PyTypeObject*)subclass, args, NULL);
+ g_assert(PyObject_IsSubclass(subclass, (PyObject*) &PyGFlags_Type));
+ item = PYGLIB_PyLong_Type.tp_new((PyTypeObject*)subclass, args, NULL);
Py_DECREF(args);
if (!item)
return NULL;
- ((PyGEnum*)item)->gtype = gtype;
+ ((PyGFlags*)item)->gtype = gtype;
return item;
}
@@ -70,7 +71,7 @@ pyg_flags_richcompare(PyGFlags *self, PyObject *other, int op)
}
static char *
-generate_repr(GType gtype, int value)
+generate_repr(GType gtype, guint value)
{
GFlagsClass *flags_class;
char *retval = NULL, *tmp;
@@ -108,13 +109,13 @@ pyg_flags_repr(PyGFlags *self)
char *tmp, *retval;
PyObject *pyretval;
- tmp = generate_repr(self->gtype, PYGLIB_PyLong_AS_LONG(self));
+ tmp = generate_repr(self->gtype, PYGLIB_PyLong_AsUnsignedLong(self));
if (tmp)
retval = g_strdup_printf("<flags %s of type %s>", tmp,
g_type_name(self->gtype));
else
- retval = g_strdup_printf("<flags %ld of type %s>", PYGLIB_PyLong_AS_LONG(self),
+ retval = g_strdup_printf("<flags %ld of type %s>", PYGLIB_PyLong_AsUnsignedLong(self),
g_type_name(self->gtype));
g_free(tmp);
@@ -128,7 +129,7 @@ static PyObject *
pyg_flags_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "value", NULL };
- long value;
+ guint value;
PyObject *pytc, *values, *ret, *pyint;
GType gtype;
GFlagsClass *eclass;
@@ -167,7 +168,7 @@ pyg_flags_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
g_type_class_unref(eclass);
- pyint = PYGLIB_PyLong_FromLong(value);
+ pyint = PYGLIB_PyLong_FromUnsignedLong(value);
ret = PyDict_GetItem(values, pyint);
if (!ret) {
PyErr_Clear();
@@ -185,10 +186,13 @@ pyg_flags_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
}
PyObject*
-pyg_flags_from_gtype (GType gtype, int value)
+pyg_flags_from_gtype (GType gtype, guint value)
{
PyObject *pyclass, *values, *retval, *pyint;
+ if (PyErr_Occurred())
+ return PYGLIB_PyLong_FromUnsignedLong(0);
+
g_return_val_if_fail(gtype != G_TYPE_INVALID, NULL);
/* Get a wrapper class by:
@@ -202,11 +206,11 @@ pyg_flags_from_gtype (GType gtype, int value)
if (!pyclass)
pyclass = pyg_flags_add(NULL, g_type_name(gtype), NULL, gtype);
if (!pyclass)
- return PYGLIB_PyLong_FromLong(value);
+ return PYGLIB_PyLong_FromUnsignedLong(value);
values = PyDict_GetItemString(((PyTypeObject *)pyclass)->tp_dict,
"__flags_values__");
- pyint = PYGLIB_PyLong_FromLong(value);
+ pyint = PYGLIB_PyLong_FromUnsignedLong(value);
retval = PyDict_GetItem(values, pyint);
if (!retval) {
PyErr_Clear();
@@ -221,6 +225,10 @@ pyg_flags_from_gtype (GType gtype, int value)
return retval;
}
+/*
+ * pyg_flags_add
+ * Dynamically create a class derived from PyGFlags based on the given GType.
+ */
PyObject *
pyg_flags_add (PyObject * module,
const char * typename,
@@ -241,13 +249,16 @@ pyg_flags_add (PyObject * module,
state = pyglib_gil_state_ensure();
+ /* Create a new type derived from GFlags. This is the same as:
+ * >>> stub = type(typename, (GFlags,), {})
+ */
instance_dict = PyDict_New();
stub = PyObject_CallFunction((PyObject *)&PyType_Type, "s(O)O",
typename, (PyObject *)&PyGFlags_Type,
instance_dict);
Py_DECREF(instance_dict);
if (!stub) {
- PyErr_SetString(PyExc_RuntimeError, "can't create const");
+ PyErr_SetString(PyExc_RuntimeError, "can't create GFlags subtype");
pyglib_gil_state_release(state);
return NULL;
}
@@ -277,7 +288,8 @@ pyg_flags_add (PyObject * module,
for (i = 0; i < eclass->n_values; i++) {
PyObject *item, *intval;
- intval = PYGLIB_PyLong_FromLong(eclass->values[i].value);
+ intval = PYGLIB_PyLong_FromUnsignedLong(eclass->values[i].value);
+ g_assert(PyErr_Occurred() == NULL);
item = pyg_flags_val_new(stub, gtype, intval);
PyDict_SetItem(values, intval, item);
Py_DECREF(intval);
@@ -312,7 +324,7 @@ pyg_flags_and(PyGFlags *a, PyGFlags *b)
(PyObject*)b);
return pyg_flags_from_gtype(a->gtype,
- PYGLIB_PyLong_AS_LONG(a) & PYGLIB_PyLong_AS_LONG(b));
+ PYGLIB_PyLong_AsUnsignedLong(a) & PYGLIB_PyLong_AsUnsignedLong(b));
}
static PyObject *
@@ -322,7 +334,7 @@ pyg_flags_or(PyGFlags *a, PyGFlags *b)
return PYGLIB_PyLong_Type.tp_as_number->nb_or((PyObject*)a,
(PyObject*)b);
- return pyg_flags_from_gtype(a->gtype, PYGLIB_PyLong_AS_LONG(a) | PYGLIB_PyLong_AS_LONG(b));
+ return pyg_flags_from_gtype(a->gtype, PYGLIB_PyLong_AsUnsignedLong(a) | PYGLIB_PyLong_AsUnsignedLong(b));
}
static PyObject *
@@ -333,7 +345,7 @@ pyg_flags_xor(PyGFlags *a, PyGFlags *b)
(PyObject*)b);
return pyg_flags_from_gtype(a->gtype,
- PYGLIB_PyLong_AS_LONG(a) ^ PYGLIB_PyLong_AS_LONG(b));
+ PYGLIB_PyLong_AsUnsignedLong(a) ^ PYGLIB_PyLong_AsUnsignedLong(b));
}
@@ -356,7 +368,7 @@ pyg_flags_get_first_value_name(PyGFlags *self, void *closure)
flags_class = g_type_class_ref(self->gtype);
g_assert(G_IS_FLAGS_CLASS(flags_class));
- flags_value = g_flags_get_first_value(flags_class, PYGLIB_PyLong_AS_LONG(self));
+ flags_value = g_flags_get_first_value(flags_class, PYGLIB_PyLong_AsUnsignedLong(self));
if (flags_value)
retval = PYGLIB_PyUnicode_FromString(flags_value->value_name);
else {
@@ -378,7 +390,7 @@ pyg_flags_get_first_value_nick(PyGFlags *self, void *closure)
flags_class = g_type_class_ref(self->gtype);
g_assert(G_IS_FLAGS_CLASS(flags_class));
- flags_value = g_flags_get_first_value(flags_class, PYGLIB_PyLong_AS_LONG(self));
+ flags_value = g_flags_get_first_value(flags_class, PYGLIB_PyLong_AsUnsignedLong(self));
if (flags_value)
retval = PYGLIB_PyUnicode_FromString(flags_value->value_nick);
else {
@@ -402,7 +414,7 @@ pyg_flags_get_value_names(PyGFlags *self, void *closure)
retval = PyList_New(0);
for (i = 0; i < flags_class->n_values; i++)
- if ((PYGLIB_PyLong_AS_LONG(self) & flags_class->values[i].value) == flags_class->values[i].value)
+ if ((PYGLIB_PyLong_AsUnsignedLong(self) & flags_class->values[i].value) == flags_class->values[i].value)
PyList_Append(retval, PYGLIB_PyUnicode_FromString(flags_class->values[i].value_name));
g_type_class_unref(flags_class);
@@ -422,8 +434,11 @@ pyg_flags_get_value_nicks(PyGFlags *self, void *closure)
retval = PyList_New(0);
for (i = 0; i < flags_class->n_values; i++)
- if ((PYGLIB_PyLong_AS_LONG(self) & flags_class->values[i].value) == flags_class->values[i].value)
- PyList_Append(retval, PYGLIB_PyUnicode_FromString(flags_class->values[i].value_nick));
+ if ((PYGLIB_PyLong_AsUnsignedLong(self) & flags_class->values[i].value) == flags_class->values[i].value) {
+ PyObject *py_nick = PYGLIB_PyUnicode_FromString(flags_class->values[i].value_nick);
+ PyList_Append(retval, py_nick);
+ Py_DECREF (py_nick);
+ }
g_type_class_unref(flags_class);
diff --git a/gi/_gobject/pygobject-private.h b/gi/_gobject/pygobject-private.h
index 0d1aca0..e1fc2b6 100644
--- a/gi/_gobject/pygobject-private.h
+++ b/gi/_gobject/pygobject-private.h
@@ -107,7 +107,7 @@ GType pyg_type_from_object_strict (PyObject *obj, gboolean strict);
GType pyg_type_from_object (PyObject *obj);
gint pyg_enum_get_value (GType enum_type, PyObject *obj, gint *val);
-gint pyg_flags_get_value (GType flag_type, PyObject *obj, gint *val);
+gint pyg_flags_get_value (GType flag_type, PyObject *obj, guint *val);
int pyg_pyobj_to_unichar_conv (PyObject* py_obj, void* ptr);
typedef PyObject *(* fromvaluefunc)(const GValue *value);
@@ -158,8 +158,6 @@ PyObject * pygobject_new_full (GObject *obj, gboolean steal, gpointer
void pygobject_sink (GObject *obj);
PyTypeObject *pygobject_lookup_class (GType gtype);
void pygobject_watch_closure (PyObject *self, GClosure *closure);
-void pygobject_register_sinkfunc(GType type,
- void (* sinkfunc)(GObject *object));
int pyg_type_register (PyTypeObject *class,
const gchar *type_name);
@@ -181,7 +179,8 @@ const gchar * pyg_constant_strip_prefix(const gchar *name, const gchar *strip_pr
/* pygflags */
typedef struct {
- PYGLIB_PyLongObject parent;
+ PYGLIB_PyLongObject parent;
+ int zero_pad; /* must always be 0 */
GType gtype;
} PyGFlags;
@@ -194,13 +193,14 @@ extern PyObject * pyg_flags_add (PyObject * module,
const char * strip_prefix,
GType gtype);
extern PyObject * pyg_flags_from_gtype (GType gtype,
- int value);
+ guint value);
/* pygenum */
#define PyGEnum_Check(x) (PyObject_IsInstance((PyObject *)x, (PyObject *)&PyGEnum_Type) && g_type_is_a(((PyGFlags*)x)->gtype, G_TYPE_ENUM))
typedef struct {
- PYGLIB_PyLongObject parent;
+ PYGLIB_PyLongObject parent;
+ int zero_pad; /* must always be 0 */
GType gtype;
} PyGEnum;
diff --git a/gi/_gobject/pygobject.h b/gi/_gobject/pygobject.h
index 92dc030..cfd88d7 100644
--- a/gi/_gobject/pygobject.h
+++ b/gi/_gobject/pygobject.h
@@ -103,7 +103,7 @@ struct _PyGObject_Functions {
PyObject *(* type_wrapper_new)(GType type);
gint (* enum_get_value)(GType enum_type, PyObject *obj, gint *val);
- gint (* flags_get_value)(GType flag_type, PyObject *obj, gint *val);
+ gint (* flags_get_value)(GType flag_type, PyObject *obj, guint *val);
void (* register_gtype_custom)(GType gtype,
PyObject *(* from_func)(const GValue *value),
int (* to_func)(GValue *value, PyObject *obj));
@@ -168,7 +168,7 @@ struct _PyGObject_Functions {
const char *type_name_,
const char *strip_prefix,
GType gtype);
- PyObject* (*flags_from_gtype)(GType gtype, int value);
+ PyObject* (*flags_from_gtype)(GType gtype, guint value);
gboolean threads_enabled;
int (*enable_threads) (void);
diff --git a/gi/_gobject/pygtype.c b/gi/_gobject/pygtype.c
index 227178f..94014ff 100644
--- a/gi/_gobject/pygtype.c
+++ b/gi/_gobject/pygtype.c
@@ -538,7 +538,7 @@ pyg_enum_get_value(GType enum_type, PyObject *obj, gint *val)
* Returns: 0 on success or -1 on failure
*/
gint
-pyg_flags_get_value(GType flag_type, PyObject *obj, gint *val)
+pyg_flags_get_value(GType flag_type, PyObject *obj, guint *val)
{
GFlagsClass *fclass = NULL;
gint res = -1;
@@ -548,7 +548,7 @@ pyg_flags_get_value(GType flag_type, PyObject *obj, gint *val)
*val = 0;
res = 0;
} else if (PYGLIB_PyLong_Check(obj)) {
- *val = PYGLIB_PyLong_AsLong(obj);
+ *val = PYGLIB_PyLong_AsUnsignedLong(obj);
res = 0;
} else if (PyLong_Check(obj)) {
*val = PyLong_AsLongLong(obj);
@@ -944,7 +944,7 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
break;
case G_TYPE_FLAGS:
{
- gint val = 0;
+ guint val = 0;
if (pyg_flags_get_value(G_VALUE_TYPE(value), obj, &val) < 0) {
PyErr_Clear();
return -1;
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 23b4d9b..108fc77 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -513,7 +513,7 @@ _wrap_pyg_variant_type_from_string (PyObject *self, PyObject *args)
py_type = _pygi_type_import_by_name ("GLib", "VariantType");
- py_variant = _pygi_boxed_new ( (PyTypeObject *) py_type, type_string, FALSE);
+ py_variant = _pygi_boxed_new ( (PyTypeObject *) py_type, type_string, FALSE, 0);
return py_variant;
}
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index b3f1563..3e660d1 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -539,6 +539,10 @@ class Source(GLib.Source):
setattr(source, '__pygi_custom_source', True)
return source
+ def __del__(self):
+ if hasattr(self, '__pygi_custom_source'):
+ self.unref()
+
# Backwards compatible API for optional arguments
def attach(self, context=None):
id = super(Source, self).attach(context)
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index 2176d84..eea8928 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -3,7 +3,7 @@
#
# Copyright (C) 2012 Canonical Ltd.
# Author: Martin Pitt <martin.pitt@ubuntu.com>
-# Copyright (C) 2012 Simon Feltman <sfeltman@src.gnome.org>
+# Copyright (C) 2012-2013 Simon Feltman <sfeltman@src.gnome.org>
# Copyright (C) 2012 Bastian Winkler <buz@netbuz.org>
#
# This library is free software; you can redistribute it and/or
@@ -23,6 +23,7 @@
import sys
import warnings
+import functools
from collections import namedtuple
import gi.overrides
@@ -193,20 +194,14 @@ __all__ += ['GBoxed', 'GEnum', 'GFlags', 'GInterface', 'GObject',
'Warning']
-add_emission_hook = _gobject.add_emission_hook
features = _gobject.features
list_properties = _gobject.list_properties
new = _gobject.new
pygobject_version = _gobject.pygobject_version
-remove_emission_hook = _gobject.remove_emission_hook
-signal_accumulator_true_handled = _gobject.signal_accumulator_true_handled
-signal_new = _gobject.signal_new
threads_init = _gobject.threads_init
type_register = _gobject.type_register
-__all__ += ['add_emission_hook', 'features', 'list_properties',
- 'new', 'pygobject_version', 'remove_emission_hook',
- 'signal_accumulator_true_handled',
- 'signal_new', 'threads_init', 'type_register']
+__all__ += ['features', 'list_properties', 'new',
+ 'pygobject_version', 'threads_init', 'type_register']
class Value(GObjectModule.Value):
@@ -225,31 +220,33 @@ class Value(GObjectModule.Value):
self.unset()
def set_value(self, py_value):
- if self.g_type == _gobject.TYPE_INVALID:
+ gtype = self.g_type
+
+ if gtype == _gobject.TYPE_INVALID:
raise TypeError("GObject.Value needs to be initialized first")
- elif self.g_type == TYPE_BOOLEAN:
+ elif gtype == TYPE_BOOLEAN:
self.set_boolean(py_value)
- elif self.g_type == TYPE_CHAR:
+ elif gtype == TYPE_CHAR:
self.set_char(py_value)
- elif self.g_type == TYPE_UCHAR:
+ elif gtype == TYPE_UCHAR:
self.set_uchar(py_value)
- elif self.g_type == TYPE_INT:
+ elif gtype == TYPE_INT:
self.set_int(py_value)
- elif self.g_type == TYPE_UINT:
+ elif gtype == TYPE_UINT:
self.set_uint(py_value)
- elif self.g_type == TYPE_LONG:
+ elif gtype == TYPE_LONG:
self.set_long(py_value)
- elif self.g_type == TYPE_ULONG:
+ elif gtype == TYPE_ULONG:
self.set_ulong(py_value)
- elif self.g_type == TYPE_INT64:
+ elif gtype == TYPE_INT64:
self.set_int64(py_value)
- elif self.g_type == TYPE_UINT64:
+ elif gtype == TYPE_UINT64:
self.set_uint64(py_value)
- elif self.g_type == TYPE_FLOAT:
+ elif gtype == TYPE_FLOAT:
self.set_float(py_value)
- elif self.g_type == TYPE_DOUBLE:
+ elif gtype == TYPE_DOUBLE:
self.set_double(py_value)
- elif self.g_type == TYPE_STRING:
+ elif gtype == TYPE_STRING:
if isinstance(py_value, str):
py_value = str(py_value)
elif sys.version_info < (3, 0):
@@ -262,75 +259,77 @@ class Value(GObjectModule.Value):
raise ValueError("Expected string but got %s%s" %
(py_value, type(py_value)))
self.set_string(py_value)
- elif self.g_type == TYPE_PARAM:
+ elif gtype == TYPE_PARAM:
self.set_param(py_value)
- elif self.g_type.is_a(TYPE_ENUM):
+ elif gtype.is_a(TYPE_ENUM):
self.set_enum(py_value)
- elif self.g_type.is_a(TYPE_FLAGS):
+ elif gtype.is_a(TYPE_FLAGS):
self.set_flags(py_value)
- elif self.g_type.is_a(TYPE_BOXED):
+ elif gtype.is_a(TYPE_BOXED):
self.set_boxed(py_value)
- elif self.g_type == TYPE_POINTER:
+ elif gtype == TYPE_POINTER:
self.set_pointer(py_value)
- elif self.g_type.is_a(TYPE_OBJECT):
+ elif gtype.is_a(TYPE_OBJECT):
self.set_object(py_value)
- elif self.g_type == TYPE_UNICHAR:
+ elif gtype == TYPE_UNICHAR:
self.set_uint(int(py_value))
- # elif self.g_type == TYPE_OVERRIDE:
+ # elif gtype == TYPE_OVERRIDE:
# pass
- elif self.g_type == TYPE_GTYPE:
+ elif gtype == TYPE_GTYPE:
self.set_gtype(py_value)
- elif self.g_type == TYPE_VARIANT:
+ elif gtype == TYPE_VARIANT:
self.set_variant(py_value)
- elif self.g_type == TYPE_PYOBJECT:
+ elif gtype == TYPE_PYOBJECT:
self.set_boxed(py_value)
else:
- raise TypeError("Unknown value type %s" % self.g_type)
+ raise TypeError("Unknown value type %s" % gtype)
def get_value(self):
- if self.g_type == TYPE_BOOLEAN:
+ gtype = self.g_type
+
+ if gtype == TYPE_BOOLEAN:
return self.get_boolean()
- elif self.g_type == TYPE_CHAR:
+ elif gtype == TYPE_CHAR:
return self.get_char()
- elif self.g_type == TYPE_UCHAR:
+ elif gtype == TYPE_UCHAR:
return self.get_uchar()
- elif self.g_type == TYPE_INT:
+ elif gtype == TYPE_INT:
return self.get_int()
- elif self.g_type == TYPE_UINT:
+ elif gtype == TYPE_UINT:
return self.get_uint()
- elif self.g_type == TYPE_LONG:
+ elif gtype == TYPE_LONG:
return self.get_long()
- elif self.g_type == TYPE_ULONG:
+ elif gtype == TYPE_ULONG:
return self.get_ulong()
- elif self.g_type == TYPE_INT64:
+ elif gtype == TYPE_INT64:
return self.get_int64()
- elif self.g_type == TYPE_UINT64:
+ elif gtype == TYPE_UINT64:
return self.get_uint64()
- elif self.g_type == TYPE_FLOAT:
+ elif gtype == TYPE_FLOAT:
return self.get_float()
- elif self.g_type == TYPE_DOUBLE:
+ elif gtype == TYPE_DOUBLE:
return self.get_double()
- elif self.g_type == TYPE_STRING:
+ elif gtype == TYPE_STRING:
return self.get_string()
- elif self.g_type == TYPE_PARAM:
+ elif gtype == TYPE_PARAM:
return self.get_param()
- elif self.g_type.is_a(TYPE_ENUM):
+ elif gtype.is_a(TYPE_ENUM):
return self.get_enum()
- elif self.g_type.is_a(TYPE_FLAGS):
+ elif gtype.is_a(TYPE_FLAGS):
return self.get_flags()
- elif self.g_type.is_a(TYPE_BOXED):
+ elif gtype.is_a(TYPE_BOXED):
return self.get_boxed()
- elif self.g_type == TYPE_POINTER:
+ elif gtype == TYPE_POINTER:
return self.get_pointer()
- elif self.g_type.is_a(TYPE_OBJECT):
+ elif gtype.is_a(TYPE_OBJECT):
return self.get_object()
- elif self.g_type == TYPE_UNICHAR:
+ elif gtype == TYPE_UNICHAR:
return self.get_uint()
- elif self.g_type == TYPE_GTYPE:
+ elif gtype == TYPE_GTYPE:
return self.get_gtype()
- elif self.g_type == TYPE_VARIANT:
+ elif gtype == TYPE_VARIANT:
return self.get_variant()
- elif self.g_type == TYPE_PYOBJECT:
+ elif gtype == TYPE_PYOBJECT:
pass
else:
return None
@@ -417,6 +416,20 @@ def signal_query(id_or_name, type_=None):
__all__.append('signal_query')
+def _get_instance_for_signal(obj):
+ if isinstance(obj, GObjectModule.Object):
+ return obj.__gpointer__
+ else:
+ raise TypeError('Unsupported object "%s" for signal function' % obj)
+
+
+def _wrap_signal_func(func):
+ @functools.wraps(func)
+ def wrapper(obj, *args, **kwargs):
+ return func(_get_instance_for_signal(obj), *args, **kwargs)
+ return wrapper
+
+
class _HandlerBlockManager(object):
def __init__(self, obj, handler_id):
self.obj = obj
@@ -426,7 +439,101 @@ class _HandlerBlockManager(object):
pass
def __exit__(self, exc_type, exc_value, traceback):
- self.obj.handler_unblock(self.handler_id)
+ signal_handler_unblock(self.obj, self.handler_id)
+
+
+def signal_handler_block(obj, handler_id):
+ """Blocks the signal handler from being invoked until handler_unblock() is called.
+
+ Returns a context manager which optionally can be used to
+ automatically unblock the handler:
+
+ >>> with GObject.signal_handler_block(obj, id):
+ >>> pass
+ """
+ GObjectModule.signal_handler_block(_get_instance_for_signal(obj), handler_id)
+ return _HandlerBlockManager(obj, handler_id)
+
+__all__.append('signal_handler_block')
+
+
+# The following functions wrap GI functions but coerce the first arg into
+# something compatible with gpointer
+
+signal_handler_unblock = _wrap_signal_func(GObjectModule.signal_handler_unblock)
+signal_handler_disconnect = _wrap_signal_func(GObjectModule.signal_handler_disconnect)
+signal_handler_is_connected = _wrap_signal_func(GObjectModule.signal_handler_is_connected)
+signal_stop_emission = _wrap_signal_func(GObjectModule.signal_stop_emission)
+signal_stop_emission_by_name = _wrap_signal_func(GObjectModule.signal_stop_emission_by_name)
+signal_has_handler_pending = _wrap_signal_func(GObjectModule.signal_has_handler_pending)
+signal_get_invocation_hint = _wrap_signal_func(GObjectModule.signal_get_invocation_hint)
+signal_connect_closure = _wrap_signal_func(GObjectModule.signal_connect_closure)
+signal_connect_closure_by_id = _wrap_signal_func(GObjectModule.signal_connect_closure_by_id)
+signal_handler_find = _wrap_signal_func(GObjectModule.signal_handler_find)
+signal_handlers_destroy = _wrap_signal_func(GObjectModule.signal_handlers_destroy)
+signal_handlers_block_matched = _wrap_signal_func(GObjectModule.signal_handlers_block_matched)
+signal_handlers_unblock_matched = _wrap_signal_func(GObjectModule.signal_handlers_unblock_matched)
+signal_handlers_disconnect_matched = _wrap_signal_func(GObjectModule.signal_handlers_disconnect_matched)
+
+__all__ += ['signal_handler_unblock',
+ 'signal_handler_disconnect', 'signal_handler_is_connected',
+ 'signal_stop_emission', 'signal_stop_emission_by_name',
+ 'signal_has_handler_pending', 'signal_get_invocation_hint',
+ 'signal_connect_closure', 'signal_connect_closure_by_id',
+ 'signal_handler_find', 'signal_handlers_destroy',
+ 'signal_handlers_block_matched', 'signal_handlers_unblock_matched',
+ 'signal_handlers_disconnect_matched']
+
+
+def signal_parse_name(detailed_signal, itype, force_detail_quark):
+ """Parse a detailed signal name into (signal_id, detail).
+
+ :Raises ValueError:
+ If the given signal is unknown.
+
+ :Returns:
+ Tuple of (signal_id, detail)
+ """
+ res, signal_id, detail = GObjectModule.signal_parse_name(detailed_signal, itype,
+ force_detail_quark)
+ if res:
+ return signal_id, detail
+ else:
+ raise ValueError('%s: unknown signal name: %s' % (itype, detailed_signal))
+
+__all__.append('signal_parse_name')
+
+
+def remove_emission_hook(obj, detailed_signal, hook_id):
+ signal_id, detail = signal_parse_name(detailed_signal, obj, True)
+ GObjectModule.signal_remove_emission_hook(signal_id, hook_id)
+
+__all__.append('remove_emission_hook')
+
+
+# GObject accumulators with pure Python implementations
+# These return a tuple of (continue_emission, accumulation_result)
+
+def signal_accumulator_first_wins(ihint, return_accu, handler_return, user_data=None):
+ # Stop emission but return the result of the last handler
+ return (False, handler_return)
+
+__all__.append('signal_accumulator_first_wins')
+
+
+def signal_accumulator_true_handled(ihint, return_accu, handler_return, user_data=None):
+ # Stop emission if the last handler returns True
+ return (not handler_return, handler_return)
+
+__all__.append('signal_accumulator_true_handled')
+
+
+# Statically bound signal functions which need to clobber GI (for now)
+
+add_emission_hook = _gobject.add_emission_hook
+signal_new = _gobject.signal_new
+
+__all__ += ['add_emission_hook', 'signal_new']
class _FreezeNotifyManager(object):
@@ -500,21 +607,6 @@ class Object(GObjectModule.Object):
__copy__ = _gobject.GObject.__copy__
__deepcopy__ = _gobject.GObject.__deepcopy__
- def handler_block(self, handler_id):
- """Blocks the signal handler from being invoked until handler_unblock() is called.
-
- Returns a context manager which optionally can be used to
- automatically unblock the handler:
-
- >>> with obj.handler_block(id):
- >>> pass
- """
- GObjectModule.signal_handler_block(self.__gpointer__, handler_id)
- return _HandlerBlockManager(self, handler_id)
-
- def handler_unblock(self, handler_id):
- GObjectModule.signal_handler_unblock(self.__gpointer__, handler_id)
-
def freeze_notify(self):
"""Freezes the object's property-changed notification queue.
@@ -530,27 +622,25 @@ class Object(GObjectModule.Object):
super(Object, self).freeze_notify()
return _FreezeNotifyManager(self)
- def handler_disconnect(self, handler_id):
- GObjectModule.signal_handler_disconnect(self.__gpointer__, handler_id)
-
- def handler_is_connected(self, handler_id):
- return bool(GObjectModule.signal_handler_is_connected(self.__gpointer__, handler_id))
-
- def stop_emission_by_name(self, detailed_signal):
- GObjectModule.signal_stop_emission_by_name(self.__gpointer__, detailed_signal)
-
#
# Aliases
#
- disconnect = handler_disconnect
+
+ disconnect = signal_handler_disconnect
+ handler_block = signal_handler_block
+ handler_unblock = signal_handler_unblock
+ handler_disconnect = signal_handler_disconnect
+ handler_is_connected = signal_handler_is_connected
+ stop_emission_by_name = signal_stop_emission_by_name
#
# Deprecated Methods
#
+
def stop_emission(self, detailed_signal):
"""Deprecated, please use stop_emission_by_name."""
warnings.warn(self.stop_emission.__doc__, PyGIDeprecationWarning, stacklevel=2)
- return self.stop_emission_by_name(detailed_signal)
+ return signal_stop_emission_by_name(self, detailed_signal)
emit_stop_by_name = stop_emission
diff --git a/gi/overrides/Gdk.py b/gi/overrides/Gdk.py
index ceda261..14edc70 100644
--- a/gi/overrides/Gdk.py
+++ b/gi/overrides/Gdk.py
@@ -19,7 +19,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
-from ..overrides import override
+from ..overrides import override, strip_boolean_result
from ..module import get_introspection_module
import sys
@@ -251,19 +251,6 @@ gsuccess_mask_funcs = ['get_state',
'get_root_coords']
-def _gsuccess_mask(func):
- def cull_success(*args):
- result = func(*args)
- success = result[0]
- if not success:
- return None
- else:
- if len(result) == 2:
- return result[1]
- else:
- return result[1:]
- return cull_success
-
for event_class in event_member_classes:
override_class = type(event_class, (getattr(Gdk, event_class),), {})
# add the event methods
@@ -276,7 +263,7 @@ for event_class in event_member_classes:
# use the _gsuccess_mask decorator if this method is whitelisted
if name in gsuccess_mask_funcs:
- event_method = _gsuccess_mask(event_method)
+ event_method = strip_boolean_result(event_method)
setattr(override_class, name, event_method)
setattr(module, event_class, override_class)
@@ -335,15 +322,8 @@ class Cursor(Gdk.Cursor):
Cursor = override(Cursor)
__all__.append('Cursor')
-_Gdk_color_parse = Gdk.color_parse
-
-
-@override(Gdk.color_parse)
-def color_parse(color):
- success, color = _Gdk_color_parse(color)
- if not success:
- return None
- return color
+color_parse = strip_boolean_result(Gdk.color_parse)
+__all__.append('color_parse')
# Note, we cannot override the entire class as Gdk.Atom has no gtype, so just
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 002f22b..ab09a26 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -21,7 +21,7 @@
import sys
from gi.repository import GObject
-from ..overrides import override
+from ..overrides import override, strip_boolean_result
from ..module import get_introspection_module
from gi import PyGIDeprecationWarning
@@ -66,11 +66,7 @@ __all__.append('_construct_target_list')
class Widget(Gtk.Widget):
- def translate_coordinates(self, dest_widget, src_x, src_y):
- success, dest_x, dest_y = super(Widget, self).translate_coordinates(
- dest_widget, src_x, src_y)
- if success:
- return (dest_x, dest_y,)
+ translate_coordinates = strip_boolean_result(Gtk.Widget.translate_coordinates)
def render_icon(self, stock_id, size, detail=None):
return super(Widget, self).render_icon(stock_id, size, detail)
@@ -107,10 +103,8 @@ class Container(Gtk.Container, Widget):
# alias for Python 2.x object protocol
__nonzero__ = __bool__
- def get_focus_chain(self):
- success, widgets = super(Container, self).get_focus_chain()
- if success:
- return widgets
+ get_focus_chain = strip_boolean_result(Gtk.Container.get_focus_chain)
+
Container = override(Container)
__all__.append('Container')
@@ -119,16 +113,10 @@ __all__.append('Container')
class Editable(Gtk.Editable):
def insert_text(self, text, position):
- pos = super(Editable, self).insert_text(text, -1, position)
+ return super(Editable, self).insert_text(text, -1, position)
- return pos
+ get_selection_bounds = strip_boolean_result(Gtk.TextBuffer.get_selection_bounds, fail_ret=())
- def get_selection_bounds(self):
- success, start_pos, end_pos = super(Editable, self).get_selection_bounds()
- if success:
- return (start_pos, end_pos,)
- else:
- return tuple()
Editable = override(Editable)
__all__.append("Editable")
@@ -333,11 +321,7 @@ __all__.append('UIManager')
class ComboBox(Gtk.ComboBox, Container):
-
- def get_active_iter(self):
- success, aiter = super(ComboBox, self).get_active_iter()
- if success:
- return aiter
+ get_active_iter = strip_boolean_result(Gtk.ComboBox.get_active_iter)
ComboBox = override(ComboBox)
__all__.append('ComboBox')
@@ -611,20 +595,9 @@ class IconView(Gtk.IconView):
def __init__(self, model=None, **kwds):
Gtk.IconView.__init__(self, model=model, **kwds)
- def get_item_at_pos(self, x, y):
- success, path, cell = super(IconView, self).get_item_at_pos(x, y)
- if success:
- return (path, cell,)
-
- def get_visible_range(self):
- success, start_path, end_path = super(IconView, self).get_visible_range()
- if success:
- return (start_path, end_path,)
-
- def get_dest_item_at_pos(self, drag_x, drag_y):
- success, path, pos = super(IconView, self).get_dest_item_at_pos(drag_x, drag_y)
- if success:
- return path, pos
+ get_item_at_pos = strip_boolean_result(Gtk.IconView.get_item_at_pos)
+ get_visible_range = strip_boolean_result(Gtk.IconView.get_visible_range)
+ get_dest_item_at_pos = strip_boolean_result(Gtk.IconView.get_dest_item_at_pos)
IconView = override(IconView)
__all__.append('IconView')
@@ -640,22 +613,14 @@ __all__.append('ToolButton')
class IMContext(Gtk.IMContext):
-
- def get_surrounding(self):
- success, text, cursor_index = super(IMContext, self).get_surrounding()
- if success:
- return (text, cursor_index,)
+ get_surrounding = strip_boolean_result(Gtk.IMContext.get_surrounding)
IMContext = override(IMContext)
__all__.append('IMContext')
class RecentInfo(Gtk.RecentInfo):
-
- def get_application_info(self, app_name):
- success, app_exec, count, time = super(RecentInfo, self).get_application_info(app_name)
- if success:
- return (app_exec, count, time,)
+ get_application_info = strip_boolean_result(Gtk.RecentInfo.get_application_info)
RecentInfo = override(RecentInfo)
__all__.append('RecentInfo')
@@ -739,12 +704,7 @@ class TextBuffer(Gtk.TextBuffer):
Gtk.TextBuffer.insert_at_cursor(self, text, length)
- def get_selection_bounds(self):
- success, start, end = super(TextBuffer, self).get_selection_bounds()
- if success:
- return (start, end)
- else:
- return ()
+ get_selection_bounds = strip_boolean_result(Gtk.TextBuffer.get_selection_bounds, fail_ret=())
TextBuffer = override(TextBuffer)
__all__.append('TextBuffer')
@@ -752,21 +712,8 @@ __all__.append('TextBuffer')
class TextIter(Gtk.TextIter):
- def forward_search(self, string, flags, limit):
- success, match_start, match_end = super(TextIter, self).forward_search(string,
- flags, limit)
- if success:
- return (match_start, match_end)
- else:
- return None
-
- def backward_search(self, string, flags, limit):
- success, match_start, match_end = super(TextIter, self).backward_search(string,
- flags, limit)
- if success:
- return (match_start, match_end)
- else:
- return None
+ forward_search = strip_boolean_result(Gtk.TextIter.forward_search)
+ backward_search = strip_boolean_result(Gtk.TextIter.backward_search)
def begins_tag(self, tag=None):
return super(TextIter, self).begins_tag(tag)
@@ -831,6 +778,13 @@ class TreeModel(Gtk.TreeModel):
def __iter__(self):
return TreeModelRowIter(self, self.get_iter_first())
+ get_iter_first = strip_boolean_result(Gtk.TreeModel.get_iter_first)
+ iter_children = strip_boolean_result(Gtk.TreeModel.iter_children)
+ iter_nth_child = strip_boolean_result(Gtk.TreeModel.iter_nth_child)
+ iter_parent = strip_boolean_result(Gtk.TreeModel.iter_parent)
+ get_iter_from_string = strip_boolean_result(Gtk.TreeModel.get_iter_from_string,
+ ValueError, 'invalid tree path')
+
def get_iter(self, path):
path = self._coerce_path(path)
success, aiter = super(TreeModel, self).get_iter(path)
@@ -838,17 +792,6 @@ class TreeModel(Gtk.TreeModel):
raise ValueError("invalid tree path '%s'" % path)
return aiter
- def get_iter_first(self):
- success, aiter = super(TreeModel, self).get_iter_first()
- if success:
- return aiter
-
- def get_iter_from_string(self, path_string):
- success, aiter = super(TreeModel, self).get_iter_from_string(path_string)
- if not success:
- raise ValueError("invalid tree path '%s'" % path_string)
- return aiter
-
def iter_next(self, aiter):
next_iter = aiter.copy()
success = super(TreeModel, self).iter_next(next_iter)
@@ -861,21 +804,6 @@ class TreeModel(Gtk.TreeModel):
if success:
return prev_iter
- def iter_children(self, aiter):
- success, child_iter = super(TreeModel, self).iter_children(aiter)
- if success:
- return child_iter
-
- def iter_nth_child(self, parent, n):
- success, child_iter = super(TreeModel, self).iter_nth_child(parent, n)
- if success:
- return child_iter
-
- def iter_parent(self, aiter):
- success, parent_iter = super(TreeModel, self).iter_parent(aiter)
- if success:
- return parent_iter
-
def _convert_row(self, row):
# TODO: Accept a dictionary for row
# model.append(None,{COLUMN_ICON: icon, COLUMN_NAME: name})
@@ -957,12 +885,7 @@ __all__.append('TreeModel')
class TreeSortable(Gtk.TreeSortable, ):
- def get_sort_column_id(self):
- success, sort_column_id, order = super(TreeSortable, self).get_sort_column_id()
- if success:
- return (sort_column_id, order,)
- else:
- return (None, None,)
+ get_sort_column_id = strip_boolean_result(Gtk.TreeSortable.get_sort_column_id, fail_ret=(None, None))
def set_sort_func(self, sort_column_id, sort_func, user_data=None):
super(TreeSortable, self).set_sort_func(sort_column_id, sort_func, user_data)
@@ -1318,20 +1241,9 @@ class TreeView(Gtk.TreeView, Container):
if model:
self.set_model(model)
- def get_path_at_pos(self, x, y):
- success, path, column, cell_x, cell_y = super(TreeView, self).get_path_at_pos(x, y)
- if success:
- return (path, column, cell_x, cell_y,)
-
- def get_visible_range(self):
- success, start_path, end_path = super(TreeView, self).get_visible_range()
- if success:
- return (start_path, end_path,)
-
- def get_dest_row_at_pos(self, drag_x, drag_y):
- success, path, pos = super(TreeView, self).get_dest_row_at_pos(drag_x, drag_y)
- if success:
- return (path, pos,)
+ get_path_at_pos = strip_boolean_result(Gtk.TreeView.get_path_at_pos)
+ get_visible_range = strip_boolean_result(Gtk.TreeView.get_visible_range)
+ get_dest_row_at_pos = strip_boolean_result(Gtk.TreeView.get_dest_row_at_pos)
def enable_model_drag_source(self, start_button_mask, targets, actions):
target_entries = _construct_target_list(targets)
@@ -1381,10 +1293,7 @@ class TreeViewColumn(Gtk.TreeViewColumn):
for (name, value) in attributes.items():
self.add_attribute(cell_renderer, name, value)
- def cell_get_position(self, cell_renderer):
- success, start_pos, width = super(TreeViewColumn, self).cell_get_position(cell_renderer)
- if success:
- return (start_pos, width,)
+ cell_get_position = strip_boolean_result(Gtk.TreeViewColumn.cell_get_position)
def set_cell_data_func(self, cell_renderer, func, func_data=None):
super(TreeViewColumn, self).set_cell_data_func(cell_renderer, func, func_data)
@@ -1587,16 +1496,8 @@ _Gtk_main_quit = Gtk.main_quit
def main_quit(*args):
_Gtk_main_quit()
-_Gtk_stock_lookup = Gtk.stock_lookup
-
-
-@override(Gtk.stock_lookup)
-def stock_lookup(*args):
- success, item = _Gtk_stock_lookup(*args)
- if not success:
- return None
-
- return item
+stock_lookup = strip_boolean_result(Gtk.stock_lookup)
+__all__.append('stock_lookup')
initialized, argv = Gtk.init_check(sys.argv)
sys.argv = list(argv)
diff --git a/gi/overrides/Makefile.in b/gi/overrides/Makefile.in
index 59b1b35..feed8d4 100644
--- a/gi/overrides/Makefile.in
+++ b/gi/overrides/Makefile.in
@@ -55,8 +55,10 @@ DIST_COMMON = $(pygioverrides_PYTHON) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/as-ac-expand.m4 \
- $(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/python.m4 \
- $(top_srcdir)/configure.ac
+ $(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/libtool.m4 \
+ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
+ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
+ $(top_srcdir)/m4/python.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py
index 0bd94b8..99cb152 100644
--- a/gi/overrides/__init__.py
+++ b/gi/overrides/__init__.py
@@ -85,3 +85,25 @@ def deprecated(fn, replacement):
PyGIDeprecationWarning, stacklevel=2)
return fn(*args, **kwargs)
return wrapped
+
+
+def strip_boolean_result(method, exc_type=None, exc_str=None, fail_ret=None):
+ '''Translate method's return value for stripping off success flag.
+
+ There are a lot of methods which return a "success" boolean and have
+ several out arguments. Translate such a method to return the out arguments
+ on success and None on failure.
+ '''
+ @functools.wraps(method)
+ def wrapped(*args, **kwargs):
+ ret = method(*args, **kwargs)
+ if ret[0]:
+ if len(ret) == 2:
+ return ret[1]
+ else:
+ return ret[1:]
+ else:
+ if exc_type:
+ raise exc_type(exc_str or 'call failed')
+ return fail_ret
+ return wrapped
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 3b65246..4cf82d0 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -762,8 +762,12 @@ check_number_release:
* _pygi_argument_to_array
* @arg: The argument to convert
* @args: Arguments to method invocation, possibly contaning the array length.
- * Set to NULL if this is not for a method call
- * @callable_info: Info on the callable, if this a method call; otherwise NULL
+ * Set to %NULL if this is not for a method call or @args_values is
+ * specified.
+ * @args_values: GValue Arguments to method invocation, possibly contaning the
+ * array length. Set to %NULL if this is not for a method call or
+ * @args is specified.
+ * @callable_info: Info on the callable, if this a method call; otherwise %NULL
* @type_info: The type info for @arg
* @out_free_array: A return location for a gboolean that indicates whether
* or not the wrapped GArray should be freed
@@ -781,6 +785,7 @@ check_number_release:
GArray *
_pygi_argument_to_array (GIArgument *arg,
GIArgument *args[],
+ const GValue *args_values,
GICallableInfo *callable_info,
GITypeInfo *type_info,
gboolean *out_free_array)
@@ -815,7 +820,7 @@ _pygi_argument_to_array (GIArgument *arg,
GIArgInfo length_arg_info;
GITypeInfo length_type_info;
- if (G_UNLIKELY (args == NULL)) {
+ if (G_UNLIKELY (args == NULL && args_values == NULL)) {
g_critical ("Unable to determine array length for %p",
arg->v_pointer);
g_array = g_array_new (is_zero_terminated, FALSE, item_size);
@@ -828,10 +833,21 @@ _pygi_argument_to_array (GIArgument *arg,
g_assert (callable_info);
g_callable_info_load_arg (callable_info, length_arg_pos, &length_arg_info);
g_arg_info_load_type (&length_arg_info, &length_type_info);
- if (!gi_argument_to_gssize (args[length_arg_pos],
- g_type_info_get_tag (&length_type_info),
- &length))
- return NULL;
+
+ if (args != NULL) {
+ if (!gi_argument_to_gssize (args[length_arg_pos],
+ g_type_info_get_tag (&length_type_info),
+ &length))
+ return NULL;
+ } else {
+ /* get it from args_values */
+ GIArgument length_arg = _pygi_argument_from_g_value (&(args_values[length_arg_pos]),
+ &length_type_info);
+ if (!gi_argument_to_gssize (&length_arg,
+ g_type_info_get_tag (&length_type_info),
+ &length))
+ return NULL;
+ }
}
}
@@ -839,6 +855,7 @@ _pygi_argument_to_array (GIArgument *arg,
g_array = g_array_new (is_zero_terminated, FALSE, item_size);
+ g_free (g_array->data);
g_array->data = arg->v_pointer;
g_array->len = length;
*out_free_array = TRUE;
@@ -1736,7 +1753,7 @@ _pygi_argument_to_object (GIArgument *arg,
if (py_type == NULL)
break;
- object = _pygi_boxed_new ( (PyTypeObject *) py_type, arg->v_pointer, transfer == GI_TRANSFER_EVERYTHING);
+ object = _pygi_boxed_new ( (PyTypeObject *) py_type, arg->v_pointer, transfer == GI_TRANSFER_EVERYTHING, 0);
Py_DECREF (py_type);
} else if (g_type_is_a (type, G_TYPE_POINTER)) {
@@ -2047,7 +2064,11 @@ _pygi_argument_from_g_value(const GValue *value,
break;
case GI_TYPE_TAG_ARRAY:
case GI_TYPE_TAG_GHASH:
- arg.v_pointer = g_value_get_boxed (value);
+ if (G_VALUE_HOLDS_BOXED (value))
+ arg.v_pointer = g_value_get_boxed (value);
+ else
+ /* e. g. GSettings::change-event */
+ arg.v_pointer = g_value_get_pointer (value);
break;
case GI_TYPE_TAG_INTERFACE:
{
diff --git a/gi/pygi-argument.h b/gi/pygi-argument.h
index a1420ee..ed88214 100644
--- a/gi/pygi-argument.h
+++ b/gi/pygi-argument.h
@@ -50,6 +50,7 @@ gint _pygi_g_registered_type_info_check_object (GIRegisteredTypeInfo *info,
GArray* _pygi_argument_to_array (GIArgument *arg,
GIArgument *args[],
+ const GValue *args_values,
GICallableInfo *callable_info,
GITypeInfo *type_info,
gboolean *out_free_array);
diff --git a/gi/pygi-boxed.c b/gi/pygi-boxed.c
index c15c927..cac2b0d 100644
--- a/gi/pygi-boxed.c
+++ b/gi/pygi-boxed.c
@@ -104,7 +104,7 @@ _boxed_new (PyTypeObject *type,
goto out;
}
- self = (PyGIBoxed *) _pygi_boxed_new (type, boxed, TRUE);
+ self = (PyGIBoxed *) _pygi_boxed_new (type, boxed, TRUE, size);
if (self == NULL) {
g_slice_free1 (size, boxed);
goto out;
@@ -133,7 +133,8 @@ PYGLIB_DEFINE_TYPE("gi.Boxed", PyGIBoxed_Type, PyGIBoxed);
PyObject *
_pygi_boxed_new (PyTypeObject *type,
gpointer boxed,
- gboolean free_on_dealloc)
+ gboolean free_on_dealloc,
+ gsize allocated_slice)
{
PyGIBoxed *self;
@@ -154,8 +155,13 @@ _pygi_boxed_new (PyTypeObject *type,
( (PyGBoxed *) self)->gtype = pyg_type_from_object ( (PyObject *) type);
( (PyGBoxed *) self)->boxed = boxed;
( (PyGBoxed *) self)->free_on_dealloc = free_on_dealloc;
- self->size = 0;
- self->slice_allocated = FALSE;
+ if (allocated_slice > 0) {
+ self->size = allocated_slice;
+ self->slice_allocated = TRUE;
+ } else {
+ self->size = 0;
+ self->slice_allocated = FALSE;
+ }
return (PyObject *) self;
}
diff --git a/gi/pygi-boxed.h b/gi/pygi-boxed.h
index a84ec4e..38ac928 100644
--- a/gi/pygi-boxed.h
+++ b/gi/pygi-boxed.h
@@ -30,7 +30,8 @@ extern PyTypeObject PyGIBoxed_Type;
PyObject * _pygi_boxed_new (PyTypeObject *type,
gpointer boxed,
- gboolean free_on_dealloc);
+ gboolean free_on_dealloc,
+ gsize allocated_slice);
void * _pygi_boxed_alloc (GIBaseInfo *info,
gsize *size);
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index 0848ccf..99f49cf 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -1462,6 +1462,20 @@ _pygi_callable_cache_new (GICallableInfo *callable_info, gboolean is_ccallback)
cache->name = g_base_info_get_name ((GIBaseInfo *)callable_info);
+ if (g_base_info_is_deprecated (callable_info)) {
+ const gchar *deprecated = g_base_info_get_attribute (callable_info, "deprecated");
+ gchar *warning;
+ if (deprecated != NULL)
+ warning = g_strdup_printf ("%s.%s is deprecated: %s",
+ g_base_info_get_namespace (callable_info), cache->name,
+ deprecated);
+ else
+ warning = g_strdup_printf ("%s.%s is deprecated",
+ g_base_info_get_namespace (callable_info), cache->name);
+ PyErr_WarnEx(PyExc_DeprecationWarning, warning, 0);
+ g_free (warning);
+ }
+
if (type == GI_INFO_TYPE_FUNCTION) {
GIFunctionInfoFlags flags;
diff --git a/gi/pygi-closure.c b/gi/pygi-closure.c
index 43f41d2..f49f8e2 100644
--- a/gi/pygi-closure.c
+++ b/gi/pygi-closure.c
@@ -353,7 +353,7 @@ _pygi_closure_convert_arguments (GICallableInfo *callable_info, void **args,
arg = (GIArgument*) g_args[i].v_pointer;
if (g_type_info_get_tag (&arg_type) == GI_TYPE_TAG_ARRAY)
- arg->v_pointer = _pygi_argument_to_array (arg, (GIArgument **) args,
+ arg->v_pointer = _pygi_argument_to_array (arg, (GIArgument **) args, NULL,
callable_info, &arg_type, &free_array);
value = _pygi_argument_to_object (arg, &arg_type, transfer);
@@ -508,8 +508,6 @@ _pygi_closure_handle (ffi_cif *cif,
end:
g_free (out_args);
- PyGILState_Release (state);
-
/* Now that the closure has finished we can make a decision about how
to free it. Scope call gets free'd at the end of wrap_g_function_info_invoke.
Scope notified will be freed when the notify is called.
@@ -532,6 +530,8 @@ end:
g_error ("Invalid scope reached inside %s. Possibly a bad annotation?",
g_base_info_get_name (closure->info));
}
+
+ PyGILState_Release (state);
}
void _pygi_invoke_closure_free (gpointer data)
diff --git a/gi/pygi-info.c b/gi/pygi-info.c
index 4d5b9bb..362e7cd 100644
--- a/gi/pygi-info.c
+++ b/gi/pygi-info.c
@@ -1245,7 +1245,7 @@ _wrap_g_constant_info_get_value (PyGIBaseInfo *self)
type_info = g_constant_info_get_type ( (GIConstantInfo *) self->info);
if (g_type_info_get_tag (type_info) == GI_TYPE_TAG_ARRAY) {
- value.v_pointer = _pygi_argument_to_array (&value, NULL, NULL,
+ value.v_pointer = _pygi_argument_to_array (&value, NULL, NULL, NULL,
type_info, &free_array);
}
@@ -1378,7 +1378,7 @@ _wrap_g_field_info_get_value (PyGIBaseInfo *self,
}
if (g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_ARRAY) {
- value.v_pointer = _pygi_argument_to_array (&value, NULL, NULL,
+ value.v_pointer = _pygi_argument_to_array (&value, NULL, NULL, NULL,
field_type_info, &free_array);
}
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index 96ffde3..0cbb9ca 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -366,7 +366,7 @@ static gboolean _caller_alloc (PyGIInvokeState *state,
state->out_args[out_count].v_pointer = NULL;
state->args[arg_count] = &state->out_args[out_count];
- if (iface_cache->g_type == G_TYPE_BOXED) {
+ if (g_type_is_a (iface_cache->g_type, G_TYPE_BOXED)) {
state->args[arg_count]->v_pointer =
_pygi_boxed_alloc (iface_cache->interface_info, NULL);
} else if (iface_cache->g_type == G_TYPE_VALUE) {
diff --git a/gi/pygi-marshal-cleanup.c b/gi/pygi-marshal-cleanup.c
index bd9522a..d7d1b63 100644
--- a/gi/pygi-marshal-cleanup.c
+++ b/gi/pygi-marshal-cleanup.c
@@ -29,7 +29,7 @@ _cleanup_caller_allocates (PyGIInvokeState *state,
{
PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)cache;
- if (iface_cache->g_type == G_TYPE_BOXED) {
+ if (g_type_is_a (iface_cache->g_type, G_TYPE_BOXED)) {
gsize size;
if (was_processed)
return; /* will be cleaned up at deallocation */
@@ -101,6 +101,12 @@ pygi_marshal_cleanup_args_from_py_marshal_success (PyGIInvokeState *state,
arg_cache->direction == PYGI_DIRECTION_FROM_PYTHON &&
state->args[i]->v_pointer != NULL)
cleanup_func (state, arg_cache, state->args[i]->v_pointer, TRUE);
+
+ if (cleanup_func &&
+ arg_cache->direction == PYGI_DIRECTION_BIDIRECTIONAL &&
+ state->args_data[i] != NULL) {
+ cleanup_func (state, arg_cache, state->args_data[i], TRUE);
+ }
}
}
@@ -368,8 +374,17 @@ _pygi_marshal_cleanup_from_py_array (PyGIInvokeState *state,
else if (sequence_cache->item_cache->is_pointer)
item = g_array_index (array_, gpointer, i);
/* case 3: C array or GArray with simple types or structs */
- else
+ else {
item = array_->data + i * sequence_cache->item_size;
+ /* special-case hack: GValue array items do not get slice
+ * allocated in _pygi_marshal_from_py_array(), so we must
+ * not try to deallocate it as a slice and thus
+ * short-circuit cleanup_func. */
+ if (cleanup_func == _pygi_marshal_cleanup_from_py_interface_struct_gvalue) {
+ g_value_unset ((GValue*) item);
+ continue;
+ }
+ }
cleanup_func (state, sequence_cache->item_cache, item, TRUE);
}
diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c
index 01138bc..9f46977 100644
--- a/gi/pygi-marshal-from-py.c
+++ b/gi/pygi-marshal-from-py.c
@@ -32,6 +32,22 @@
#include "pygi-marshal-cleanup.h"
#include "pygi-marshal-from-py.h"
+#ifdef _WIN32
+#ifdef _MSC_VER
+#include <math.h>
+
+#ifndef NAN
+static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
+#define NAN (*(const float *) __nan)
+#endif
+
+#ifndef INFINITY
+#define INFINITY HUGE_VAL
+#endif
+
+#endif
+#endif
+
static gboolean
gi_argument_from_py_ssize_t (GIArgument *arg_out,
Py_ssize_t size_in,
@@ -999,14 +1015,10 @@ _pygi_marshal_from_py_array (PyGIInvokeState *state,
g_value_init (dest, G_VALUE_TYPE ((GValue*) item.v_pointer));
g_value_copy ((GValue*) item.v_pointer, dest);
}
-
- if (from_py_cleanup) {
+ /* we free the original copy already, the new one is a plain struct
+ * in an array. _pygi_marshal_cleanup_from_py_array() does not free it again */
+ if (from_py_cleanup)
from_py_cleanup (state, item_arg_cache, item.v_pointer, TRUE);
- /* we freed the original copy already, the new one is a
- * struct in an array. _pygi_marshal_cleanup_from_py_array()
- * must not free it again */
- item_arg_cache->from_py_cleanup = NULL;
- }
} else if (!is_boxed) {
/* HACK: Gdk.Atom is merely an integer wrapped in a pointer,
* so we must not dereference it; just copy the pointer
@@ -1092,6 +1104,10 @@ array_success:
if (sequence_cache->array_type == GI_ARRAY_TYPE_C) {
arg->v_pointer = array_->data;
g_array_free (array_, FALSE);
+ /* remember the originally allocated array in args_data, as args and
+ * in_args get changed for (inout) arguments */
+ if (arg_cache->transfer == GI_TRANSFER_NOTHING)
+ state->args_data[arg_cache->c_arg_index] = arg->v_pointer;
} else {
arg->v_pointer = array_;
}
@@ -1388,10 +1404,11 @@ _pygi_destroy_notify_create (void)
if (!global_destroy_notify) {
PyGICClosure *destroy_notify = g_slice_new0 (PyGICClosure);
+ GIBaseInfo* glib_destroy_notify;
g_assert (destroy_notify);
- GIBaseInfo* glib_destroy_notify = g_irepository_find_by_name (NULL, "GLib", "DestroyNotify");
+ glib_destroy_notify = g_irepository_find_by_name (NULL, "GLib", "DestroyNotify");
g_assert (glib_destroy_notify != NULL);
g_assert (g_base_info_get_type (glib_destroy_notify) == GI_INFO_TYPE_CALLBACK);
diff --git a/gi/pygi-marshal-to-py.c b/gi/pygi-marshal-to-py.c
index 172561d..6dde41d 100644
--- a/gi/pygi-marshal-to-py.c
+++ b/gi/pygi-marshal-to-py.c
@@ -434,7 +434,8 @@ _pygi_marshal_to_py_array (PyGIInvokeState *state,
item_arg.v_pointer = g_variant_ref_sink (g_array_index (array_, gpointer, i));
else
item_arg.v_pointer = g_array_index (array_, gpointer, i);
- } else if (arg_cache->transfer == GI_TRANSFER_EVERYTHING && !item_arg_cache->is_pointer) {
+ } else if (arg_cache->transfer == GI_TRANSFER_EVERYTHING && !item_arg_cache->is_pointer &&
+ !g_type_is_a (iface_cache->g_type, G_TYPE_BOXED)) {
/* array elements are structs */
gpointer *_struct = g_malloc (item_size);
memcpy (_struct, array_->data + i * item_size,
@@ -814,10 +815,10 @@ _pygi_marshal_to_py_interface_struct (PyGIInvokeState *state,
py_obj = pygi_struct_foreign_convert_from_g_argument (iface_cache->interface_info,
arg->v_pointer);
} else if (g_type_is_a (type, G_TYPE_BOXED)) {
- py_obj = _pygi_boxed_new ( (PyTypeObject *)iface_cache->py_type, arg->v_pointer,
- arg_cache->transfer == GI_TRANSFER_EVERYTHING || arg_cache->is_caller_allocates);
- if (arg_cache->is_caller_allocates)
- ((PyGIBoxed *)py_obj)->slice_allocated = TRUE;
+ py_obj = _pygi_boxed_new ( (PyTypeObject *)iface_cache->py_type, arg->v_pointer,
+ arg_cache->transfer == GI_TRANSFER_EVERYTHING || arg_cache->is_caller_allocates,
+ arg_cache->is_caller_allocates ?
+ g_struct_info_get_size(iface_cache->interface_info) : 0);
} else if (g_type_is_a (type, G_TYPE_POINTER)) {
if (iface_cache->py_type == NULL ||
!PyType_IsSubtype ( (PyTypeObject *)iface_cache->py_type, &PyGIStruct_Type)) {
diff --git a/gi/pygi-private.h b/gi/pygi-private.h
index 1f59fdf..97eced5 100644
--- a/gi/pygi-private.h
+++ b/gi/pygi-private.h
@@ -51,6 +51,7 @@ G_BEGIN_DECLS
} \
} \
PyErr_Restore(py_error_type, py_error_value, py_error_traceback); \
+ Py_DECREF(py_error_prefix); \
} \
} G_STMT_END
diff --git a/gi/pygi-property.c b/gi/pygi-property.c
index e7afc6b..ae49f08 100644
--- a/gi/pygi-property.c
+++ b/gi/pygi-property.c
@@ -95,6 +95,15 @@ _pygi_lookup_property_from_g_type (GType g_type, const gchar *attr_name)
return ret;
}
+static inline gpointer
+g_value_get_or_dup_boxed (const GValue *value, GITransfer transfer)
+{
+ if (transfer == GI_TRANSFER_EVERYTHING)
+ return g_value_dup_boxed (value);
+ else
+ return g_value_get_boxed (value);
+}
+
PyObject *
pygi_get_property_value_real (PyGObject *instance, GParamSpec *pspec)
{
@@ -194,7 +203,7 @@ pygi_get_property_value_real (PyGObject *instance, GParamSpec *pspec)
case GI_INFO_TYPE_UNION:
if (g_type_is_a (type, G_TYPE_BOXED)) {
- arg.v_pointer = g_value_get_boxed (&value);
+ arg.v_pointer = g_value_dup_boxed (&value);
} else if (g_type_is_a (type, G_TYPE_POINTER)) {
arg.v_pointer = g_value_get_pointer (&value);
} else if (g_type_is_a (type, G_TYPE_VARIANT)) {
@@ -214,12 +223,12 @@ pygi_get_property_value_real (PyGObject *instance, GParamSpec *pspec)
break;
}
case GI_TYPE_TAG_GHASH:
- arg.v_pointer = g_value_get_boxed (&value);
+ arg.v_pointer = g_value_get_or_dup_boxed (&value, transfer);
break;
case GI_TYPE_TAG_GLIST:
case GI_TYPE_TAG_GSLIST:
if (G_VALUE_HOLDS_BOXED(&value))
- arg.v_pointer = g_value_get_boxed (&value);
+ arg.v_pointer = g_value_get_or_dup_boxed (&value, transfer);
else
arg.v_pointer = g_value_get_pointer (&value);
break;
@@ -229,7 +238,7 @@ pygi_get_property_value_real (PyGObject *instance, GParamSpec *pspec)
GArray *arg_items;
int i;
- strings = g_value_get_boxed (&value);
+ strings = g_value_get_or_dup_boxed (&value, transfer);
if (strings == NULL)
arg.v_pointer = NULL;
else {
@@ -250,6 +259,7 @@ pygi_get_property_value_real (PyGObject *instance, GParamSpec *pspec)
}
py_value = _pygi_argument_to_object (&arg, type_info, transfer);
+ g_value_unset (&value);
out:
if (property_info != NULL)
@@ -410,7 +420,7 @@ pygi_set_property_value_real (PyGObject *instance,
strings[i] = g_array_index (arg_items, GIArgument, i).v_string;
}
strings[arg_items->len] = NULL;
- g_value_set_boxed (&value, strings);
+ g_value_take_boxed (&value, strings);
g_array_free (arg_items, TRUE);
break;
}
@@ -422,6 +432,7 @@ pygi_set_property_value_real (PyGObject *instance,
}
g_object_set_property (instance->obj, pspec->name, &value);
+ g_value_unset (&value);
ret_value = 0;
diff --git a/gi/pygi-signal-closure.c b/gi/pygi-signal-closure.c
index 36ea168..6e026de 100644
--- a/gi/pygi-signal-closure.c
+++ b/gi/pygi-signal-closure.c
@@ -141,7 +141,8 @@ pygi_signal_closure_marshal(GClosure *closure,
arg = _pygi_argument_from_g_value(&param_values[i], &type_info);
if (g_type_info_get_tag (&type_info) == GI_TYPE_TAG_ARRAY) {
- arg.v_pointer = _pygi_argument_to_array (&arg, NULL, NULL,
+ /* Skip the self argument of param_values */
+ arg.v_pointer = _pygi_argument_to_array (&arg, NULL, param_values + 1, signal_info,
&type_info, &free_array);
}
diff --git a/gi/pygi-source.c b/gi/pygi-source.c
index b713b73..66bbc3c 100644
--- a/gi/pygi-source.c
+++ b/gi/pygi-source.c
@@ -240,7 +240,8 @@ pyg_source_new (void)
source = (PyGRealSource*) g_source_new (&pyg_source_funcs, sizeof (PyGRealSource));
py_type = _pygi_type_import_by_name ("GLib", "Source");
- source->obj = _pygi_boxed_new ( (PyTypeObject *) py_type, source, FALSE);
+ /* g_source_new uses malloc, not slices */
+ source->obj = _pygi_boxed_new ( (PyTypeObject *) py_type, source, FALSE, 0);
return source->obj;
}
diff --git a/gi/pygtkcompat.py b/gi/pygtkcompat.py
index 9a80eef..4a9c4be 100644
--- a/gi/pygtkcompat.py
+++ b/gi/pygtkcompat.py
@@ -1,4 +1,6 @@
+from __future__ import absolute_import
import warnings
+
from gi import PyGIDeprecationWarning
warnings.warn('gi.pygtkcompat is being deprecated in favor of using "pygtkcompat" directly.',
diff --git a/gi/repository/Makefile.in b/gi/repository/Makefile.in
index 81ab81c..6f3c096 100644
--- a/gi/repository/Makefile.in
+++ b/gi/repository/Makefile.in
@@ -55,8 +55,10 @@ DIST_COMMON = $(pygirepository_PYTHON) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/as-ac-expand.m4 \
- $(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/python.m4 \
- $(top_srcdir)/configure.ac
+ $(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/libtool.m4 \
+ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
+ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
+ $(top_srcdir)/m4/python.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d