From d438b90ac17fbae25ba2554dd76f4e156f420437 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 22 Oct 2015 16:31:26 +0200 Subject: [PATCH] Cleanup de-init function YAZ-863 New function yaz_deinit_globals --- include/yaz/yconfig.h | 2 ++ src/init_globals.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/test.c | 1 + test/test_icu.c | 4 ---- test/test_record_conv.c | 4 ---- 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/include/yaz/yconfig.h b/include/yaz/yconfig.h index ce0d44f..83f0b6c 100644 --- a/include/yaz/yconfig.h +++ b/include/yaz/yconfig.h @@ -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 diff --git a/src/init_globals.c b/src/init_globals.c index 6bd03fb..786cb9c 100644 --- a/src/init_globals.c +++ b/src/init_globals.c @@ -12,6 +12,8 @@ #include #endif +#include + #if YAZ_POSIX_THREADS #include #endif @@ -25,6 +27,14 @@ #include #endif +#if YAZ_HAVE_XML2 +#include +#endif + +#if YAZ_HAVE_XSLT +#include +#endif + #if YAZ_HAVE_EXSLT #include #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 diff --git a/src/test.c b/src/test.c index 258517e..4e6b960 100644 --- a/src/test.c +++ b/src/test.c @@ -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); diff --git a/test/test_icu.c b/test/test_icu.c index 5107693..e7fc1ef 100644 --- a/test/test_icu.c +++ b/test/test_icu.c @@ -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"); diff --git a/test/test_record_conv.c b/test/test_record_conv.c index fa65224..37cb520 100644 --- a/test/test_record_conv.c +++ b/test/test_record_conv.c @@ -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; } -- 1.7.10.4