[vlc-commits] misc: ensure vlc_object_t is correctly aligned

Rémi Denis-Courmont git at videolan.org
Tue Jun 13 21:36:15 CEST 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Jun 13 22:31:50 2017 +0300| [4f91e6bc15d8b72deb1f761ca857a33d672c91ef] | committer: Rémi Denis-Courmont

misc: ensure vlc_object_t is correctly aligned

To hide private data before (and/or after) public data, we normally
embed the public data within the private data structure. This ensures
proper alignment.

For VLC objects, that was unfortunately not an option, since the type of
the public data varies with the VLC object sub-classes. Thus the size,
and potentially the alignment, also vary.

This change ensures that the private data have the maximum possible
normal alignment. That will be adequate regardless of the public data
type.

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

 src/misc/variables.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/misc/variables.h b/src/misc/variables.h
index e5853e449c..cdfafe19d6 100644
--- a/src/misc/variables.h
+++ b/src/misc/variables.h
@@ -23,6 +23,7 @@
 #ifndef LIBVLC_VARIABLES_H
 # define LIBVLC_VARIABLES_H 1
 
+# include <stdalign.h>
 # include <vlc_atomic.h>
 
 /**
@@ -48,10 +49,13 @@ struct vlc_object_internals
     vlc_object_internals_t *prev;  /* previous sibling */
     vlc_object_internals_t *first; /* first child */
     vlc_mutex_t tree_lock;
+
+    max_align_t aligned_end[];
 };
 
-# define vlc_internals( obj ) (((vlc_object_internals_t*)(VLC_OBJECT(obj)))-1)
-# define vlc_externals( priv ) ((vlc_object_t *)((priv) + 1))
+# define vlc_internals(obj) \
+    container_of(VLC_OBJECT(obj), struct vlc_object_internals, aligned_end)
+# define vlc_externals(priv ) ((vlc_object_t *)((priv)->aligned_end))
 
 void DumpVariables(vlc_object_t *obj);
 



More information about the vlc-commits mailing list