summaryrefslogtreecommitdiff
path: root/gtk/gtkobject-support.c
diff options
context:
space:
mode:
authorJames Henstridge <james@daa.com.au>2000-06-24 11:24:51 +0000
committerJames Henstridge <jamesh@src.gnome.org>2000-06-24 11:24:51 +0000
commit5a220e9fd5a4287497356ce2275806b22b10349b (patch)
tree99409728cbecdb63e5366b621f45fff694684473 /gtk/gtkobject-support.c
parentff3ec329a32c72e45209f5bb15c8eff003fdba89 (diff)
downloadpygtk-extension-class-branch.tar.gz
moved this bit of code here, so it can be used in other functions in thisextension-class-branch
2000-06-24 James Henstridge <james@daa.com.au> * gtk/gtkobject-support.c (pygtk_lookup_class): moved this bit of code here, so it can be used in other functions in this file. (pygtk_arg_from_pyobject): perform stricter type checking here. (pygtk_ret_from_pyobject): and here. * gtk/pygtk.h (pygtk_register_{class,wrapper}): add define here. Without it, addon modules were using symbols from _gtkmodule's namespace.
Diffstat (limited to 'gtk/gtkobject-support.c')
-rw-r--r--gtk/gtkobject-support.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/gtk/gtkobject-support.c b/gtk/gtkobject-support.c
index 408cb95e..092094a1 100644
--- a/gtk/gtkobject-support.c
+++ b/gtk/gtkobject-support.c
@@ -136,6 +136,19 @@ pygtk_no_constructor(PyObject *self, PyObject *args)
return NULL;
}
+static PyExtensionClass *
+pygtk_lookup_class(GtkType type)
+{
+ PyExtensionClass *ec;
+
+ /* find the python type for this object. If not found, use parent. */
+ while ((ec = g_hash_table_lookup(class_hash, gtk_type_name(type))) == NULL
+ && type != 0)
+ type = gtk_type_parent(type);
+ g_assert(ec != NULL);
+ return ec;
+}
+
PyObject *
PyGtk_New(GtkObject *obj)
{
@@ -160,10 +173,7 @@ PyGtk_New(GtkObject *obj)
return (PyObject *)self;
}
- type = GTK_OBJECT_TYPE(obj);
- /* find the python type for this object. If not found, use parent. */
- while ((tp = g_hash_table_lookup(class_hash, gtk_type_name(type))) == NULL)
- type = gtk_type_parent(type);
+ tp = (PyTypeObject *)pygtk_lookup_class(GTK_OBJECT_TYPE(obj));
/* can't use PyObject_NEW, as we want to create a slightly larger struct */
self = malloc(sizeof(PyGtk_Object));
@@ -287,6 +297,7 @@ int
pygtk_arg_from_pyobject(GtkArg *arg, PyObject *obj)
{
PyObject *tmp;
+
switch (GTK_FUNDAMENTAL_TYPE(arg->type)) {
case GTK_TYPE_NONE:
case GTK_TYPE_INVALID:
@@ -383,7 +394,7 @@ pygtk_arg_from_pyobject(GtkArg *arg, PyObject *obj)
Py_DECREF(tmp);
break;
case GTK_TYPE_OBJECT:
- if (PyGtk_Check(obj, &PyGtkObject_Type))
+ if (PyGtk_Check(obj, pygtk_lookup_class(arg->type)))
GTK_VALUE_OBJECT(*arg) = PyGtk_Get(obj);
else
return -1;
@@ -704,7 +715,7 @@ pygtk_ret_from_pyobject(GtkArg *ret, PyObject *py_ret)
}
break;
case GTK_TYPE_OBJECT:
- if (PyGtk_Check(py_ret, &PyGtkObject_Type))
+ if (PyGtk_Check(py_ret, pygtk_lookup_class(ret->type)))
*GTK_RETLOC_OBJECT(*ret) = PyGtk_Get(py_ret);
else
*GTK_RETLOC_OBJECT(*ret) = NULL;