From 7c0437a9da8a0f6d2747d276ed27940d177ac8a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 9 May 2008 18:25:44 +0000 Subject: [PATCH] gst/gstutils.h: Try to fix 'dereferencing type-punned pointer will break strict aliasing rules' warnings with C++ com... Original commit message from CVS: * gst/gstutils.h: (GST_BOILERPLATE_FULL): Try to fix 'dereferencing type-punned pointer will break strict aliasing rules' warnings with C++ compilers and GLib >= 2.14.0: GLib changed the default GType typedef from gulong to gsize at some point, but kept GType typedef'ed to gulong for C++ for ABI reasons; the g_once_* functions all take a gsize * though, so work around the type mismatch for C++ by doing everything in gsize and casting to GType later. --- ChangeLog | 11 +++++++++++ gst/gstutils.h | 11 +++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index b7a8fa6788..a60af45d27 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-05-09 Tim-Philipp Müller + + * gst/gstutils.h: (GST_BOILERPLATE_FULL): + Try to fix 'dereferencing type-punned pointer will break strict + aliasing rules' warnings with C++ compilers and GLib >= 2.14.0: GLib + changed the default GType typedef from gulong to gsize at some point, + but kept GType typedef'ed to gulong for C++ for ABI reasons; the + g_once_* functions all take a gsize * though, so work around the type + mismatch for C++ by doing everything in gsize and casting to GType + later. + 2008-05-09 Jan Schmidt * plugins/elements/gstmultiqueue.c: diff --git a/gst/gstutils.h b/gst/gstutils.h index 23c4bcd5b4..c6ed717a1e 100644 --- a/gst/gstutils.h +++ b/gst/gstutils.h @@ -137,8 +137,11 @@ GType type_as_function ## _get_type (void); \ GType \ type_as_function ## _get_type (void) \ { \ - static volatile GType object_type = 0; \ - if (__gst_once_init_enter ((gsize *) &object_type)) { \ + /* The typedef for GType may be gulong or gsize, depending on the \ + * system and whether the compiler is c++ or not. The g_once_init_* \ + * functions always take a gsize * though ... */ \ + static volatile gsize gonce_data; \ + if (__gst_once_init_enter (&gonce_data)) { \ GType _type; \ _type = gst_type_register_static_full (parent_type_macro, \ g_intern_static_string (#type), \ @@ -154,9 +157,9 @@ type_as_function ## _get_type (void) \ NULL, \ (GTypeFlags) 0); \ additional_initializations (_type); \ - __gst_once_init_leave ((gsize *) &object_type, (gsize) _type); \ + __gst_once_init_leave (&gonce_data, (gsize) _type); \ } \ - return object_type; \ + return (GType) gonce_data; \ } #define __GST_DO_NOTHING(type) /* NOP */