-
Notifications
You must be signed in to change notification settings - Fork 1.3k
minimal compile time check for wrong signal handler return type #19825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
I'm getting these btw |
|
I'll stay on the safe side... And will register this for 5.6. |
|
Sure. This is a developer diagnostic tool. It can be used locally without needing to be merged upstream. What I meant is that you might still consider applying fixes for the cases of wrong return types in 5.4 (i.e. for the list I pasted above). We've seen this kind of thing causing crashes on intel mac. I can't remember if that was when bool expected and void returned or vice versa. @zisoft ? The above list seems to contain both instances. Would you be able to do some hammer testing on the functionality involved and see if you can trigger disaster? Remember that this is just the list generated at startup. Opening dialogs or menus could expose more. BTW I admit when "fixing" the issues (in the other PR) I may not have been very careful. The general rule is that for button-press/release/scroll/key events, you I now found a compile time check that works even on gcc. The only thing it doesn't do is catch situations where the signal name is "misspelled" (i.e. button_press_event instead of button-press-event) and the return type is wrong at the same time. Once all positives are fixed, I suggest this is the one to be merged. There is no run-time cost at all and it should catch everything without having to open dialogs/menus etc. |
bool expected, void returned: #19338 (comment) No crash on Intel Mac, just a misbehavior. |
703944c to
9276c59
Compare
EDIT: This is now a compile time check (so compilation will intentionally break if a wrong callback signature is used).
Uses of
g_signal_connectthat cannot be checked (for example because they get passed the callback in a variable) or that need to return the connected signal id are changed to useg_signal_connect_datainstead.g_signal_connect_afterandg_signal_connect_swappedare not covered by this check.All issues that caused this check to fail have been fixed in the second commit.
A minimal version of #19818 which just checks the return type when connecting signal handlers. There's a compile-time part (matching the actual function against void/gboolean(*)() ) and a run-time part (looking up what the signal actually wants). So the overhead is an extra indirection before calling
g_signal_connect_dataand looking up the signal id and querying it. Which should be fairly minimal but could be made debug build only.The only source changes required are to consistently wrap the c_handler in
G_CALLBACKrather than casting it with(GCallback)(because the macro disables the cast by attaching a prefix). So unlike #19818 here it is fine to keep the instance wrapped in G_OBJECT or whatever. And the check ing_signal_connectis skipped for helper functions (likedt_iop_button_new) where we don't know what the real handler signature is.@jenshannoschwalm Some of the issues this catches are already addressed in the first commit of the other PR but I didn't track the fixes down or added them here because I wanted to keep this minimal. However, they are all bugs (unless someone can argue when this would generate false positives?) so might still qualify for 5.4 @TurboGit ? If not, and if everybody is OK with the style changes in #19818/1 then merging them first and then fixing the remainder highlighted by this would be less work.