[vlc-commits] [Git][videolan/vlc][master] Use static assertions to check constant predicates

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Tue Aug 2 14:07:43 UTC 2022



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
815116d8 by Rémi Denis-Courmont at 2022-08-02T13:44:55+00:00
Use static assertions to check constant predicates

This is more straightforward than #if/#error/#endif.

- - - - -


8 changed files:

- doc/libvlc/vlc-thumb.c
- modules/access/http/h2frame.c
- modules/codec/faad.c
- modules/demux/mpeg/ts.h
- modules/gui/qt/qt.hpp
- modules/mux/mpeg/ts.c
- modules/stream_filter/cache_read.c
- src/clock/input_clock.c


Changes:

=====================================
doc/libvlc/vlc-thumb.c
=====================================
@@ -33,9 +33,7 @@
 #  define _POSIX_CLOCK_SELECTION (-1)
 #endif
 
-#if (_POSIX_CLOCK_SELECTION < 0)
-#   error Clock selection is not available!
-#endif
+static_assert (_POSIX_CLOCK_SELECTION >= 0, "Clock selection unavailable!");
 
 #include <vlc/vlc.h>
 


=====================================
modules/access/http/h2frame.c
=====================================
@@ -284,18 +284,16 @@ struct vlc_h2_frame *vlc_h2_frame_settings(void)
 #endif
 
 #if (VLC_H2_INIT_WINDOW != VLC_H2_DEFAULT_INIT_WINDOW)
-# if (VLC_H2_INIT_WINDOW > 2147483647)
-#  error Illegal initial window value
-# endif
+    static_assert (VLC_H2_INIT_WINDOW < 2147483648,
+                   "Illegal initial window value");
     SetWBE(p, VLC_H2_SETTING_INITIAL_WINDOW_SIZE);
     SetDWBE(p + 2, VLC_H2_INIT_WINDOW);
     p += 6;
 #endif
 
 #if (VLC_H2_MAX_FRAME != VLC_H2_DEFAULT_MAX_FRAME)
-# if (VLC_H2_MAX_FRAME < 16384 || VLC_H2_MAX_FRAME > 16777215)
-#  error Illegal maximum frame size
-# endif
+    static_assert (VLC_H2_MAX_FRAME >= 16384 && VLC_H2_MAX_FRAME < 16777216,
+                   "Illegal maximum frame size");
     SetWBE(p, VLC_H2_SETTING_MAX_FRAME_SIZE);
     SetDWBE(p + 2, VLC_H2_MAX_FRAME);
     p += 6;


=====================================
modules/codec/faad.c
=====================================
@@ -33,6 +33,8 @@
 # include "config.h"
 #endif
 
+#include <assert.h>
+
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_input_item.h>
@@ -81,9 +83,7 @@ typedef struct
     bool b_sbr, b_ps, b_discontinuity;
 } decoder_sys_t;
 
-#if MPEG4_ASC_MAX_INDEXEDPOS != LFE_CHANNEL
-    #error MPEG4_ASC_MAX_INDEXEDPOS != LFE_CHANNEL
-#endif
+static_assert (MPEG4_ASC_MAX_INDEXEDPOS == LFE_CHANNEL, "Mismatch");
 
 #define FAAD_CHANNEL_ID_COUNT (LFE_CHANNEL + 1)
 static const uint32_t pi_tovlcmapping[FAAD_CHANNEL_ID_COUNT] =


=====================================
modules/demux/mpeg/ts.h
=====================================
@@ -29,11 +29,10 @@ typedef struct csa_t csa_t;
 
 #define TS_PSI_PAT_PID 0x00
 
-#if (VLC_TICK_INVALID + 1 != VLC_TICK_0)
-#   error "can't define TS_UNKNOWN reference"
-#else
-#   define TS_TICK_UNKNOWN (VLC_TICK_INVALID - 1)
-#endif
+_Static_assert (VLC_TICK_INVALID + 1 == VLC_TICK_0,
+                "can't define TS_UNKNOWN reference");
+#define TS_TICK_UNKNOWN (VLC_TICK_INVALID - 1)
+
 #define SETANDVALID(a) (a != TS_TICK_UNKNOWN && a != VLC_TICK_INVALID)
 
 typedef enum ts_standards_e


=====================================
modules/gui/qt/qt.hpp
=====================================
@@ -40,9 +40,8 @@
 #define QT_NO_CAST_TO_ASCII
 #include <QString>
 
-#if ( QT_VERSION < QT_VERSION_CHECK(5, 11, 0) )
-# error Update your Qt version to at least 5.11.0
-#endif
+static_assert (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0),
+               "Update your Qt version to at least 5.11.0");
 
 #if ( QT_VERSION < QT_VERSION_CHECK(5, 15, 0) )
 # define QSIGNALMAPPER_MAPPEDINT_SIGNAL QOverload<int>::of(&QSignalMapper::mapped)


=====================================
modules/mux/mpeg/ts.c
=====================================
@@ -31,6 +31,7 @@
 # include "config.h"
 #endif
 
+#include <assert.h>
 #include <limits.h>
 
 #include <vlc_common.h>
@@ -184,9 +185,8 @@ static const char *const ts_standards_list_text[] =
 #define SOUT_CFG_PREFIX "sout-ts-"
 #define MAX_PMT 64       /* Maximum number of programs. FIXME: I just chose an arbitrary number. Where is the maximum in the spec? */
 #define MAX_PMT_PID 64       /* Maximum pids in each pmt.  FIXME: I just chose an arbitrary number. Where is the maximum in the spec? */
-#if MAX_SDT_DESC < MAX_PMT
-  #error "MAX_SDT_DESC < MAX_PMT"
-#endif
+
+static_assert (MAX_SDT_DESC >= MAX_PMT, "MAX_SDT_DESC < MAX_PMT");
 
 #define BLOCK_FLAG_NO_KEYFRAME (1 << BLOCK_FLAG_PRIVATE_SHIFT) /* This is not a key frame for bitrate shaping */
 


=====================================
modules/stream_filter/cache_read.c
=====================================
@@ -520,9 +520,8 @@ static int Open(vlc_object_t *obj)
 
     sys->i_used   = 0;
     sys->i_read_size = STREAM_READ_ATONCE;
-#if STREAM_READ_ATONCE < 256
-#   error "Invalid STREAM_READ_ATONCE value"
-#endif
+    static_assert (STREAM_READ_ATONCE >= 256,
+                   "Invalid STREAM_READ_ATONCE value");
 
     for (unsigned i = 0; i < STREAM_CACHE_TRACK; i++)
     {


=====================================
src/clock/input_clock.c
=====================================
@@ -459,9 +459,8 @@ void input_clock_SetJitter( input_clock_t *cl,
 
 vlc_tick_t input_clock_GetJitter( input_clock_t *cl )
 {
-#if INPUT_CLOCK_LATE_COUNT != 3
-#   error "unsupported INPUT_CLOCK_LATE_COUNT"
-#endif
+    static_assert (INPUT_CLOCK_LATE_COUNT == 3,
+                   "unsupported INPUT_CLOCK_LATE_COUNT");
     /* Find the median of the last late values
      * It works pretty well at rejecting bad values
      *



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/815116d80ceecd79f654fdd49de7f52adbfc42b5

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/815116d80ceecd79f654fdd49de7f52adbfc42b5
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list