Always use the unaligned variants of GST_READ_UINT* and GST_WRITE_UINT* as it's too...
authorSebastian Dröge <slomo@circular-chaos.org>
Tue, 7 Oct 2008 12:00:49 +0000 (12:00 +0000)
committerSebastian Dröge <slomo@circular-chaos.org>
Tue, 7 Oct 2008 12:00:49 +0000 (12:00 +0000)
Original commit message from CVS:
* docs/gst/gstreamer-sections.txt:
* gst/gstutils.h:
Always use the unaligned variants of GST_READ_UINT* and GST_WRITE_UINT*
as it's too easy to break the ISO C strict aliasing rules with simple
casts to the corresponding type and this would introduce hard to debug
bugs. Fixes bug #545714.
API: Add GST_READ_UINT24_(LE|BE) and GST_WRITE_UINT24_(LE|BE).

ChangeLog
common
docs/gst/gstreamer-sections.txt
gst/gstutils.h

index d304050..0775efd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2008-10-07  Sebastian Dröge  <sebastian.droege@collabora.co.uk>
+
+       * docs/gst/gstreamer-sections.txt:
+       * gst/gstutils.h:
+       Always use the unaligned variants of GST_READ_UINT* and GST_WRITE_UINT*
+       as it's too easy to break the ISO C strict aliasing rules with simple
+       casts to the corresponding type and this would introduce hard to debug
+       bugs. Fixes bug #545714.
+
+       API: Add GST_READ_UINT24_(LE|BE) and GST_WRITE_UINT24_(LE|BE).
+
 2008-10-07  Tim-Philipp Müller  <tim.muller at collabora co uk>
 
        * gst/gstbuffer.h: (GST_BUFFER_FREE_FUNC):
diff --git a/common b/common
index ea93f2e..46eefd2 160000 (submodule)
--- a/common
+++ b/common
@@ -1 +1 @@
-Subproject commit ea93f2ed580bcc19322e4c07f677eda980c821eb
+Subproject commit 46eefd2f8474ee748864c59635be87b5a29317d1
index 744f29d..aa78517 100644 (file)
@@ -2266,6 +2266,8 @@ GST_CALL_PARENT_WITH_DEFAULT
 GST_READ_UINT8
 GST_READ_UINT16_LE
 GST_READ_UINT16_BE
+GST_READ_UINT24_LE
+GST_READ_UINT24_BE
 GST_READ_UINT32_LE
 GST_READ_UINT32_BE
 GST_READ_UINT64_LE
@@ -2273,6 +2275,8 @@ GST_READ_UINT64_BE
 GST_WRITE_UINT8
 GST_WRITE_UINT16_LE
 GST_WRITE_UINT16_BE
+GST_WRITE_UINT24_LE
+GST_WRITE_UINT24_BE
 GST_WRITE_UINT32_LE
 GST_WRITE_UINT32_BE
 GST_WRITE_UINT64_LE
