Commit 80d88b05 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Mark unreachable code on GCC even if NDEBUG

This might suppress some warnings (and very slightly reduce code size)
when assertions are disabled. Not that I particularly like to create
VLC-specific macros.
parent c63f722d
......@@ -114,11 +114,15 @@
#ifdef __GNUC__
# define likely(p) __builtin_expect(!!(p), 1)
# define unlikely(p) __builtin_expect(!!(p), 0)
# define unreachable() __builtin_unreachable()
#else
# define likely(p) (!!(p))
# define unlikely(p) (!!(p))
# define unreachable() ((void)0)
#endif
#define vlc_assert_unreachable() (assert(!"unreachable"), unreachable())
/* Linkage */
#ifdef __cplusplus
# define VLC_EXTERN extern "C"
......
......@@ -373,7 +373,7 @@ int event_attach( libvlc_event_manager_t * p_event_manager,
free(listener);
fprintf( stderr, "This object event manager doesn't know about '%s' events",
libvlc_event_type_name(event_type) );
assert(0);
vlc_assert_unreachable();
return -1;
}
......
......@@ -773,7 +773,7 @@ static int onMouseEvent(vlc_object_t *p_vout, const char *psz_var, vlc_value_t o
bd_mouse_select(p_sys->bluray, now, val.coords.x, val.coords.y);
bd_user_input(p_sys->bluray, now, BD_VK_MOUSE_ACTIVATE);
} else {
assert(0);
vlc_assert_unreachable();
}
return VLC_SUCCESS;
}
......
......@@ -2108,7 +2108,7 @@ void en50221_Poll( cam_t * p_cam )
case CA_CI:
return;
default:
assert( 0 );
vlc_assert_unreachable();
}
for ( unsigned i_slot = 0; i_slot < p_cam->i_nb_slots; i_slot++ )
......
......@@ -366,7 +366,7 @@ static ssize_t StreamRead (access_t *p_access, uint8_t *p_buffer, size_t i_len)
static int NoSeek (access_t *p_access, uint64_t i_pos)
{
/* assert(0); ?? */
/* vlc_assert_unreachable(); ?? */
(void) p_access; (void) i_pos;
return VLC_EGENERIC;
}
......
......@@ -429,7 +429,7 @@ connect:
break;
default:
assert(0);
vlc_assert_unreachable();
}
if( p_sys->i_code == 401 )
......
......@@ -2107,7 +2107,7 @@ static void* TimeoutPrevention( void *p_data )
msleep (((int64_t)p_timeout->p_sys->i_timeout - 2) * CLOCK_FREQ);
}
assert(0); /* dead code */
vlc_assert_unreachable(); /* dead code */
}
/*****************************************************************************
......
......@@ -1573,7 +1573,7 @@ static void *KeepAliveThread( void *p_data )
msleep( 10 * CLOCK_FREQ );
}
assert(0);
vlc_assert_unreachable();
}
static void KeepAliveStart( access_t *p_access )
......
......@@ -172,7 +172,7 @@ static int ControlSetCallback (vlc_object_t *obj, const char *var,
ret = ControlSetStr (ctrl, cur.psz_string);
break;
default:
assert (0);
vlc_assert_unreachable ();
}
if (ret)
......
......@@ -631,7 +631,7 @@ static void *MmapThread (void *data)
#endif
}
assert (0);
vlc_assert_unreachable ();
}
static void *ReadThread (void *data)
......@@ -693,7 +693,7 @@ static void *ReadThread (void *data)
GrabVBI (demux, sys->vbi);
#endif
}
assert (0);
vlc_assert_unreachable ();
}
static int DemuxControl( demux_t *demux, int query, va_list args )
......
......@@ -159,8 +159,7 @@ static inline uint32_t CanonicaliseChannels( uint32_t i_physical_channels )
if( (i_physical_channels & ~valid_channels[i]) == 0 )
return valid_channels[i];
assert( false );
return 0;
vlc_assert_unreachable();
}
/*****************************************************************************
......
......@@ -224,7 +224,7 @@ static int Start (audio_output_t *aout, audio_sample_format_t *fmt)
fmt->i_physical_channels = AOUT_CHANS_7_1;
break;
default:
assert(0);
vlc_assert_unreachable();
}
fmt->i_format = VLC_CODEC_S16N;
......
......@@ -611,8 +611,7 @@ JNIThread( void *data )
&p_sys->p_cmd->out.time_get.i_delay );
break;
default:
assert( false );
break;
vlc_assert_unreachable();
}
if( b_error )
p_sys->b_thread_run = false;
......
......@@ -430,7 +430,7 @@ static void context_cb(pa_context *ctx, pa_subscription_event_type_t type,
break;
default: /* unsubscribed facility?! */
assert(0);
vlc_assert_unreachable();
}
}
......
......@@ -479,7 +479,7 @@ static int Eia608GetWritingScreenIndex( eia608_t *h )
return h->i_screen;
default:
/* It cannot happen, else it is a bug */
assert( 0 );
vlc_assert_unreachable();
return 0;
}
}
......
......@@ -273,7 +273,7 @@ static int OpenCommon( vlc_object_t *p_this, bool b_packetizer )
p_dec->fmt_out.i_codec = VLC_CODEC_WIDI_LPCM;
break;
default:
assert(0);
vlc_assert_unreachable();
case LPCM_BD:
p_dec->fmt_out.i_codec = VLC_CODEC_BD_LPCM;
break;
......@@ -451,7 +451,7 @@ static block_t *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
AobExtract( p_aout_buffer, p_block, i_bits, p_aob_group );
break;
default:
assert(0);
vlc_assert_unreachable();
case LPCM_BD:
BdExtract( p_aout_buffer, p_block, i_frame_length, i_channels, i_channels_padding, i_bits );
break;
......@@ -575,7 +575,7 @@ static block_t *EncodeFrames( encoder_t *p_enc, block_t *p_aout_buf )
i_freq_code = 3;
break;
default:
assert(0);
vlc_assert_unreachable();
}
int i_bytes_consumed = 0;
......
......@@ -630,7 +630,7 @@ static void ProcessEvents( intf_thread_t *p_intf,
break;
}
default:
assert(0);
vlc_assert_unreachable();
}
free( p_events[i] );
}
......@@ -1015,7 +1015,7 @@ static int AllCallback( vlc_object_t *p_this, const char *psz_var,
else if( !strcmp( "can-pause", psz_var ) )
info.signal = SIGNAL_CAN_PAUSE;
else
assert(0);
vlc_assert_unreachable();
if( info.signal == SIGNAL_NONE )
return VLC_SUCCESS;
......
......@@ -188,7 +188,7 @@ static void *RunIntf( void *data )
vlc_restorecancel( canc );
}
assert(0);
vlc_assert_unreachable();
}
#undef LOW_THRESHOLD
#undef HIGH_THRESHOLD
......@@ -194,7 +194,7 @@ static int GetOrientation( motion_sensors_t *motion )
return 0;
#endif
default:
assert( 0 );
vlc_assert_unreachable();
}
}
......
......@@ -1540,7 +1540,7 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
}
else
/* This case can't happen */
assert( 0 );
vlc_assert_unreachable();
if( newval.psz_string && *newval.psz_string )
{
......
......@@ -220,7 +220,7 @@ static CGEventRef tapEventCallback2(CGEventTapProxy proxy, CGEventType type, CGE
}
@catch (NSException * e) {
NSLog(@"Strange CGEventType: %d: %@", type, e);
assert(0);
vlc_assert_unreachable();
return event;
}
......
......@@ -389,7 +389,7 @@ bool checkProgressPanel (void *priv)
ret = 3;
break;
default:
assert(0);
vlc_assert_unreachable();
ret = 0;
break;
}
......@@ -666,7 +666,7 @@ static NSView *createControlFromWidget(extension_widget_t *widget, id self)
return spinner;
}
default:
assert(0);
vlc_assert_unreachable();
return nil;
}
......
......@@ -94,7 +94,7 @@ int PLItem::id( int type )
return i_playlist_id;
default:
case MLMEDIA_ID:
assert( 0 );
vlc_assert_unreachable();
return -1;
}
}
......
......@@ -787,7 +787,7 @@ void StandardPLPanel::cycleViews()
#endif
showView( ICON_VIEW );
else
assert( 0 );
vlc_assert_unreachable();
}
void StandardPLPanel::activate( const QModelIndex &index )
......
......@@ -149,7 +149,7 @@ void SoutDialog::addDest( )
caption = "Icecast";
break;
default:
assert(0);
vlc_assert_unreachable();
return;
}
......
......@@ -301,7 +301,7 @@ void InputManager::customEvent( QEvent *event )
break;
default:
msg_Warn( p_intf, "This shouldn't happen: %i", i_type );
assert(0);
vlc_assert_unreachable();
}
}
......
......@@ -693,7 +693,7 @@ static int WindowOpen( vout_window_t *p_wnd, const vout_window_cfg_t *cfg )
p_wnd->handle.nsobject = (void *)wid;
break;
default:
assert(0);
vlc_assert_unreachable();
}
p_wnd->control = WindowControl;
......
......@@ -381,7 +381,7 @@ static picture_t *VideoImport(filter_t *filter, picture_t *src)
fmt.i_chroma = VLC_CODEC_VDPAU_VIDEO_444;
break;
default:
assert(0);
vlc_assert_unreachable();
}
picture_t *dst = picture_NewFromFormat(&fmt);
......@@ -433,7 +433,7 @@ static picture_t *VideoRender(filter_t *filter, picture_t *src)
case VDP_CHROMA_TYPE_420: fmt.i_chroma = VLC_CODEC_NV12; break;
case VDP_CHROMA_TYPE_422: fmt.i_chroma = VLC_CODEC_UYVY; break;
case VDP_CHROMA_TYPE_444: fmt.i_chroma = VLC_CODEC_NV24; break;
default: assert(0);
default: vlc_assert_unreachable();
}
picture_t *pic = picture_NewFromFormat(&fmt);
......
......@@ -248,7 +248,7 @@ static void *Run( void *data )
vlc_restorecancel (canc);
}
vlc_cleanup_pop();
assert(0); /* dead code */
vlc_assert_unreachable(); /* dead code */
}
static int UrlsChange( vlc_object_t *p_this, char const *psz_var,
......
......@@ -603,7 +603,7 @@ static void *Run( void *data )
else if( timeout < 200 )
timeout = 200; /* Don't wakeup too fast. */
}
assert (0);
vlc_assert_unreachable ();
}
/**********************************************************************
......
......@@ -1499,7 +1499,7 @@ static void *rtp_listen_thread( void *data )
vlc_restorecancel( canc );
}
assert( 0 );
vlc_assert_unreachable();
}
......
......@@ -486,7 +486,7 @@ int rtp_get_fmt( vlc_object_t *obj, es_format_t *p_fmt, const char *mux,
c1 = c2 = 4;
break;
default:
assert(0);
vlc_assert_unreachable();
}
if( asprintf( &rtp_fmt->fmtp,
......@@ -1550,7 +1550,7 @@ static int rtp_packetize_rawvideo( sout_stream_id_sys_t *id, block_t *in, vlc_fo
i_xdec = i_ydec = 2;
break;
default:
assert(0);
vlc_assert_unreachable();
}
static const int RTP_HEADER_LEN = 12;
......@@ -1653,7 +1653,7 @@ static int rtp_packetize_rawvideo( sout_stream_id_sys_t *id, block_t *in, vlc_fo
p_outdata += i_length;
p_data += i_length;
}
else assert(0);
else vlc_assert_unreachable();
}
/* rtp common header */
......
......@@ -336,7 +336,7 @@ int RenderPhosphor( filter_t *p_filter,
break;
default:
/* The above are the only possibilities, if there are no bugs. */
assert(0);
vlc_assert_unreachable();
break;
}
}
......
......@@ -241,7 +241,7 @@ static void VerticalMirror( picture_t *p_pic, picture_t *p_outpic, int i_plane,
RV32VerticalMirror( p_pic, p_outpic, i_plane, b_left_to_right );
break;
default:
assert( false );
vlc_assert_unreachable();
}
}
......
......@@ -192,7 +192,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
PackedYUVPosterize( p_pic, p_outpic, level );
break;
default:
assert( false );
vlc_assert_unreachable();
}
return CopyInfoAndRelease( p_outpic, p_pic );
......@@ -316,7 +316,7 @@ static void PackedYUVPosterize( picture_t *p_pic, picture_t *p_outpic, int i_lev
u = *p_in++;
break;
default:
assert( false );
vlc_assert_unreachable();
}
/* do posterization */
YuvPosterization( &posterized_y1, &posterized_y2, &posterized_u,
......@@ -349,7 +349,7 @@ static void PackedYUVPosterize( picture_t *p_pic, picture_t *p_outpic, int i_lev
*p_out++ = posterized_u;
break;
default:
assert( false );
vlc_assert_unreachable();
}
}
p_in += p_pic->p[0].i_pitch - p_pic->p[0].i_visible_pitch;
......
......@@ -330,7 +330,7 @@ static int Control (vout_display_t *vd, int query, va_list ap)
}
case VOUT_DISPLAY_RESET_PICTURES:
assert (0);
vlc_assert_unreachable ();
default:
msg_Err (vd, "Unhandled request %d", query);
case VOUT_DISPLAY_CHANGE_FULLSCREEN:
......
......@@ -217,7 +217,7 @@ static int Control (vout_display_t *vd, int query, va_list ap)
break;
#ifndef NDEBUG
case VOUT_DISPLAY_RESET_PICTURES: // not needed
assert(0);
vlc_assert_unreachable();
#endif
case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
......
......@@ -315,7 +315,7 @@ static int Control(vout_display_t *vd, int query, va_list ap)
}
case VOUT_DISPLAY_RESET_PICTURES:
assert (0);
vlc_assert_unreachable ();
default:
msg_Err(vd, "Unknown request %d", query);
case VOUT_DISPLAY_CHANGE_FULLSCREEN:
......
......@@ -376,7 +376,7 @@ static int Control (vout_display_t *vd, int query, va_list ap)
}
case VOUT_DISPLAY_RESET_PICTURES:
assert (0);
vlc_assert_unreachable ();
default:
msg_Err (vd, "Unknown request in Mac OS X vout display");
return VLC_EGENERIC;
......
......@@ -619,7 +619,7 @@ int CommonControl(vout_display_t *vd, int query, va_list args)
EventThreadMouseHide(sys->event);
return VLC_SUCCESS;
case VOUT_DISPLAY_RESET_PICTURES:
assert(0);
vlc_assert_unreachable();
default:
return VLC_EGENERIC;
}
......
......@@ -173,7 +173,7 @@ static int Control(vout_display_t *vd, int query, va_list args)
{
switch (query) {
case VOUT_DISPLAY_RESET_PICTURES:
assert(0);
vlc_assert_unreachable();
return VLC_EGENERIC;
default:
return CommonControl(vd, query, args);
......
......@@ -87,7 +87,7 @@ static void *Thread(void *data)
wl_display_read_events(display);
wl_display_dispatch_pending(display);
}
assert(0);
vlc_assert_unreachable();
vlc_cleanup_pop();
//vlc_restorecancel(canc);
//return NULL;
......
......@@ -248,7 +248,7 @@ static int Control (vout_display_t *vd, int query, va_list ap)
return VLC_SUCCESS;
case VOUT_DISPLAY_RESET_PICTURES:
assert (0);
vlc_assert_unreachable ();
default:
msg_Err (vd, "Unknown request in XCB vout display");
return VLC_EGENERIC;
......
......@@ -769,7 +769,7 @@ static int Control (vout_display_t *vd, int query, va_list ap)
xcb_flush (p_sys->conn);
return VLC_SUCCESS;
case VOUT_DISPLAY_RESET_PICTURES:
assert(0);
vlc_assert_unreachable();
default:
msg_Err (vd, "Unknown request in XCB vout display");
return VLC_EGENERIC;
......
......@@ -446,7 +446,7 @@ static int Mouse( video_splitter_t *p_splitter, vlc_mouse_t *p_mouse,
}
}
}
assert(0);
vlc_assert_unreachable();
return VLC_EGENERIC;
}
......@@ -493,5 +493,5 @@ release:
vlc_restorecancel(canc);
}
assert(0);
vlc_assert_unreachable();
}
......@@ -381,7 +381,7 @@ static void *Thread( void *data )
block_Release( DoRealWork( p_filter, block ) );
vlc_restorecancel( canc );
}
assert(0);
vlc_assert_unreachable();
}
static block_t *DoWork( filter_t *p_filter, block_t *p_in_buf )
......
......@@ -184,7 +184,7 @@ bool window_init( int i_buffer_size, window_param * p_param,
}
default:
/* We should not reach here */
assert(0);
vlc_assert_unreachable();
break;
}
......
......@@ -303,7 +303,7 @@ int vlc_cond_timedwait (vlc_cond_t *condvar, vlc_mutex_t *p_mutex,
cb = pthread_cond_timedwait_monotonic_np;
break;
default:
assert (0);
vlc_assert_unreachable ();
}
int val = cb (&condvar->cond, p_mutex, &ts);
......
......@@ -373,7 +373,7 @@ do { \
case VLC_CODEC_FL32: INTERLEAVE_TYPE(float); break;
case VLC_CODEC_S32N: INTERLEAVE_TYPE(int32_t); break;
case VLC_CODEC_FL64: INTERLEAVE_TYPE(double); break;
default: assert(0);
default: vlc_assert_unreachable();
}
#undef INTERLEAVE_TYPE
}
......@@ -409,7 +409,7 @@ do { \
case VLC_CODEC_FL32: DEINTERLEAVE_TYPE(float); break;
case VLC_CODEC_S32N: DEINTERLEAVE_TYPE(int32_t); break;
case VLC_CODEC_FL64: DEINTERLEAVE_TYPE(double); break;
default: assert(0);
default: vlc_assert_unreachable();
}
#undef DEINTERLEAVE_TYPE
}
......
......@@ -132,7 +132,7 @@ static char *getAppDependentDir(vlc_userdir_t type)
psz_path = "%s/Library/Caches/%s";
break;
default:
assert(0);
vlc_assert_unreachable();
break;
}
......
......@@ -730,7 +730,7 @@ void vlc_testcancel (void)
void vlc_control_cancel (int cmd, ...)
{
(void) cmd;
assert (0);
vlc_assert_unreachable ();
}
/* Precision monotonic clock.
......
......@@ -2490,7 +2490,7 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args )
case ES_OUT_RESTART_ES_BY_ID: i_new_query = ES_OUT_RESTART_ES; break;
case ES_OUT_SET_ES_DEFAULT_BY_ID: i_new_query = ES_OUT_SET_ES_DEFAULT; break;
default:
assert(0);
vlc_assert_unreachable();
}
/* TODO if the lock is made non recursive it should be changed */
int i_ret = es_out_Control( out, i_new_query, p_es );
......
......@@ -583,7 +583,7 @@ static int ControlLocked( es_out_t *p_out, int i_query, va_list args )
case ES_OUT_GET_ES_OBJECTS_BY_ID:
case ES_OUT_SET_DELAY:
case ES_OUT_SET_RECORD_STATE:
assert(0);
vlc_assert_unreachable();
return VLC_EGENERIC;
/* Pass-through control */
......@@ -700,7 +700,7 @@ static int ControlLocked( es_out_t *p_out, int i_query, va_list args )
default:
msg_Err( p_sys->p_input, "Unknown es_out_Control query !" );
assert(0);
vlc_assert_unreachable();
return VLC_EGENERIC;
}
}
......@@ -1041,7 +1041,7 @@ static void *TsRun( void *p_data )
CmdExecuteDel( p_ts->p_out, &cmd );
break;
default:
assert(0);
vlc_assert_unreachable();
break;
}
vlc_restorecancel( canc );
......@@ -1222,7 +1222,7 @@ static void CmdClean( ts_cmd_t *p_cmd )
case C_DEL:
break;
default:
assert(0);
vlc_assert_unreachable();
break;
}
}
......@@ -1437,7 +1437,7 @@ static int CmdInitControl( ts_cmd_t *p_cmd, int i_query, va_list args, bool b_co
}
default:
assert(0);
vlc_assert_unreachable();
return VLC_EGENERIC;
}
......@@ -1506,7 +1506,7 @@ static int CmdExecuteControl( es_out_t *p_out, ts_cmd_t *p_cmd )
p_cmd->u.control.u.jitter.i_cr_average );
default:
assert(0);
vlc_assert_unreachable();
return VLC_EGENERIC;
}
}
......
......@@ -633,7 +633,7 @@ static int AStreamControl( stream_t *s, int i_query, va_list args )
case STREAM_METHOD_STREAM:
return AStreamSeekStream( s, offset );
default:
assert(0);
vlc_assert_unreachable();
return VLC_EGENERIC;
}
}
......
......@@ -270,7 +270,7 @@ int vlc_event_attach( vlc_event_manager_t * p_em,
}
FOREACH_END()
/* Unknown event = BUG */
assert( 0 );
vlc_assert_unreachable();
}
/**
......@@ -311,5 +311,5 @@ void vlc_event_detach( vlc_event_manager_t *p_em,
}
FOREACH_END()
assert( 0 );
vlc_assert_unreachable();
}
......@@ -255,7 +255,7 @@ int var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
p_var->ops = &void_ops;
break;
default:
assert (0);
vlc_assert_unreachable ();
}
if( (i_type & VLC_VAR_DOINHERIT)
......@@ -904,7 +904,7 @@ static int DelCallback( vlc_object_t *p_this, const char *psz_name,
if( b_found_similar )
fprintf( stderr, "Calling var_DelCallback for '%s' with the same "
"function but not the same data.", psz_name );
assert( 0 );
vlc_assert_unreachable();
#endif
vlc_mutex_unlock( &p_priv->var_lock );
return VLC_EGENERIC;
......@@ -1275,7 +1275,7 @@ int var_Inherit( vlc_object_t *p_this, const char *psz_name, int i_type,
p_val->b_bool = config_GetInt( p_this, psz_name );
break;
default:
assert(0);
vlc_assert_unreachable();
case VLC_VAR_ADDRESS:
return VLC_ENOOBJ;