diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:48:49 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:48:52 +0900 |
commit | ed14d55c2e6e867dceed5b50d601d4d83a838619 (patch) | |
tree | 5c86789730b159290064228379a48aa47781d52d /gi/_gobject | |
parent | 265684897ba0b24e28710a988cab901acbec1775 (diff) | |
download | pygobject2-ed14d55c2e6e867dceed5b50d601d4d83a838619.tar.gz pygobject2-ed14d55c2e6e867dceed5b50d601d4d83a838619.tar.bz2 pygobject2-ed14d55c2e6e867dceed5b50d601d4d83a838619.zip |
Imported Upstream version 3.7.91.1
Change-Id: I3dcc605b8af37b73443f8f89d884b7b9659959c8
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'gi/_gobject')
-rw-r--r-- | gi/_gobject/Makefile.in | 6 | ||||
-rw-r--r-- | gi/_gobject/gobjectmodule.c | 59 | ||||
-rw-r--r-- | gi/_gobject/pygflags.c | 57 | ||||
-rw-r--r-- | gi/_gobject/pygobject-private.h | 12 | ||||
-rw-r--r-- | gi/_gobject/pygobject.h | 4 | ||||
-rw-r--r-- | gi/_gobject/pygtype.c | 6 |
6 files changed, 59 insertions, 85 deletions
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; |