3

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?

Name
  • 399
  • 2
  • 13

1 Answers1

1

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.

ptomato
  • 56,175
  • 13
  • 112
  • 165
  • Why can't it use another function pointer for that? Eg. `void (*)(void)` ? Or why not use an union that can hold `void*` and `void (*)(void)`? Based on`answeres [why-cant-i-cast-a-function-pointer-to-void](https://stackoverflow.com/questions/36645660/why-cant-i-cast-a-function-pointer-to-void) and [c-function-pointer-casting-to-void-pointer](https://stackoverflow.com/questions/5579835/c-function-pointer-casting-to-void-pointer) – Name Apr 21 '19 at 09:06
  • This is presumably not the only place in GObject that requires that functionality. – ptomato Apr 21 '19 at 21:41