Cleanup de-init function YAZ-863
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 22 Oct 2015 14:31:26 +0000 (16:31 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 22 Oct 2015 14:31:39 +0000 (16:31 +0200)
New function yaz_deinit_globals

include/yaz/yconfig.h
src/init_globals.c
src/test.c
test/test_icu.c
test/test_record_conv.c

index ce0d44f..83f0b6c 100644 (file)
@@ -59,6 +59,8 @@
 
 YAZ_BEGIN_CDECL
 YAZ_EXPORT void yaz_init_globals(void);
+YAZ_EXPORT void yaz_deinit_globals(void);
+
 YAZ_END_CDECL
 
 #endif
index 6bd03fb..786cb9c 100644 (file)
@@ -12,6 +12,8 @@
 #include <config.h>
 #endif
 
+#include <yaz/yconfig.h>
+
 #if YAZ_POSIX_THREADS
 #include <pthread.h>
 #endif
 #include <gcrypt.h>
 #endif
 
+#if YAZ_HAVE_XML2
+#include <libxml/parser.h>
+#endif
+
+#if YAZ_HAVE_XSLT
+#include <libxslt/xslt.h>
+#endif
+
 #if YAZ_HAVE_EXSLT
 #include <libexslt/exslt.h>
 #endif
@@ -64,6 +74,12 @@ void yaz_init_globals(void)
             gcry_control(GCRYCTL_INITIALIZATION_FINISHED, NULL, 0);
         }
 #endif
+#if YAZ_HAVE_XML2
+        xmlInitParser();
+#endif
+#if YAZ_HAVE_XSLT
+        xsltInit();
+#endif
 #if YAZ_HAVE_EXSLT
         exsltRegisterAll();
 #endif
@@ -74,6 +90,31 @@ void yaz_init_globals(void)
 #endif
 }
 
+void yaz_deinit_globals(void)
+{
+    if (!yaz_init_flag)
+        return;
+#if YAZ_POSIX_THREADS
+    pthread_mutex_lock(&yaz_init_mutex);
+#endif
+    if (yaz_init_flag)
+    {
+#if HAVE_GNUTLS_H
+        gnutls_global_deinit();
+#endif
+#if YAZ_HAVE_XSLT
+        xsltCleanupGlobals();
+#endif
+#if YAZ_HAVE_XML2
+        xmlCleanupParser();
+#endif
+        yaz_init_flag = 0;
+    }
+#if YAZ_POSIX_THREADS
+    pthread_mutex_unlock(&yaz_init_mutex);
+#endif
+}
+
 /*
  * Local variables:
  * c-basic-offset: 4
index 258517e..4e6b960 100644 (file)
@@ -158,6 +158,7 @@ void yaz_check_term1(void)
     }
     if (test_fout)
         fclose(test_fout);
+    yaz_deinit_globals();
     if (test_failed)
         exit(1);
     exit(0);
index 5107693..e7fc1ef 100644 (file)
@@ -984,10 +984,6 @@ int main(int argc, char **argv)
     check_norm();
 
     u_cleanup();
-#if YAZ_HAVE_XML2
-    xmlCleanupParser();
-#endif
-
 #else /* YAZ_HAVE_ICU */
 
     yaz_log(YLOG_LOG, "ICU unit tests omitted");
index fa65224..37cb520 100644 (file)
@@ -626,10 +626,6 @@ int main(int argc, char **argv)
     tst_convert2();
     tst_convert3();
     tst_convert4();
-    xsltCleanupGlobals();
-#endif
-#if YAZ_HAVE_XML2
-    xmlCleanupParser();
 #endif
     YAZ_CHECK_TERM;
 }