[vlc-commits] medialib: Remove risky type deduction from list conversion
Hugo Beauzée-Luyssen
git at videolan.org
Wed Jul 18 17:08:05 CEST 2018
vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Wed Jul 18 15:38:21 2018 +0200| [0b2ac577ae96efc59768ef4c637d0ccacea9dc9e] | committer: Hugo Beauzée-Luyssen
medialib: Remove risky type deduction from list conversion
Since flexible arrays are only language extensions, it's unsafe to do
any assumption on what decltype(<flexible array>) will yield.
This fixes the build on gcc 5 (at least)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0b2ac577ae96efc59768ef4c637d0ccacea9dc9e
---
modules/misc/medialibrary/entities.cpp | 2 +-
modules/misc/medialibrary/medialib.cpp | 58 +++++++++++++++++++++-----------
modules/misc/medialibrary/medialibrary.h | 10 +++---
3 files changed, 46 insertions(+), 24 deletions(-)
diff --git a/modules/misc/medialibrary/entities.cpp b/modules/misc/medialibrary/entities.cpp
index 98a80ae141..66caa08c5b 100644
--- a/modules/misc/medialibrary/entities.cpp
+++ b/modules/misc/medialibrary/entities.cpp
@@ -241,7 +241,7 @@ bool Convert( const medialibrary::IMedia* input, vlc_ml_media_t& output )
return false;
auto files = input->files();
- output.p_files = ml_convert_list<vlc_ml_file_list_t>( files );
+ output.p_files = ml_convert_list<vlc_ml_file_list_t, vlc_ml_file_t>( files );
if ( output.p_files == nullptr )
return false;
diff --git a/modules/misc/medialibrary/medialib.cpp b/modules/misc/medialibrary/medialib.cpp
index 20607e28ce..b455424afa 100644
--- a/modules/misc/medialibrary/medialib.cpp
+++ b/modules/misc/medialibrary/medialib.cpp
@@ -404,7 +404,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
query = m_ml->searchVideo( psz_pattern, paramsPtr );
else
query = m_ml->videoFiles( paramsPtr );
- auto res = ml_convert_list<vlc_ml_media_list_t>( query->items( nbItems, offset ) );
+ auto res = ml_convert_list<vlc_ml_media_list_t, vlc_ml_media_t>(
+ query->items( nbItems, offset ) );
*va_arg( args, vlc_ml_media_list_t**) = res;
break;
}
@@ -425,7 +426,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
query = m_ml->searchAudio( psz_pattern, paramsPtr );
else
query = m_ml->audioFiles( paramsPtr );
- auto res = ml_convert_list<vlc_ml_media_list_t>( query->items( nbItems, offset ) );
+ auto res = ml_convert_list<vlc_ml_media_list_t, vlc_ml_media_t>(
+ query->items( nbItems, offset ) );
*va_arg( args, vlc_ml_media_list_t**) = res;
break;
}
@@ -446,7 +448,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
query = m_ml->searchAlbums( psz_pattern, paramsPtr );
else
query = m_ml->albums( paramsPtr );
- auto res = ml_convert_list<vlc_ml_album_list_t>( query->items( nbItems, offset ) );
+ auto res = ml_convert_list<vlc_ml_album_list_t, vlc_ml_album_t>(
+ query->items( nbItems, offset ) );
*va_arg( args, vlc_ml_album_list_t**) = res;
break;
}
@@ -467,7 +470,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
query = m_ml->searchGenre( psz_pattern, paramsPtr );
else
query = m_ml->genres( paramsPtr );
- auto res = ml_convert_list<vlc_ml_genre_list_t>( query->items( nbItems, offset ) );
+ auto res = ml_convert_list<vlc_ml_genre_list_t,vlc_ml_genre_t>(
+ query->items( nbItems, offset ) );
*va_arg( args, vlc_ml_genre_list_t**) = res;
break;
}
@@ -491,7 +495,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
{
query = m_ml->artists( includeAll, paramsPtr );
}
- auto res = ml_convert_list<vlc_ml_artist_list_t>( query->items( nbItems, offset ) );
+ auto res = ml_convert_list<vlc_ml_artist_list_t, vlc_ml_artist_t>(
+ query->items( nbItems, offset ) );
*va_arg( args, vlc_ml_artist_list_t**) = res;
break;
}
@@ -524,7 +529,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
switch ( listQuery )
{
case VLC_ML_LIST_MEDIA_LABELS:
- *va_arg( args, vlc_ml_label_list_t**) = ml_convert_list<vlc_ml_label_list_t>(
+ *va_arg( args, vlc_ml_label_list_t**) =
+ ml_convert_list<vlc_ml_label_list_t, vlc_ml_label_t>(
query->items( nbItems, offset ) );
return VLC_SUCCESS;
case VLC_ML_COUNT_MEDIA_LABELS:
@@ -541,7 +547,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
query = m_ml->searchShows( psz_pattern, paramsPtr );
else
query = m_ml->shows( paramsPtr );
- *va_arg( args, vlc_ml_show_list_t** ) = ml_convert_list<vlc_ml_show_list_t>(
+ *va_arg( args, vlc_ml_show_list_t** ) =
+ ml_convert_list<vlc_ml_show_list_t, vlc_ml_show_t>(
query->items( nbItems, offset ) );
return VLC_SUCCESS;
}
@@ -565,7 +572,8 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
switch ( listQuery )
{
case VLC_ML_LIST_SHOW_EPISODES:
- *va_arg( args, vlc_ml_media_list_t**) = ml_convert_list<vlc_ml_media_list_t>(
+ *va_arg( args, vlc_ml_media_list_t**) =
+ ml_convert_list<vlc_ml_media_list_t, vlc_ml_media_t>(
query->items( nbItems, offset ) );
return VLC_SUCCESS;
case VLC_ML_COUNT_SHOW_EPISODES:
@@ -583,14 +591,16 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
case VLC_ML_LIST_HISTORY:
{
auto query = m_ml->history();
- *va_arg( args, vlc_ml_media_list_t**) = ml_convert_list<vlc_ml_media_list_t>(
+ *va_arg( args, vlc_ml_media_list_t**) =
+ ml_convert_list<vlc_ml_media_list_t, vlc_ml_media_t>(
query->items( nbItems, offset ) );
return VLC_SUCCESS;
}
case VLC_ML_LIST_STREAM_HISTORY:
{
auto query = m_ml->streamHistory();
- *va_arg( args, vlc_ml_media_list_t**) = ml_convert_list<vlc_ml_media_list_t>(
+ *va_arg( args, vlc_ml_media_list_t**) =
+ ml_convert_list<vlc_ml_media_list_t, vlc_ml_media_t>(
query->items( nbItems, offset ) );
return VLC_SUCCESS;
}
@@ -910,7 +920,8 @@ int MediaLibrary::listAlbums( int listQuery, const medialibrary::QueryParameters
switch ( listQuery )
{
case VLC_ML_LIST_ALBUM_TRACKS:
- *va_arg( args, vlc_ml_media_list_t**) = ml_convert_list<vlc_ml_media_list_t>(
+ *va_arg( args, vlc_ml_media_list_t**) =
+ ml_convert_list<vlc_ml_media_list_t, vlc_ml_media_t>(
query->items( nbItems, offset ) );
return VLC_SUCCESS;
case VLC_ML_COUNT_ALBUM_TRACKS:
@@ -927,7 +938,8 @@ int MediaLibrary::listAlbums( int listQuery, const medialibrary::QueryParameters
switch ( listQuery )
{
case VLC_ML_LIST_ALBUM_ARTISTS:
- *va_arg( args, vlc_ml_artist_list_t**) = ml_convert_list<vlc_ml_artist_list_t>(
+ *va_arg( args, vlc_ml_artist_list_t**) =
+ ml_convert_list<vlc_ml_artist_list_t, vlc_ml_artist_t>(
query->items( nbItems, offset ) );
return VLC_SUCCESS;
case VLC_ML_COUNT_ALBUM_ARTISTS:
@@ -962,7 +974,8 @@ int MediaLibrary::listArtists( int listQuery, const medialibrary::QueryParameter
switch ( listQuery )
{
case VLC_ML_LIST_ARTIST_ALBUMS:
- *va_arg( args, vlc_ml_album_list_t**) = ml_convert_list<vlc_ml_album_list_t>(
+ *va_arg( args, vlc_ml_album_list_t**) =
+ ml_convert_list<vlc_ml_album_list_t, vlc_ml_album_t>(
query->items( nbItems, offset ) );
return VLC_SUCCESS;
case VLC_ML_COUNT_ARTIST_ALBUMS:
@@ -983,7 +996,8 @@ int MediaLibrary::listArtists( int listQuery, const medialibrary::QueryParameter
switch ( listQuery )
{
case VLC_ML_LIST_ARTIST_TRACKS:
- *va_arg( args, vlc_ml_media_list_t**) = ml_convert_list<vlc_ml_media_list_t>(
+ *va_arg( args, vlc_ml_media_list_t**) =
+ ml_convert_list<vlc_ml_media_list_t, vlc_ml_media_t>(
query->items( nbItems, offset ) );
return VLC_SUCCESS;
case VLC_ML_COUNT_ARTIST_TRACKS:
@@ -1017,7 +1031,8 @@ int MediaLibrary::listGenre( int listQuery, const medialibrary::QueryParameters*
switch ( listQuery )
{
case VLC_ML_LIST_GENRE_ARTISTS:
- *va_arg( args, vlc_ml_artist_list_t**) = ml_convert_list<vlc_ml_artist_list_t>(
+ *va_arg( args, vlc_ml_artist_list_t**) =
+ ml_convert_list<vlc_ml_artist_list_t, vlc_ml_artist_t>(
query->items( nbItems, offset ) );
return VLC_SUCCESS;
case VLC_ML_COUNT_GENRE_ARTISTS:
@@ -1038,7 +1053,9 @@ int MediaLibrary::listGenre( int listQuery, const medialibrary::QueryParameters*
switch ( listQuery )
{
case VLC_ML_LIST_GENRE_TRACKS:
- *va_arg( args, vlc_ml_media_list_t**) = ml_convert_list<vlc_ml_media_list_t>( query->items( nbItems, offset ) );
+ *va_arg( args, vlc_ml_media_list_t**) =
+ ml_convert_list<vlc_ml_media_list_t, vlc_ml_media_t>(
+ query->items( nbItems, offset ) );
return VLC_SUCCESS;
case VLC_ML_COUNT_GENRE_TRACKS:
*va_arg( args, size_t*) = query->count();
@@ -1058,7 +1075,8 @@ int MediaLibrary::listGenre( int listQuery, const medialibrary::QueryParameters*
switch ( listQuery )
{
case VLC_ML_LIST_GENRE_ALBUMS:
- *va_arg( args, vlc_ml_album_list_t**) = ml_convert_list<vlc_ml_album_list_t>(
+ *va_arg( args, vlc_ml_album_list_t**) =
+ ml_convert_list<vlc_ml_album_list_t, vlc_ml_album_t>(
query->items( nbItems, offset ) );
return VLC_SUCCESS;
case VLC_ML_COUNT_GENRE_ALBUMS:
@@ -1089,7 +1107,8 @@ int MediaLibrary::listPlaylist( int listQuery, const medialibrary::QueryParamete
switch ( listQuery )
{
case VLC_ML_LIST_PLAYLISTS:
- *va_arg( args, vlc_ml_playlist_list_t** ) = ml_convert_list<vlc_ml_playlist_list_t>(
+ *va_arg( args, vlc_ml_playlist_list_t** ) =
+ ml_convert_list<vlc_ml_playlist_list_t, vlc_ml_playlist_t>(
query->items( nbItems, offset ) );
return VLC_SUCCESS;
case VLC_ML_COUNT_PLAYLISTS:
@@ -1113,7 +1132,8 @@ int MediaLibrary::listPlaylist( int listQuery, const medialibrary::QueryParamete
switch ( listQuery )
{
case VLC_ML_LIST_PLAYLIST_MEDIA:
- *va_arg( args, vlc_ml_media_list_t**) = ml_convert_list<vlc_ml_media_list_t>(
+ *va_arg( args, vlc_ml_media_list_t**) =
+ ml_convert_list<vlc_ml_media_list_t, vlc_ml_media_t>(
query->items( nbItems, offset ) );
return VLC_SUCCESS;
case VLC_ML_COUNT_PLAYLIST_MEDIA:
diff --git a/modules/misc/medialibrary/medialibrary.h b/modules/misc/medialibrary/medialibrary.h
index 0b2a86abe0..8246704f8c 100644
--- a/modules/misc/medialibrary/medialibrary.h
+++ b/modules/misc/medialibrary/medialibrary.h
@@ -172,17 +172,19 @@ bool Convert( const medialibrary::IShow* input, vlc_ml_show_t& output );
bool Convert( const medialibrary::ILabel* input, vlc_ml_label_t& output );
bool Convert( const medialibrary::IPlaylist* input, vlc_ml_playlist_t& output );
-template <typename To, typename From>
+template <typename To, typename ItemType, typename From>
To* ml_convert_list( const std::vector<std::shared_ptr<From>>& input )
{
// This function uses duck typing and assumes all lists have a p_items member
static_assert( std::is_pointer<To>::value == false,
"Destination type must not be a pointer" );
- static_assert( std::is_array<decltype(To::p_items)>::value == true,
- "Missing or invalid p_items member" );
+ // If decltype( To::p_items ) doesn't yield an array type, we can't deduce
+ // the items type. however if it does, we can ensure To and ItemType are coherent
+ static_assert( std::is_array<decltype(To::p_items)>::value == false ||
+ ( std::is_same<typename std::remove_extent<decltype(To::p_items)>::type,
+ ItemType>::value ), "Invalid/mismatching list/item types" );
// Allocate the ml_*_list_t
- using ItemType = typename std::remove_extent<decltype(To::p_items)>::type;
auto list = vlc::wrap_cptr(
static_cast<To*>( malloc( sizeof( To ) + input.size() * sizeof( ItemType ) ) ),
static_cast<void(*)(To*)>( &vlc_ml_release_obj ) );
More information about the vlc-commits
mailing list