From: RĂ©mi Denis-Courmont Date: Sun, 31 Jan 2010 21:40:16 +0000 (+0200) Subject: LibVLC core: remove exceptions X-Git-Tag: 1.1.0-ff~580 X-Git-Url: https://git.sesse.net/?p=vlc;a=commitdiff_plain;h=09020b63ba7513eeaff38f1cc40e2b4937c61030 LibVLC core: remove exceptions --- diff --git a/bin/cachegen.c b/bin/cachegen.c index b10270b64e..8c96f08735 100644 --- a/bin/cachegen.c +++ b/bin/cachegen.c @@ -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); diff --git a/bin/vlc.c b/bin/vlc.c index b76d8fb121..f944aaeecf 100644 --- a/bin/vlc.c +++ b/bin/vlc.c @@ -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; } diff --git a/bin/winvlc.c b/bin/winvlc.c index 8741160358..09f56b6e96 100644 --- a/bin/winvlc.c +++ b/bin/winvlc.c @@ -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 ) diff --git a/include/vlc/libvlc.h b/include/vlc/libvlc.h index ed07d2c9a6..f364dab332 100644 --- a/include/vlc/libvlc.h +++ b/include/vlc/libvlc.h @@ -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 diff --git a/src/control/core.c b/src/control/core.c index fd5a44430c..5131ab3c0b 100644 --- a/src/control/core.c +++ b/src/control/core.c @@ -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 ) diff --git a/src/control/libvlc_internal.h b/src/control/libvlc_internal.h index 3cb97d6ef1..522620a7bb 100644 --- a/src/control/libvlc_internal.h +++ b/src/control/libvlc_internal.h @@ -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; diff --git a/src/control/mediacontrol_core.c b/src/control/mediacontrol_core.c index 7ab5e8f557..f721ec8745 100644 --- a/src/control/mediacontrol_core.c +++ b/src/control/mediacontrol_core.c @@ -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" ); diff --git a/test/libvlc/core.c b/test/libvlc/core.c index 53cb8c8c51..fe274a7cb3 100644 --- a/test/libvlc/core.c +++ b/test/libvlc/core.c @@ -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); diff --git a/test/libvlc/events.c b/test/libvlc/events.c index bbe18b81ce..17d5a8aedd 100644 --- a/test/libvlc/events.c +++ b/test/libvlc/events.c @@ -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); diff --git a/test/libvlc/media_list.c b/test/libvlc/media_list.c index 42156baf3f..a41e839d85 100644 --- a/test/libvlc/media_list.c +++ b/test/libvlc/media_list.c @@ -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); diff --git a/test/libvlc/media_list_player.c b/test/libvlc/media_list_player.c index 0a59b23f30..7e0717ac35 100644 --- a/test/libvlc/media_list_player.c +++ b/test/libvlc/media_list_player.c @@ -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: diff --git a/test/libvlc/media_player.c b/test/libvlc/media_player.c index 369eb8352d..2137fa7210 100644 --- a/test/libvlc/media_player.c +++ b/test/libvlc/media_player.c @@ -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 (); diff --git a/test/libvlc/meta.c b/test/libvlc/meta.c index c969a01b97..c4131ebbb9 100644 --- a/test/libvlc/meta.c +++ b/test/libvlc/meta.c @@ -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 (); diff --git a/test/src/misc/variables.c b/test/src/misc/variables.c index 0eff75544f..e2524618da 100644 --- a/test/src/misc/variables.c +++ b/test/src/misc/variables.c @@ -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 );