summaryrefslogtreecommitdiff
path: root/src/bootstrap
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2007-09-29 01:41:23 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2007-09-29 01:41:23 +0000
commit878df9ef2b47cd09ffe6c8c9c2324435535ef52b (patch)
treeff2739087c040f4872adef4a3d0b3731f04ebea3 /src/bootstrap
parent7eb2967d9be33c58e7927b7973c9dc50c9f71a62 (diff)
downloadlibdom-878df9ef2b47cd09ffe6c8c9c2324435535ef52b.tar.gz
libdom-878df9ef2b47cd09ffe6c8c9c2324435535ef52b.tar.bz2
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. svn path=/trunk/dom/; revision=3606
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/init_fini.c28
1 files changed, 23 insertions, 5 deletions
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;
}