History

avcodec/cbs: Avoid leaving the ... out in calls to variadic macros

According to C99, there has to be at least one argument for every ... in a variadic function-like macro. In practice most (all?) compilers also allow to leave it completely out, but it is nevertheless required: In a variadic macro "there shall be more arguments in the invocation than there are parameters in the macro definition (excluding the ...)." (C99, 6.10.3.4). CBS (not the framework itself, but the macros used in the cbs_*_syntax_template.c files) relies on the compiler allowing to leave a variadic macro argument out. This leads to warnings when compiling in -pedantic mode, e.g. "warning: must specify at least one argument for '...' parameter of variadic macro [-Wgnu-zero-variadic-macro-arguments]" from Clang. Most of these warnings can be easily avoided: The syntax_templates mostly contain helper macros that expand to more complex variadic macros and these helper macros often omit an argument for the .... Modifying them to always expand to complex macros with an empty argument for the ... at the end fixes most of these warnings: The number of warnings went down from 400 to 0 for cbs_av1, from 1114 to 32 for cbs_h2645, from 38 to 0 for cbs_jpeg, from 166 to 0 for cbs_mpeg2 and from 110 to 8 for cbs_vp9. These eight remaining warnings for cbs_vp9 have been fixed by switching to another macro in cbs_vp9_syntax_template: The fixed values for the sync bytes as well as the trailing bits for byte-alignment are now read via the fixed() macro (this also adds a check to ensure that trailing bits are indeed zero as they have to be).

Andreas Rheinhardt committed 6 years ago

Commit 14dd0a91 parent b7d95076 files · +29 −43Browse files

Unified · Split

6 files
  1. libavcodec/cbs_av1.c +8 −8
  2. libavcodec/cbs_h2645.c +7 −7
  3. libavcodec/cbs_jpeg.c +1 −1
  4. libavcodec/cbs_mpeg2.c +3 −3
  5. libavcodec/cbs_vp9.c +6 −7
  6. libavcodec/cbs_vp9_syntax_template.c +4 −17
