summaryrefslogtreecommitdiffstats
path: root/gobject
diff options
context:
space:
mode:
Diffstat (limited to 'gobject')
-rw-r--r--gobject/gobjectmodule.c16
-rw-r--r--gobject/pygenum.c16
-rw-r--r--gobject/pygflags.c28
3 files changed, 36 insertions, 24 deletions
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index 0ec1382..7fb9154 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -1045,7 +1045,7 @@ pygobject__g_instance_init(GTypeInstance *instance,
wrapper = pygobject_new_full(object, FALSE, g_class);
args = PyTuple_New(0);
kwargs = PyDict_New();
- if (wrapper->ob_type->tp_init(wrapper, args, kwargs))
+ if (Py_TYPE(wrapper)->tp_init(wrapper, args, kwargs))
PyErr_Print();
Py_DECREF(args);
Py_DECREF(kwargs);
@@ -2306,7 +2306,6 @@ pyg_set_object_has_new_constructor(GType type)
g_type_set_qdata(type, pygobject_has_updated_constructor_key, GINT_TO_POINTER(1));
}
-#define GET_INT(x) (((_PyLongObject*)x)->ob_ival)
PyObject *
pyg_integer_richcompare(PyObject *v, PyObject *w, int op)
{
@@ -2314,12 +2313,12 @@ pyg_integer_richcompare(PyObject *v, PyObject *w, int op)
gboolean t;
switch (op) {
- case Py_EQ: t = GET_INT(v) == GET_INT(w); break;
- case Py_NE: t = GET_INT(v) != GET_INT(w); break;
- case Py_LE: t = GET_INT(v) <= GET_INT(w); break;
- case Py_GE: t = GET_INT(v) >= GET_INT(w); break;
- case Py_LT: t = GET_INT(v) < GET_INT(w); break;
- case Py_GT: t = GET_INT(v) > GET_INT(w); break;
+ case Py_EQ: t = _PyLong_AS_LONG(v) == _PyLong_AS_LONG(w); break;
+ case Py_NE: t = _PyLong_AS_LONG(v) != _PyLong_AS_LONG(w); break;
+ case Py_LE: t = _PyLong_AS_LONG(v) <= _PyLong_AS_LONG(w); break;
+ case Py_GE: t = _PyLong_AS_LONG(v) >= _PyLong_AS_LONG(w); break;
+ case Py_LT: t = _PyLong_AS_LONG(v) < _PyLong_AS_LONG(w); break;
+ case Py_GT: t = _PyLong_AS_LONG(v) > _PyLong_AS_LONG(w); break;
default: g_assert_not_reached();
}
@@ -2327,7 +2326,6 @@ pyg_integer_richcompare(PyObject *v, PyObject *w, int op)
Py_INCREF(result);
return result;
}
-#undef GET_INT
static void
_log_func(const gchar *log_domain,
diff --git a/gobject/pygenum.c b/gobject/pygenum.c
index bf40cc1..e35f738 100644
--- a/gobject/pygenum.c
+++ b/gobject/pygenum.c
@@ -64,13 +64,13 @@ pyg_enum_repr(PyGEnum *self)
g_assert(G_IS_ENUM_CLASS(enum_class));
for (index = 0; index < enum_class->n_values; index++)
- if (self->parent.ob_ival == enum_class->values[index].value)
+ if (_PyLong_AS_LONG(self) == enum_class->values[index].value)
break;
value = enum_class->values[index].value_name;
if (value)
sprintf(tmp, "<enum %s of type %s>", value, g_type_name(self->gtype));
else
- sprintf(tmp, "<enum %ld of type %s>", self->parent.ob_ival, g_type_name(self->gtype));
+ sprintf(tmp, "<enum %ld of type %s>", _PyLong_AS_LONG(self), g_type_name(self->gtype));
g_type_class_unref(enum_class);
@@ -168,7 +168,11 @@ pyg_enum_from_gtype (GType gtype, int value)
retval = ((PyTypeObject *)pyclass)->tp_alloc((PyTypeObject *)pyclass, 0);
g_assert(retval != NULL);
+#if PY_VERSION_HEX >= 0x03000000
+# warning "FIXME: figure out how to subclass long"
+#else
((_PyLongObject*)retval)->ob_ival = value;
+#endif
((PyGFlags*)retval)->gtype = gtype;
//return _PyLong_FromLong(value);
}
@@ -236,7 +240,11 @@ pyg_enum_add (PyObject * module,
PyObject *item, *intval;
item = ((PyTypeObject *)stub)->tp_alloc((PyTypeObject *)stub, 0);
+#if PY_VERSION_HEX >= 0x03000000
+# warning "FIXME: figure out how to subclass long"
+#else
((_PyLongObject*)item)->ob_ival = eclass->values[i].value;
+#endif
((PyGEnum*)item)->gtype = gtype;
intval = _PyLong_FromLong(eclass->values[i].value);
@@ -284,7 +292,7 @@ pyg_enum_get_value_name(PyGEnum *self, void *closure)
enum_class = g_type_class_ref(self->gtype);
g_assert(G_IS_ENUM_CLASS(enum_class));
- enum_value = g_enum_get_value(enum_class, self->parent.ob_ival);
+ enum_value = g_enum_get_value(enum_class, _PyLong_AS_LONG(self));
retval = _PyUnicode_FromString(enum_value->value_name);
g_type_class_unref(enum_class);
@@ -302,7 +310,7 @@ pyg_enum_get_value_nick(PyGEnum *self, void *closure)
enum_class = g_type_class_ref(self->gtype);
g_assert(G_IS_ENUM_CLASS(enum_class));
- enum_value = g_enum_get_value(enum_class, self->parent.ob_ival);
+ enum_value = g_enum_get_value(enum_class, _PyLong_AS_LONG(self));
retval = _PyUnicode_FromString(enum_value->value_nick);
g_type_class_unref(enum_class);
diff --git a/gobject/pygflags.c b/gobject/pygflags.c
index f419161..34b328f 100644
--- a/gobject/pygflags.c
+++ b/gobject/pygflags.c
@@ -33,8 +33,6 @@ GQuark pygflags_class_key;
PYGLIB_DEFINE_TYPE("gobject.GFlags", PyGFlags_Type, PyGFlags);
-#define GET_INT_VALUE(x) (((_PyLongObject*)x)->ob_ival)
-
static PyObject *
pyg_flags_richcompare(PyGFlags *self, PyObject *other, int op)
{
@@ -94,13 +92,13 @@ pyg_flags_repr(PyGFlags *self)
char *tmp, *retval;
PyObject *pyretval;
- tmp = generate_repr(self->gtype, self->parent.ob_ival);
+ tmp = generate_repr(self->gtype, _PyLong_AS_LONG(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>", self->parent.ob_ival,
+ retval = g_strdup_printf("<flags %ld of type %s>", _PyLong_AS_LONG(self),
g_type_name(self->gtype));
g_free(tmp);
@@ -192,7 +190,11 @@ pyg_flags_from_gtype (GType gtype, int value)
retval = ((PyTypeObject *)pyclass)->tp_alloc((PyTypeObject *)pyclass, 0);
g_assert(retval != NULL);
+#if PY_VERSION_HEX >= 0x03000000
+# warning "FIXME: figure out how to subclass long"
+#else
((_PyLongObject*)retval)->ob_ival = value;
+#endif
((PyGFlags*)retval)->gtype = gtype;
} else {
Py_INCREF(retval);
@@ -257,7 +259,11 @@ pyg_flags_add (PyObject * module,
PyObject *item, *intval;
item = ((PyTypeObject *)stub)->tp_alloc((PyTypeObject *)stub, 0);
+#if PY_VERSION_HEX >= 0x03000000
+# warning "FIXME: figure out how to subclass long"
+#else
((_PyLongObject*)item)->ob_ival = eclass->values[i].value;
+#endif
((PyGFlags*)item)->gtype = gtype;
intval = _PyLong_FromLong(eclass->values[i].value);
@@ -294,7 +300,7 @@ pyg_flags_and(PyGFlags *a, PyGFlags *b)
(PyObject*)b);
return pyg_flags_from_gtype(a->gtype,
- GET_INT_VALUE(a) & GET_INT_VALUE(b));
+ _PyLong_AS_LONG(a) & _PyLong_AS_LONG(b));
}
static PyObject *
@@ -304,7 +310,7 @@ pyg_flags_or(PyGFlags *a, PyGFlags *b)
return _PyLong_Type.tp_as_number->nb_or((PyObject*)a,
(PyObject*)b);
- return pyg_flags_from_gtype(a->gtype, GET_INT_VALUE(a) | GET_INT_VALUE(b));
+ return pyg_flags_from_gtype(a->gtype, _PyLong_AS_LONG(a) | _PyLong_AS_LONG(b));
}
static PyObject *
@@ -315,7 +321,7 @@ pyg_flags_xor(PyGFlags *a, PyGFlags *b)
(PyObject*)b);
return pyg_flags_from_gtype(a->gtype,
- GET_INT_VALUE(a) ^ GET_INT_VALUE(b));
+ _PyLong_AS_LONG(a) ^ _PyLong_AS_LONG(b));
}
@@ -338,7 +344,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, self->parent.ob_ival);
+ flags_value = g_flags_get_first_value(flags_class, _PyLong_AS_LONG(self));
if (flags_value)
retval = _PyUnicode_FromString(flags_value->value_name);
else {
@@ -360,7 +366,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, self->parent.ob_ival);
+ flags_value = g_flags_get_first_value(flags_class, _PyLong_AS_LONG(self));
if (flags_value)
retval = _PyUnicode_FromString(flags_value->value_nick);
else {
@@ -384,7 +390,7 @@ pyg_flags_get_value_names(PyGFlags *self, void *closure)
retval = PyList_New(0);
for (i = 0; i < flags_class->n_values; i++)
- if ((self->parent.ob_ival & flags_class->values[i].value) == flags_class->values[i].value)
+ if ((_PyLong_AS_LONG(self) & flags_class->values[i].value) == flags_class->values[i].value)
PyList_Append(retval, _PyUnicode_FromString(flags_class->values[i].value_name));
g_type_class_unref(flags_class);
@@ -404,7 +410,7 @@ pyg_flags_get_value_nicks(PyGFlags *self, void *closure)
retval = PyList_New(0);
for (i = 0; i < flags_class->n_values; i++)
- if ((self->parent.ob_ival & flags_class->values[i].value) == flags_class->values[i].value)
+ if ((_PyLong_AS_LONG(self) & flags_class->values[i].value) == flags_class->values[i].value)
PyList_Append(retval, _PyUnicode_FromString(flags_class->values[i].value_nick));
g_type_class_unref(flags_class);