summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bindings/xml/xmlbinding.c11
-rw-r--r--include/dom/bootstrap/implpriv.h10
-rw-r--r--include/dom/bootstrap/init_fini.h21
-rw-r--r--src/bootstrap/init_fini.c28
-rw-r--r--test/lib/testobject.c8
5 files changed, 51 insertions, 27 deletions
diff --git a/bindings/xml/xmlbinding.c b/bindings/xml/xmlbinding.c
index 9c0d832..fbdc4c9 100644
--- a/bindings/xml/xmlbinding.c
+++ b/bindings/xml/xmlbinding.c
@@ -385,10 +385,6 @@ xml_error xml_dom_binding_initialise(xml_alloc alloc, void *pw)
{
dom_exception err;
- err = dom_initialise(alloc, pw);
- if (err != DOM_NO_ERR)
- return XML_NOMEM;
-
err = dom_register_source(&xml_dom_impl_src, (dom_alloc) alloc, pw);
if (err != DOM_NO_ERR)
return XML_NOMEM;
@@ -403,13 +399,6 @@ xml_error xml_dom_binding_initialise(xml_alloc alloc, void *pw)
*/
xml_error xml_dom_binding_finalise(void)
{
- dom_exception err;
-
- err = dom_finalise();
- if (err != DOM_NO_ERR) {
- /** \todo Do something about it */
- }
-
return XML_OK;
}
diff --git a/include/dom/bootstrap/implpriv.h b/include/dom/bootstrap/implpriv.h
index c83eb3a..36359c5 100644
--- a/include/dom/bootstrap/implpriv.h
+++ b/include/dom/bootstrap/implpriv.h
@@ -18,10 +18,6 @@
* The DocumentType implementation includes this as it needs the declaration
* of dom_document_type_create.
*
- * The DOM library's core initialisation/finalisation implementation also
- * includes this as it needs the declaration of dom_initialise and
- * dom_finalise.
- *
* No other client should be including this.
*/
@@ -247,12 +243,6 @@ struct dom_implementation_source {
dom_alloc alloc, void *pw);
};
-/* Initialise the DOM library */
-dom_exception dom_initialise(dom_alloc alloc, void *pw);
-
-/* Finalise the DOM library */
-dom_exception dom_finalise(void);
-
/* Register a source with the DOM library */
dom_exception dom_register_source(struct dom_implementation_source *source,
dom_alloc alloc, void *pw);
diff --git a/include/dom/bootstrap/init_fini.h b/include/dom/bootstrap/init_fini.h
new file mode 100644
index 0000000..5773af6
--- /dev/null
+++ b/include/dom/bootstrap/init_fini.h
@@ -0,0 +1,21 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#ifndef dom_bootstrap_init_fini_h_
+#define dom_bootstrap_init_fini_h_
+
+#include <dom/functypes.h>
+#include <dom/core/exceptions.h>
+
+/* Initialise the DOM library */
+dom_exception dom_initialise(dom_alloc alloc, void *pw);
+
+/* Finalise the DOM library */
+dom_exception dom_finalise(void);
+
+#endif
+
diff --git a/src/bootstrap/init_fini.c b/src/bootstrap/init_fini.c
index 001eaf9..001e798 100644
--- a/src/bootstrap/init_fini.c
+++ b/src/bootstrap/init_fini.c
@@ -5,10 +5,14 @@
* Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
*/
-#include <dom/bootstrap/implpriv.h>
+#include <stdbool.h>
+
+#include <dom/bootstrap/init_fini.h>
#include "utils/namespace.h"
+static bool __initialised;
+
/**
* Initialise the dom library
*
@@ -16,15 +20,23 @@
* \param pw Pointer to client-specific private data
* \return DOM_NO_ERR on success.
*
- * This should be invoked by the binding's initialiser and must be
- * the first DOM library method called.
+ * This must be the first DOM library method called.
*/
dom_exception dom_initialise(dom_alloc alloc, void *pw)
{
dom_exception err;
+ /* Ensure we only initialise once */
+ if (__initialised) {
+ return DOM_NO_ERR;
+ }
+
err = _dom_namespace_initialise(alloc, pw);
+ if (err == DOM_NO_ERR) {
+ __initialised = true;
+ }
+
return err;
}
@@ -33,15 +45,21 @@ dom_exception dom_initialise(dom_alloc alloc, void *pw)
*
* \return DOM_NO_ERR on success.
*
- * This should be invoked by the binding's finaliser and must be
- * the last DOM library method called.
+ * This must be the last DOM library method called.
*/
dom_exception dom_finalise(void)
{
dom_exception err;
+ /* Ensure we only finalise once */
+ if (__initialised == false) {
+ return DOM_NO_ERR;
+ }
+
err = _dom_namespace_finalise();
+ __initialised = false;
+
return err;
}
diff --git a/test/lib/testobject.c b/test/lib/testobject.c
index 17e5233..6873475 100644
--- a/test/lib/testobject.c
+++ b/test/lib/testobject.c
@@ -8,6 +8,8 @@
#include <stdio.h>
#include <stdlib.h>
+#include <dom/bootstrap/init_fini.h>
+
#include "bindings/xml/xmlbinding.h"
#include "bindings/xml/xmlparser.h"
@@ -42,6 +44,8 @@ TestObject *test_object_create(int argc, char **argv,
}
if (xml_parser_initialised == false) {
+ assert(dom_initialise(myrealloc, NULL) == DOM_NO_ERR);
+
assert(xml_dom_binding_initialise(myrealloc, NULL) == XML_OK);
atexit(test_object_cleanup);
@@ -119,7 +123,9 @@ const char *test_object_get_mimetype(TestObject *obj)
void test_object_cleanup(void)
{
- if (xml_parser_initialised)
+ if (xml_parser_initialised) {
xml_dom_binding_finalise();
+ dom_finalise();
+ }
}