libavcodec/cbs_av1.c+8−8
@@ -550,12 +550,12 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) · 549 unmodified lines
550#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)550#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
551 551
552#define fb(width, name) \552#define fb(width, name) \
553 xf(width, name, current->name, 0, MAX_UINT_BITS(width), 0)553 xf(width, name, current->name, 0, MAX_UINT_BITS(width), 0, )
554#define fc(width, name, range_min, range_max) \554#define fc(width, name, range_min, range_max) \
555 xf(width, name, current->name, range_min, range_max, 0)555 xf(width, name, current->name, range_min, range_max, 0, )
556#define flag(name) fb(1, name)556#define flag(name) fb(1, name)
557#define su(width, name) \557#define su(width, name) \
558 xsu(width, name, current->name, 0)558 xsu(width, name, current->name, 0, )
559 559
560#define fbs(width, name, subs, ...) \560#define fbs(width, name, subs, ...) \
561 xf(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)561 xf(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
@@ -568,7 +568,7 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) · 6 unmodified lines
568 568
569#define fixed(width, name, value) do { \569#define fixed(width, name, value) do { \
570 av_unused uint32_t fixed_value = value; \570 av_unused uint32_t fixed_value = value; \
571 xf(width, name, fixed_value, value, value, 0); \571 xf(width, name, fixed_value, value, value, 0, ); \
572 } while (0)572 } while (0)
573 573
574 574
@@ -623,9 +623,9 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) · 48 unmodified lines
623#define delta_q(name) do { \623#define delta_q(name) do { \
624 uint8_t delta_coded; \624 uint8_t delta_coded; \
625 int8_t delta_q; \625 int8_t delta_q; \
626 xf(1, name.delta_coded, delta_coded, 0, 1, 0); \626 xf(1, name.delta_coded, delta_coded, 0, 1, 0, ); \
627 if (delta_coded) \627 if (delta_coded) \
628 xsu(1 + 6, name.delta_q, delta_q, 0); \628 xsu(1 + 6, name.delta_q, delta_q, 0, ); \
629 else \629 else \
630 delta_q = 0; \630 delta_q = 0; \
631 current->name = delta_q; \631 current->name = delta_q; \
@@ -700,9 +700,9 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) · 68 unmodified lines
700 } while (0)700 } while (0)
701 701
702#define delta_q(name) do { \702#define delta_q(name) do { \
703 xf(1, name.delta_coded, current->name != 0, 0, 1, 0); \703 xf(1, name.delta_coded, current->name != 0, 0, 1, 0, ); \
704 if (current->name) \704 if (current->name) \
705 xsu(1 + 6, name.delta_q, current->name, 0); \705 xsu(1 + 6, name.delta_q, current->name, 0, ); \
706 } while (0)706 } while (0)
707 707
708#define leb128(name) do { \708#define leb128(name) do { \
libavcodec/cbs_h2645.c+7−7
@@ -250,18 +250,18 @@ static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc, · 249 unmodified lines
250#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)250#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
251 251
252#define u(width, name, range_min, range_max) \252#define u(width, name, range_min, range_max) \
253 xu(width, name, current->name, range_min, range_max, 0)253 xu(width, name, current->name, range_min, range_max, 0, )
254#define ub(width, name) \254#define ub(width, name) \
255 xu(width, name, current->name, 0, MAX_UINT_BITS(width), 0)255 xu(width, name, current->name, 0, MAX_UINT_BITS(width), 0, )
256#define flag(name) ub(1, name)256#define flag(name) ub(1, name)
257#define ue(name, range_min, range_max) \257#define ue(name, range_min, range_max) \
258 xue(name, current->name, range_min, range_max, 0)258 xue(name, current->name, range_min, range_max, 0, )
259#define i(width, name, range_min, range_max) \259#define i(width, name, range_min, range_max) \
260 xi(width, name, current->name, range_min, range_max, 0)260 xi(width, name, current->name, range_min, range_max, 0, )
261#define ib(width, name) \261#define ib(width, name) \
262 xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), 0)262 xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), 0, )
263#define se(name, range_min, range_max) \263#define se(name, range_min, range_max) \
264 xse(name, current->name, range_min, range_max, 0)264 xse(name, current->name, range_min, range_max, 0, )
265 265
266#define us(width, name, range_min, range_max, subs, ...) \266#define us(width, name, range_min, range_max, subs, ...) \
267 xu(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)267 xu(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
@@ -280,7 +280,7 @@ static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc, · 12 unmodified lines
280 280
281#define fixed(width, name, value) do { \281#define fixed(width, name, value) do { \
282 av_unused uint32_t fixed_value = value; \282 av_unused uint32_t fixed_value = value; \
283 xu(width, name, fixed_value, value, value, 0); \283 xu(width, name, fixed_value, value, value, 0, ); \
284 } while (0)284 } while (0)
285 285
286 286
libavcodec/cbs_jpeg.c+1−1
@@ -34,7 +34,7 @@ · 33 unmodified lines
34#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)34#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
35 35
36#define u(width, name, range_min, range_max) \36#define u(width, name, range_min, range_max) \
37 xu(width, name, range_min, range_max, 0)37 xu(width, name, range_min, range_max, 0, )
38#define us(width, name, sub, range_min, range_max) \38#define us(width, name, sub, range_min, range_max) \
39 xu(width, name, range_min, range_max, 1, sub)39 xu(width, name, range_min, range_max, 1, sub)
40 40
libavcodec/cbs_mpeg2.c+3−3
@@ -41,9 +41,9 @@ · 40 unmodified lines
41#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)41#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
42 42
43#define ui(width, name) \43#define ui(width, name) \
44 xui(width, name, current->name, 0, MAX_UINT_BITS(width), 0)44 xui(width, name, current->name, 0, MAX_UINT_BITS(width), 0, )
45#define uir(width, name) \45#define uir(width, name) \
46 xui(width, name, current->name, 1, MAX_UINT_BITS(width), 0)46 xui(width, name, current->name, 1, MAX_UINT_BITS(width), 0, )
47#define uis(width, name, subs, ...) \47#define uis(width, name, subs, ...) \
48 xui(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)48 xui(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
49#define uirs(width, name, subs, ...) \49#define uirs(width, name, subs, ...) \
@@ -57,7 +57,7 @@ · 7 unmodified lines
57 bit("marker_bit", 1)57 bit("marker_bit", 1)
58#define bit(string, value) do { \58#define bit(string, value) do { \
59 av_unused uint32_t bit = value; \59 av_unused uint32_t bit = value; \
60 xuia(1, string, bit, value, value, 0); \60 xuia(1, string, bit, value, value, 0, ); \
61 } while (0)61 } while (0)
62 62
63 63
libavcodec/cbs_vp9.c+6−7
@@ -253,15 +253,14 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc, · 252 unmodified lines
253#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)253#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
254 254
255#define f(width, name) \255#define f(width, name) \
256 xf(width, name, current->name, 0)256 xf(width, name, current->name, 0, )
257#define s(width, name) \257#define s(width, name) \
258 xs(width, name, current->name, 0)258 xs(width, name, current->name, 0, )
259#define fs(width, name, subs, ...) \259#define fs(width, name, subs, ...) \
260 xf(width, name, current->name, subs, __VA_ARGS__)260 xf(width, name, current->name, subs, __VA_ARGS__)
261#define ss(width, name, subs, ...) \261#define ss(width, name, subs, ...) \
262 xs(width, name, current->name, subs, __VA_ARGS__)262 xs(width, name, current->name, subs, __VA_ARGS__)
263 263
264
265#define READ264#define READ
266#define READWRITE read265#define READWRITE read
267#define RWContext GetBitContext266#define RWContext GetBitContext
@@ -295,9 +294,9 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc, · 27 unmodified lines
295#define delta_q(name) do { \294#define delta_q(name) do { \
296 uint8_t delta_coded; \295 uint8_t delta_coded; \
297 int8_t delta_q; \296 int8_t delta_q; \
298 xf(1, name.delta_coded, delta_coded, 0); \297 xf(1, name.delta_coded, delta_coded, 0, ); \
299 if (delta_coded) \298 if (delta_coded) \
300 xs(4, name.delta_q, delta_q, 0); \299 xs(4, name.delta_q, delta_q, 0, ); \
301 else \300 else \
302 delta_q = 0; \301 delta_q = 0; \
303 current->name = delta_q; \302 current->name = delta_q; \
@@ -366,9 +365,9 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc, · 62 unmodified lines
366 } while (0)365 } while (0)
367 366
368#define delta_q(name) do { \367#define delta_q(name) do { \
369 xf(1, name.delta_coded, !!current->name, 0); \368 xf(1, name.delta_coded, !!current->name, 0, ); \
370 if (current->name) \369 if (current->name) \
371 xs(4, name.delta_q, current->name, 0); \370 xs(4, name.delta_q, current->name, 0, ); \
372 } while (0)371 } while (0)
373 372
374#define prob(name, subs, ...) do { \373#define prob(name, subs, ...) do { \
libavcodec/cbs_vp9_syntax_template.c+4−17
@@ -19,23 +19,11 @@ · 18 unmodified lines
19static int FUNC(frame_sync_code)(CodedBitstreamContext *ctx, RWContext *rw,19static int FUNC(frame_sync_code)(CodedBitstreamContext *ctx, RWContext *rw,
20 VP9RawFrameHeader *current)20 VP9RawFrameHeader *current)
21{21{
22 uint8_t frame_sync_byte_0 = VP9_FRAME_SYNC_0;
23 uint8_t frame_sync_byte_1 = VP9_FRAME_SYNC_1;
24 uint8_t frame_sync_byte_2 = VP9_FRAME_SYNC_2;
25 int err;22 int err;
26 23
27 xf(8, frame_sync_byte_0, frame_sync_byte_0, 0);24 fixed(8, frame_sync_byte_0, VP9_FRAME_SYNC_0);
28 xf(8, frame_sync_byte_1, frame_sync_byte_1, 0);25 fixed(8, frame_sync_byte_1, VP9_FRAME_SYNC_1);
29 xf(8, frame_sync_byte_2, frame_sync_byte_2, 0);26 fixed(8, frame_sync_byte_2, VP9_FRAME_SYNC_2);
30
31 if (frame_sync_byte_0 != VP9_FRAME_SYNC_0 ||
32 frame_sync_byte_1 != VP9_FRAME_SYNC_1 ||
33 frame_sync_byte_2 != VP9_FRAME_SYNC_2) {
34 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid frame sync code: "
35 "%02x %02x %02x.\n", frame_sync_byte_0,
36 frame_sync_byte_1, frame_sync_byte_2);
37 return AVERROR_INVALIDDATA;
38 }
39 27
40 return 0;28 return 0;
41}29}
@@ -396,9 +384,8 @@ static int FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw, · 354 unmodified lines
396static int FUNC(trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw)384static int FUNC(trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw)
397{385{
398 int err;386 int err;
399 av_unused int zero = 0;
400 while (byte_alignment(rw) != 0)387 while (byte_alignment(rw) != 0)
401 xf(1, zero_bit, zero, 0);388 fixed(1, zero_bit, 0);
402 389
403 return 0;390 return 0;
404}391}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t