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