summaryrefslogtreecommitdiff
path: root/libavcodec/tableprint_vlc.h
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-06-13 23:02:57 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-06-17 16:47:29 +0200
commit2d764069be3b4092dc986467660607d922023332 (patch)
tree1504ef9e286b8df559635e97d31ebe767a9e6426 /libavcodec/tableprint_vlc.h
parent97141ffeec803c448d81ee4a53cfa2355f79f7ec (diff)
downloadffmpeg-2d764069be3b4092dc986467660607d922023332.tar.gz
avcodec/vlc: Use structure instead of VLC_TYPE array as VLC element
In C, qualifiers for arrays are broken: const VLC_TYPE (*foo)[2] is a pointer to an array of two const VLC_TYPE elements and unfortunately this is not compatible with a pointer to a const array of two VLC_TYPE, because the latter does not exist as array types are never qualified (the qualifier applies to the base type instead). This is the reason why get_vlc2() doesn't accept a const VLC table despite not modifying the table at all, as there is no automatic conversion from VLC_TYPE (*)[2] to const VLC_TYPE (*)[2]. Fix this by using a structure VLCElem for the VLC table. This also has the advantage of making it clear which element is which. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/tableprint_vlc.h')
-rw-r--r--libavcodec/tableprint_vlc.h17
1 files changed, 8 insertions, 9 deletions
diff --git a/libavcodec/tableprint_vlc.h b/libavcodec/tableprint_vlc.h
index d53ae5799f..b97c1f9cfb 100644
--- a/libavcodec/tableprint_vlc.h
+++ b/libavcodec/tableprint_vlc.h
@@ -39,23 +39,22 @@
#include "libavutil/reverse.c"
#include "vlc.c"
-#define REPLACE_DEFINE2(type) write_##type##_array
-#define REPLACE_DEFINE(type) REPLACE_DEFINE2(type)
-static void write_VLC_TYPE_array(const VLC_TYPE *p, int s) {
- REPLACE_DEFINE(VLC_TYPE)(p, s);
-}
-
-WRITE_2D_FUNC(VLC_TYPE)
+// The following will have to be modified if VLCBaseType changes.
+WRITE_1D_FUNC_ARGV(VLCElem, 3, "{ .sym =%5" PRId16 ", .len =%2"PRIi16 " }",
+ data[i].sym, data[i].len)
-static void write_vlc_type(const VLC *vlc, VLC_TYPE (*base_table)[2], const char *base_table_name)
+static void write_vlc_type(const VLC *vlc, const VLCElem *base_table, const char *base_table_name)
{
printf(" .bits = %i,\n", vlc->bits);
// Unfortunately need to cast away const currently
- printf(" .table = (VLC_TYPE (*)[2])(%s + 0x%x),\n", base_table_name, (int)(vlc->table - base_table));
+ printf(" .table = (VLCElem *)(%s + 0x%x),\n", base_table_name, (int)(vlc->table - base_table));
printf(" .table_size = 0x%x,\n", vlc->table_size);
printf(" .table_allocated = 0x%x,\n", vlc->table_allocated);
}
+#define WRITE_VLC_TABLE(prefix, name) \
+ WRITE_ARRAY(prefix, VLCElem, name)
+
#define WRITE_VLC_TYPE(prefix, name, base_table) \
do { \
printf(prefix" VLC "#name" = {\n"); \