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
550550 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
551551
552552 #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, )
554554 #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, )
556556 #define flag(name) fb(1, name)
557557 #define su(width, name) \
558− xsu(width, name, current->name, 0)
558+ xsu(width, name, current->name, 0, )
559559
560560 #define fbs(width, name, subs, ...) \
561561 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
568568
569569 #define fixed(width, name, value) do { \
570570 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, ); \
572572 } while (0)
573573
574574
@@ -623,9 +623,9 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) · 48 unmodified lines
623623 #define delta_q(name) do { \
624624 uint8_t delta_coded; \
625625 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, ); \
627627 if (delta_coded) \
628− xsu(1 + 6, name.delta_q, delta_q, 0); \
628+ xsu(1 + 6, name.delta_q, delta_q, 0, ); \
629629 else \
630630 delta_q = 0; \
631631 current->name = delta_q; \
@@ -700,9 +700,9 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) · 68 unmodified lines
700700 } while (0)
701701
702702 #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, ); \
704704 if (current->name) \
705− xsu(1 + 6, name.delta_q, current->name, 0); \
705+ xsu(1 + 6, name.delta_q, current->name, 0, ); \
706706 } while (0)
707707
708708 #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
250250 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
251251
252252 #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, )
254254 #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, )
256256 #define flag(name) ub(1, name)
257257 #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, )
259259 #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, )
261261 #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, )
263263 #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, )
265265
266266 #define us(width, name, range_min, range_max, subs, ...) \
267267 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
280280
281281 #define fixed(width, name, value) do { \
282282 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, ); \
284284 } while (0)
285285
286286
libavcodec/cbs_jpeg.c+1−1
@@ -34,7 +34,7 @@ · 33 unmodified lines
3434 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
3535
3636 #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, )
3838 #define us(width, name, sub, range_min, range_max) \
3939 xu(width, name, range_min, range_max, 1, sub)
4040
libavcodec/cbs_mpeg2.c+3−3
@@ -41,9 +41,9 @@ · 40 unmodified lines
4141 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
4242
4343 #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, )
4545 #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, )
4747 #define uis(width, name, subs, ...) \
4848 xui(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
4949 #define uirs(width, name, subs, ...) \
@@ -57,7 +57,7 @@ · 7 unmodified lines
5757 bit("marker_bit", 1)
5858 #define bit(string, value) do { \
5959 av_unused uint32_t bit = value; \
60− xuia(1, string, bit, value, value, 0); \
60+ xuia(1, string, bit, value, value, 0, ); \
6161 } while (0)
6262
6363
libavcodec/cbs_vp9.c+6−7
@@ -253,15 +253,14 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc, · 252 unmodified lines
253253 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
254254
255255 #define f(width, name) \
256− xf(width, name, current->name, 0)
256+ xf(width, name, current->name, 0, )
257257 #define s(width, name) \
258− xs(width, name, current->name, 0)
258+ xs(width, name, current->name, 0, )
259259 #define fs(width, name, subs, ...) \
260260 xf(width, name, current->name, subs, __VA_ARGS__)
261261 #define ss(width, name, subs, ...) \
262262 xs(width, name, current->name, subs, __VA_ARGS__)
263263
264−
265264 #define READ
266265 #define READWRITE read
267266 #define RWContext GetBitContext
@@ -295,9 +294,9 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc, · 27 unmodified lines
295294 #define delta_q(name) do { \
296295 uint8_t delta_coded; \
297296 int8_t delta_q; \
298− xf(1, name.delta_coded, delta_coded, 0); \
297+ xf(1, name.delta_coded, delta_coded, 0, ); \
299298 if (delta_coded) \
300− xs(4, name.delta_q, delta_q, 0); \
299+ xs(4, name.delta_q, delta_q, 0, ); \
301300 else \
302301 delta_q = 0; \
303302 current->name = delta_q; \
@@ -366,9 +365,9 @@ static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc, · 62 unmodified lines
366365 } while (0)
367366
368367 #define delta_q(name) do { \
369− xf(1, name.delta_coded, !!current->name, 0); \
368+ xf(1, name.delta_coded, !!current->name, 0, ); \
370369 if (current->name) \
371− xs(4, name.delta_q, current->name, 0); \
370+ xs(4, name.delta_q, current->name, 0, ); \
372371 } while (0)
373372
374373 #define prob(name, subs, ...) do { \
libavcodec/cbs_vp9_syntax_template.c+4−17
@@ -19,23 +19,11 @@ · 18 unmodified lines
1919 static int FUNC(frame_sync_code)(CodedBitstreamContext *ctx, RWContext *rw,
2020 VP9RawFrameHeader *current)
2121 {
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;
2522 int err;
2623
27− xf(8, frame_sync_byte_0, frame_sync_byte_0, 0);
28− xf(8, frame_sync_byte_1, frame_sync_byte_1, 0);
29− xf(8, frame_sync_byte_2, frame_sync_byte_2, 0);
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− }
24+ fixed(8, frame_sync_byte_0, VP9_FRAME_SYNC_0);
25+ fixed(8, frame_sync_byte_1, VP9_FRAME_SYNC_1);
26+ fixed(8, frame_sync_byte_2, VP9_FRAME_SYNC_2);
3927
4028 return 0;
4129 }
@@ -396,9 +384,8 @@ static int FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw, · 354 unmodified lines
396384 static int FUNC(trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw)
397385 {
398386 int err;
399− av_unused int zero = 0;
400387 while (byte_alignment(rw) != 0)
401− xf(1, zero_bit, zero, 0);
388+ fixed(1, zero_bit, 0);
402389
403390 return 0;
404391 }

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