]> git.sesse.net Git - vlc/blobdiff - modules/misc/xml/libxml.c
Require libxml2 < 2.7
[vlc] / modules / misc / xml / libxml.c
index cc46ab44ac490ddb3a23fdd16987db64935a5683..09c200e80e476d127dcd1b188c4a4e9d006193e5 100644 (file)
 #include <libxml/xmlreader.h>
 #include <libxml/catalog.h>
 
+#if !defined (LIBXML_VERSION) || (LIBXML_VERSION > 20700)
+# error Stale config.cache detected. Erase it and re-run configure.
+#endif
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
-vlc_module_begin();
-    set_description( N_("XML Parser (using libxml2)") );
-    set_capability( "xml", 10 );
-    set_callbacks( Open, Close );
-vlc_module_end();
+vlc_module_begin ()
+    set_description( N_("XML Parser (using libxml2)") )
+    set_capability( "xml", 10 )
+    set_callbacks( Open, Close )
+vlc_module_end ()
 
 struct xml_reader_sys_t
 {
@@ -67,6 +71,9 @@ static void CatalogLoad( xml_t *, const char * );
 static void CatalogAdd( xml_t *, const char *, const char *, const char * );
 static int StreamRead( void *p_context, char *p_buffer, int i_buffer );
 
+static unsigned refs = 0;
+static vlc_mutex_t lock = VLC_STATIC_MUTEX;
+
 /*****************************************************************************
  * Module initialization
  *****************************************************************************/
@@ -74,7 +81,13 @@ static int Open( vlc_object_t *p_this )
 {
     xml_t *p_xml = (xml_t *)p_this;
 
-    xmlInitParser();
+    if( !xmlHasFeature( XML_WITH_THREAD ) )
+        return VLC_EGENERIC;
+
+    vlc_mutex_lock( &lock );
+    if( refs++ == 0 )
+        xmlInitParser();
+    vlc_mutex_unlock( &lock );
 
     p_xml->pf_reader_create = ReaderCreate;
     p_xml->pf_reader_delete = ReaderDelete;
@@ -90,7 +103,11 @@ static int Open( vlc_object_t *p_this )
  *****************************************************************************/
 static void Close( vlc_object_t *p_this )
 {
-    xmlCleanupParser();
+    vlc_mutex_lock( &lock );
+    if( --refs == 0 )
+        xmlCleanupParser();
+    vlc_mutex_unlock( &lock );
+
     VLC_UNUSED(p_this);
     return;
 }
@@ -143,14 +160,14 @@ static xml_reader_t *ReaderCreate( xml_t *p_xml, stream_t *p_stream )
     p_reader = malloc( sizeof(xml_reader_t) );
     if( !p_reader )
     {
-        xmlFreeTextReader( p_reader->p_sys->p_reader );
+        xmlFreeTextReader( p_libxml_reader );
         return NULL;
     }
     p_reader->p_sys = p_sys = malloc( sizeof(xml_reader_sys_t) );
     if( !p_sys )
     {
+        xmlFreeTextReader( p_libxml_reader );
         free( p_reader );
-        xmlFreeTextReader( p_reader->p_sys->p_reader );
         return NULL;
     }
     p_reader->p_sys->p_reader = p_libxml_reader;