mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-28 11:10:37 +00:00
Always use the unaligned variants of GST_READ_UINT* and GST_WRITE_UINT* as it's too easy to break the ISO C strict al...
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).
This commit is contained in:
parent
cabf154dc6
commit
22dd04f7e0
4 changed files with 160 additions and 121 deletions
11
ChangeLog
11
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):
|
||||
|
|
2
common
2
common
|
@ -1 +1 @@
|
|||
Subproject commit ea93f2ed580bcc19322e4c07f677eda980c821eb
|
||||
Subproject commit 46eefd2f8474ee748864c59635be87b5a29317d1
|
|
@ -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
|
||||
|
|
264
gst/gstutils.h
264
gst/gstutils.h
|
@ -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,115 +285,6 @@ 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)
|
||||
/**
|
||||
* 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)
|
||||
/**
|
||||
* 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)
|
||||
/**
|
||||
* 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)
|
||||
/**
|
||||
* GST_READ_UINT16_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 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.
|
||||
*/
|
||||
#define GST_READ_UINT8(data) (* ((guint8 *) (data)))
|
||||
|
||||
#define _GST_PUT(__data, __size, __end, __num) \
|
||||
((* (guint##__size *) (__data)) = GUINT##__size##_TO_##__end (__num))
|
||||
|
||||
/**
|
||||
* 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:
|
||||
* @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
|
||||
*
|
||||
* Store a 32 bit unsigned integer value in big endian format into the memory buffer.
|
||||
*/
|
||||
#define GST_WRITE_UINT32_BE(data, num) _GST_PUT(data, 32, BE, num)
|
||||
/**
|
||||
* 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) _GST_PUT(data, 32, LE, num)
|
||||
/**
|
||||
* 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) _GST_PUT(data, 16, BE, num)
|
||||
/**
|
||||
* 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) _GST_PUT(data, 16, LE, num)
|
||||
/**
|
||||
* 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) ((* (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) | \
|
||||
|
@ -403,6 +294,12 @@ GST_BOILERPLATE_FULL (type, type_as_function, parent_type, \
|
|||
_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, 7, 64, 56) | \
|
||||
_GST_GET (data, 6, 64, 48) | \
|
||||
_GST_GET (data, 5, 64, 40) | \
|
||||
|
@ -412,27 +309,85 @@ GST_BOILERPLATE_FULL (type, type_as_function, parent_type, \
|
|||
_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, 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, 3, 32, 24) | \
|
||||
_GST_GET (data, 2, 32, 16) | \
|
||||
_GST_GET (data, 1, 32, 8) | \
|
||||
_GST_GET (data, 0, 32, 0))
|
||||
|
||||
/**
|
||||
* GST_READ_UINT24_BE:
|
||||
* @data: memory location
|
||||
*
|
||||
* Read a 24 bit unsigned integer value in big endian format from the memory buffer.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*/
|
||||
#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_READ_UINT24_LE:
|
||||
* @data: memory location
|
||||
*
|
||||
* Read a 24 bit unsigned integer value in little endian format from the memory buffer.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*/
|
||||
#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_READ_UINT16_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, 0, 16, 8) | \
|
||||
_GST_GET (data, 1, 16, 0))
|
||||
|
||||
/**
|
||||
* GST_READ_UINT16_LE:
|
||||
* @data: memory location
|
||||
*
|
||||
* Read a 16 bit unsigned integer value in little endian format from the memory buffer.
|
||||
*/
|
||||
#define GST_READ_UINT16_LE(data) (_GST_GET (data, 1, 16, 8) | \
|
||||
_GST_GET (data, 0, 16, 0))
|
||||
|
||||
/**
|
||||
* GST_READ_UINT8:
|
||||
* @data: memory location
|
||||
*
|
||||
* Read an 8 bit unsigned integer value from the memory buffer.
|
||||
*/
|
||||
#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)
|
||||
|
||||
/**
|
||||
* 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) 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 */
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue