From c2d430551d355245c74e8b30ca4796e772f42275 Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Mon, 19 Jul 2004 11:29:13 +0000 Subject: Fix, a window is really WITHDRAWN if it's not SHOWN and not ICONIFIED... * tests/enum.py (EnumTest.testWindowGetState): Fix, a window is really WITHDRAWN if it's not SHOWN and not ICONIFIED... * tests/common.py: Add .. and ../gobject when distcheck isn't ran * gobject/pygenum.c: Use a dict instead of a tuple for __enum_values__, so we can handle negative enum values (eg: GDK_NOTHING) * gobject/pyflags.c: Ditto for __flag_values__ * gobject/pygparamspec.c (pyg_param_spec_getattr): reference count fixing --- gobject/pygenum.c | 40 ++++++++++++++++++++-------------------- gobject/pygflags.c | 10 +++++----- gobject/pygparamspec.c | 2 ++ 3 files changed, 27 insertions(+), 25 deletions(-) (limited to 'gobject') diff --git a/gobject/pygenum.c b/gobject/pygenum.c index ecc4dbe..0ccbb90 100644 --- a/gobject/pygenum.c +++ b/gobject/pygenum.c @@ -108,7 +108,7 @@ pyg_enum_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) return NULL; } - if (!PyTuple_Check(values) || PyTuple_Size(values) != eclass->n_values) { + if (!PyDict_Check(values) || PyDict_Size(values) != eclass->n_values) { PyErr_SetString(PyExc_TypeError, "__enum_values__ badly formed"); Py_DECREF(values); g_type_class_unref(eclass); @@ -117,7 +117,7 @@ pyg_enum_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) g_type_class_unref(eclass); - ret = PyTuple_GetItem(values, value); + ret = PyDict_GetItem(values, PyInt_FromLong(value)); Py_INCREF(ret); Py_DECREF(values); return ret; @@ -135,9 +135,9 @@ pyg_enum_from_gtype (GType gtype, int value) values = PyDict_GetItemString(((PyTypeObject *)pyclass)->tp_dict, "__enum_values__"); - retval = PyTuple_GetItem(values, value); + retval = PyDict_GetItem(values, PyInt_FromLong(value)); Py_INCREF(retval); - + return retval; } @@ -181,28 +181,28 @@ pyg_enum_add (PyObject * module, /* Register enum values */ eclass = G_ENUM_CLASS(g_type_class_ref(gtype)); - values = PyTuple_New(eclass->n_values); + values = PyDict_New(); for (i = 0; i < eclass->n_values; i++) { - PyObject *item; + PyObject *item; + + item = ((PyTypeObject *)stub)->tp_alloc((PyTypeObject *)stub, 0); + ((PyIntObject*)item)->ob_ival = eclass->values[i].value; + ((PyGEnum*)item)->gtype = gtype; + + PyDict_SetItem(values, PyInt_FromLong(eclass->values[i].value), item); - item = ((PyTypeObject *)stub)->tp_alloc((PyTypeObject *)stub, 0); - ((PyIntObject*)item)->ob_ival = eclass->values[i].value; - ((PyGEnum*)item)->gtype = gtype; - - PyTuple_SetItem(values, i, item); - - PyModule_AddObject(module, - pyg_constant_strip_prefix(eclass->values[i].value_name, - strip_prefix), - item); - Py_INCREF(item); - } + PyModule_AddObject(module, + pyg_constant_strip_prefix(eclass->values[i].value_name, + strip_prefix), + item); + Py_INCREF(item); + } PyDict_SetItemString(((PyTypeObject *)stub)->tp_dict, "__enum_values__", values); - Py_DECREF(values); + Py_DECREF(values); - g_type_class_unref(eclass); + g_type_class_unref(eclass); return stub; } diff --git a/gobject/pygflags.c b/gobject/pygflags.c index d90f677..9a07ffb 100644 --- a/gobject/pygflags.c +++ b/gobject/pygflags.c @@ -133,7 +133,7 @@ pyg_flags_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) return NULL; } - if (!PyTuple_Check(values) || PyTuple_Size(values) != eclass->n_values) { + if (!PyDict_Check(values) || PyDict_Size(values) != eclass->n_values) { PyErr_SetString(PyExc_TypeError, "__flags_values__ badly formed"); Py_DECREF(values); g_type_class_unref(eclass); @@ -142,7 +142,7 @@ pyg_flags_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) g_type_class_unref(eclass); - ret = PyTuple_GetItem(values, value); + ret = PyDict_GetItem(values, PyInt_FromLong(value)); Py_INCREF(ret); Py_DECREF(values); return ret; @@ -160,7 +160,7 @@ pyg_flags_from_gtype (GType gtype, int value) values = PyDict_GetItemString(((PyTypeObject *)pyclass)->tp_dict, "__flags_values__"); - retval = PyTuple_GetItem(values, value); + retval = PyDict_GetItem(values, PyInt_FromLong(value)); if (!retval) { PyErr_Clear(); @@ -215,7 +215,7 @@ pyg_flags_add (PyObject * module, /* Register flag values */ eclass = G_FLAGS_CLASS(g_type_class_ref(gtype)); - values = PyTuple_New(eclass->n_values); + values = PyDict_New(); for (i = 0; i < eclass->n_values; i++) { PyObject *item; @@ -223,7 +223,7 @@ pyg_flags_add (PyObject * module, ((PyIntObject*)item)->ob_ival = eclass->values[i].value; ((PyGFlags*)item)->gtype = gtype; - PyTuple_SetItem(values, i, item); + PyDict_SetItem(values, PyInt_FromLong(eclass->values[i].value), item); PyModule_AddObject(module, pyg_constant_strip_prefix(eclass->values[i].value_name, diff --git a/gobject/pygparamspec.c b/gobject/pygparamspec.c index b515baa..530bb3c 100644 --- a/gobject/pygparamspec.c +++ b/gobject/pygparamspec.c @@ -156,6 +156,7 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr) pyclass = (PyObject*)g_type_get_qdata(G_ENUM_CLASS_TYPE(G_PARAM_SPEC_ENUM(self->pspec)->enum_class), quark); g_assert(pyclass != NULL); + Py_INCREF(pyclass); return pyclass; } } else if (!strcmp(attr, "flags_class")) { @@ -167,6 +168,7 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr) pyclass = (PyObject*)g_type_get_qdata(G_FLAGS_CLASS_TYPE(G_PARAM_SPEC_FLAGS(self->pspec)->flags_class), quark); g_assert(pyclass != NULL); + Py_INCREF(pyclass); return pyclass; } } -- cgit