]> git.sesse.net Git - vlc/blobdiff - src/libvlc.c
Don't fail with no-debug
[vlc] / src / libvlc.c
index 06ea4a25fa230c44055a8a4c3c72200458162fd1..a81ba730e607ca0dc145e0be03652619bab888ac 100644 (file)
@@ -1,13 +1,14 @@
 /*****************************************************************************
  * libvlc.c: main libvlc source
  *****************************************************************************
- * Copyright (C) 1998-2004 the VideoLAN team
+ * Copyright (C) 1998-2006 the VideoLAN team
  * $Id$
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
  *          Gildas Bazin <gbazin@videolan.org>
  *          Derk-Jan Hartman <hartman at videolan dot org>
+ *          RĂ©mi Denis-Courmont <rem # videolan : org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include <stdio.h>                                              /* sprintf() */
 #include <string.h>                                            /* strerror() */
 #include <stdlib.h>                                                /* free() */
+#ifdef HAVE_ASSERT
+# include <assert.h>
+#else
+# define assert( c ) ((void)0)
+#endif
 
 #ifndef WIN32
 #   include <netinet/in.h>                            /* BSD: struct in_addr */
@@ -248,7 +254,7 @@ int VLC_Create( void )
 
     /* Initialize mutexes */
     vlc_mutex_init( p_vlc, &p_vlc->config_lock );
-#ifdef SYS_DARWIN
+#ifdef __APPLE__
     vlc_mutex_init( p_vlc, &p_vlc->quicktime_lock );
     vlc_thread_set_priority( p_vlc, VLC_THREAD_PRIORITY_LOW );
 #endif
@@ -643,7 +649,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
     if( !config_GetInt( p_vlc, "sse2" ) )
         libvlc.i_cpu &= ~CPU_CAPABILITY_SSE2;
 #endif
-#if defined( __powerpc__ ) || defined( SYS_DARWIN )
+#if defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
     if( !config_GetInt( p_vlc, "altivec" ) )
         libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
 #endif
@@ -685,6 +691,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
     }
 
     libvlc.b_stats = config_GetInt( p_vlc, "stats" );
+    libvlc.p_stats = NULL;
 
     /*
      * Initialize hotkey handling
@@ -780,11 +787,13 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
     {
         VLC_AddIntf( 0, "logger", VLC_FALSE, VLC_FALSE );
     }
+#ifdef HAVE_SYSLOG_H
     if( config_GetInt( p_vlc, "syslog" ) == 1 )
     {
         char *psz_logmode = "logmode=syslog";
         AddIntfInternal( 0, "logger", VLC_FALSE, VLC_FALSE, 1, &psz_logmode );
     }
+#endif
 
     if( config_GetInt( p_vlc, "show-intf" ) == 1 )
     {
@@ -940,6 +949,7 @@ int VLC_CleanUp( int i_object )
 
     while( ( p_stats = vlc_object_find( p_vlc, VLC_OBJECT_STATS, FIND_CHILD) ))
     {
+        stats_TimersDumpAll( p_vlc );
         stats_HandlerDestroy( p_stats );
         vlc_object_detach( (vlc_object_t*) p_stats );
         vlc_object_release( (vlc_object_t *)p_stats );
@@ -2008,7 +2018,7 @@ static void SetLanguage ( char const *psz_lang )
      && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
 
     char *          psz_path;
-#if defined( SYS_DARWIN ) || defined ( WIN32 ) || defined( SYS_BEOS )
+#if defined( __APPLE__ ) || defined ( WIN32 ) || defined( SYS_BEOS )
     char            psz_tmp[1024];
 #endif
 
@@ -2021,7 +2031,7 @@ static void SetLanguage ( char const *psz_lang )
     }
     else if( psz_lang )
     {
-#ifdef SYS_DARWIN
+#ifdef __APPLE__
         /* I need that under Darwin, please check it doesn't disturb
          * other platforms. --Meuuh */
         setenv( "LANG", psz_lang, 1 );
@@ -2045,7 +2055,7 @@ static void SetLanguage ( char const *psz_lang )
     }
 
     /* Specify where to find the locales for current domain */
-#if !defined( SYS_DARWIN ) && !defined( WIN32 ) && !defined( SYS_BEOS )
+#if !defined( __APPLE__ ) && !defined( WIN32 ) && !defined( SYS_BEOS )
     psz_path = LOCALEDIR;
 #else
     snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath,
@@ -2705,10 +2715,10 @@ char *FromLocale( const char *locale )
          * to non-const.
          */
         inb = strlen( locale );
-        outb = inb * 6 + 1;
-
         /* FIXME: I'm not sure about the value for the multiplication
          * (for western people, multiplication by 3 (Latin9) is sufficient) */
+        outb = inb * 6 + 1;
+
         optr = output = calloc( outb , 1);
 
         vlc_mutex_lock( &libvlc.from_locale_lock );
@@ -2717,14 +2727,19 @@ char *FromLocale( const char *locale )
         while( vlc_iconv( libvlc.from_locale, &iptr, &inb, &optr, &outb )
                                                                == (size_t)-1 )
         {
-            *optr = '?';
-            optr++;
+            *optr++ = '?';
+            outb--;
             iptr++;
+            inb--;
             vlc_iconv( libvlc.from_locale, NULL, NULL, NULL, NULL );
         }
-        vlc_mutex_unlock( &libvlc.from_locale_lock );
+       vlc_mutex_unlock( &libvlc.from_locale_lock );
 
-        return realloc( output, strlen( output ) + 1 );
+        assert (inb == 0);
+        assert (*iptr == '\0');
+        assert (*optr == '\0');
+        assert (strlen( output ) == (size_t)(optr - output));
+        return realloc( output, optr - output + 1 );
     }
     return (char *)locale;
 }
@@ -2758,14 +2773,19 @@ char *ToLocale( const char *utf8 )
         while( vlc_iconv( libvlc.to_locale, &iptr, &inb, &optr, &outb )
                                                                == (size_t)-1 )
         {
-            *optr = '?'; /* should not happen, and yes, it sucks */
-            optr++;
+            *optr++ = '?'; /* should not happen, and yes, it sucks */
+            outb--;
             iptr++;
+            inb--;
             vlc_iconv( libvlc.to_locale, NULL, NULL, NULL, NULL );
         }
         vlc_mutex_unlock( &libvlc.to_locale_lock );
 
-        return realloc( output, strlen( output ) + 1 );
+        assert (inb == 0);
+        assert (*iptr == '\0');
+        assert (*optr == '\0');
+        assert (strlen( output ) == (size_t)(optr - output));
+       return realloc( output, optr - output + 1 );
     }
     return (char *)utf8;
 }