From: <svn...@op...> - 2009-02-26 12:55:29
|
Author: bellmich Date: Thu Feb 26 13:49:35 2009 New Revision: 958 URL: http://libsyncml.opensync.org/changeset/958 Log: libxml initialization and cleanup can only be handled correctly by the main thread of the process Modified: trunk/libsyncml/parser/sml_xml_assm.c trunk/libsyncml/parser/sml_xml_parse.c trunk/libsyncml/sml_support.c trunk/libsyncml/sml_support.h Modified: trunk/libsyncml/parser/sml_xml_assm.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_assm.c Wed Feb 25 16:53:34 2009 (r957) +++ trunk/libsyncml/parser/sml_xml_assm.c Thu Feb 26 13:49:35 2009 (r958) @@ -1504,8 +1504,6 @@ g_mutex_free(assm->mutex); smlSafeFree((gpointer *)&assm); - smlLibxmlUnref(); - smlTrace(TRACE_EXIT, "%s", __func__); } @@ -1960,8 +1958,6 @@ functions->flush = (SmlAssemblerFlushFunction)smlXmlAssemblerFlush; functions->restore_cmds = (SmlAssemblerRestoreCommandsFunction)smlXmlAssemblerRestoreCommands; - smlLibxmlRef(); - smlTrace(TRACE_EXIT, "%s: %p", __func__, assm); return assm; @@ -2405,8 +2401,6 @@ version = devinf->version; smlAssert(devinf->version == version); - smlLibxmlRef(); - SmlXmlAssembler *assm = smlTryMalloc0(sizeof(SmlXmlAssembler), error); if (!assm) goto error; @@ -2560,8 +2554,6 @@ smlSafeFree((gpointer *)&assm); - smlLibxmlUnref(); - smlTrace(TRACE_INTERNAL, "Message Assembled: %s", *data); smlTrace(TRACE_EXIT, "%s", __func__); @@ -2575,7 +2567,6 @@ error_free_assm: smlSafeFree((gpointer *)&assm); error: - smlLibxmlUnref(); g_warning("%s: %s", __func__, smlErrorPrint(error)); smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); return FALSE; Modified: trunk/libsyncml/parser/sml_xml_parse.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_parse.c Wed Feb 25 16:53:34 2009 (r957) +++ trunk/libsyncml/parser/sml_xml_parse.c Thu Feb 26 13:49:35 2009 (r958) @@ -1904,7 +1904,6 @@ parser->got_command = FALSE; /* Create the new parser */ - smlLibxmlRef(); parser->reader = xmlReaderForMemory(parser->data, parser->size, "/", NULL, XML_PARSE_NONET | XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NOCDATA); if (!parser->reader) { smlErrorSet(error, SML_ERROR_GENERIC, "Unable to create new reader"); @@ -1925,7 +1924,6 @@ error_free_reader: xmlFreeTextReader(parser->reader); - smlLibxmlUnref(); error: parser->reader = NULL; if (parser->data) @@ -1985,7 +1983,6 @@ goto error; xmlFreeTextReader(parser->reader); - smlLibxmlUnref(); parser->reader = NULL; parser->size = 0; smlSafeCFree(&(parser->data)); @@ -2005,7 +2002,6 @@ if (parser->reader) { xmlFreeTextReader(parser->reader); - smlLibxmlUnref(); } if (parser->data) smlSafeCFree(&(parser->data)); @@ -3280,7 +3276,6 @@ goto error; /* Create the new parser */ - smlLibxmlRef(); parser->reader = xmlReaderForMemory(data, size, "/", NULL, XML_PARSE_NONET | XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NOCDATA | XML_PARSER_SUBST_ENTITIES); if (!parser->reader) { smlErrorSet(error, SML_ERROR_GENERIC, "Unable to create new reader"); @@ -3453,7 +3448,6 @@ xmlFreeTextReader(parser->reader); parser->reader = NULL; - smlLibxmlUnref(); smlSafeFree((gpointer *)&parser); smlTrace(TRACE_EXIT, "%s", __func__); @@ -3463,7 +3457,6 @@ if (parser && parser->reader) { xmlFreeTextReader(parser->reader); parser->reader = NULL; - smlLibxmlUnref(); } if (parser) smlSafeFree((gpointer *)&parser); Modified: trunk/libsyncml/sml_support.c ============================================================================== --- trunk/libsyncml/sml_support.c Wed Feb 25 16:53:34 2009 (r957) +++ trunk/libsyncml/sml_support.c Thu Feb 26 13:49:35 2009 (r958) @@ -509,37 +509,4 @@ smlSafeFree((gpointer *)address); } -static size_t __sml_libxml_ref_count = 0; -GStaticMutex __sml_libxml_mutex = G_STATIC_MUTEX_INIT; - -void smlLibxmlRef() -{ - g_static_mutex_lock(&__sml_libxml_mutex); - if (__sml_libxml_ref_count > 0) { - __sml_libxml_ref_count++; - } else if (__sml_libxml_ref_count == 0) { - __sml_libxml_ref_count++; - xmlInitParser(); - smlTrace(TRACE_INTERNAL, "%s: libxml initialized", __func__); - } - g_static_mutex_unlock(&__sml_libxml_mutex); -} - -void smlLibxmlUnref() -{ - g_static_mutex_lock(&__sml_libxml_mutex); - if (__sml_libxml_ref_count > 1) { - __sml_libxml_ref_count--; - } else if (__sml_libxml_ref_count == 1) { - __sml_libxml_ref_count--; - xmlCleanupParser(); - xmlCleanupGlobals(); - smlTrace(TRACE_INTERNAL, "%s: libxml cleaned up", __func__); - } else if (__sml_libxml_ref_count == 0) { - g_warning("libsyncml: libxml is not referenced but somebody tries to cleanup."); - smlTrace(TRACE_ERROR, "%s: reference counter is already zero.", __func__); - } - g_static_mutex_unlock(&__sml_libxml_mutex); -} - /*@}*/ Modified: trunk/libsyncml/sml_support.h ============================================================================== --- trunk/libsyncml/sml_support.h Wed Feb 25 16:53:34 2009 (r957) +++ trunk/libsyncml/sml_support.h Thu Feb 26 13:49:35 2009 (r958) @@ -66,7 +66,4 @@ void smlSafeFree(gpointer *address); void smlSafeCFree(char **address); -void smlLibxmlRef(); -void smlLibxmlUnref(); - #endif //_SML_SUPPORT_H_ |