Commit 09020b63 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

LibVLC core: remove exceptions

parent 0851b345
......@@ -96,10 +96,7 @@ int main (int argc, char *argv[])
};
size_t vlc_argc = sizeof (vlc_argv) / sizeof (vlc_argv[0]) - 1;
libvlc_exception_t ex;
libvlc_exception_init (&ex);
libvlc_instance_t *vlc = libvlc_new (vlc_argc, vlc_argv, &ex);
libvlc_instance_t *vlc = libvlc_new (vlc_argc, vlc_argv);
if (vlc != NULL)
libvlc_release (vlc);
free (arg);
......
......@@ -150,11 +150,8 @@ int main( int i_argc, const char *ppsz_argv[] )
return 1; // BOOM!
argv[argc] = NULL;
libvlc_exception_t ex;
libvlc_exception_init (&ex);
/* Initialize libvlc */
libvlc_instance_t *vlc = libvlc_new (argc, argv, &ex);
libvlc_instance_t *vlc = libvlc_new (argc, argv);
if (vlc != NULL)
{
......@@ -174,5 +171,5 @@ int main( int i_argc, const char *ppsz_argv[] )
for (int i = 1; i < argc; i++)
LocaleFree (argv[i]);
return vlc == NULL || libvlc_exception_raised (&ex);
return 0;
}
......@@ -123,7 +123,7 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
#endif
int nCmdShow )
{
int argc, ret;
int argc;
#ifndef UNDER_CE
HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
wchar_t **wargv = CommandLineToArgvW (GetCommandLine (), &argc);
......@@ -169,12 +169,9 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
argc = parse_cmdline (psz_cmdline, &argv);
#endif
libvlc_exception_t ex;
libvlc_exception_init (&ex);
/* Initialize libvlc */
libvlc_instance_t *vlc;
vlc = libvlc_new (argc, (const char **)argv, &ex);
vlc = libvlc_new (argc, (const char **)argv);
if (vlc != NULL)
{
libvlc_add_intf (vlc, "globalhotkeys,none");
......@@ -184,14 +181,11 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
libvlc_release (vlc);
}
ret = libvlc_exception_raised (&ex);
libvlc_exception_clear (&ex);
for (int i = 0; i < argc; i++)
free (argv[i]);
(void)hInstance; (void)hPrevInstance; (void)lpCmdLine; (void)nCmdShow;
return ret;
return 0;
}
#if !defined( UNDER_CE ) && !defined( _WIN64 )
......
......@@ -162,13 +162,11 @@ const char *libvlc_printerr (const char *fmt, ...);
* Create and initialize a libvlc instance.
*
* \param argc the number of arguments
* \param argv command-line-type arguments. argv[0] must be the path of the
* calling program.
* \param p_e an initialized exception pointer
* \return the libvlc instance
* \param argv command-line-type arguments
* \return the libvlc instance or NULL in case of error
*/
VLC_PUBLIC_API libvlc_instance_t *
libvlc_new( int , const char *const *, libvlc_exception_t *);
libvlc_new( int , const char *const * );
/**
* Decrement the reference count of a libvlc instance, and destroy it
......
......@@ -78,49 +78,28 @@ void libvlc_exception_raise( libvlc_exception_t *p_exception )
p_exception->b_raised = 1;
}
libvlc_instance_t * libvlc_new( int argc, const char *const *argv,
libvlc_exception_t *p_e )
libvlc_instance_t * libvlc_new( int argc, const char *const *argv )
{
libvlc_instance_t *p_new;
int i_ret;
libvlc_instance_t *p_new = malloc (sizeof (*p_new));
if (unlikely(p_new == NULL))
return NULL;
libvlc_init_threads ();
libvlc_int_t *p_libvlc_int = libvlc_InternalCreate();
if( !p_libvlc_int )
{
libvlc_deinit_threads ();
RAISENULL( "VLC initialization failed" );
}
p_new = malloc( sizeof( libvlc_instance_t ) );
if( !p_new )
{
libvlc_deinit_threads ();
RAISENULL( "Out of memory" );
}
const char *my_argv[argc + 2];
my_argv[0] = "libvlc"; /* dummy arg0, skipped by getopt() et al */
for( int i = 0; i < argc; i++ )
my_argv[i + 1] = argv[i];
my_argv[argc + 1] = NULL; /* C calling conventions require a NULL */
/** \todo Look for interface settings. If we don't have any, add -I dummy */
/* Because we probably don't want a GUI by default */
libvlc_int_t *p_libvlc_int = libvlc_InternalCreate();
if (unlikely (p_libvlc_int == NULL))
goto error;
i_ret = libvlc_InternalInit( p_libvlc_int, argc + 1, my_argv );
if( i_ret )
if (libvlc_InternalInit( p_libvlc_int, argc + 1, my_argv ))
{
libvlc_InternalDestroy( p_libvlc_int );
free( p_new );
libvlc_deinit_threads ();
if( i_ret == VLC_EEXITSUCCESS )
return NULL;
else
RAISENULL( "VLC initialization failed" );
goto error;
}
p_new->p_libvlc_int = p_libvlc_int;
......@@ -131,8 +110,12 @@ libvlc_instance_t * libvlc_new( int argc, const char *const *argv,
p_new->verbosity = 1;
p_new->p_callback_list = NULL;
vlc_mutex_init(&p_new->instance_lock);
return p_new;
error:
libvlc_deinit_threads ();
free (p_new);
return NULL;
}
void libvlc_retain( libvlc_instance_t *p_instance )
......
......@@ -99,15 +99,6 @@ void libvlc_event_attach_async( libvlc_event_manager_t * p_event_manager,
libvlc_callback_t pf_callback,
void *p_user_data );
/* Exception shorcuts */
#define RAISENULL( ... ) { libvlc_printerr(__VA_ARGS__); \
libvlc_exception_raise( p_e ); \
return NULL; }
#define RAISEZERO( ... ) { libvlc_printerr(__VA_ARGS__); \
libvlc_exception_raise( p_e ); \
return 0; }
static inline libvlc_time_t from_mtime(mtime_t time)
{
return (time + 500ULL)/ 1000ULL;
......
......@@ -51,17 +51,15 @@
mediacontrol_Instance* mediacontrol_new( int argc, char** argv, mediacontrol_Exception *exception )
{
mediacontrol_Instance* retval;
libvlc_exception_t ex;
libvlc_exception_init( &ex );
mediacontrol_exception_init( exception );
retval = ( mediacontrol_Instance* )malloc( sizeof( mediacontrol_Instance ) );
if( !retval )
RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
retval->p_instance = libvlc_new( argc, (const char**)argv, &ex );
HANDLE_LIBVLC_EXCEPTION_NULL( &ex );
retval->p_instance = libvlc_new( argc, (const char**)argv );
if( !retval->p_instance )
RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
retval->p_media_player = libvlc_media_player_new( retval->p_instance );
if( !retval->p_media_player )
RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
......
......@@ -30,8 +30,8 @@ static void test_core (const char ** argv, int argc)
log ("Testing core\n");
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
vlc = libvlc_new (argc, argv);
assert (vlc != NULL);
libvlc_retain (vlc);
libvlc_release (vlc);
......
......@@ -75,8 +75,8 @@ static void test_events (const char ** argv, int argc)
log ("Testing events\n");
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
vlc = libvlc_new (argc, argv);
assert (vlc != NULL);
mi = libvlc_media_player_new (vlc);
assert (mi != NULL);
......
......@@ -32,8 +32,8 @@ static void test_media_list (const char ** argv, int argc)
log ("Testing media_list\n");
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
vlc = libvlc_new (argc, argv);
assert (vlc != NULL);
ml = libvlc_media_list_new (vlc);
assert (ml != NULL);
......
......@@ -101,8 +101,8 @@ static void test_media_list_player_items_queue(const char** argv, int argc)
log ("Testing media player item queue-ing\n");
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
vlc = libvlc_new (argc, argv);
assert (vlc != NULL);
md = libvlc_media_new (vlc, file, &ex);
catch ();
......@@ -172,8 +172,8 @@ static void test_media_list_player_previous(const char** argv, int argc)
log ("Testing media player previous()\n");
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
vlc = libvlc_new (argc, argv);
assert (vlc != NULL);
md = libvlc_media_new (vlc, file, &ex);
catch ();
......@@ -249,8 +249,8 @@ static void test_media_list_player_next(const char** argv, int argc)
log ("Testing media player next()\n");
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
vlc = libvlc_new (argc, argv);
assert (vlc != NULL);
md = libvlc_media_new (vlc, file, &ex);
catch ();
......@@ -325,8 +325,8 @@ static void test_media_list_player_pause_stop(const char** argv, int argc)
log ("Testing play and pause of %s using the media list.\n", file);
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
vlc = libvlc_new (argc, argv);
assert (vlc != NULL);
md = libvlc_media_new (vlc, file, &ex);
catch ();
......@@ -373,7 +373,7 @@ static void test_media_list_player_play_item_at_index(const char** argv, int arg
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
assert (vlc != NULL);
md = libvlc_media_new (vlc, file, &ex);
catch ();
......@@ -428,8 +428,8 @@ static void test_media_list_player_playback_options (const char** argv, int argc
log ("Testing media player playback options()\n");
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
vlc = libvlc_new (argc, argv);
assert (vlc != NULL);
/*
* Create the following media tree:
......
......@@ -33,8 +33,8 @@ static void test_media_player_play_stop(const char** argv, int argc)
log ("Testing play and pause of %s\n", file);
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
vlc = libvlc_new (argc, argv);
assert (vlc != NULL);
md = libvlc_media_new (vlc, file, &ex);
catch ();
......@@ -71,8 +71,8 @@ static void test_media_player_pause_stop(const char** argv, int argc)
log ("Testing pause and stop of %s\n", file);
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
vlc = libvlc_new (argc, argv);
assert (vlc != NULL);
md = libvlc_media_new (vlc, file, &ex);
catch ();
......
......@@ -35,8 +35,8 @@ static void test_meta (const char ** argv, int argc)
log ("Testing meta\n");
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
vlc = libvlc_new (argc, argv);
assert (vlc != NULL);
media = libvlc_media_new (vlc, "samples/meta.sample", &ex);
catch ();
......
......@@ -446,9 +446,8 @@ int main( void )
test_init();
log( "Testing the core variables\n" );
libvlc_exception_init( &ex );
p_vlc = libvlc_new( test_defaults_nargs, test_defaults_args, &ex );
catch();
p_vlc = libvlc_new( test_defaults_nargs, test_defaults_args );
assert( p_vlc != NULL );
test_variables( p_vlc );
......
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