summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Henstridge <james@daa.com.au>2002-08-18 02:55:16 +0000
committerJames Henstridge <jamesh@src.gnome.org>2002-08-18 02:55:16 +0000
commitc6ca78eb2cea9b7e1df04d42852a2c98a08f5303 (patch)
tree4627472a04143eb96e7bf1f08fed5965fbeec030
parent53f22d8e4f362ca96c543311d0c107c6b88633a7 (diff)
downloadpygobject-c6ca78eb2cea9b7e1df04d42852a2c98a08f5303.tar.gz
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.
-rw-r--r--gobject/gobjectmodule.c1
-rw-r--r--gobject/pygobject-private.h2
-rw-r--r--gobject/pygobject.c42
-rw-r--r--gobject/pygobject.h55
4 files changed, 71 insertions, 29 deletions
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index de1d4bbf..fe0d3c20 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -1291,6 +1291,7 @@ pyg_error_check(GError **error)
struct _PyGObject_Functions pygobject_api_functions = {
pygobject_register_class,
pygobject_register_wrapper,
+ pygobject_register_sinkfunc,
pygobject_lookup_class,
pygobject_new,
diff --git a/gobject/pygobject-private.h b/gobject/pygobject-private.h
index 816615ea..f87941c0 100644
--- a/gobject/pygobject-private.h
+++ b/gobject/pygobject-private.h
@@ -77,6 +77,8 @@ void pygobject_register_wrapper (PyObject *self);
PyObject * pygobject_new (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));
/* from pygboxed.c */
extern PyTypeObject PyGBoxed_Type;
diff --git a/gobject/pygobject.c b/gobject/pygobject.c
index d5501277..b0e85b0d 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;
diff --git a/gobject/pygobject.h b/gobject/pygobject.h
index 90bfba03..9b0897cf 100644
--- a/gobject/pygobject.h
+++ b/gobject/pygobject.h
@@ -45,6 +45,8 @@ struct _PyGObject_Functions {
void (* register_class)(PyObject *dict, const gchar *class_name,
GType gtype, PyTypeObject *type, PyObject *bases);
void (* register_wrapper)(PyObject *self);
+ void (* register_sinkfunc)(GType type,
+ void (* sinkfunc)(GObject *object));
PyTypeObject *(* lookup_class)(GType type);
PyObject *(* newgobj)(GObject *obj);
@@ -104,32 +106,33 @@ extern struct _PyGObject_Functions *_PyGObject_API;
struct _PyGObject_Functions *_PyGObject_API;
#endif
-#define pygobject_register_class (_PyGObject_API->register_class)
-#define pygobject_register_wrapper (_PyGObject_API->register_wrapper)
-#define pygobject_lookup_class (_PyGObject_API->lookup_class)
-#define pygobject_new (_PyGObject_API->newgobj)
-#define pyg_closure_new (_PyGObject_API->closure_new)
-#define pygobject_watch_closure (_PyGObject_API->object_watch_closure)
-#define pyg_destroy_notify (_PyGObject_API->destroy_notify)
-#define pyg_type_from_object (_PyGObject_API->type_from_object)
-#define pyg_type_wrapper_new (_PyGObject_API->type_wrapper_new)
-#define pyg_enum_get_value (_PyGObject_API->enum_get_value)
-#define pyg_flags_get_value (_PyGObject_API->flags_get_value)
-#define pyg_register_boxed_custom (_PyGObject_API->register_boxed_custom)
-#define pyg_value_from_pyobject (_PyGObject_API->value_from_pyobject)
-#define pyg_value_as_pyobject (_PyGObject_API->value_as_pyobject)
-#define pyg_register_interface (_PyGObject_API->register_interface)
-#define PyGBoxed_Type (*_PyGObject_API->boxed_type)
-#define pyg_register_boxed (_PyGObject_API->register_boxed)
-#define pyg_boxed_new (_PyGObject_API->boxed_new)
-#define PyGPointer_Type (*_PyGObject_API->pointer_type)
-#define pyg_register_pointer (_PyGObject_API->register_pointer)
-#define pyg_pointer_new (_PyGObject_API->pointer_new)
-#define pyg_enum_add_constants (_PyGObject_API->enum_add_constants)
-#define pyg_flags_add_constants (_PyGObject_API->flags_add_constants)
-#define pyg_constant_strip_prefix (_PyGObject_API->constant_strip_prefix)
-#define pyg_error_check (_PyGObject_API->error_check)
-#define pyg_set_thread_block_funcs (_PyGObject_API->set_thread_block_funcs)
+#define pygobject_register_class (_PyGObject_API->register_class)
+#define pygobject_register_wrapper (_PyGObject_API->register_wrapper)
+#define pygobject_register_sinkfunc (_PyGObject_API->register_sinkfunc)
+#define pygobject_lookup_class (_PyGObject_API->lookup_class)
+#define pygobject_new (_PyGObject_API->newgobj)
+#define pyg_closure_new (_PyGObject_API->closure_new)
+#define pygobject_watch_closure (_PyGObject_API->object_watch_closure)
+#define pyg_destroy_notify (_PyGObject_API->destroy_notify)
+#define pyg_type_from_object (_PyGObject_API->type_from_object)
+#define pyg_type_wrapper_new (_PyGObject_API->type_wrapper_new)
+#define pyg_enum_get_value (_PyGObject_API->enum_get_value)
+#define pyg_flags_get_value (_PyGObject_API->flags_get_value)
+#define pyg_register_boxed_custom (_PyGObject_API->register_boxed_custom)
+#define pyg_value_from_pyobject (_PyGObject_API->value_from_pyobject)
+#define pyg_value_as_pyobject (_PyGObject_API->value_as_pyobject)
+#define pyg_register_interface (_PyGObject_API->register_interface)
+#define PyGBoxed_Type (*_PyGObject_API->boxed_type)
+#define pyg_register_boxed (_PyGObject_API->register_boxed)
+#define pyg_boxed_new (_PyGObject_API->boxed_new)
+#define PyGPointer_Type (*_PyGObject_API->pointer_type)
+#define pyg_register_pointer (_PyGObject_API->register_pointer)
+#define pyg_pointer_new (_PyGObject_API->pointer_new)
+#define pyg_enum_add_constants (_PyGObject_API->enum_add_constants)
+#define pyg_flags_add_constants (_PyGObject_API->flags_add_constants)
+#define pyg_constant_strip_prefix (_PyGObject_API->constant_strip_prefix)
+#define pyg_error_check (_PyGObject_API->error_check)
+#define pyg_set_thread_block_funcs (_PyGObject_API->set_thread_block_funcs)
#define pyg_block_threads() G_STMT_START { \
if (_PyGObject_API->block_threads != NULL) \