Author: jmb
Date: Sat Sep 29 02:41:23 2007
New Revision: 3606
URL:
http://source.netsurf-browser.org?rev=3606&view=rev
Log:
dom_initialise() and dom_finalise() are now completely public, rather than hidden away in
a header only meant for inclusion by bindings. Client applications are responsible for
initialisation and finalisation of the dom library. This must happen before/after
(respectively) any call to a dom library or dom binding library function.
The reason for this change is that, if multiple bindings are required, then the dom
library should still only be initialised/finalised once. Only the client can enforce this
sensibly.
Added:
trunk/dom/include/dom/bootstrap/init_fini.h
Modified:
trunk/dom/bindings/xml/xmlbinding.c
trunk/dom/include/dom/bootstrap/implpriv.h
trunk/dom/src/bootstrap/init_fini.c
trunk/dom/test/lib/testobject.c
Modified: trunk/dom/bindings/xml/xmlbinding.c
URL:
http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlbinding.c?rev...
==============================================================================
--- trunk/dom/bindings/xml/xmlbinding.c (original)
+++ trunk/dom/bindings/xml/xmlbinding.c Sat Sep 29 02:41:23 2007
@@ -385,10 +385,6 @@
{
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_finalise(void)
{
- dom_exception err;
-
- err = dom_finalise();
- if (err != DOM_NO_ERR) {
- /** \todo Do something about it */
- }
-
return XML_OK;
}
Modified: trunk/dom/include/dom/bootstrap/implpriv.h
URL:
http://source.netsurf-browser.org/trunk/dom/include/dom/bootstrap/implpri...
==============================================================================
--- trunk/dom/include/dom/bootstrap/implpriv.h (original)
+++ trunk/dom/include/dom/bootstrap/implpriv.h Sat Sep 29 02:41:23 2007
@@ -17,10 +17,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 @@
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);
Added: trunk/dom/include/dom/bootstrap/init_fini.h
URL:
http://source.netsurf-browser.org/trunk/dom/include/dom/bootstrap/init_fi...
==============================================================================
--- trunk/dom/include/dom/bootstrap/init_fini.h (added)
+++ trunk/dom/include/dom/bootstrap/init_fini.h Sat Sep 29 02:41:23 2007
@@ -1,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(a)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
+
Modified: trunk/dom/src/bootstrap/init_fini.c
URL:
http://source.netsurf-browser.org/trunk/dom/src/bootstrap/init_fini.c?rev...
==============================================================================
--- trunk/dom/src/bootstrap/init_fini.c (original)
+++ trunk/dom/src/bootstrap/init_fini.c Sat Sep 29 02:41:23 2007
@@ -5,9 +5,13 @@
* Copyright 2007 John-Mark Bell <jmb(a)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,14 +20,22 @@
* \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,14 +45,20 @@
*
* \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;
}
Modified: trunk/dom/test/lib/testobject.c
URL:
http://source.netsurf-browser.org/trunk/dom/test/lib/testobject.c?rev=360...
==============================================================================
--- trunk/dom/test/lib/testobject.c (original)
+++ trunk/dom/test/lib/testobject.c Sat Sep 29 02:41:23 2007
@@ -7,6 +7,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 @@
}
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 @@
void test_object_cleanup(void)
{
- if (xml_parser_initialised)
+ if (xml_parser_initialised) {
xml_dom_binding_finalise();
+ dom_finalise();
+ }
}