[vlc-commits] include: do not issue assertions in external plug-ins

Rémi Denis-Courmont git at videolan.org
Mon Jul 2 20:52:23 CEST 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Jul  2 21:45:54 2018 +0300| [c85147a421b3bad8e5f4de0cfb365a491622259a] | committer: Rémi Denis-Courmont

include: do not issue assertions in external plug-ins

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c85147a421b3bad8e5f4de0cfb365a491622259a
---

 include/vlc_codec.h   | 41 ++++++++++++++++++++++++-----------------
 include/vlc_common.h  | 21 ++++++++++++++++++++-
 include/vlc_picture.h |  2 +-
 3 files changed, 45 insertions(+), 19 deletions(-)

diff --git a/include/vlc_codec.h b/include/vlc_codec.h
index 9d5c8de25c..b3f8ea35a0 100644
--- a/include/vlc_codec.h
+++ b/include/vlc_codec.h
@@ -271,7 +271,8 @@ struct encoder_t
 VLC_USED
 static inline int decoder_UpdateVideoFormat( decoder_t *dec )
 {
-    assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
+    vlc_assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
+
     if( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs->video.format_update != NULL )
         return dec->cbs->video.format_update( dec );
     else
@@ -298,7 +299,7 @@ static inline int decoder_UpdateVideoFormat( decoder_t *dec )
 VLC_USED
 static inline picture_t *decoder_NewPicture( decoder_t *dec )
 {
-    assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
+    vlc_assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
     return dec->cbs->video.buffer_new( dec );
 }
 
@@ -321,9 +322,9 @@ VLC_API void decoder_AbortPictures( decoder_t *dec, bool b_abort );
  */
 static inline void decoder_QueueVideo( decoder_t *dec, picture_t *p_pic )
 {
-    assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
-    assert( p_pic->p_next == NULL );
-    assert( dec->cbs->video.queue != NULL );
+    vlc_assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
+    vlc_assert( p_pic->p_next == NULL );
+    vlc_assert( dec->cbs->video.queue != NULL );
     dec->cbs->video.queue( dec, p_pic );
 }
 
@@ -337,7 +338,8 @@ static inline void decoder_QueueVideo( decoder_t *dec, picture_t *p_pic )
 static inline void decoder_QueueCc( decoder_t *dec, block_t *p_cc,
                                    const decoder_cc_desc_t *p_desc )
 {
-    assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
+    vlc_assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
+
     if( dec->cbs->video.queue_cc == NULL )
         block_Release( p_cc );
     else
@@ -353,9 +355,9 @@ static inline void decoder_QueueCc( decoder_t *dec, block_t *p_cc,
  */
 static inline void decoder_QueueAudio( decoder_t *dec, block_t *p_aout_buf )
 {
-    assert( dec->fmt_in.i_cat == AUDIO_ES && dec->cbs != NULL );
-    assert( p_aout_buf->p_next == NULL );
-    assert( dec->cbs->audio.queue != NULL );
+    vlc_assert( dec->fmt_in.i_cat == AUDIO_ES && dec->cbs != NULL );
+    vlc_assert( p_aout_buf->p_next == NULL );
+    vlc_assert( dec->cbs->audio.queue != NULL );
     dec->cbs->audio.queue( dec, p_aout_buf );
 }
 
@@ -368,9 +370,9 @@ static inline void decoder_QueueAudio( decoder_t *dec, block_t *p_aout_buf )
  */
 static inline void decoder_QueueSub( decoder_t *dec, subpicture_t *p_spu )
 {
-    assert( dec->fmt_in.i_cat == SPU_ES && dec->cbs != NULL );
-    assert( p_spu->p_next == NULL );
-    assert( dec->cbs->spu.queue != NULL );
+    vlc_assert( dec->fmt_in.i_cat == SPU_ES && dec->cbs != NULL );
+    vlc_assert( p_spu->p_next == NULL );
+    vlc_assert( dec->cbs->spu.queue != NULL );
     dec->cbs->spu.queue( dec, p_spu );
 }
 
@@ -382,7 +384,8 @@ static inline void decoder_QueueSub( decoder_t *dec, subpicture_t *p_spu )
 VLC_USED
 static inline int decoder_UpdateAudioFormat( decoder_t *dec )
 {
-    assert( dec->fmt_in.i_cat == AUDIO_ES && dec->cbs != NULL );
+    vlc_assert( dec->fmt_in.i_cat == AUDIO_ES && dec->cbs != NULL );
+
     if( dec->fmt_in.i_cat == AUDIO_ES && dec->cbs->audio.format_update != NULL )
         return dec->cbs->audio.format_update( dec );
     else
@@ -405,7 +408,8 @@ VLC_USED
 static inline subpicture_t *decoder_NewSubpicture( decoder_t *dec,
                                                    const subpicture_updater_t *p_dyn )
 {
-    assert( dec->fmt_in.i_cat == SPU_ES && dec->cbs != NULL );
+    vlc_assert( dec->fmt_in.i_cat == SPU_ES && dec->cbs != NULL );
+
     subpicture_t *p_subpicture = dec->cbs->spu.buffer_new( dec, p_dyn );
     if( !p_subpicture )
         msg_Warn( dec, "can't get output subpicture" );
@@ -421,7 +425,8 @@ static inline int decoder_GetInputAttachments( decoder_t *dec,
                                                input_attachment_t ***ppp_attachment,
                                                int *pi_attachment )
 {
-    assert( dec->cbs != NULL );
+    vlc_assert( dec->cbs != NULL );
+
     if( !dec->cbs->get_attachments )
         return VLC_EGENERIC;
 
@@ -436,7 +441,8 @@ static inline int decoder_GetInputAttachments( decoder_t *dec,
 VLC_USED
 static inline vlc_tick_t decoder_GetDisplayDate( decoder_t *dec, vlc_tick_t i_ts )
 {
-    assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
+    vlc_assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
+
     if( !dec->cbs->video.get_display_date )
         return VLC_TS_INVALID;
 
@@ -450,7 +456,8 @@ static inline vlc_tick_t decoder_GetDisplayDate( decoder_t *dec, vlc_tick_t i_ts
 VLC_USED
 static inline float decoder_GetDisplayRate( decoder_t *dec )
 {
-    assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
+    vlc_assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
+
     if( !dec->cbs->video.get_display_rate )
         return 1.f;
 
diff --git a/include/vlc_common.h b/include/vlc_common.h
index e94af42203..c88503c1a5 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -246,7 +246,26 @@
  * If the branch is reached in a non-debug build, this macro is equivalent to
  * \ref unreachable and the behaviour is undefined.
  */
-#define vlc_assert_unreachable() (assert(!"unreachable"), unreachable())
+#define vlc_assert_unreachable() (vlc_assert(!"unreachable"), unreachable())
+
+/**
+ * Run-time assertion
+ *
+ * This macro performs a run-time assertion if C assertions are enabled
+ * and the following preprocessor symbol is defined:
+ * @verbatim __LIBVLC__ @endverbatim
+ * That restriction ensures that assertions in public header files are not
+ * unwittingly <i>leaked</i> to externally-compiled plug-ins
+ * including those header files.
+ *
+ * Within the LibVLC code base, this is exactly the same as assert(), which can
+ * and probably should be used directly instead.
+ */
+#ifdef __LIBVLC__
+# define vlc_assert(pred) assert(pred)
+#else
+# define vlc_assert(pred) ((void)0)
+#endif
 
 /* Linkage */
 #ifdef __cplusplus
diff --git a/include/vlc_picture.h b/include/vlc_picture.h
index dc6dc68573..f9d55b3175 100644
--- a/include/vlc_picture.h
+++ b/include/vlc_picture.h
@@ -263,7 +263,7 @@ enum
  */
 static inline void picture_SwapUV(picture_t *picture)
 {
-    assert(picture->i_planes == 3);
+    vlc_assert(picture->i_planes == 3);
 
     plane_t tmp_plane   = picture->p[U_PLANE];
     picture->p[U_PLANE] = picture->p[V_PLANE];



More information about the vlc-commits mailing list