GNOME Bugzilla – Bug 707249
Signal emission sets return values to NULL only in debug builds
Last modified: 2018-05-24 15:39:16 UTC
This came up while looking at bug #707170. The issue is NULL is passed as the return value to closures only when G_ENABLE_DEBUG is set (and the closure doesn't specify a return type). This forces implemented closures to react to two different cases for closures which don't return a value. This most likely isn't much of a problem since closure implementers would generally leave the return_value alone for closures without returns, but for binding layers we need to compute things at runtime.
The docs for GClosureMarshal note:
"return_value : ... May be NULL if the callback of closure doesn't return a value. [allow-none]"
In short, it seems a bit odd to have different behaviours depending on whether or not G_ENABLE_DEBUG is set. I can't think of a good reason to have this difference and perhaps it was a mistake of being a bit overzealous when the G_ENABLE_DEBUG check was added 13 years ago?
At this point, it might also be a bit of a problem to always set this to NULL because it could break people who only rely on release builds for development and have never needed a NULL check. If we were to make this consistent, I think never setting it to NULL would be the safer bet. If making it consistent is not desired, Minimally I think the docs could be a bit more specific, e.g. "May be NULL or invalid if ..."
But even that would not be totally correct because I think the return_value will point to what the caller of g_signal_emitv passed in.
-- GitLab Migration Automatic Message --
This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.
You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/753.