diff options
| author | James Henstridge <james@daa.com.au> | 2002-08-18 02:55:16 +0000 |
|---|---|---|
| committer | James Henstridge <jamesh@src.gnome.org> | 2002-08-18 02:55:16 +0000 |
| commit | c6ca78eb2cea9b7e1df04d42852a2c98a08f5303 (patch) | |
| tree | 4627472a04143eb96e7bf1f08fed5965fbeec030 /gobject/pygobject.c | |
| parent | 53f22d8e4f362ca96c543311d0c107c6b88633a7 (diff) | |
| download | pygobject-c6ca78eb2cea9b7e1df04d42852a2c98a08f5303.tar.gz pygobject-c6ca78eb2cea9b7e1df04d42852a2c98a08f5303.tar.xz pygobject-c6ca78eb2cea9b7e1df04d42852a2c98a08f5303.zip | |
don't need to manually sink. (_wrap_gtk_tree_view_column_new): same here.
2002-08-18 James Henstridge <james@daa.com.au>
* gtk/gtk.override (_wrap_gtk_clist_new_with_titles): don't need
to manually sink.
(_wrap_gtk_tree_view_column_new): same here.
(_wrap_gtk_button_new): same here.
(_wrap_gtk_toggle_button_new): same here.
(_wrap_gtk_check_button_new): same here.
(_wrap_gtk_radio_button_new): same here.
(_wrap_gtk_list_item_new): same here.
(_wrap_gtk_menu_item_new): same here.
(_wrap_gtk_check_menu_item_new): same here.
(_wrap_gtk_radio_menu_item_new): same here.
(_wrap_gtk_image_menu_item_new): same here.
(_wrap_gtk_ctree_new_with_titles): same here.
(_wrap_gtk_dialog_new_with_buttons): same here.
(_wrap_gtk_message_dialog_new): same here.
(_wrap_gtk_progress_bar_new_with_adjustment): same here.
* gtk/gtkmodule.c (sink_gtkobject): function to sink a GtkObject
if it is floating.
(init_gtk): register sink_gtkobject for sinking GtkObjects.
* codegen/codegen.py
(GObjectWrapper.get_initial_constructor_substdict): get rid of
gtkobjectsink bit of code.
* pygobject.c (pygobject_register_sinkfunc): new function to
register a function to get rid of the floating reference from an
object.
(sink_object): run a sinkfunc for an object if it has been
registered.
(pygobject_new): call sink_object
(pygobject_register_wrapper): call sink_object.
Diffstat (limited to 'gobject/pygobject.c')
| -rw-r--r-- | gobject/pygobject.c | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/gobject/pygobject.c b/gobject/pygobject.c index d550127..b0e85b0 100644 --- a/gobject/pygobject.c +++ b/gobject/pygobject.c @@ -8,12 +8,46 @@ static GQuark pygobject_wrapper_key = 0; static const gchar *pygobject_ownedref_id = "PyGObject::ownedref"; static GQuark pygobject_ownedref_key = 0; - static void pygobject_dealloc(PyGObject *self); static int pygobject_traverse(PyGObject *self, visitproc visit, void *arg); /* -------------- class <-> wrapper manipulation --------------- */ +typedef struct { + GType type; + void (* sinkfunc)(GObject *object); +} SinkFunc; +static GArray *sink_funcs = NULL; + +static inline void +sink_object(GObject *obj) +{ + if (sink_funcs) { + gint i; + + for (i = 0; i < sink_funcs->len; i++) { + if (g_type_is_a(G_OBJECT_TYPE(obj), + g_array_index(sink_funcs, SinkFunc, i).type)) { + g_array_index(sink_funcs, SinkFunc, i).sinkfunc(obj); + break; + } + } + } +} + +void +pygobject_register_sinkfunc(GType type, void (* sinkfunc)(GObject *object)) +{ + SinkFunc sf; + + if (!sink_funcs) + sink_funcs = g_array_new(FALSE, FALSE, sizeof(SinkFunc)); + + sf.type = type; + sf.sinkfunc = sinkfunc; + g_array_append_val(sink_funcs, sf); +} + void pygobject_register_class(PyObject *dict, const gchar *type_name, GType gtype, PyTypeObject *type, @@ -72,7 +106,7 @@ pygobject_register_wrapper(PyObject *self) if (!pygobject_wrapper_key) pygobject_wrapper_key=g_quark_from_static_string(pygobject_wrapper_id); - /* g_object_ref(obj); -- not needed because no floating reference */ + sink_object(obj); g_object_set_qdata(obj, pygobject_wrapper_key, self); } @@ -118,12 +152,14 @@ pygobject_new(GObject *obj) return (PyObject *)self; } - tp = pygobject_lookup_class(G_TYPE_FROM_INSTANCE(obj)); + tp = pygobject_lookup_class(G_OBJECT_TYPE(obj)); self = PyObject_GC_New(PyGObject, tp); if (self == NULL) return NULL; self->obj = g_object_ref(obj); + sink_object(self->obj); + self->hasref = FALSE; self->inst_dict = NULL; self->weakreflist = NULL; |