index c4b3b69..dce88c8 100644 (file)
@@ -272,12 +272,12 @@ GST_BOILERPLATE_FULL (type, type_as_function, parent_type,              \
        ((parent_class_cast(parent_class)->name != NULL) ?              \
         parent_class_cast(parent_class)->name args : def_return)
 
-/* Define possibly unaligned memory access method whether the type of
- * architecture. */
-#if GST_HAVE_UNALIGNED_ACCESS
+/* Define PUT and GET functions for unaligned memory */
+#define _GST_GET(__data, __idx, __size, __shift) \
+    (((guint##__size) (((guint8 *) (__data))[__idx])) << __shift)
 
-#define _GST_GET(__data, __size, __end) \
-    (GUINT##__size##_FROM_##__end (* ((guint##__size *) (__data))))
+#define _GST_PUT(__data, __idx, __size, __shift, __num) \
+    (((guint8 *) (__data))[__idx] = (((guint##__size) __num) >> __shift) & 0xff)
 
 /**
  * GST_READ_UINT64_BE:
@@ -285,154 +285,109 @@ GST_BOILERPLATE_FULL (type, type_as_function, parent_type,              \
  *
  * Read a 64 bit unsigned integer value in big endian format from the memory buffer.
  */
-#define GST_READ_UINT64_BE(data)       _GST_GET (data, 64, BE)
+#define GST_READ_UINT64_BE(data)       (_GST_GET (data, 0, 64, 56) | \
+                                        _GST_GET (data, 1, 64, 48) | \
+                                        _GST_GET (data, 2, 64, 40) | \
+                                        _GST_GET (data, 3, 64, 32) | \
+                                        _GST_GET (data, 4, 64, 24) | \
+                                        _GST_GET (data, 5, 64, 16) | \
+                                        _GST_GET (data, 6, 64,  8) | \
+                                        _GST_GET (data, 7, 64,  0))
+
 /**
  * GST_READ_UINT64_LE:
  * @data: memory location
  *
  * Read a 64 bit unsigned integer value in little endian format from the memory buffer.
  */
-#define GST_READ_UINT64_LE(data)       _GST_GET (data, 64, LE)
+#define GST_READ_UINT64_LE(data)       (_GST_GET (data, 7, 64, 56) | \
+                                        _GST_GET (data, 6, 64, 48) | \
+                                        _GST_GET (data, 5, 64, 40) | \
+                                        _GST_GET (data, 4, 64, 32) | \
+                                        _GST_GET (data, 3, 64, 24) | \
+                                        _GST_GET (data, 2, 64, 16) | \
+                                        _GST_GET (data, 1, 64,  8) | \
+                                        _GST_GET (data, 0, 64,  0))
+
 /**
  * GST_READ_UINT32_BE:
  * @data: memory location
  *
  * Read a 32 bit unsigned integer value in big endian format from the memory buffer.
  */
-#define GST_READ_UINT32_BE(data)       _GST_GET (data, 32, BE)
+#define GST_READ_UINT32_BE(data)       (_GST_GET (data, 0, 32, 24) | \
+                                        _GST_GET (data, 1, 32, 16) | \
+                                        _GST_GET (data, 2, 32,  8) | \
+                                        _GST_GET (data, 3, 32,  0))
+
 /**
  * GST_READ_UINT32_LE:
  * @data: memory location
  *
  * Read a 32 bit unsigned integer value in little endian format from the memory buffer.
  */
-#define GST_READ_UINT32_LE(data)        _GST_GET (data, 32, LE)
+#define GST_READ_UINT32_LE(data)       (_GST_GET (data, 3, 32, 24) | \
+                                        _GST_GET (data, 2, 32, 16) | \
+                                        _GST_GET (data, 1, 32,  8) | \
+                                        _GST_GET (data, 0, 32,  0))
+
 /**
- * GST_READ_UINT16_BE:
+ * GST_READ_UINT24_BE:
  * @data: memory location
  *
- * Read a 16 bit unsigned integer value in big endian format from the memory buffer.
- */
-#define GST_READ_UINT16_BE(data)        _GST_GET (data, 16, BE)
-/**
- * GST_READ_UINT16_LE:
- * @data: memory location
+ * Read a 24 bit unsigned integer value in big endian format from the memory buffer.
  *
- * Read a 16 bit unsigned integer value in little endian format from the memory buffer.
- */
-#define GST_READ_UINT16_LE(data)        _GST_GET (data, 16, LE)
-/**
- * GST_READ_UINT8:
- * @data: memory location
- *
- * Read an 8 bit unsigned integer value from the memory buffer.
+ * Since: 0.10.22
  */
-#define GST_READ_UINT8(data)           (* ((guint8 *) (data)))
-
-#define _GST_PUT(__data, __size, __end, __num) \
-    ((* (guint##__size *) (__data)) = GUINT##__size##_TO_##__end (__num))
+#define GST_READ_UINT24_BE(data)       (_GST_GET (data, 0, 32, 16) | \
+                                        _GST_GET (data, 1, 32,  8) | \
+                                        _GST_GET (data, 2, 32,  0))
 
 /**
- * GST_WRITE_UINT64_BE:
- * @data: memory location
- * @num: value to store
- *
- * Store a 64 bit unsigned integer value in big endian format into the memory buffer.
- */
-#define GST_WRITE_UINT64_BE(data, num) _GST_PUT(data, 64, BE, num)
-/**
- * GST_WRITE_UINT64_LE:
+ * GST_READ_UINT24_LE:
  * @data: memory location
- * @num: value to store
  *
- * Store a 64 bit unsigned integer value in little endian format into the memory buffer.
- */
-#define GST_WRITE_UINT64_LE(data, num)  _GST_PUT(data, 64, LE, num)
-/**
- * GST_WRITE_UINT32_BE:
- * @data: memory location
- * @num: value to store
+ * Read a 24 bit unsigned integer value in little endian format from the memory buffer.
  *
- * Store a 32 bit unsigned integer value in big endian format into the memory buffer.
+ * Since: 0.10.22
  */
-#define GST_WRITE_UINT32_BE(data, num)  _GST_PUT(data, 32, BE, num)
+#define GST_READ_UINT24_LE(data)       (_GST_GET (data, 2, 32, 16) | \
+                                        _GST_GET (data, 1, 32,  8) | \
+                                        _GST_GET (data, 0, 32,  0))
+
 /**
- * GST_WRITE_UINT32_LE:
+ * GST_READ_UINT16_BE:
  * @data: memory location
- * @num: value to store
  *
- * Store a 32 bit unsigned integer value in little endian format into the memory buffer.
+ * Read a 16 bit unsigned integer value in big endian format from the memory buffer.
  */
-#define GST_WRITE_UINT32_LE(data, num)  _GST_PUT(data, 32, LE, num)
+#define GST_READ_UINT16_BE(data)       (_GST_GET (data, 0, 16,  8) | \
+                                        _GST_GET (data, 1, 16,  0))
+
 /**
- * GST_WRITE_UINT16_BE:
+ * GST_READ_UINT16_LE:
  * @data: memory location
- * @num: value to store
  *
- * Store a 16 bit unsigned integer value in big endian format into the memory buffer.
+ * Read a 16 bit unsigned integer value in little endian format from the memory buffer.
  */
-#define GST_WRITE_UINT16_BE(data, num)  _GST_PUT(data, 16, BE, num)
+#define GST_READ_UINT16_LE(data)       (_GST_GET (data, 1, 16,  8) | \
+                                        _GST_GET (data, 0, 16,  0))
+
 /**
- * GST_WRITE_UINT16_LE:
+ * GST_READ_UINT8:
  * @data: memory location
- * @num: value to store
  *
- * Store a 16 bit unsigned integer value in little endian format into the memory buffer.
+ * Read an 8 bit unsigned integer value from the memory buffer.
  */
-#define GST_WRITE_UINT16_LE(data, num)  _GST_PUT(data, 16, LE, num)
+#define GST_READ_UINT8(data)           (_GST_GET (data, 0,  8,  0))
+
 /**
- * GST_WRITE_UINT8:
+ * GST_WRITE_UINT64_BE:
  * @data: memory location
  * @num: value to store
  *
- * Store an 8 bit unsigned integer value into the memory buffer.
+ * Store a 64 bit unsigned integer value in big endian format into the memory buffer.
  */
-#define GST_WRITE_UINT8(data, num)     ((* (guint8 *) (data)) = (num))
-
-#else /* GST_HAVE_UNALIGNED_ACCESS */
-
-#define _GST_GET(__data, __idx, __size, __shift) \
-    (((guint##__size) (((guint8 *) (__data))[__idx])) << __shift)
-
-#define GST_READ_UINT64_BE(data)       (_GST_GET (data, 0, 64, 56) | \
-                                        _GST_GET (data, 1, 64, 48) | \
-                                        _GST_GET (data, 2, 64, 40) | \
-                                        _GST_GET (data, 3, 64, 32) | \
-                                        _GST_GET (data, 4, 64, 24) | \
-                                        _GST_GET (data, 5, 64, 16) | \
-                                        _GST_GET (data, 6, 64,  8) | \
-                                        _GST_GET (data, 7, 64,  0))
-
-#define GST_READ_UINT64_LE(data)       (_GST_GET (data, 7, 64, 56) | \
-                                        _GST_GET (data, 6, 64, 48) | \
-                                        _GST_GET (data, 5, 64, 40) | \
-                                        _GST_GET (data, 4, 64, 32) | \
-                                        _GST_GET (data, 3, 64, 24) | \
-                                        _GST_GET (data, 2, 64, 16) | \
-                                        _GST_GET (data, 1, 64,  8) | \
-                                        _GST_GET (data, 0, 64,  0))
-
-#define GST_READ_UINT32_BE(data)       (_GST_GET (data, 0, 32, 24) | \
-                                        _GST_GET (data, 1, 32, 16) | \
-                                        _GST_GET (data, 2, 32,  8) | \
-                                        _GST_GET (data, 3, 32,  0))
-
-#define GST_READ_UINT32_LE(data)       (_GST_GET (data, 3, 32, 24) | \
-                                        _GST_GET (data, 2, 32, 16) | \
-                                        _GST_GET (data, 1, 32,  8) | \
-                                        _GST_GET (data, 0, 32,  0))
-
-#define GST_READ_UINT16_BE(data)       (_GST_GET (data, 0, 16,  8) | \
-                                        _GST_GET (data, 1, 16,  0))
-
-#define GST_READ_UINT16_LE(data)       (_GST_GET (data, 1, 16,  8) | \
-                                        _GST_GET (data, 0, 16,  0))
-
-#define GST_READ_UINT8(data)           (_GST_GET (data, 0,  8,  0))
-
-#define _GST_PUT(__data, __idx, __size, __shift, __num) \
-    (((guint8 *) (__data))[__idx] = (((guint##__size) __num) >> __shift) & 0xff)
-
 #define GST_WRITE_UINT64_BE(data, num) do { \
                                          _GST_PUT (data, 0, 64, 56, num); \
                                          _GST_PUT (data, 1, 64, 48, num); \
@@ -444,6 +399,13 @@ GST_BOILERPLATE_FULL (type, type_as_function, parent_type,              \
                                          _GST_PUT (data, 7, 64,  0, num); \
                                        } while (0)
 
+/**
+ * GST_WRITE_UINT64_LE:
+ * @data: memory location
+ * @num: value to store
+ *
+ * Store a 64 bit unsigned integer value in little endian format into the memory buffer.
+ */
 #define GST_WRITE_UINT64_LE(data, num) do { \
                                          _GST_PUT (data, 0, 64,  0, num); \
                                          _GST_PUT (data, 1, 64,  8, num); \
@@ -455,6 +417,13 @@ GST_BOILERPLATE_FULL (type, type_as_function, parent_type,              \
                                          _GST_PUT (data, 7, 64, 56, num); \
                                        } while (0)
 
+/**
+ * GST_WRITE_UINT32_BE:
+ * @data: memory location
+ * @num: value to store
+ *
+ * Store a 32 bit unsigned integer value in big endian format into the memory buffer.
+ */
 #define GST_WRITE_UINT32_BE(data, num) do { \
                                          _GST_PUT (data, 0, 32, 24, num); \
                                          _GST_PUT (data, 1, 32, 16, num); \
@@ -462,6 +431,13 @@ GST_BOILERPLATE_FULL (type, type_as_function, parent_type,              \
                                          _GST_PUT (data, 3, 32,  0, num); \
                                        } while (0)
 
+/**
+ * GST_WRITE_UINT32_LE:
+ * @data: memory location
+ * @num: value to store
+ *
+ * Store a 32 bit unsigned integer value in little endian format into the memory buffer.
+ */
 #define GST_WRITE_UINT32_LE(data, num) do { \
                                          _GST_PUT (data, 0, 32,  0, num); \
                                          _GST_PUT (data, 1, 32,  8, num); \
@@ -469,23 +445,71 @@ GST_BOILERPLATE_FULL (type, type_as_function, parent_type,              \
                                          _GST_PUT (data, 3, 32, 24, num); \
                                        } while (0)
 
+/**
+ * GST_WRITE_UINT24_BE:
+ * @data: memory location
+ * @num: value to store
+ *
+ * Store a 24 bit unsigned integer value in big endian format into the memory buffer.
+ *
+ * Since: 0.10.22
+ */
+#define GST_WRITE_UINT24_BE(data, num) do { \
+                                         _GST_PUT (data, 0, 32,  16, num); \
+                                         _GST_PUT (data, 1, 32,  8, num); \
+                                         _GST_PUT (data, 2, 32,  0, num); \
+                                       } while (0)
+
+/**
+ * GST_WRITE_UINT24_LE:
+ * @data: memory location
+ * @num: value to store
+ *
+ * Store a 24 bit unsigned integer value in little endian format into the memory buffer.
+ *
+ * Since: 0.10.22
+ */
+#define GST_WRITE_UINT24_LE(data, num) do { \
+                                         _GST_PUT (data, 0, 32,  0, num); \
+                                         _GST_PUT (data, 1, 32,  8, num); \
+                                         _GST_PUT (data, 2, 32,  16, num); \
+                                       } while (0)
+
+/**
+ * GST_WRITE_UINT16_BE:
+ * @data: memory location
+ * @num: value to store
+ *
+ * Store a 16 bit unsigned integer value in big endian format into the memory buffer.
+ */
 #define GST_WRITE_UINT16_BE(data, num) do { \
                                          _GST_PUT (data, 0, 16,  8, num); \
                                          _GST_PUT (data, 1, 16,  0, num); \
                                        } while (0)
 
+/**
+ * GST_WRITE_UINT16_LE:
+ * @data: memory location
+ * @num: value to store
+ *
+ * Store a 16 bit unsigned integer value in little endian format into the memory buffer.
+ */
 #define GST_WRITE_UINT16_LE(data, num) do { \
                                          _GST_PUT (data, 0, 16,  0, num); \
                                          _GST_PUT (data, 1, 16,  8, num); \
                                        } while (0)
 
+/**
+ * GST_WRITE_UINT8:
+ * @data: memory location
+ * @num: value to store
+ *
+ * Store an 8 bit unsigned integer value into the memory buffer.
+ */
 #define GST_WRITE_UINT8(data, num)     do { \
                                          _GST_PUT (data, 0,  8,  0, num); \
                                        } while (0)
 
-#endif /* GST_HAVE_UNALIGNED_ACCESS */
-
-
 /* Miscellaneous utility macros */
 
 /**