From 83f3338663c4969eebefd8c2c43bd3fc43587fdd Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Wed, 21 Dec 2011 22:18:10 +0000 Subject: Merge branches/jmb/dom-alloc-purge back to trunk svn path=/trunk/libdom/; revision=13316 --- src/html/html_base_element.c | 48 +++++++++-------------------- src/html/html_base_element.h | 13 +++----- src/html/html_body_element.c | 48 +++++++++-------------------- src/html/html_body_element.h | 13 +++----- src/html/html_collection.c | 27 ++++++---------- src/html/html_document.c | 14 +++------ src/html/html_document.h | 2 +- src/html/html_element.c | 63 +++++++++----------------------------- src/html/html_element.h | 13 +++----- src/html/html_form_element.c | 47 +++++++++------------------- src/html/html_form_element.h | 13 +++----- src/html/html_head_element.c | 48 +++++++++-------------------- src/html/html_head_element.h | 13 +++----- src/html/html_html_element.c | 49 ++++++++++------------------- src/html/html_html_element.h | 13 +++----- src/html/html_isindex_element.c | 47 +++++++++------------------- src/html/html_isindex_element.h | 13 +++----- src/html/html_link_element.c | 47 +++++++++------------------- src/html/html_link_element.h | 13 +++----- src/html/html_meta_element.c | 48 +++++++++-------------------- src/html/html_meta_element.h | 13 +++----- src/html/html_options_collection.c | 7 ++--- src/html/html_select_element.c | 60 +++++++++++++----------------------- src/html/html_select_element.h | 13 +++----- src/html/html_style_element.c | 47 +++++++++------------------- src/html/html_style_element.h | 13 +++----- src/html/html_title_element.c | 46 +++++++++------------------- src/html/html_title_element.h | 13 +++----- 28 files changed, 252 insertions(+), 552 deletions(-) (limited to 'src/html') diff --git a/src/html/html_base_element.c b/src/html/html_base_element.c index dad0985..5bfd245 100644 --- a/src/html/html_base_element.c +++ b/src/html/html_base_element.c @@ -5,6 +5,8 @@ * Copyright 2009 Bo Yang */ +#include + #include "html/html_base_element.h" #include "core/node.h" @@ -28,7 +30,7 @@ static struct dom_element_protected_vtable _protect_vtable = { dom_exception _dom_html_base_element_create(struct dom_document *doc, struct dom_html_base_element **ele) { - *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_base_element)); + *ele = malloc(sizeof(dom_html_base_element)); if (*ele == NULL) return DOM_NO_MEM_ERR; @@ -50,17 +52,15 @@ dom_exception _dom_html_base_element_create(struct dom_document *doc, dom_exception _dom_html_base_element_initialise(struct dom_document *doc, struct dom_html_base_element *ele) { - const char *str = "BASE"; - lwc_string *name = NULL; + dom_string *name = NULL; dom_exception err; - err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), - &name); + err = dom_string_create((const uint8_t *) "BASE", SLEN("BASE"), &name); if (err != DOM_NO_ERR) return err; err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - _dom_document_unref_lwcstring(doc, name); + dom_string_unref(name); return err; } @@ -68,26 +68,22 @@ dom_exception _dom_html_base_element_initialise(struct dom_document *doc, /** * Finalise a dom_html_base_element object * - * \param doc The document object * \param ele The dom_html_base_element object */ -void _dom_html_base_element_finalise(struct dom_document *doc, - struct dom_html_base_element *ele) +void _dom_html_base_element_finalise(struct dom_html_base_element *ele) { - _dom_html_element_finalise(doc, &ele->base); + _dom_html_element_finalise(&ele->base); } /** * Destroy a dom_html_base_element object * - * \param doc The document object * \param ele The dom_html_base_element object */ -void _dom_html_base_element_destroy(struct dom_document *doc, - struct dom_html_base_element *ele) +void _dom_html_base_element_destroy(struct dom_html_base_element *ele) { - _dom_html_base_element_finalise(doc, ele); - _dom_document_alloc(doc, ele, 0); + _dom_html_base_element_finalise(ele); + free(ele); } /*------------------------------------------------------------------------*/ @@ -111,27 +107,13 @@ dom_exception _dom_html_base_element_parse_attribute(dom_element *ele, /* The virtual destroy function, see src/core/node.c for detail */ void _dom_virtual_html_base_element_destroy(dom_node_internal *node) { - struct dom_document *doc = dom_node_get_owner(node); - _dom_html_base_element_destroy(doc, (struct dom_html_base_element *) node); -} - -/* The virtual allocation function, see src/core/node.c for detail */ -dom_exception _dom_html_base_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret) -{ - UNUSED(n); - - *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_base_element)); - if (*ret == NULL) - return DOM_NO_MEM_ERR; - - return DOM_NO_ERR; + _dom_html_base_element_destroy((struct dom_html_base_element *) node); } /* The virtual copy function, see src/core/node.c for detail */ -dom_exception _dom_html_base_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old) +dom_exception _dom_html_base_element_copy(dom_node_internal *old, + dom_node_internal **copy) { - return _dom_html_element_copy(new, old); + return _dom_html_element_copy(old, copy); } diff --git a/src/html/html_base_element.h b/src/html/html_base_element.h index c9143f5..ab5641a 100644 --- a/src/html/html_base_element.h +++ b/src/html/html_base_element.h @@ -26,29 +26,24 @@ dom_exception _dom_html_base_element_initialise(struct dom_document *doc, struct dom_html_base_element *ele); /* Finalise a dom_html_base_element object */ -void _dom_html_base_element_finalise(struct dom_document *doc, - struct dom_html_base_element *ele); +void _dom_html_base_element_finalise(struct dom_html_base_element *ele); /* Destroy a dom_html_base_element object */ -void _dom_html_base_element_destroy(struct dom_document *doc, - struct dom_html_base_element *ele); +void _dom_html_base_element_destroy(struct dom_html_base_element *ele); /* The protected virtual functions */ dom_exception _dom_html_base_element_parse_attribute(dom_element *ele, dom_string *name, dom_string *value, dom_string **parsed); void _dom_virtual_html_base_element_destroy(dom_node_internal *node); -dom_exception _dom_html_base_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret); -dom_exception _dom_html_base_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old); +dom_exception _dom_html_base_element_copy(dom_node_internal *old, + dom_node_internal **copy); #define DOM_HTML_BASE_ELEMENT_PROTECT_VTABLE \ _dom_html_base_element_parse_attribute #define DOM_NODE_PROTECT_VTABLE_HTML_BASE_ELEMENT \ _dom_virtual_html_base_element_destroy, \ - _dom_html_base_element_alloc, \ _dom_html_base_element_copy #endif diff --git a/src/html/html_body_element.c b/src/html/html_body_element.c index afe8ee4..d29c86c 100644 --- a/src/html/html_body_element.c +++ b/src/html/html_body_element.c @@ -5,6 +5,8 @@ * Copyright 2009 Bo Yang */ +#include + #include "html/html_body_element.h" #include "core/node.h" @@ -28,7 +30,7 @@ static struct dom_element_protected_vtable _protect_vtable = { dom_exception _dom_html_body_element_create(struct dom_document *doc, struct dom_html_body_element **ele) { - *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_body_element)); + *ele = malloc(sizeof(dom_html_body_element)); if (*ele == NULL) return DOM_NO_MEM_ERR; @@ -50,17 +52,15 @@ dom_exception _dom_html_body_element_create(struct dom_document *doc, dom_exception _dom_html_body_element_initialise(struct dom_document *doc, struct dom_html_body_element *ele) { - const char *str = "BODY"; - lwc_string *name = NULL; + dom_string *name = NULL; dom_exception err; - err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), - &name); + err = dom_string_create((const uint8_t *) "BODY", SLEN("BODY"), &name); if (err != DOM_NO_ERR) return err; err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - _dom_document_unref_lwcstring(doc, name); + dom_string_unref(name); return err; } @@ -68,26 +68,22 @@ dom_exception _dom_html_body_element_initialise(struct dom_document *doc, /** * Finalise a dom_html_body_element object * - * \param doc The document object * \param ele The dom_html_body_element object */ -void _dom_html_body_element_finalise(struct dom_document *doc, - struct dom_html_body_element *ele) +void _dom_html_body_element_finalise(struct dom_html_body_element *ele) { - _dom_html_element_finalise(doc, &ele->base); + _dom_html_element_finalise(&ele->base); } /** * Destroy a dom_html_body_element object * - * \param doc The document object * \param ele The dom_html_body_element object */ -void _dom_html_body_element_destroy(struct dom_document *doc, - struct dom_html_body_element *ele) +void _dom_html_body_element_destroy(struct dom_html_body_element *ele) { - _dom_html_body_element_finalise(doc, ele); - _dom_document_alloc(doc, ele, 0); + _dom_html_body_element_finalise(ele); + free(ele); } /*------------------------------------------------------------------------*/ @@ -111,27 +107,13 @@ dom_exception _dom_html_body_element_parse_attribute(dom_element *ele, /* The virtual destroy function, see src/core/node.c for detail */ void _dom_virtual_html_body_element_destroy(dom_node_internal *node) { - struct dom_document *doc = dom_node_get_owner(node); - _dom_html_body_element_destroy(doc, (struct dom_html_body_element *) node); -} - -/* The virtual allocation function, see src/core/node.c for detail */ -dom_exception _dom_html_body_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret) -{ - UNUSED(n); - - *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_body_element)); - if (*ret == NULL) - return DOM_NO_MEM_ERR; - - return DOM_NO_ERR; + _dom_html_body_element_destroy((struct dom_html_body_element *) node); } /* The virtual copy function, see src/core/node.c for detail */ -dom_exception _dom_html_body_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old) +dom_exception _dom_html_body_element_copy(dom_node_internal *old, + dom_node_internal **copy) { - return _dom_html_element_copy(new, old); + return _dom_html_element_copy(old, copy); } diff --git a/src/html/html_body_element.h b/src/html/html_body_element.h index ccb6091..028cac3 100644 --- a/src/html/html_body_element.h +++ b/src/html/html_body_element.h @@ -26,29 +26,24 @@ dom_exception _dom_html_body_element_initialise(struct dom_document *doc, struct dom_html_body_element *ele); /* Finalise a dom_html_body_element object */ -void _dom_html_body_element_finalise(struct dom_document *doc, - struct dom_html_body_element *ele); +void _dom_html_body_element_finalise(struct dom_html_body_element *ele); /* Destroy a dom_html_body_element object */ -void _dom_html_body_element_destroy(struct dom_document *doc, - struct dom_html_body_element *ele); +void _dom_html_body_element_destroy(struct dom_html_body_element *ele); /* The protected virtual functions */ dom_exception _dom_html_body_element_parse_attribute(dom_element *ele, dom_string *name, dom_string *value, dom_string **parsed); void _dom_virtual_html_body_element_destroy(dom_node_internal *node); -dom_exception _dom_html_body_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret); -dom_exception _dom_html_body_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old); +dom_exception _dom_html_body_element_copy(dom_node_internal *old, + dom_node_internal **copy); #define DOM_HTML_BODY_ELEMENT_PROTECT_VTABLE \ _dom_html_body_element_parse_attribute #define DOM_NODE_PROTECT_VTABLE_HTML_BODY_ELEMENT \ _dom_virtual_html_body_element_destroy, \ - _dom_html_body_element_alloc, \ _dom_html_body_element_copy #endif diff --git a/src/html/html_collection.c b/src/html/html_collection.c index 9b34c51..03ac6ae 100644 --- a/src/html/html_collection.c +++ b/src/html/html_collection.c @@ -6,6 +6,7 @@ */ #include +#include #include @@ -34,7 +35,7 @@ dom_exception _dom_html_collection_create(struct dom_document *doc, dom_callback_is_in_collection ic, struct dom_html_collection **col) { - *col = _dom_document_alloc(doc, NULL, sizeof(dom_html_collection)); + *col = malloc(sizeof(dom_html_collection)); if (*col == NULL) return DOM_NO_MEM_ERR; @@ -94,10 +95,9 @@ void _dom_html_collection_finalise(struct dom_html_collection *col) */ void _dom_html_collection_destroy(struct dom_html_collection *col) { - struct dom_document *doc = col->doc; _dom_html_collection_finalise(col); - _dom_document_alloc(doc, col, 0); + free(col); } @@ -210,33 +210,27 @@ dom_exception dom_html_collection_named_item(dom_html_collection *col, { struct dom_node_internal *n = col->root; dom_exception err; - lwc_string *str = NULL; - err = _dom_node_get_intern_string(n, name, &str); - if (err != DOM_NO_ERR) - return err; - while (node != NULL) { if (n->type == DOM_ELEMENT_NODE && col->ic(n) == true) { - lwc_string *id = NULL; + dom_string *id = NULL; + err = _dom_element_get_id((struct dom_element *) n, &id); if (err != DOM_NO_ERR) { - _dom_node_unref_intern_string(n, id); return err; } - /* Compare the lwc_string directly */ - if (str == id) { + if (id != NULL && dom_string_isequal(name, id)) { *node = (struct dom_node *) n; dom_node_ref(n); - _dom_node_unref_intern_string(n, id); - _dom_node_unref_intern_string(n, str); - + dom_string_unref(id); + return DOM_NO_ERR; } - _dom_node_unref_intern_string(n, id); + if (id != NULL) + dom_string_unref(id); } /* Depth first iterating */ @@ -263,7 +257,6 @@ dom_exception dom_html_collection_named_item(dom_html_collection *col, /* Not found the target node */ *node = NULL; - _dom_node_unref_intern_string(n, str); return DOM_NO_ERR; } diff --git a/src/html/html_document.c b/src/html/html_document.c index 6b9eb5c..0022e0d 100644 --- a/src/html/html_document.c +++ b/src/html/html_document.c @@ -6,6 +6,7 @@ */ #include +#include #include "html/html_document.h" @@ -13,29 +14,24 @@ #include "utils/utils.h" /* Create a HTMLDocument */ -dom_exception dom_html_document_create(dom_alloc alloc, void *pw, dom_msg msg, - void *msg_pw, +dom_exception dom_html_document_create(dom_msg msg, void *msg_pw, dom_events_default_action_fetcher daf, dom_ui_handler *ui, dom_parser_type pt, dom_html_document **doc) { - assert(alloc != NULL); - *doc = alloc(NULL, sizeof(dom_html_document), pw); + *doc = malloc(sizeof(dom_html_document)); if (*doc == NULL) return DOM_NO_MEM_ERR; - return _dom_html_document_initialise(*doc, alloc, pw, msg, msg_pw, - daf, ui, pt); + return _dom_html_document_initialise(*doc, msg, msg_pw, daf, ui, pt); } /* Initialise a HTMLDocument */ dom_exception _dom_html_document_initialise(dom_html_document *doc, - dom_alloc alloc, void *pw, dom_msg msg, void *msg_pw, + dom_msg msg, void *msg_pw, dom_events_default_action_fetcher daf, dom_ui_handler *ui, dom_parser_type pt) { UNUSED(doc); - UNUSED(alloc); - UNUSED(pw); UNUSED(msg); UNUSED(msg_pw); UNUSED(daf); diff --git a/src/html/html_document.h b/src/html/html_document.h index 27f5cf9..a865695 100644 --- a/src/html/html_document.h +++ b/src/html/html_document.h @@ -35,7 +35,7 @@ struct dom_html_document { /* Initialise a HTMLDocument */ dom_exception _dom_html_document_initialise(dom_html_document *doc, - dom_alloc alloc, void *pw, dom_msg msg, void *msg_pw, + dom_msg msg, void *msg_pw, dom_events_default_action_fetcher daf, dom_ui_handler *ui, dom_parser_type pt); /* Finalise a HTMLDocument */ diff --git a/src/html/html_element.c b/src/html/html_element.c index 3552c67..5fbf0da 100644 --- a/src/html/html_element.c +++ b/src/html/html_element.c @@ -6,6 +6,7 @@ */ #include +#include #include "html/html_element.h" @@ -15,8 +16,8 @@ #include "utils/utils.h" dom_exception _dom_html_element_initialise(struct dom_document *doc, - struct dom_html_element *el, struct lwc_string_s *name, - struct lwc_string_s *namespace, struct lwc_string_s *prefix) + struct dom_html_element *el, dom_string *name, + dom_string *namespace, dom_string *prefix) { dom_exception err; @@ -28,13 +29,12 @@ dom_exception _dom_html_element_initialise(struct dom_document *doc, return err; } -void _dom_html_element_finalise(struct dom_document *doc, - struct dom_html_element *ele) +void _dom_html_element_finalise(struct dom_html_element *ele) { dom_node_unref(ele->form); ele->form = NULL; - _dom_element_finalise(doc, &ele->base); + _dom_element_finalise(&ele->base); } /*------------------------------------------------------------------------*/ @@ -47,24 +47,11 @@ void _dom_virtual_html_element_destroy(dom_node_internal *node) assert("Should never be here" == NULL); } -/* The virtual allocation function, see src/core/node.c for detail */ -dom_exception _dom_html_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret) -{ - UNUSED(doc); - UNUSED(n); - UNUSED(ret); - - assert("Should never be here" == NULL); - - return DOM_NO_MEM_ERR; -} - /* The virtual copy function, see src/core/node.c for detail */ -dom_exception _dom_html_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old) +dom_exception _dom_html_element_copy(dom_node_internal *old, + dom_node_internal **copy) { - return _dom_element_copy(new, old); + return _dom_element_copy(old, copy); } /*-----------------------------------------------------------------------*/ @@ -74,15 +61,9 @@ dom_exception _dom_html_element_get_id(dom_html_element *element, dom_string **id) { dom_exception ret; - dom_document *doc; dom_string *idstr; - ret = dom_node_get_owner_document(element, &doc); - if (ret != DOM_NO_ERR) - return ret; - - ret = _dom_document_create_string(doc, (const uint8_t *) "id", - SLEN("id"), &idstr); + ret = dom_string_create((const uint8_t *) "id", SLEN("id"), &idstr); if (ret != DOM_NO_ERR) return ret; @@ -97,15 +78,9 @@ dom_exception _dom_html_element_set_id(dom_html_element *element, dom_string *id) { dom_exception ret; - dom_document *doc; dom_string *idstr; - ret = dom_node_get_owner_document(element, &doc); - if (ret != DOM_NO_ERR) - return ret; - - ret = _dom_document_create_string(doc, (const uint8_t *) "id", - SLEN("id"), &idstr); + ret = dom_string_create((const uint8_t *) "id", SLEN("id"), &idstr); if (ret != DOM_NO_ERR) return ret; @@ -131,13 +106,11 @@ dom_exception _dom_html_element_set_id(dom_html_element *element, dom_exception dom_html_element_get_bool_property(dom_html_element *ele, const char *name, unsigned long len, bool *has) { - dom_document *doc = dom_node_get_owner(ele); dom_string *str = NULL; dom_attr *a = NULL; dom_exception err; - err = _dom_document_create_string(doc, (const uint8_t *) name, - len, &str); + err = dom_string_create((const uint8_t *) name, len, &str); if (err != DOM_NO_ERR) goto fail; @@ -172,13 +145,11 @@ fail: dom_exception dom_html_element_set_bool_property(dom_html_element *ele, const char *name, unsigned long len, bool has) { - dom_document *doc = dom_node_get_owner(ele); dom_string *str = NULL; dom_attr *a = NULL; dom_exception err; - err = _dom_document_create_string(doc, (const uint8_t *) name, - len, &str); + err = dom_string_create((const uint8_t *) name, len, &str); if (err != DOM_NO_ERR) goto fail; @@ -195,19 +166,13 @@ dom_exception dom_html_element_set_bool_property(dom_html_element *ele, dom_node_unref(res); } else if (a == NULL && has == true) { + dom_document *doc = dom_node_get_owner(ele); dom_attr *res = NULL; - lwc_string *lstr = NULL; - - err = _dom_string_intern(str, &lstr); - if (err != DOM_NO_ERR) - goto cleanup1; - err = _dom_attr_create(doc, lstr, NULL, NULL, true, &a); + err = _dom_attr_create(doc, str, NULL, NULL, true, &a); if (err != DOM_NO_ERR) { - lwc_string_unref(lstr); goto cleanup1; } - lwc_string_unref(lstr); err = dom_element_set_attribute_node(ele, a, &res); if (err != DOM_NO_ERR) diff --git a/src/html/html_element.h b/src/html/html_element.h index 2a433a8..29fb28d 100644 --- a/src/html/html_element.h +++ b/src/html/html_element.h @@ -28,18 +28,15 @@ struct dom_html_element { }; dom_exception _dom_html_element_initialise(struct dom_document *doc, - struct dom_html_element *el, struct lwc_string_s *name, - struct lwc_string_s *namespace, struct lwc_string_s *prefix); + struct dom_html_element *el, dom_string *name, + dom_string *namespace, dom_string *prefix); -void _dom_html_element_finalise(struct dom_document *doc, - struct dom_html_element *ele); +void _dom_html_element_finalise(struct dom_html_element *ele); /* The protected virtual functions */ void _dom_virtual_html_element_destroy(dom_node_internal *node); -dom_exception _dom_html_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret); -dom_exception _dom_html_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old); +dom_exception _dom_html_element_copy(dom_node_internal *old, + dom_node_internal **copy); /* The API functions */ dom_exception _dom_html_element_get_id(dom_html_element *element, diff --git a/src/html/html_form_element.c b/src/html/html_form_element.c index 1b6ab91..11c4b98 100644 --- a/src/html/html_form_element.c +++ b/src/html/html_form_element.c @@ -6,6 +6,7 @@ */ #include +#include #include "html/html_form_element.h" @@ -34,7 +35,7 @@ static bool _dom_is_form_control(struct dom_node_internal *node); dom_exception _dom_html_form_element_create(struct dom_document *doc, struct dom_html_form_element **ele) { - *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_form_element)); + *ele = malloc(sizeof(dom_html_form_element)); if (*ele == NULL) return DOM_NO_MEM_ERR; @@ -56,17 +57,15 @@ dom_exception _dom_html_form_element_create(struct dom_document *doc, dom_exception _dom_html_form_element_initialise(struct dom_document *doc, struct dom_html_form_element *ele) { - const char *str = "FORM"; - lwc_string *name = NULL; + dom_string *name = NULL; dom_exception err; - err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), - &name); + err = dom_string_create((const uint8_t *) "FORM", SLEN("FORM"), &name); if (err != DOM_NO_ERR) return err; err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - _dom_document_unref_lwcstring(doc, name); + dom_string_unref(name); ele->col = NULL; @@ -76,26 +75,22 @@ dom_exception _dom_html_form_element_initialise(struct dom_document *doc, /** * Finalise a dom_html_form_element object * - * \param doc The document object * \param ele The dom_html_form_element object */ -void _dom_html_form_element_finalise(struct dom_document *doc, - struct dom_html_form_element *ele) +void _dom_html_form_element_finalise(struct dom_html_form_element *ele) { - _dom_html_element_finalise(doc, &ele->base); + _dom_html_element_finalise(&ele->base); } /** * Destroy a dom_html_form_element object * - * \param doc The document object * \param ele The dom_html_form_element object */ -void _dom_html_form_element_destroy(struct dom_document *doc, - struct dom_html_form_element *ele) +void _dom_html_form_element_destroy(struct dom_html_form_element *ele) { - _dom_html_form_element_finalise(doc, ele); - _dom_document_alloc(doc, ele, 0); + _dom_html_form_element_finalise(ele); + free(ele); } /*------------------------------------------------------------------------*/ @@ -119,28 +114,14 @@ dom_exception _dom_html_form_element_parse_attribute(dom_element *ele, /* The virtual destroy function, see src/core/node.c for detail */ void _dom_virtual_html_form_element_destroy(dom_node_internal *node) { - struct dom_document *doc = dom_node_get_owner(node); - _dom_html_form_element_destroy(doc, (struct dom_html_form_element *) node); -} - -/* The virtual allocation function, see src/core/node.c for detail */ -dom_exception _dom_html_form_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret) -{ - UNUSED(n); - - *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_form_element)); - if (*ret == NULL) - return DOM_NO_MEM_ERR; - - return DOM_NO_ERR; + _dom_html_form_element_destroy((struct dom_html_form_element *) node); } /* The virtual copy function, see src/core/node.c for detail */ -dom_exception _dom_html_form_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old) +dom_exception _dom_html_form_element_copy(dom_node_internal *old, + dom_node_internal **copy) { - return _dom_html_element_copy(new, old); + return _dom_html_element_copy(old, copy); } /*-----------------------------------------------------------------------*/ diff --git a/src/html/html_form_element.h b/src/html/html_form_element.h index dd1482b..3dc66e1 100644 --- a/src/html/html_form_element.h +++ b/src/html/html_form_element.h @@ -30,29 +30,24 @@ dom_exception _dom_html_form_element_initialise(struct dom_document *doc, struct dom_html_form_element *ele); /* Finalise a dom_html_form_element object */ -void _dom_html_form_element_finalise(struct dom_document *doc, - struct dom_html_form_element *ele); +void _dom_html_form_element_finalise(struct dom_html_form_element *ele); /* Destroy a dom_html_form_element object */ -void _dom_html_form_element_destroy(struct dom_document *doc, - struct dom_html_form_element *ele); +void _dom_html_form_element_destroy(struct dom_html_form_element *ele); /* The protected virtual functions */ dom_exception _dom_html_form_element_parse_attribute(dom_element *ele, dom_string *name, dom_string *value, dom_string **parsed); void _dom_virtual_html_form_element_destroy(dom_node_internal *node); -dom_exception _dom_html_form_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret); -dom_exception _dom_html_form_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old); +dom_exception _dom_html_form_element_copy(dom_node_internal *old, + dom_node_internal **copy); #define DOM_HTML_FORM_ELEMENT_PROTECT_VTABLE \ _dom_html_form_element_parse_attribute #define DOM_NODE_PROTECT_VTABLE_HTML_FORM_ELEMENT \ _dom_virtual_html_form_element_destroy, \ - _dom_html_form_element_alloc, \ _dom_html_form_element_copy #endif diff --git a/src/html/html_head_element.c b/src/html/html_head_element.c index a37acfe..ec8070a 100644 --- a/src/html/html_head_element.c +++ b/src/html/html_head_element.c @@ -5,6 +5,8 @@ * Copyright 2009 Bo Yang */ +#include + #include "html/html_head_element.h" #include "core/node.h" @@ -28,7 +30,7 @@ static struct dom_element_protected_vtable _protect_vtable = { dom_exception _dom_html_head_element_create(struct dom_document *doc, struct dom_html_head_element **ele) { - *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_head_element)); + *ele = malloc(sizeof(dom_html_head_element)); if (*ele == NULL) return DOM_NO_MEM_ERR; @@ -50,17 +52,15 @@ dom_exception _dom_html_head_element_create(struct dom_document *doc, dom_exception _dom_html_head_element_initialise(struct dom_document *doc, struct dom_html_head_element *ele) { - const char *str = "HEAD"; - lwc_string *name = NULL; + dom_string *name = NULL; dom_exception err; - err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), - &name); + err = dom_string_create((const uint8_t *) "HEAD", SLEN("HEAD"), &name); if (err != DOM_NO_ERR) return err; err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - _dom_document_unref_lwcstring(doc, name); + dom_string_unref(name); return err; } @@ -68,26 +68,22 @@ dom_exception _dom_html_head_element_initialise(struct dom_document *doc, /** * Finalise a dom_html_head_element object * - * \param doc The document object * \param ele The dom_html_head_element object */ -void _dom_html_head_element_finalise(struct dom_document *doc, - struct dom_html_head_element *ele) +void _dom_html_head_element_finalise(struct dom_html_head_element *ele) { - _dom_html_element_finalise(doc, &ele->base); + _dom_html_element_finalise(&ele->base); } /** * Destroy a dom_html_head_element object * - * \param doc The document object * \param ele The dom_html_head_element object */ -void _dom_html_head_element_destroy(struct dom_document *doc, - struct dom_html_head_element *ele) +void _dom_html_head_element_destroy(struct dom_html_head_element *ele) { - _dom_html_head_element_finalise(doc, ele); - _dom_document_alloc(doc, ele, 0); + _dom_html_head_element_finalise(ele); + free(ele); } /*------------------------------------------------------------------------*/ @@ -111,27 +107,13 @@ dom_exception _dom_html_head_element_parse_attribute(dom_element *ele, /* The virtual destroy function, see src/core/node.c for detail */ void _dom_virtual_html_head_element_destroy(dom_node_internal *node) { - struct dom_document *doc = dom_node_get_owner(node); - _dom_html_head_element_destroy(doc, (struct dom_html_head_element *) node); -} - -/* The virtual allocation function, see src/core/node.c for detail */ -dom_exception _dom_html_head_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret) -{ - UNUSED(n); - - *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_head_element)); - if (*ret == NULL) - return DOM_NO_MEM_ERR; - - return DOM_NO_ERR; + _dom_html_head_element_destroy((struct dom_html_head_element *) node); } /* The virtual copy function, see src/core/node.c for detail */ -dom_exception _dom_html_head_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old) +dom_exception _dom_html_head_element_copy(dom_node_internal *old, + dom_node_internal **copy) { - return _dom_html_element_copy(new, old); + return _dom_html_element_copy(old, copy); } diff --git a/src/html/html_head_element.h b/src/html/html_head_element.h index bb58720..c917593 100644 --- a/src/html/html_head_element.h +++ b/src/html/html_head_element.h @@ -26,29 +26,24 @@ dom_exception _dom_html_head_element_initialise(struct dom_document *doc, struct dom_html_head_element *ele); /* Finalise a dom_html_head_element object */ -void _dom_html_head_element_finalise(struct dom_document *doc, - struct dom_html_head_element *ele); +void _dom_html_head_element_finalise(struct dom_html_head_element *ele); /* Destroy a dom_html_head_element object */ -void _dom_html_head_element_destroy(struct dom_document *doc, - struct dom_html_head_element *ele); +void _dom_html_head_element_destroy(struct dom_html_head_element *ele); /* The protected virtual functions */ dom_exception _dom_html_head_element_parse_attribute(dom_element *ele, dom_string *name, dom_string *value, dom_string **parsed); void _dom_virtual_html_head_element_destroy(dom_node_internal *node); -dom_exception _dom_html_head_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret); -dom_exception _dom_html_head_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old); +dom_exception _dom_html_head_element_copy(dom_node_internal *old, + dom_node_internal **copy); #define DOM_HTML_HEAD_ELEMENT_PROTECT_VTABLE \ _dom_html_head_element_parse_attribute #define DOM_NODE_PROTECT_VTABLE_HTML_HEAD_ELEMENT \ _dom_virtual_html_head_element_destroy, \ - _dom_html_head_element_alloc, \ _dom_html_head_element_copy #endif diff --git a/src/html/html_html_element.c b/src/html/html_html_element.c index 2da67f6..9083394 100644 --- a/src/html/html_html_element.c +++ b/src/html/html_html_element.c @@ -5,6 +5,8 @@ * Copyright 2009 Bo Yang */ +#include + #include "html/html_html_element.h" #include "core/node.h" @@ -28,7 +30,7 @@ static struct dom_element_protected_vtable _protect_vtable = { dom_exception _dom_html_html_element_create(struct dom_document *doc, struct dom_html_html_element **ele) { - *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_html_element)); + *ele = malloc(sizeof(dom_html_html_element)); if (*ele == NULL) return DOM_NO_MEM_ERR; @@ -50,17 +52,15 @@ dom_exception _dom_html_html_element_create(struct dom_document *doc, dom_exception _dom_html_html_element_initialise(struct dom_document *doc, struct dom_html_html_element *ele) { - const char *str = "HTML"; - lwc_string *name = NULL; + dom_string *name = NULL; dom_exception err; - err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), - &name); + err = dom_string_create((const uint8_t *) "HTML", SLEN("HTML"), &name); if (err != DOM_NO_ERR) return err; err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - _dom_document_unref_lwcstring(doc, name); + dom_string_unref(name); return err; } @@ -68,26 +68,23 @@ dom_exception _dom_html_html_element_initialise(struct dom_document *doc, /** * Finalise a dom_html_html_element object * - * \param doc The document object * \param ele The dom_html_html_element object */ -void _dom_html_html_element_finalise(struct dom_document *doc, - struct dom_html_html_element *ele) +void _dom_html_html_element_finalise(struct dom_html_html_element *ele) { - _dom_html_element_finalise(doc, &ele->base); + _dom_html_element_finalise(&ele->base); } /** * Destroy a dom_html_html_element object * - * \param doc The document object * \param ele The dom_html_html_element object */ -void _dom_html_html_element_destroy(struct dom_document *doc, - struct dom_html_html_element *ele) +void _dom_html_html_element_destroy(struct dom_html_html_element *ele) { - _dom_html_html_element_finalise(doc, ele); - _dom_document_alloc(doc, ele, 0); + _dom_html_html_element_finalise(ele); + + free(ele); } /*------------------------------------------------------------------------*/ @@ -111,27 +108,13 @@ dom_exception _dom_html_html_element_parse_attribute(dom_element *ele, /* The virtual destroy function, see src/core/node.c for detail */ void _dom_virtual_html_html_element_destroy(dom_node_internal *node) { - struct dom_document *doc = dom_node_get_owner(node); - _dom_html_html_element_destroy(doc, (struct dom_html_html_element *) node); -} - -/* The virtual allocation function, see src/core/node.c for detail */ -dom_exception _dom_html_html_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret) -{ - UNUSED(n); - - *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_html_element)); - if (*ret == NULL) - return DOM_NO_MEM_ERR; - - return DOM_NO_ERR; + _dom_html_html_element_destroy((struct dom_html_html_element *) node); } /* The virtual copy function, see src/core/node.c for detail */ -dom_exception _dom_html_html_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old) +dom_exception _dom_html_html_element_copy(dom_node_internal *old, + dom_node_internal **copy) { - return _dom_html_element_copy(new, old); + return _dom_html_element_copy(old, copy); } diff --git a/src/html/html_html_element.h b/src/html/html_html_element.h index 4ffc9ba..e6f1737 100644 --- a/src/html/html_html_element.h +++ b/src/html/html_html_element.h @@ -26,29 +26,24 @@ dom_exception _dom_html_html_element_initialise(struct dom_document *doc, struct dom_html_html_element *ele); /* Finalise a dom_html_html_element object */ -void _dom_html_html_element_finalise(struct dom_document *doc, - struct dom_html_html_element *ele); +void _dom_html_html_element_finalise(struct dom_html_html_element *ele); /* Destroy a dom_html_html_element object */ -void _dom_html_html_element_destroy(struct dom_document *doc, - struct dom_html_html_element *ele); +void _dom_html_html_element_destroy(struct dom_html_html_element *ele); /* The protected virtual functions */ dom_exception _dom_html_html_element_parse_attribute(dom_element *ele, dom_string *name, dom_string *value, dom_string **parsed); void _dom_virtual_html_html_element_destroy(dom_node_internal *node); -dom_exception _dom_html_html_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret); -dom_exception _dom_html_html_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old); +dom_exception _dom_html_html_element_copy(dom_node_internal *old, + dom_node_internal **copy); #define DOM_HTML_HTML_ELEMENT_PROTECT_VTABLE \ _dom_html_html_element_parse_attribute #define DOM_NODE_PROTECT_VTABLE_HTML_HTML_ELEMENT \ _dom_virtual_html_html_element_destroy, \ - _dom_html_html_element_alloc, \ _dom_html_html_element_copy #endif diff --git a/src/html/html_isindex_element.c b/src/html/html_isindex_element.c index 295ee38..a1343cb 100644 --- a/src/html/html_isindex_element.c +++ b/src/html/html_isindex_element.c @@ -5,6 +5,8 @@ * Copyright 2009 Bo Yang */ +#include + #include "html/html_isindex_element.h" #include "core/node.h" @@ -30,7 +32,7 @@ dom_exception _dom_html_isindex_element_create(struct dom_document *doc, struct dom_html_form_element *form, struct dom_html_isindex_element **ele) { - *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_isindex_element)); + *ele = malloc(sizeof(dom_html_isindex_element)); if (*ele == NULL) return DOM_NO_MEM_ERR; @@ -54,17 +56,16 @@ dom_exception _dom_html_isindex_element_initialise(struct dom_document *doc, struct dom_html_form_element *form, struct dom_html_isindex_element *ele) { - const char *str = "ISINDEX"; - lwc_string *name = NULL; + dom_string *name = NULL; dom_exception err; - err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), + err = dom_string_create((const uint8_t *) "ISINDEX", SLEN("ISINDEX"), &name); if (err != DOM_NO_ERR) return err; err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - _dom_document_unref_lwcstring(doc, name); + dom_string_unref(name); ele->base.form = form; dom_node_ref(form); @@ -75,26 +76,22 @@ dom_exception _dom_html_isindex_element_initialise(struct dom_document *doc, /** * Finalise a dom_html_isindex_element object * - * \param doc The document object * \param ele The dom_html_isindex_element object */ -void _dom_html_isindex_element_finalise(struct dom_document *doc, - struct dom_html_isindex_element *ele) +void _dom_html_isindex_element_finalise(struct dom_html_isindex_element *ele) { - _dom_html_element_finalise(doc, &ele->base); + _dom_html_element_finalise(&ele->base); } /** * Destroy a dom_html_isindex_element object * - * \param doc The document object * \param ele The dom_html_isindex_element object */ -void _dom_html_isindex_element_destroy(struct dom_document *doc, - struct dom_html_isindex_element *ele) +void _dom_html_isindex_element_destroy(struct dom_html_isindex_element *ele) { - _dom_html_isindex_element_finalise(doc, ele); - _dom_document_alloc(doc, ele, 0); + _dom_html_isindex_element_finalise(ele); + free(ele); } /*------------------------------------------------------------------------*/ @@ -118,28 +115,14 @@ dom_exception _dom_html_isindex_element_parse_attribute(dom_element *ele, /* The virtual destroy function, see src/core/node.c for detail */ void _dom_virtual_html_isindex_element_destroy(dom_node_internal *node) { - struct dom_document *doc = dom_node_get_owner(node); - _dom_html_isindex_element_destroy(doc, (struct dom_html_isindex_element *) node); -} - -/* The virtual allocation function, see src/core/node.c for detail */ -dom_exception _dom_html_isindex_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret) -{ - UNUSED(n); - - *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_isindex_element)); - if (*ret == NULL) - return DOM_NO_MEM_ERR; - - return DOM_NO_ERR; + _dom_html_isindex_element_destroy((struct dom_html_isindex_element *) node); } /* The virtual copy function, see src/core/node.c for detail */ -dom_exception _dom_html_isindex_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old) +dom_exception _dom_html_isindex_element_copy(dom_node_internal *old, + dom_node_internal **copy) { - return _dom_html_element_copy(new, old); + return _dom_html_element_copy(old, copy); } diff --git a/src/html/html_isindex_element.h b/src/html/html_isindex_element.h index b64c6c0..9cf9a02 100644 --- a/src/html/html_isindex_element.h +++ b/src/html/html_isindex_element.h @@ -28,29 +28,24 @@ dom_exception _dom_html_isindex_element_initialise(struct dom_document *doc, struct dom_html_isindex_element *ele); /* Finalise a dom_html_isindex_element object */ -void _dom_html_isindex_element_finalise(struct dom_document *doc, - struct dom_html_isindex_element *ele); +void _dom_html_isindex_element_finalise(struct dom_html_isindex_element *ele); /* Destroy a dom_html_isindex_element object */ -void _dom_html_isindex_element_destroy(struct dom_document *doc, - struct dom_html_isindex_element *ele); +void _dom_html_isindex_element_destroy(struct dom_html_isindex_element *ele); /* The protected virtual functions */ dom_exception _dom_html_isindex_element_parse_attribute(dom_element *ele, dom_string *name, dom_string *value, dom_string **parsed); void _dom_virtual_html_isindex_element_destroy(dom_node_internal *node); -dom_exception _dom_html_isindex_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret); -dom_exception _dom_html_isindex_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old); +dom_exception _dom_html_isindex_element_copy(dom_node_internal *old, + dom_node_internal **copy); #define DOM_HTML_ISINDEX_ELEMENT_PROTECT_VTABLE \ _dom_html_isindex_element_parse_attribute #define DOM_NODE_PROTECT_VTABLE_HTML_ISINDEX_ELEMENT \ _dom_virtual_html_isindex_element_destroy, \ - _dom_html_isindex_element_alloc, \ _dom_html_isindex_element_copy #endif diff --git a/src/html/html_link_element.c b/src/html/html_link_element.c index b7b143c..35362c6 100644 --- a/src/html/html_link_element.c +++ b/src/html/html_link_element.c @@ -6,6 +6,7 @@ */ #include +#include #include "html/html_link_element.h" @@ -31,7 +32,7 @@ static struct dom_element_protected_vtable _protect_vtable = { dom_exception _dom_html_link_element_create(struct dom_document *doc, struct dom_html_link_element **ele) { - *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_link_element)); + *ele = malloc(sizeof(dom_html_link_element)); if (*ele == NULL) return DOM_NO_MEM_ERR; @@ -53,17 +54,15 @@ dom_exception _dom_html_link_element_create(struct dom_document *doc, dom_exception _dom_html_link_element_initialise(struct dom_document *doc, struct dom_html_link_element *ele) { - const char *str = "LINK"; - lwc_string *name = NULL; + dom_string *name = NULL; dom_exception err; - err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), - &name); + err = dom_string_create((const uint8_t *) "HEAD", SLEN("HEAD"), &name); if (err != DOM_NO_ERR) return err; err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - _dom_document_unref_lwcstring(doc, name); + dom_string_unref(name); return err; } @@ -71,26 +70,22 @@ dom_exception _dom_html_link_element_initialise(struct dom_document *doc, /** * Finalise a dom_html_link_element object * - * \param doc The document object * \param ele The dom_html_link_element object */ -void _dom_html_link_element_finalise(struct dom_document *doc, - struct dom_html_link_element *ele) +void _dom_html_link_element_finalise(struct dom_html_link_element *ele) { - _dom_html_element_finalise(doc, &ele->base); + _dom_html_element_finalise(&ele->base); } /** * Destroy a dom_html_link_element object * - * \param doc The document object * \param ele The dom_html_link_element object */ -void _dom_html_link_element_destroy(struct dom_document *doc, - struct dom_html_link_element *ele) +void _dom_html_link_element_destroy(struct dom_html_link_element *ele) { - _dom_html_link_element_finalise(doc, ele); - _dom_document_alloc(doc, ele, 0); + _dom_html_link_element_finalise(ele); + free(ele); } /*-----------------------------------------------------------------------*/ @@ -145,27 +140,13 @@ dom_exception _dom_html_link_element_parse_attribute(dom_element *ele, /* The virtual destroy function, see src/core/node.c for detail */ void _dom_virtual_html_link_element_destroy(dom_node_internal *node) { - struct dom_document *doc = dom_node_get_owner(node); - _dom_html_link_element_destroy(doc, (struct dom_html_link_element *) node); -} - -/* The virtual allocation function, see src/core/node.c for detail */ -dom_exception _dom_html_link_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret) -{ - UNUSED(n); - - *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_link_element)); - if (*ret == NULL) - return DOM_NO_MEM_ERR; - - return DOM_NO_ERR; + _dom_html_link_element_destroy((struct dom_html_link_element *) node); } /* The virtual copy function, see src/core/node.c for detail */ -dom_exception _dom_html_link_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old) +dom_exception _dom_html_link_element_copy(dom_node_internal *old, + dom_node_internal **copy) { - return _dom_html_element_copy(new, old); + return _dom_html_element_copy(old, copy); } diff --git a/src/html/html_link_element.h b/src/html/html_link_element.h index 613665b..23abd33 100644 --- a/src/html/html_link_element.h +++ b/src/html/html_link_element.h @@ -26,29 +26,24 @@ dom_exception _dom_html_link_element_initialise(struct dom_document *doc, struct dom_html_link_element *ele); /* Finalise a dom_html_link_element object */ -void _dom_html_link_element_finalise(struct dom_document *doc, - struct dom_html_link_element *ele); +void _dom_html_link_element_finalise(struct dom_html_link_element *ele); /* Destroy a dom_html_link_element object */ -void _dom_html_link_element_destroy(struct dom_document *doc, - struct dom_html_link_element *ele); +void _dom_html_link_element_destroy(struct dom_html_link_element *ele); /* The protected virtual functions */ dom_exception _dom_html_link_element_parse_attribute(dom_element *ele, dom_string *name, dom_string *value, dom_string **parsed); void _dom_virtual_html_link_element_destroy(dom_node_internal *node); -dom_exception _dom_html_link_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret); -dom_exception _dom_html_link_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old); +dom_exception _dom_html_link_element_copy(dom_node_internal *old, + dom_node_internal **copy); #define DOM_HTML_LINK_ELEMENT_PROTECT_VTABLE \ _dom_html_link_element_parse_attribute #define DOM_NODE_PROTECT_VTABLE_HTML_LINK_ELEMENT \ _dom_virtual_html_link_element_destroy, \ - _dom_html_link_element_alloc, \ _dom_html_link_element_copy #endif diff --git a/src/html/html_meta_element.c b/src/html/html_meta_element.c index 92b293b..2ec64c3 100644 --- a/src/html/html_meta_element.c +++ b/src/html/html_meta_element.c @@ -5,6 +5,8 @@ * Copyright 2009 Bo Yang */ +#include + #include "html/html_meta_element.h" #include "core/node.h" @@ -28,7 +30,7 @@ static struct dom_element_protected_vtable _protect_vtable = { dom_exception _dom_html_meta_element_create(struct dom_document *doc, struct dom_html_meta_element **ele) { - *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_meta_element)); + *ele = malloc(sizeof(dom_html_meta_element)); if (*ele == NULL) return DOM_NO_MEM_ERR; @@ -50,17 +52,15 @@ dom_exception _dom_html_meta_element_create(struct dom_document *doc, dom_exception _dom_html_meta_element_initialise(struct dom_document *doc, struct dom_html_meta_element *ele) { - const char *str = "META"; - lwc_string *name = NULL; + dom_string *name = NULL; dom_exception err; - err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), - &name); + err = dom_string_create((const uint8_t *) "META", SLEN("META"), &name); if (err != DOM_NO_ERR) return err; err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - _dom_document_unref_lwcstring(doc, name); + dom_string_unref(name); return err; } @@ -68,26 +68,22 @@ dom_exception _dom_html_meta_element_initialise(struct dom_document *doc, /** * Finalise a dom_html_meta_element object * - * \param doc The document object * \param ele The dom_html_meta_element object */ -void _dom_html_meta_element_finalise(struct dom_document *doc, - struct dom_html_meta_element *ele) +void _dom_html_meta_element_finalise(struct dom_html_meta_element *ele) { - _dom_html_element_finalise(doc, &ele->base); + _dom_html_element_finalise(&ele->base); } /** * Destroy a dom_html_meta_element object * - * \param doc The document object * \param ele The dom_html_meta_element object */ -void _dom_html_meta_element_destroy(struct dom_document *doc, - struct dom_html_meta_element *ele) +void _dom_html_meta_element_destroy(struct dom_html_meta_element *ele) { - _dom_html_meta_element_finalise(doc, ele); - _dom_document_alloc(doc, ele, 0); + _dom_html_meta_element_finalise(ele); + free(ele); } /*------------------------------------------------------------------------*/ @@ -111,27 +107,13 @@ dom_exception _dom_html_meta_element_parse_attribute(dom_element *ele, /* The virtual destroy function, see src/core/node.c for detail */ void _dom_virtual_html_meta_element_destroy(dom_node_internal *node) { - struct dom_document *doc = dom_node_get_owner(node); - _dom_html_meta_element_destroy(doc, (struct dom_html_meta_element *) node); -} - -/* The virtual allocation function, see src/core/node.c for detail */ -dom_exception _dom_html_meta_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret) -{ - UNUSED(n); - - *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_meta_element)); - if (*ret == NULL) - return DOM_NO_MEM_ERR; - - return DOM_NO_ERR; + _dom_html_meta_element_destroy((struct dom_html_meta_element *) node); } /* The virtual copy function, see src/core/node.c for detail */ -dom_exception _dom_html_meta_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old) +dom_exception _dom_html_meta_element_copy(dom_node_internal *old, + dom_node_internal **copy) { - return _dom_html_element_copy(new, old); + return _dom_html_element_copy(old, copy); } diff --git a/src/html/html_meta_element.h b/src/html/html_meta_element.h index 6574913..5674ceb 100644 --- a/src/html/html_meta_element.h +++ b/src/html/html_meta_element.h @@ -26,29 +26,24 @@ dom_exception _dom_html_meta_element_initialise(struct dom_document *doc, struct dom_html_meta_element *ele); /* Finalise a dom_html_meta_element object */ -void _dom_html_meta_element_finalise(struct dom_document *doc, - struct dom_html_meta_element *ele); +void _dom_html_meta_element_finalise(struct dom_html_meta_element *ele); /* Destroy a dom_html_meta_element object */ -void _dom_html_meta_element_destroy(struct dom_document *doc, - struct dom_html_meta_element *ele); +void _dom_html_meta_element_destroy(struct dom_html_meta_element *ele); /* The protected virtual functions */ dom_exception _dom_html_meta_element_parse_attribute(dom_element *ele, dom_string *name, dom_string *value, dom_string **parsed); void _dom_virtual_html_meta_element_destroy(dom_node_internal *node); -dom_exception _dom_html_meta_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret); -dom_exception _dom_html_meta_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old); +dom_exception _dom_html_meta_element_copy(dom_node_internal *old, + dom_node_internal **copy); #define DOM_HTML_META_ELEMENT_PROTECT_VTABLE \ _dom_html_meta_element_parse_attribute #define DOM_NODE_PROTECT_VTABLE_HTML_META_ELEMENT \ _dom_virtual_html_meta_element_destroy, \ - _dom_html_meta_element_alloc, \ _dom_html_meta_element_copy #endif diff --git a/src/html/html_options_collection.c b/src/html/html_options_collection.c index 0b80df2..b24d3a2 100644 --- a/src/html/html_options_collection.c +++ b/src/html/html_options_collection.c @@ -6,6 +6,7 @@ */ #include +#include #include @@ -35,8 +36,7 @@ dom_exception _dom_html_options_collection_create(struct dom_document *doc, dom_callback_is_in_collection ic, struct dom_html_options_collection **col) { - *col = _dom_document_alloc(doc, NULL, - sizeof(dom_html_options_collection)); + *col = malloc(sizeof(dom_html_options_collection)); if (*col == NULL) return DOM_NO_MEM_ERR; @@ -77,10 +77,9 @@ void _dom_html_options_collection_finalise(struct dom_html_options_collection *c */ void _dom_html_options_collection_destroy(struct dom_html_options_collection *col) { - struct dom_document *doc = col->base.doc; _dom_html_options_collection_finalise(col); - _dom_document_alloc(doc, col, 0); + free(col); } diff --git a/src/html/html_select_element.c b/src/html/html_select_element.c index 134df3e..e8cf39e 100644 --- a/src/html/html_select_element.c +++ b/src/html/html_select_element.c @@ -6,6 +6,7 @@ */ #include +#include #include "html/html_select_element.h" @@ -21,6 +22,7 @@ static struct dom_element_protected_vtable _protect_vtable = { }; static bool is_option(struct dom_node_internal *node); + /** * Create a dom_html_select_element object * @@ -31,7 +33,7 @@ static bool is_option(struct dom_node_internal *node); dom_exception _dom_html_select_element_create(struct dom_document *doc, struct dom_html_select_element **ele) { - *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_select_element)); + *ele = malloc(sizeof(dom_html_select_element)); if (*ele == NULL) return DOM_NO_MEM_ERR; @@ -53,17 +55,16 @@ dom_exception _dom_html_select_element_create(struct dom_document *doc, dom_exception _dom_html_select_element_initialise(struct dom_document *doc, struct dom_html_select_element *ele) { - const char *str = "SELECT"; - lwc_string *name = NULL; + dom_string *name = NULL; dom_exception err; - err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), + err = dom_string_create((const uint8_t *) "SELECT", SLEN("SELECT"), &name); if (err != DOM_NO_ERR) return err; err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - _dom_document_unref_lwcstring(doc, name); + dom_string_unref(name); ele->selected = -1; ele->options = NULL; @@ -74,26 +75,22 @@ dom_exception _dom_html_select_element_initialise(struct dom_document *doc, /** * Finalise a dom_html_select_element object * - * \param doc The document object * \param ele The dom_html_select_element object */ -void _dom_html_select_element_finalise(struct dom_document *doc, - struct dom_html_select_element *ele) +void _dom_html_select_element_finalise(struct dom_html_select_element *ele) { - _dom_html_element_finalise(doc, &ele->base); + _dom_html_element_finalise(&ele->base); } /** * Destroy a dom_html_select_element object * - * \param doc The document object * \param ele The dom_html_select_element object */ -void _dom_html_select_element_destroy(struct dom_document *doc, - struct dom_html_select_element *ele) +void _dom_html_select_element_destroy(struct dom_html_select_element *ele) { - _dom_html_select_element_finalise(doc, ele); - _dom_document_alloc(doc, ele, 0); + _dom_html_select_element_finalise(ele); + free(ele); } /*------------------------------------------------------------------------*/ @@ -117,28 +114,14 @@ dom_exception _dom_html_select_element_parse_attribute(dom_element *ele, /* The virtual destroy function, see src/core/node.c for detail */ void _dom_virtual_html_select_element_destroy(dom_node_internal *node) { - struct dom_document *doc = dom_node_get_owner(node); - _dom_html_select_element_destroy(doc, (struct dom_html_select_element *) node); -} - -/* The virtual allocation function, see src/core/node.c for detail */ -dom_exception _dom_html_select_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret) -{ - UNUSED(n); - - *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_select_element)); - if (*ret == NULL) - return DOM_NO_MEM_ERR; - - return DOM_NO_ERR; + _dom_html_select_element_destroy((struct dom_html_select_element *) node); } /* The virtual copy function, see src/core/node.c for detail */ -dom_exception _dom_html_select_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old) +dom_exception _dom_html_select_element_copy(dom_node_internal *old, + dom_node_internal **copy) { - return _dom_html_element_copy(new, old); + return _dom_html_element_copy(old, copy); } /*-----------------------------------------------------------------------*/ @@ -327,18 +310,19 @@ dom_exception dom_html_element_focus(struct dom_html_select_element *ele); /* Test whether certain node is an option node */ bool is_option(struct dom_node_internal *node) { - lwc_string *name = NULL; + dom_string *name = NULL; bool ret = false; dom_exception err; - err = _dom_node_create_lwcstring(node, (const uint8_t *) "OPTION", - SLEN("OPTION"), &name); - assert(err == DOM_NO_ERR); + err = dom_string_create((const uint8_t *) "OPTION", SLEN("OPTION"), + &name); + if (err != DOM_NO_ERR) + return false; - if (name == node->name) + if (dom_string_isequal(name, node->name)) ret = true; - _dom_node_unref_intern_string(node, name); + dom_string_unref(name); return ret; } diff --git a/src/html/html_select_element.h b/src/html/html_select_element.h index acaa929..2f813ac 100644 --- a/src/html/html_select_element.h +++ b/src/html/html_select_element.h @@ -31,29 +31,24 @@ dom_exception _dom_html_select_element_initialise(struct dom_document *doc, struct dom_html_select_element *ele); /* Finalise a dom_html_select_element object */ -void _dom_html_select_element_finalise(struct dom_document *doc, - struct dom_html_select_element *ele); +void _dom_html_select_element_finalise(struct dom_html_select_element *ele); /* Destroy a dom_html_select_element object */ -void _dom_html_select_element_destroy(struct dom_document *doc, - struct dom_html_select_element *ele); +void _dom_html_select_element_destroy(struct dom_html_select_element *ele); /* The protected virtual functions */ dom_exception _dom_html_select_element_parse_attribute(dom_element *ele, dom_string *name, dom_string *value, dom_string **parsed); void _dom_virtual_html_select_element_destroy(dom_node_internal *node); -dom_exception _dom_html_select_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret); -dom_exception _dom_html_select_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old); +dom_exception _dom_html_select_element_copy(dom_node_internal *old, + dom_node_internal **copy); #define DOM_HTML_SELECT_ELEMENT_PROTECT_VTABLE \ _dom_html_select_element_parse_attribute #define DOM_NODE_PROTECT_VTABLE_HTML_SELECT_ELEMENT \ _dom_virtual_html_select_element_destroy, \ - _dom_html_select_element_alloc, \ _dom_html_select_element_copy #endif diff --git a/src/html/html_style_element.c b/src/html/html_style_element.c index b39995a..e4cb6f2 100644 --- a/src/html/html_style_element.c +++ b/src/html/html_style_element.c @@ -5,6 +5,8 @@ * Copyright 2009 Bo Yang */ +#include + #include "html/html_style_element.h" #include "core/node.h" @@ -28,7 +30,7 @@ static struct dom_element_protected_vtable _protect_vtable = { dom_exception _dom_html_style_element_create(struct dom_document *doc, struct dom_html_style_element **ele) { - *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_style_element)); + *ele = malloc(sizeof(dom_html_style_element)); if (*ele == NULL) return DOM_NO_MEM_ERR; @@ -50,17 +52,16 @@ dom_exception _dom_html_style_element_create(struct dom_document *doc, dom_exception _dom_html_style_element_initialise(struct dom_document *doc, struct dom_html_style_element *ele) { - const char *str = "STYLE"; - lwc_string *name = NULL; + dom_string *name = NULL; dom_exception err; - err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), + err = dom_string_create((const uint8_t *) "STYLE", SLEN("STYLE"), &name); if (err != DOM_NO_ERR) return err; err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - _dom_document_unref_lwcstring(doc, name); + dom_string_unref(name); return err; } @@ -68,26 +69,22 @@ dom_exception _dom_html_style_element_initialise(struct dom_document *doc, /** * Finalise a dom_html_style_element object * - * \param doc The document object * \param ele The dom_html_style_element object */ -void _dom_html_style_element_finalise(struct dom_document *doc, - struct dom_html_style_element *ele) +void _dom_html_style_element_finalise(struct dom_html_style_element *ele) { - _dom_html_element_finalise(doc, &ele->base); + _dom_html_element_finalise(&ele->base); } /** * Destroy a dom_html_style_element object * - * \param doc The document object * \param ele The dom_html_style_element object */ -void _dom_html_style_element_destroy(struct dom_document *doc, - struct dom_html_style_element *ele) +void _dom_html_style_element_destroy(struct dom_html_style_element *ele) { - _dom_html_style_element_finalise(doc, ele); - _dom_document_alloc(doc, ele, 0); + _dom_html_style_element_finalise(ele); + free(ele); } /*------------------------------------------------------------------------*/ @@ -111,28 +108,14 @@ dom_exception _dom_html_style_element_parse_attribute(dom_element *ele, /* The virtual destroy function, see src/core/node.c for detail */ void _dom_virtual_html_style_element_destroy(dom_node_internal *node) { - struct dom_document *doc = dom_node_get_owner(node); - _dom_html_style_element_destroy(doc, (struct dom_html_style_element *) node); -} - -/* The virtual allocation function, see src/core/node.c for detail */ -dom_exception _dom_html_style_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret) -{ - UNUSED(n); - - *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_style_element)); - if (*ret == NULL) - return DOM_NO_MEM_ERR; - - return DOM_NO_ERR; + _dom_html_style_element_destroy((struct dom_html_style_element *) node); } /* The virtual copy function, see src/core/node.c for detail */ -dom_exception _dom_html_style_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old) +dom_exception _dom_html_style_element_copy(dom_node_internal *old, + dom_node_internal **copy) { - return _dom_html_element_copy(new, old); + return _dom_html_element_copy(old, copy); } /*-----------------------------------------------------------------------*/ diff --git a/src/html/html_style_element.h b/src/html/html_style_element.h index b20acb0..3eeca55 100644 --- a/src/html/html_style_element.h +++ b/src/html/html_style_element.h @@ -26,29 +26,24 @@ dom_exception _dom_html_style_element_initialise(struct dom_document *doc, struct dom_html_style_element *ele); /* Finalise a dom_html_style_element object */ -void _dom_html_style_element_finalise(struct dom_document *doc, - struct dom_html_style_element *ele); +void _dom_html_style_element_finalise(struct dom_html_style_element *ele); /* Destroy a dom_html_style_element object */ -void _dom_html_style_element_destroy(struct dom_document *doc, - struct dom_html_style_element *ele); +void _dom_html_style_element_destroy(struct dom_html_style_element *ele); /* The protected virtual functions */ dom_exception _dom_html_style_element_parse_attribute(dom_element *ele, dom_string *name, dom_string *value, dom_string **parsed); void _dom_virtual_html_style_element_destroy(dom_node_internal *node); -dom_exception _dom_html_style_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret); -dom_exception _dom_html_style_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old); +dom_exception _dom_html_style_element_copy(dom_node_internal *old, + dom_node_internal **copy); #define DOM_HTML_STYLE_ELEMENT_PROTECT_VTABLE \ _dom_html_style_element_parse_attribute #define DOM_NODE_PROTECT_VTABLE_HTML_STYLE_ELEMENT \ _dom_virtual_html_style_element_destroy, \ - _dom_html_style_element_alloc, \ _dom_html_style_element_copy #endif diff --git a/src/html/html_title_element.c b/src/html/html_title_element.c index 1a440b1..df021fc 100644 --- a/src/html/html_title_element.c +++ b/src/html/html_title_element.c @@ -6,6 +6,7 @@ */ #include +#include #include #include @@ -33,7 +34,7 @@ static struct dom_element_protected_vtable _protect_vtable = { dom_exception _dom_html_title_element_create(struct dom_document *doc, struct dom_html_title_element **ele) { - *ele = _dom_document_alloc(doc, NULL, sizeof(dom_html_title_element)); + *ele = malloc(sizeof(dom_html_title_element)); if (*ele == NULL) return DOM_NO_MEM_ERR; @@ -55,17 +56,16 @@ dom_exception _dom_html_title_element_create(struct dom_document *doc, dom_exception _dom_html_title_element_initialise(struct dom_document *doc, struct dom_html_title_element *ele) { - const char *str = "TITLE"; - lwc_string *name = NULL; + dom_string *name = NULL; dom_exception err; - err = _dom_document_create_lwcstring(doc, (const uint8_t *) str, SLEN(str), + err = dom_string_create((const uint8_t *) "TITLE", SLEN("TITLE"), &name); if (err != DOM_NO_ERR) return err; err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL); - _dom_document_unref_lwcstring(doc, name); + dom_string_unref(name); return err; } @@ -73,26 +73,22 @@ dom_exception _dom_html_title_element_initialise(struct dom_document *doc, /** * Finalise a dom_html_title_element object * - * \param doc The document object * \param ele The dom_html_title_element object */ -void _dom_html_title_element_finalise(struct dom_document *doc, - struct dom_html_title_element *ele) +void _dom_html_title_element_finalise(struct dom_html_title_element *ele) { - _dom_html_element_finalise(doc, &ele->base); + _dom_html_element_finalise(&ele->base); } /** * Destroy a dom_html_title_element object * - * \param doc The document object * \param ele The dom_html_title_element object */ -void _dom_html_title_element_destroy(struct dom_document *doc, - struct dom_html_title_element *ele) +void _dom_html_title_element_destroy(struct dom_html_title_element *ele) { - _dom_html_title_element_finalise(doc, ele); - _dom_document_alloc(doc, ele, 0); + _dom_html_title_element_finalise(ele); + free(ele); } /*------------------------------------------------------------------------*/ @@ -116,28 +112,14 @@ dom_exception _dom_html_title_element_parse_attribute(dom_element *ele, /* The virtual destroy function, see src/core/node.c for detail */ void _dom_virtual_html_title_element_destroy(dom_node_internal *node) { - struct dom_document *doc = dom_node_get_owner(node); - _dom_html_title_element_destroy(doc, (struct dom_html_title_element *) node); -} - -/* The virtual allocation function, see src/core/node.c for detail */ -dom_exception _dom_html_title_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret) -{ - UNUSED(n); - - *ret = _dom_document_alloc(doc, NULL, sizeof(dom_html_title_element)); - if (*ret == NULL) - return DOM_NO_MEM_ERR; - - return DOM_NO_ERR; + _dom_html_title_element_destroy((struct dom_html_title_element *) node); } /* The virtual copy function, see src/core/node.c for detail */ -dom_exception _dom_html_title_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old) +dom_exception _dom_html_title_element_copy(dom_node_internal *old, + dom_node_internal **copy) { - return _dom_html_element_copy(new, old); + return _dom_html_element_copy(old, copy); } /*-----------------------------------------------------------------------*/ diff --git a/src/html/html_title_element.h b/src/html/html_title_element.h index 87dabd8..e4641ec 100644 --- a/src/html/html_title_element.h +++ b/src/html/html_title_element.h @@ -26,29 +26,24 @@ dom_exception _dom_html_title_element_initialise(struct dom_document *doc, struct dom_html_title_element *ele); /* Finalise a dom_html_title_element object */ -void _dom_html_title_element_finalise(struct dom_document *doc, - struct dom_html_title_element *ele); +void _dom_html_title_element_finalise(struct dom_html_title_element *ele); /* Destroy a dom_html_title_element object */ -void _dom_html_title_element_destroy(struct dom_document *doc, - struct dom_html_title_element *ele); +void _dom_html_title_element_destroy(struct dom_html_title_element *ele); /* The protected virtual functions */ dom_exception _dom_html_title_element_parse_attribute(dom_element *ele, dom_string *name, dom_string *value, dom_string **parsed); void _dom_virtual_html_title_element_destroy(dom_node_internal *node); -dom_exception _dom_html_title_element_alloc(struct dom_document *doc, - struct dom_node_internal *n, struct dom_node_internal **ret); -dom_exception _dom_html_title_element_copy(struct dom_node_internal *new, - struct dom_node_internal *old); +dom_exception _dom_html_title_element_copy(dom_node_internal *old, + dom_node_internal **copy); #define DOM_HTML_TITLE_ELEMENT_PROTECT_VTABLE \ _dom_html_title_element_parse_attribute #define DOM_NODE_PROTECT_VTABLE_HTML_TITLE_ELEMENT \ _dom_virtual_html_title_element_destroy, \ - _dom_html_title_element_alloc, \ _dom_html_title_element_copy #endif -- cgit v1.2.3