Commit f063bb30 authored by Filip Roséen's avatar Filip Roséen Committed by Rémi Denis-Courmont
Browse files

input/mrl_helpers: remove usage of vlc_array_{new, destroy} vlc_array_new


Signed-off-by: Rémi Denis-Courmont's avatarRémi Denis-Courmont <remi@remlab.net>
parent efcf185a
...@@ -2261,7 +2261,7 @@ static int ...@@ -2261,7 +2261,7 @@ static int
InputStreamHandleAnchor( input_source_t *source, stream_t **stream, InputStreamHandleAnchor( input_source_t *source, stream_t **stream,
char const *anchor ) char const *anchor )
{ {
vlc_array_t* identifiers = NULL; vlc_array_t identifiers;
char const* extra; char const* extra;
if( mrl_FragmentSplit( &identifiers, &extra, anchor ) ) if( mrl_FragmentSplit( &identifiers, &extra, anchor ) )
...@@ -2274,9 +2274,9 @@ InputStreamHandleAnchor( input_source_t *source, stream_t **stream, ...@@ -2274,9 +2274,9 @@ InputStreamHandleAnchor( input_source_t *source, stream_t **stream,
&source->i_title_start, &source->i_title_end, &source->i_title_start, &source->i_title_end,
&source->i_seekpoint_start, &source->i_seekpoint_end ); &source->i_seekpoint_start, &source->i_seekpoint_end );
while( vlc_array_count( identifiers ) ) while( vlc_array_count( &identifiers ) )
{ {
char* id = vlc_array_item_at_index( identifiers, 0 ); char* id = vlc_array_item_at_index( &identifiers, 0 );
if( vlc_stream_extractor_Attach( stream, id, NULL ) ) if( vlc_stream_extractor_Attach( stream, id, NULL ) )
{ {
...@@ -2286,16 +2286,16 @@ InputStreamHandleAnchor( input_source_t *source, stream_t **stream, ...@@ -2286,16 +2286,16 @@ InputStreamHandleAnchor( input_source_t *source, stream_t **stream,
else else
msg_Dbg( source, "successfully located entity '%s' within stream", id ); msg_Dbg( source, "successfully located entity '%s' within stream", id );
vlc_array_remove( identifiers, 0 ); vlc_array_remove( &identifiers, 0 );
free( id ); free( id );
} }
int remaining = vlc_array_count( identifiers ); int remaining = vlc_array_count( &identifiers );
for( int i = 0; i < remaining; ++i ) for( int i = 0; i < remaining; ++i )
free( vlc_array_item_at_index( identifiers, i ) ); free( vlc_array_item_at_index( &identifiers, i ) );
vlc_array_destroy( identifiers ); vlc_array_clear( &identifiers );
if( remaining == 0 ) if( remaining == 0 )
{ {
......
...@@ -101,21 +101,24 @@ mrl_EscapeFragmentIdentifier( char** out, char const* payload ) ...@@ -101,21 +101,24 @@ mrl_EscapeFragmentIdentifier( char** out, char const* payload )
* See the \link mrl MRL-specification\endlink for detailed * See the \link mrl MRL-specification\endlink for detailed
* information regarding how `payload` will be interpreted. * information regarding how `payload` will be interpreted.
* *
* \param[out] out_items `*out_items` contains the individual entries on success * \warning On success, the caller has ownership of the contents of *out_items
* which means that it is responsible for freeing the individual
* elements, as well as cleaning the array itself.
*
* \param[out] out_items storage for a vlc_array_t that will contain the
* parsed identifiers on success.
* \param[out] out_extra `*out_extra` will point to any remaining data (if any) * \param[out] out_extra `*out_extra` will point to any remaining data (if any)
* \param[in] payload the data to parse * \param[in] payload the data to parse
* \return VLC_SUCCESS on success, an error-code on failure * \return VLC_SUCCESS on success, an error-code on failure
**/ **/
static inline int static inline int
mrl_FragmentSplit( vlc_array_t** out_items, mrl_FragmentSplit( vlc_array_t* out_items,
char const** out_extra, char const** out_extra,
char const* payload ) char const* payload )
{ {
vlc_array_t* items = vlc_array_new();
char const* extra = NULL; char const* extra = NULL;
if( unlikely( !items ) ) vlc_array_init( out_items );
return VLC_ENOMEM;
while( strncmp( payload, "!/", 2 ) == 0 ) while( strncmp( payload, "!/", 2 ) == 0 )
{ {
...@@ -127,7 +130,7 @@ mrl_FragmentSplit( vlc_array_t** out_items, ...@@ -127,7 +130,7 @@ mrl_FragmentSplit( vlc_array_t** out_items,
if( unlikely( !decoded ) || !vlc_uri_decode( decoded ) ) if( unlikely( !decoded ) || !vlc_uri_decode( decoded ) )
goto error; goto error;
vlc_array_append( items, decoded ); vlc_array_append( out_items, decoded );
payload += len; payload += len;
} }
...@@ -136,20 +139,19 @@ mrl_FragmentSplit( vlc_array_t** out_items, ...@@ -136,20 +139,19 @@ mrl_FragmentSplit( vlc_array_t** out_items,
if( *payload == '!' ) if( *payload == '!' )
goto error; goto error;
if( *payload == '?' && vlc_array_count( items ) ) if( *payload == '?' && vlc_array_count( out_items ) )
++payload; ++payload;
extra = payload; extra = payload;
} }
*out_items = items;
*out_extra = extra; *out_extra = extra;
return VLC_SUCCESS; return VLC_SUCCESS;
error: error:
for( size_t i = 0; i < vlc_array_count( items ); ++i ) for( size_t i = 0; i < vlc_array_count( out_items ); ++i )
free( vlc_array_item_at_index( items, i ) ); free( vlc_array_item_at_index( out_items, i ) );
vlc_array_destroy( items ); vlc_array_clear( out_items );
return VLC_EGENERIC;; return VLC_EGENERIC;;
} }
......
...@@ -70,13 +70,12 @@ int main (void) ...@@ -70,13 +70,12 @@ int main (void)
{ {
for (size_t i = 0; i < ARRAY_SIZE(testcase); ++i) for (size_t i = 0; i < ARRAY_SIZE(testcase); ++i)
{ {
vlc_array_t *out; vlc_array_t out;
const char *extra = NULL; const char *extra = NULL;
int ret = mrl_FragmentSplit(&out, &extra, testcase[i].payload); int ret = mrl_FragmentSplit(&out, &extra, testcase[i].payload);
if (testcase[i].success) if (testcase[i].success)
{ {
assert(ret == VLC_SUCCESS); assert(ret == VLC_SUCCESS);
assert(out != NULL);
if (extra != NULL) if (extra != NULL)
assert(strcmp(extra, testcase[i].extra) == 0); assert(strcmp(extra, testcase[i].extra) == 0);
else else
...@@ -85,8 +84,8 @@ int main (void) ...@@ -85,8 +84,8 @@ int main (void)
const char *p = testcase[i].payload + 2; const char *p = testcase[i].payload + 2;
for (int j = 0; testcase[i].results[j] != NULL; ++j) for (int j = 0; testcase[i].results[j] != NULL; ++j)
{ {
assert(j < vlc_array_count(out) && j < MAX_RESULT); assert(j < vlc_array_count(&out) && j < MAX_RESULT);
char *res = vlc_array_item_at_index(out, j); char *res = vlc_array_item_at_index(&out, j);
assert(strcmp(testcase[i].results[j], res) == 0); assert(strcmp(testcase[i].results[j], res) == 0);
...@@ -99,7 +98,7 @@ int main (void) ...@@ -99,7 +98,7 @@ int main (void)
free(res_escaped); free(res_escaped);
free(res); free(res);
} }
vlc_array_destroy(out); vlc_array_clear(&out);
} }
else else
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment