Name
Name

Reputation: 419

How to use g_signal_handlers_block_by_func()

I listen to "changed" signal of a GtkComboBox. I empty and refill GtkComboBoxText which is a simple variant of GtkComboBox. I'm trying to use a macro g_signal_handlers_block_by_func(instance, func, data) so that the "changed" signal won't be emitted to my callback function while emptying and refilling that box.

I get an error when passing a function as a func: error: ISO C forbids passing argument 6 of ‘g_signal_handlers_block_matched’ between function pointer and ‘void *’ [-Werror=pedantic]

It happens because func is casted to gpointer (typedef to (void*)) in g_signal_handlers_block_matched. As I have understood casting function pointer to data pointer is illegal.

Example:

static void my_callback(GtkComboBox *box, GtkComboBox *other_box)
{
  // Some code here
}


g_signal_connect(combo_box, "changed", G_CALLBACK(my_callback), other_box);

// To temporary block changed signals for reaching other_box:
g_signal_handlers_block_by_func(combo_box, G_CALLBACK(my_callback), other_box);

Also tried without G_CALLBACK but it doesn't make a difference. The issue is the same.

How should I use g_signal_handlers_block_by_func?

Upvotes: 3

Views: 659

Answers (1)

ptomato
ptomato

Reputation: 57920

GObject and GLib require a compiler that "does the right thing" when casting function pointers to void* and vice versa.

From the build code and GLib wiki:

GLib heavily relies on the ability to convert a function pointer to a void* and back again losslessly. Any platform or compiler which doesn’t support this cannot be used to compile GLib or code which uses GLib. This precludes use of the -pedantic GCC flag with GLib.

Upvotes: 1

Related Questions