From: Emmanuele Bassi Date: Tue, 3 Aug 2010 23:57:52 +0000 (+0100) Subject: binding: Add a default marshaller for the closure API X-Git-Tag: 2.25.13~31 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4bc9654c63feee596de5aa214d7cbd8fc293cd9d;p=platform%2Fupstream%2Fglib.git binding: Add a default marshaller for the closure API The g_object_bind_property_with_closures() function should set a marshaller if the two GClosures don't have one already. This simplifies the caller code and avoids duplication. We need to add a new marshaller to the gmarshal.list matching the signature of the GBindingTransformFunc function. --- diff --git a/gobject/gbinding.c b/gobject/gbinding.c index 06273ac..c73c4e6 100644 --- a/gobject/gbinding.c +++ b/gobject/gbinding.c @@ -105,6 +105,7 @@ #include "gbinding.h" #include "genums.h" +#include "gmarshal.h" #include "gobject.h" #include "gsignal.h" #include "gparamspecs.h" @@ -1161,12 +1162,18 @@ g_object_bind_property_with_closures (gpointer source, if (transform_to != NULL) { + if (G_CLOSURE_NEEDS_MARSHAL (transform_to)) + g_closure_set_marshal (transform_to, g_cclosure_marshal_BOOLEAN__BOXED_BOXED); + data->transform_to_closure = g_closure_ref (transform_to); g_closure_sink (data->transform_to_closure); } if (transform_from != NULL) { + if (G_CLOSURE_NEEDS_MARSHAL (transform_from)) + g_closure_set_marshal (transform_from, g_cclosure_marshal_BOOLEAN__BOXED_BOXED); + data->transform_from_closure = g_closure_ref (transform_from); g_closure_sink (data->transform_from_closure); } diff --git a/gobject/gclosure.c b/gobject/gclosure.c index 1c5af30..8a6b0f7 100644 --- a/gobject/gclosure.c +++ b/gobject/gclosure.c @@ -1236,3 +1236,18 @@ g_signal_type_cclosure_new (GType itype, * A marshaller for a #GCClosure with a callback of type * gchar* (*callback) (gpointer instance, GObject *arg1, gpointer arg2, gpointer user_data). */ +/** + * g_cclosure_marshal_BOOLEAN__OBJECT_BOXED_BOXED: + * @closure: the #GClosure to which the marshaller belongs + * @return_value: a #GValue, which can store the returned string + * @n_param_values: 3 + * @param_values: a #GValue array holding instance, arg1 and arg2 + * @invocation_hint: the invocation hint given as the last argument + * to g_closure_invoke() + * @marshal_data: additional data specified when registering the marshaller + * + * A marshaller for a #GCClosure with a callback of type + * gboolean (*callback) (gpointer instance, GBoxed *arg1, GBoxed *arg2, gpointer user_data). + * + * Since: 2.26 + */ diff --git a/gobject/gmarshal.list b/gobject/gmarshal.list index 533307b..41cf74a 100644 --- a/gobject/gmarshal.list +++ b/gobject/gmarshal.list @@ -47,3 +47,4 @@ VOID:VARIANT VOID:UINT,POINTER BOOL:FLAGS STRING:OBJECT,POINTER +BOOL:BOXED,BOXED diff --git a/gobject/gobject.symbols b/gobject/gobject.symbols index 0eca5e7..9d1a021 100644 --- a/gobject/gobject.symbols +++ b/gobject/gobject.symbols @@ -58,6 +58,7 @@ g_variant_get_gtype G_GNUC_CONST #if IN_HEADER(__G_MARSHAL_H__) #if IN_FILE(__G_SIGNAL_C__) g_cclosure_marshal_BOOLEAN__FLAGS +g_cclosure_marshal_BOOLEAN__BOXED_BOXED g_cclosure_marshal_STRING__OBJECT_POINTER g_cclosure_marshal_VOID__BOOLEAN g_cclosure_marshal_VOID__BOXED diff --git a/gobject/tests/binding.c b/gobject/tests/binding.c index 979a681..dc3b83c 100644 --- a/gobject/tests/binding.c +++ b/gobject/tests/binding.c @@ -356,43 +356,6 @@ binding_transform (void) } static void -binding_transform_marshal (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint G_GNUC_UNUSED, - gpointer marshal_data) -{ - typedef gboolean (* GMarshalFunc_BOOLEAN__VALUE_VALUE) (gpointer data1, - gpointer arg_2, - gpointer arg_3, - gpointer data2); - register GMarshalFunc_BOOLEAN__VALUE_VALUE callback; - register GCClosure *cc = (GCClosure *) closure; - register gpointer data1, data2; - gboolean v_return; - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - - callback = (GMarshalFunc_BOOLEAN__VALUE_VALUE) (marshal_data ? marshal_data : cc->callback); - v_return = callback (data1, - g_value_get_boxed (param_values + 1), - g_value_get_boxed (param_values + 2), - data2); - - g_value_set_boolean (return_value, v_return); -} - -static void binding_transform_closure (void) { BindingSource *source = g_object_new (binding_source_get_type (), NULL); @@ -402,10 +365,8 @@ binding_transform_closure (void) GClosure *c2f_clos, *f2c_clos; c2f_clos = g_cclosure_new (G_CALLBACK (celsius_to_fahrenheit), &unused_data_1, (GClosureNotify) data_free); - g_closure_set_marshal (c2f_clos, binding_transform_marshal); f2c_clos = g_cclosure_new (G_CALLBACK (fahrenheit_to_celsius), &unused_data_2, (GClosureNotify) data_free); - g_closure_set_marshal (f2c_clos, binding_transform_marshal); binding = g_object_bind_property_with_closures (source, "value", target, "value",