Author: jmb
Date: Sun Jun 26 15:49:52 2011
New Revision: 12512
URL:
http://source.netsurf-browser.org?rev=12512&view=rev
Log:
Fix up comment node implementation
Modified:
branches/jmb/dom-alloc-purge/src/core/comment.c
branches/jmb/dom-alloc-purge/src/core/comment.h
Modified: branches/jmb/dom-alloc-purge/src/core/comment.c
URL:
http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/c...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/comment.c (original)
+++ branches/jmb/dom-alloc-purge/src/core/comment.c Sun Jun 26 15:49:52 2011
@@ -5,6 +5,8 @@
* Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
* Copyright 2009 Bo Yang <struggleyb.nku(a)gmail.com>
*/
+
+#include <stdlib.h>
#include "core/characterdata.h"
#include "core/comment.h"
@@ -16,7 +18,7 @@
* A DOM Comment node
*/
struct dom_comment {
- struct dom_characterdata base; /**< Base node */
+ dom_characterdata base; /**< Base node */
};
static struct dom_node_protect_vtable comment_protect_vtable = {
@@ -37,15 +39,15 @@
*
* The returned node will already be referenced.
*/
-dom_exception _dom_comment_create(struct dom_document *doc,
- struct lwc_string_s *name, dom_string *value,
- struct dom_comment **result)
+dom_exception _dom_comment_create(dom_document *doc,
+ dom_string *name, dom_string *value,
+ dom_comment **result)
{
- struct dom_comment *c;
+ dom_comment *c;
dom_exception err;
/* Allocate the comment node */
- c = _dom_document_alloc(doc, NULL, sizeof(struct dom_comment));
+ c = malloc(sizeof(dom_comment));
if (c == NULL)
return DOM_NO_MEM_ERR;
@@ -57,7 +59,7 @@
err = _dom_characterdata_initialise(&c->base, doc, DOM_COMMENT_NODE,
name, value);
if (err != DOM_NO_ERR) {
- _dom_document_alloc(doc, c, 0);
+ free(c);
return err;
}
@@ -69,19 +71,17 @@
/**
* Destroy a comment node
*
- * \param doc The owning document
* \param comment The node to destroy
*
* The contents of ::comment will be destroyed and ::comment will be freed
*/
-void _dom_comment_destroy(struct dom_document *doc,
- struct dom_comment *comment)
+void _dom_comment_destroy(dom_comment *comment)
{
/* Finalise base class contents */
- _dom_characterdata_finalise(doc, &comment->base);
+ _dom_characterdata_finalise(&comment->base);
/* Free node */
- _dom_document_alloc(doc, comment, 0);
+ free(comment);
}
@@ -89,35 +89,30 @@
/* The protected virtual functions */
/* The virtual destroy function */
-void __dom_comment_destroy(struct dom_node_internal *node)
+void __dom_comment_destroy(dom_node_internal *node)
{
- struct dom_document *doc;
- doc = dom_node_get_owner(node);
-
- _dom_comment_destroy(doc, (struct dom_comment *) node);
+ _dom_comment_destroy((dom_comment *) node);
}
-/* The memory allocation function of this class */
-dom_exception _dom_comment_alloc(struct dom_document *doc,
- struct dom_node_internal *n, struct dom_node_internal **ret)
+/* The copy constructor of this class */
+dom_exception _dom_comment_copy(dom_node_internal *old,
+ dom_node_internal **copy)
{
- UNUSED(n);
- dom_comment *c;
-
- c = _dom_document_alloc(doc, NULL, sizeof(struct dom_comment));
- if (c == NULL)
+ dom_comment *new_comment;
+ dom_exception err;
+
+ new_comment = malloc(sizeof(dom_comment));
+ if (new_comment == NULL)
return DOM_NO_MEM_ERR;
-
- *ret = (dom_node_internal *) c;
- dom_node_set_owner(*ret, doc);
+
+ err = dom_characterdata_copy_internal(old, new_comment);
+ if (err != DOM_NO_ERR) {
+ free(new_comment);
+ return err;
+ }
+
+ *copy = (dom_node_internal *) new_comment;
return DOM_NO_ERR;
}
-/* The copy constructor of this class */
-dom_exception _dom_comment_copy(struct dom_node_internal *new,
- struct dom_node_internal *old)
-{
- return _dom_characterdata_copy(new, old);
-}
-
Modified: branches/jmb/dom-alloc-purge/src/core/comment.h
URL:
http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/c...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/comment.h (original)
+++ branches/jmb/dom-alloc-purge/src/core/comment.h Sun Jun 26 15:49:52 2011
@@ -13,28 +13,23 @@
struct dom_comment;
struct dom_document;
-struct lwc_string_s;
dom_exception _dom_comment_create(struct dom_document *doc,
- struct lwc_string_s *name, dom_string *value,
- struct dom_comment **result);
+ dom_string *name, dom_string *value,
+ dom_comment **result);
#define _dom_comment_initialise _dom_characterdata_initialise
#define _dom_comment_finalise _dom_characterdata_finalise
-void _dom_comment_destroy(struct dom_document *doc,
- struct dom_comment *comment);
+void _dom_comment_destroy(dom_comment *comment);
/* Following comes the protected vtable */
-void __dom_comment_destroy(struct dom_node_internal *node);
-dom_exception _dom_comment_alloc(struct dom_document *doc,
- struct dom_node_internal *n, struct dom_node_internal **ret);
-dom_exception _dom_comment_copy(struct dom_node_internal *new,
- struct dom_node_internal *old);
+void __dom_comment_destroy(dom_node_internal *node);
+dom_exception _dom_comment_copy(dom_node_internal *old,
+ dom_node_internal **copy);
#define DOM_COMMENT_PROTECT_VTABLE \
__dom_comment_destroy, \
- _dom_comment_alloc, \
_dom_comment_copy
#endif