]> git.sesse.net Git - vlc/commitdiff
LibVLC core: remove exceptions
authorRémi Denis-Courmont <remi@remlab.net>
Sun, 31 Jan 2010 21:40:16 +0000 (23:40 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Sun, 31 Jan 2010 21:40:16 +0000 (23:40 +0200)
14 files changed:
bin/cachegen.c
bin/vlc.c
bin/winvlc.c
include/vlc/libvlc.h
src/control/core.c
src/control/libvlc_internal.h
src/control/mediacontrol_core.c
test/libvlc/core.c
test/libvlc/events.c
test/libvlc/media_list.c
test/libvlc/media_list_player.c
test/libvlc/media_player.c
test/libvlc/meta.c
test/src/misc/variables.c

index b10270b64e8ae21c148280df95d293b2cbd81ba0..8c96f08735fe2caf8fe9834254c83ff58ca5323b 100644 (file)
@@ -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);
index b76d8fb121c1c7353097f41cffd48f07d99ccbff..f944aaeecf89810368bd5c356015a0e72e6ace1c 100644 (file)
--- 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;
 }
index 874116035847621e195a4aae3262b5224efe6ac8..09f56b6e9629d637e277a1941ff7e7b36d30a37f 100644 (file)
@@ -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 )
index ed07d2c9a6c1e952cb9a3a34b568c5edab97e496..f364dab3323ec1a05cdd929077543eb76a7cd809 100644 (file)
@@ -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
index fd5a44430c3bd7bea12763357ee1d18e12e43b32..5131ab3c0b67f72737b4e22bf97cbf3e0caf3562 100644 (file)
@@ -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 )
index 3cb97d6ef1adb54af778dc6cc2e6000559b170e9..522620a7bb6ad1c64c9acf76539547238d37a16f 100644 (file)
@@ -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;
index 7ab5e8f557439f08fa137c64272d45a35b81ec82..f721ec874549ad1300355c2ad8c0bb82af5c9921 100644 (file)
 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" );
index 53cb8c8c511bb4f736d7cd32d4b70f825565aa47..fe274a7cb354b78c13f14bd1b808d76ad76ec9da 100644 (file)
@@ -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);
index bbe18b81ce855a5d6f933ea71c0470e17320a8e8..17d5a8aedd23091720b539c696d4a9fedd1d4d80 100644 (file)
@@ -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);
index 42156baf3fe810d73bcf73aef6f01ddef21ee437..a41e839d8528bb30467ec2d19315a77711bf16fd 100644 (file)
@@ -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);
index 0a59b23f309d62058a4327f89fd30048aa842530..7e0717ac3577c534300ca81c055cb12dcebee00d 100644 (file)
@@ -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:
index 369eb8352db37c7677e189669329fd5427ed22a4..2137fa7210cc8176dea43a2d91f15486026a73d1 100644 (file)
@@ -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 ();
index c969a01b9726b0099947b19a7918dc413265eb57..c4131ebbb9ebbf323b9e40b3882ecf2798d39f64 100644 (file)
@@ -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 ();
index 0eff75544f2d9f6955d3eeb25e2ac6f1093dee32..e2524618da8642d59428dd4071a3043f321092d6 100644 (file)
@@ -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 );