]> git.sesse.net Git - vlc/commitdiff
Remove be_sure_to_add_VLC_COMMOM_MEMBERS and check offset
authorRémi Denis-Courmont <remi@remlab.net>
Thu, 4 Feb 2010 18:01:15 +0000 (20:01 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Thu, 4 Feb 2010 18:12:43 +0000 (20:12 +0200)
This saves a bit of space (though the message becomes a bit more
confusing). This also ensures that VLC_COMMOM_MEMBERS is actually at the
top of the struct (in C only).

include/vlc_common.h

index a45bd973d34c9bebf47dfe09283e0f66678a8e0a..4ec66cc845a471a2009fa07b1840cf18d854d815 100644 (file)
@@ -540,9 +540,6 @@ typedef int ( * vlc_callback_t ) ( vlc_object_t *,      /* variable's object */
     volatile bool b_die;                   /**< set by the outside */ \
     bool b_force;      /**< set by the outside (eg. module_need()) */ \
                                                                             \
-    /** Just a reminder so that people don't cast garbage */                \
-    bool be_sure_to_add_VLC_COMMON_MEMBERS_to_struct;                       \
-                                                                            \
     /* Stuff related to the libvlc structure */                             \
     libvlc_int_t *p_libvlc;                  /**< (root of all evil) - 1 */ \
                                                                             \
@@ -552,8 +549,15 @@ typedef int ( * vlc_callback_t ) ( vlc_object_t *,      /* variable's object */
 
 /* VLC_OBJECT: attempt at doing a clever cast */
 #ifdef __GNUC__
-# define VLC_OBJECT( x ) \
-    (((vlc_object_t *)(x))+0*(((__typeof__(x))0)->be_sure_to_add_VLC_COMMON_MEMBERS_to_struct))
+# ifndef __cplusplus
+#  define VLC_OBJECT( x ) \
+    __builtin_choose_expr(__builtin_offsetof(__typeof__(*x), psz_object_type), \
+                          (void)0 /* screw you */, (vlc_object_t *)(x))
+# else
+#  define VLC_OBJECT( x ) \
+    ((vlc_object_t *)(x) \
+      + 0 * __builtin_offsetof(__typeof__(*x), psz_object_type))
+# endif
 #else
 # define VLC_OBJECT( x ) ((vlc_object_t *)(x))
 #endif