[vlc-devel] commit: Remove be_sure_to_add_VLC_COMMOM_MEMBERS and check offset ( Rémi Denis-Courmont )

git version control git at videolan.org
Thu Feb 4 19:12:55 CET 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Feb  4 20:01:15 2010 +0200| [feeef1ef3945c3080ed828381fe9cf02d051863d] | committer: Rémi Denis-Courmont 

Remove be_sure_to_add_VLC_COMMOM_MEMBERS and check offset

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).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=feeef1ef3945c3080ed828381fe9cf02d051863d
---

 include/vlc_common.h |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/include/vlc_common.h b/include/vlc_common.h
index a45bd97..4ec66cc 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -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




More information about the vlc-devel mailing list