After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 796087 - Fix vte_regex_unref()
Fix vte_regex_unref()
Status: RESOLVED DUPLICATE of bug 796237
Product: vte
Classification: Core
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: VTE Maintainers
VTE Maintainers
Depends on: 796237
Blocks:
 
 
Reported: 2018-05-14 02:06 UTC by Igor
Modified: 2018-05-24 17:21 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch (1.39 KB, patch)
2018-05-14 02:09 UTC, Igor
none Details | Review
patch v2 (1.40 KB, patch)
2018-05-14 20:41 UTC, Igor
none Details | Review

Description Igor 2018-05-14 02:06:48 UTC
vte_regex_unref() is declared to return VteRegex* which is unnecessary and produces function type cast warnings.
The proposed patch makes it return void which eliminates the warnings.
Comment 1 Igor 2018-05-14 02:09:31 UTC
Created attachment 371986 [details] [review]
patch
Comment 2 Egmont Koblinger 2018-05-14 09:29:28 UTC
Thanks; alas I'm afraid we'll have to postpone it til next API breakage (soname bump).
Comment 3 Christian Persch 2018-05-14 09:35:53 UTC
This was done by design actually, so you can do

regex = vte_regex_unref(regex)

and thus NULL out the variable in one go.
Comment 4 Christian Persch 2018-05-14 09:36:44 UTC
(In reply to Igor from comment #0)
> vte_regex_unref() is declared to return VteRegex* which is unnecessary and
> produces function type cast warnings.
> The proposed patch makes it return void which eliminates the warnings.

What's the warning exactly?
Comment 5 Egmont Koblinger 2018-05-14 09:41:18 UTC
I'd say ideally should follow existing practice, e.g. void g_object_unref; but once done differently, I'm not sure if it's worth the hassle to change it.
Comment 6 Igor 2018-05-14 13:10:09 UTC
(In reply to Christian Persch from comment #4)
> What's the warning exactly?

There are 2 of them that are repeated like 20 times when building vte on an up-to-date Arch system with gcc 8.1.0:

/usr/include/vte-2.91/vte/vteregex.h: In function ‘glib_listautoptr_cleanup_VteRegex’:

/usr/include/glib-2.0/glib/gmacros.h:462:99: warning: cast between incompatible function types from ‘VteRegex * (*)(VteRegex *)’ {aka ‘struct _VteRegex * (*)(struct _VteRegex *)’} to ‘void (*)(void *)’ [-Wcast-function-type]

static inline void _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) (GList **_l) { g_list_free_full (*_l, (GDestroyNotify) func); } \

^

/usr/include/vte-2.91/vte/vteregex.h:71:1: note: in expansion of macro ‘G_DEFINE_AUTOPTR_CLEANUP_FUNC’

G_DEFINE_AUTOPTR_CLEANUP_FUNC(VteRegex, vte_regex_unref)

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/usr/include/vte-2.91/vte/vteregex.h: In function ‘glib_slistautoptr_cleanup_VteRegex’:

/usr/include/glib-2.0/glib/gmacros.h:463:102: warning: cast between incompatible function types from ‘VteRegex * (*)(VteRegex *)’ {aka ‘struct _VteRegex * (*)(struct _VteRegex *)’} to ‘void (*)(void *)’ [-Wcast-function-type]

static inline void _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) (GSList **_l) { g_slist_free_full (*_l, (GDestroyNotify) func); } \

^

/usr/include/vte-2.91/vte/vteregex.h:71:1: note: in expansion of macro ‘G_DEFINE_AUTOPTR_CLEANUP_FUNC’

G_DEFINE_AUTOPTR_CLEANUP_FUNC(VteRegex, vte_regex_unref)

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Moreover, when building an application depending on vte, like xfce4-terminal, the compiler is producing a bunch of similar warnings.

(In reply to Christian Persch from comment #3)
> This was done by design actually, so you can do
> regex = vte_regex_unref(regex)
> and thus NULL out the variable in one go.

Well, as far as I can tell all other unref functions return void...
Comment 7 Christian Persch 2018-05-14 17:42:55 UTC
Does changing 

G_DEFINE_AUTOPTR_CLEANUP_FUNC(VteRegex, vte_regex_unref)

to add a cast before the vte_regex_unref() work?
Comment 8 Igor 2018-05-14 19:15:10 UTC
In fact, changing it as
G_DEFINE_AUTOPTR_CLEANUP_FUNC(VteRegex, (GDestroyNotify) vte_regex_unref)
adds even more warnings.

Also, it seems type casting function pointers is undefined behavior in C:
https://stackoverflow.com/questions/559581/casting-a-function-pointer-to-another-type
https://stackoverflow.com/questions/188839/function-pointer-cast-to-different-signature
Comment 9 Christian Persch 2018-05-14 20:18:03 UTC
That may be UB, but glib relies on this anyway, so that's not a problem.

Would the

#pragma GCC diagnostic push
#if G_GNUC_CHECK_VERSION(major, minor)
#pragma GCC diagnostic ignored "-Wcast-function-type"
#endif
G_DEFINE_AUTOPTR_CLEANUP_FUNC(...)
#pragma GCC diagnostic pop

dance fix this? (need to find out which gcc version added this -W flag).
Comment 10 Igor 2018-05-14 20:41:48 UTC
Created attachment 372034 [details] [review]
patch v2
Comment 11 Igor 2018-05-14 20:42:13 UTC
gcc 8 add this flag to -Wextra: https://gcc.gnu.org/gcc-8/changes.html

#if GLIB_CHECK_VERSION(2, 44, 0)
#pragma GCC diagnostic push
#if __GNUC__ >= 8
#pragma GCC diagnostic ignored "-Wcast-function-type"
#endif
G_DEFINE_AUTOPTR_CLEANUP_FUNC(VteRegex, vte_regex_unref)
#pragma GCC diagnostic pop
#endif

does the job of suppressing the warnings.
I've uploaded a new patch for the code above. I've also suppressed the warning in another place where vte_regex_unref() gets cast to GBoxedFreeFunc.

It seems that some other Gnome projects have also done similar suppressions, see e.g. https://gitlab.gnome.org/GNOME/gjs/commit/5aba4c855ae7a72567ac83304e407b729f8018ca
Comment 12 Christian Persch 2018-05-24 17:21:08 UTC
This will be fixed in glib, bug 796237  -> closing.

*** This bug has been marked as a duplicate of bug 796237 ***