From 229af12d7ab2c071a6888eb8ffc49bb0bbeb9ddd Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Thu, 26 Aug 2010 23:00:23 +0000 Subject: Sync with modified libwapcaplet API: 11 additional DOM Level1 testsuite failures. Most importantly, it actually compiles now. svn path=/trunk/dom/; revision=10717 --- bindings/hubbub/parser.c | 14 +-- bindings/hubbub/parser.h | 4 +- bindings/xml/xmlparser.c | 15 +-- bindings/xml/xmlparser.h | 4 +- include/dom/bootstrap/implpriv.h | 9 +- include/dom/core/implementation.h | 4 +- include/dom/core/string.h | 2 +- include/dom/events/document_event.h | 1 - src/bootstrap/implementation.c | 12 +-- src/core/document.c | 142 ++++++++++---------------- src/core/document.h | 7 -- src/core/document_type.c | 20 ++-- src/core/document_type.h | 3 +- src/core/element.c | 65 ++++-------- src/core/implementation.c | 8 +- src/core/node.c | 198 ++++++------------------------------ src/core/node.h | 6 +- src/core/nodelist.c | 22 ++-- src/core/string.c | 95 ++++------------- src/core/string.h | 12 +-- src/core/text.h | 1 - src/events/document_event.c | 13 ++- src/events/event.c | 17 ++-- src/events/event_target.c | 34 +++---- src/utils/resource_mgr.c | 11 +- src/utils/resource_mgr.h | 2 - test/DOMTSHandler.pm | 7 +- test/testutils/domts.h | 4 - test/testutils/load.c | 10 +- 29 files changed, 214 insertions(+), 528 deletions(-) diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c index a19647b..b567978 100644 --- a/bindings/hubbub/parser.c +++ b/bindings/hubbub/parser.c @@ -45,8 +45,6 @@ struct dom_hubbub_parser { dom_msg msg; /**< Informational messaging function */ void *mctx; /**< Pointer to client data */ - - struct lwc_context_s *ctx; /**< The string intern context */ }; @@ -117,8 +115,7 @@ static bool __initialised = false; */ dom_hubbub_parser *dom_hubbub_parser_create(const char *aliases, const char *enc, bool fix_enc, - dom_alloc alloc, void *pw, dom_msg msg, void *mctx, - lwc_context *ctx) + dom_alloc alloc, void *pw, dom_msg msg, void *mctx) { dom_hubbub_parser *parser; hubbub_parser_optparams params; @@ -157,7 +154,6 @@ dom_hubbub_parser *dom_hubbub_parser_create(const char *aliases, parser->pw = pw; parser->msg = msg; parser->mctx = mctx; - parser->ctx = ctx; error = hubbub_parser_create(enc, fix_enc, alloc, pw, &parser->parser); if (error != HUBBUB_OK) { @@ -194,7 +190,7 @@ dom_hubbub_parser *dom_hubbub_parser_create(const char *aliases, * we should pass the real function when we integrate libDOM with * Netsurf */ err = dom_implementation_create_document(parser->impl, NULL, NULL, NULL, - alloc, pw, ctx, NULL, &parser->doc); + alloc, pw, NULL, &parser->doc); if (err != DOM_NO_ERR) { hubbub_parser_destroy(parser->parser); alloc(parser, 0, pw); @@ -280,12 +276,12 @@ dom_hubbub_error dom_hubbub_parser_completed(dom_hubbub_parser *parser) parser->complete = true; - lerr = lwc_context_intern(parser->ctx, "id", strlen("id"), &name); + lerr = lwc_intern_string("id", strlen("id"), &name); if (lerr != lwc_error_ok) return HUBBUB_UNKNOWN; _dom_document_set_id_name(parser->doc, name); - lwc_context_string_unref(parser->ctx, name); + lwc_string_unref(name); return DOM_HUBBUB_OK; } @@ -408,7 +404,7 @@ static hubbub_error create_doctype(void *parser, const hubbub_doctype *doctype, err = dom_implementation_create_document_type(dom_parser->impl, qname, public_id, system_id, dom_parser->alloc, - dom_parser->pw, dom_parser->ctx, &dtype); + dom_parser->pw, &dtype); if (err != DOM_NO_ERR) { dom_parser->msg(DOM_MSG_CRITICAL, dom_parser->mctx, "Can't create the document type"); diff --git a/bindings/hubbub/parser.h b/bindings/hubbub/parser.h index 8b2218d..350f3d6 100644 --- a/bindings/hubbub/parser.h +++ b/bindings/hubbub/parser.h @@ -16,7 +16,6 @@ #include "errors.h" struct dom_document; -struct lwc_context_s; typedef struct dom_hubbub_parser dom_hubbub_parser; @@ -51,8 +50,7 @@ typedef enum dom_hubub_encoding_source { /* Create a Hubbub parser instance */ dom_hubbub_parser *dom_hubbub_parser_create(const char *aliases, const char *enc, bool fix_enc, - dom_alloc alloc, void *pw, dom_msg msg, void *mctx, - struct lwc_context_s *ctx); + dom_alloc alloc, void *pw, dom_msg msg, void *mctx); /* Destroy a Hubbub parser instance */ void dom_hubbub_parser_destroy(dom_hubbub_parser *parser); diff --git a/bindings/xml/xmlparser.c b/bindings/xml/xmlparser.c index 8cae01c..8e1013f 100644 --- a/bindings/xml/xmlparser.c +++ b/bindings/xml/xmlparser.c @@ -104,8 +104,6 @@ struct dom_xml_parser { dom_msg msg; /**< Informational message function */ void *mctx; /**< Pointer to client data */ - - struct lwc_context_s *ctx; /**< The lwc_context of the parser */ }; /** @@ -162,8 +160,7 @@ static xmlSAXHandler sax_handler = { * parser encoding is not yet implemented */ dom_xml_parser *dom_xml_parser_create(const char *enc, const char *int_enc, - dom_alloc alloc, void *pw, dom_msg msg, void *mctx, - lwc_context *ctx) + dom_alloc alloc, void *pw, dom_msg msg, void *mctx) { dom_xml_parser *parser; struct dom_string *features; @@ -239,8 +236,6 @@ dom_xml_parser *dom_xml_parser_create(const char *enc, const char *int_enc, parser->msg = msg; parser->mctx = mctx; - parser->ctx = ctx; - return parser; } @@ -311,12 +306,12 @@ dom_xml_error dom_xml_parser_completed(dom_xml_parser *parser) /* TODO: In future, this string "id" should be extracted from the * document schema file instead of just setting it as "id". */ - lerr = lwc_context_intern(parser->ctx, "id", SLEN("id"), &name); + lerr = lwc_intern_string("id", SLEN("id"), &name); if (lerr != lwc_error_ok) return _dom_exception_from_lwc_error(lerr); _dom_document_set_id_name(parser->doc, name); - lwc_context_string_unref(parser->ctx, name); + lwc_string_unref(name); return DOM_XML_OK; } @@ -355,7 +350,7 @@ void xml_parser_start_document(void *ctx) /* namespace */ NULL, /* qname */ NULL, /* doctype */ NULL, - parser->alloc, parser->pw, parser->ctx, NULL, + parser->alloc, parser->pw, NULL, &doc); if (err != DOM_NO_ERR) { parser->msg(DOM_MSG_CRITICAL, parser->mctx, @@ -1242,7 +1237,7 @@ void xml_parser_add_document_type(dom_xml_parser *parser, /* Create doctype */ err = dom_implementation_create_document_type(parser->impl, qname, public_id, system_id, - parser->alloc, parser->pw, parser->ctx, &doctype); + parser->alloc, parser->pw, &doctype); if (err != DOM_NO_ERR) { dom_string_unref(system_id); dom_string_unref(public_id); diff --git a/bindings/xml/xmlparser.h b/bindings/xml/xmlparser.h index 366ceec..7bf3807 100644 --- a/bindings/xml/xmlparser.h +++ b/bindings/xml/xmlparser.h @@ -16,14 +16,12 @@ #include "xmlerror.h" struct dom_document; -struct lwc_context_s; typedef struct dom_xml_parser dom_xml_parser; /* Create an XML parser instance */ dom_xml_parser *dom_xml_parser_create(const char *enc, const char *int_enc, - dom_alloc alloc, void *pw, dom_msg msg, void *mctx, - struct lwc_context_s *ctx); + dom_alloc alloc, void *pw, dom_msg msg, void *mctx); /* Destroy an XML parser instance */ void dom_xml_parser_destroy(dom_xml_parser *parser); diff --git a/include/dom/bootstrap/implpriv.h b/include/dom/bootstrap/implpriv.h index 17ffcde..93ce34d 100644 --- a/include/dom/bootstrap/implpriv.h +++ b/include/dom/bootstrap/implpriv.h @@ -34,7 +34,6 @@ struct dom_document; struct dom_document_type; -struct lwc_context_s; /** * DOM Implementation @@ -83,7 +82,7 @@ struct dom_implementation { struct dom_string *qname, struct dom_string *public_id, struct dom_string *system_id, - dom_alloc alloc, void *pw, struct lwc_context_s *ctx, + dom_alloc alloc, void *pw, struct dom_document_type **doctype); /** @@ -126,7 +125,7 @@ struct dom_implementation { struct dom_string *namespace, struct dom_string *qname, struct dom_document_type *doctype, - dom_alloc alloc, void *pw, struct lwc_context_s *ctx, + dom_alloc alloc, void *pw, dom_events_default_action_fetcher daf, struct dom_document **doc); @@ -246,7 +245,7 @@ dom_exception dom_register_source(struct dom_implementation_source *source); /* Create a DOM document */ dom_exception dom_document_create(struct dom_implementation *impl, - dom_alloc alloc, void *pw, struct lwc_context_s *ctx, + dom_alloc alloc, void *pw, dom_events_default_action_fetcher daf, struct dom_document **doc); @@ -258,7 +257,7 @@ void dom_document_set_buffer(struct dom_document *doc, uint8_t *buffer, dom_exception dom_document_type_create(struct dom_string *qname, struct dom_string *public_id, struct dom_string *system_id, - dom_alloc alloc, void *pw, struct lwc_context_s *ctx, + dom_alloc alloc, void *pw, struct dom_document_type **doctype); #endif diff --git a/include/dom/core/implementation.h b/include/dom/core/implementation.h index 92cce99..7865b10 100644 --- a/include/dom/core/implementation.h +++ b/include/dom/core/implementation.h @@ -31,14 +31,14 @@ dom_exception dom_implementation_has_feature( dom_exception dom_implementation_create_document_type( struct dom_implementation *impl, struct dom_string *qname, struct dom_string *public_id, struct dom_string *system_id, - dom_alloc alloc, void *pw, struct lwc_context_s *ctx, + dom_alloc alloc, void *pw, struct dom_document_type **doctype); dom_exception dom_implementation_create_document( struct dom_implementation *impl, struct dom_string *namespace, struct dom_string *qname, struct dom_document_type *doctype, - dom_alloc alloc, void *pw, struct lwc_context_s *ctx, + dom_alloc alloc, void *pw, dom_events_default_action_fetcher daf, struct dom_document **doc); diff --git a/include/dom/core/string.h b/include/dom/core/string.h index 2502623..7da2114 100644 --- a/include/dom/core/string.h +++ b/include/dom/core/string.h @@ -33,7 +33,7 @@ dom_exception dom_string_clone(dom_alloc alloc, void *pw, /* Get the internal lwc_string */ dom_exception dom_string_get_intern(struct dom_string *str, - struct lwc_context_s **ctx, struct lwc_string_s **lwcstr); + struct lwc_string_s **lwcstr); /* Case sensitively compare two DOM strings */ int dom_string_cmp(struct dom_string *s1, struct dom_string *s2); diff --git a/include/dom/events/document_event.h b/include/dom/events/document_event.h index e349bc2..3c1ea1b 100644 --- a/include/dom/events/document_event.h +++ b/include/dom/events/document_event.h @@ -13,7 +13,6 @@ struct dom_string; struct dom_event; struct dom_document; -struct lwc_context_s; struct lwc_string_s; typedef struct dom_document dom_document_event; diff --git a/src/bootstrap/implementation.c b/src/bootstrap/implementation.c index bb0e125..6b9dcd7 100644 --- a/src/bootstrap/implementation.c +++ b/src/bootstrap/implementation.c @@ -51,14 +51,14 @@ static dom_exception impl_implementation_create_document_type( struct dom_string *qname, struct dom_string *public_id, struct dom_string *system_id, - dom_alloc alloc, void *pw, struct lwc_context_s *ctx, + dom_alloc alloc, void *pw, struct dom_document_type **doctype); static dom_exception impl_implementation_create_document( struct dom_implementation *impl, struct dom_string *namespace, struct dom_string *qname, struct dom_document_type *doctype, - dom_alloc alloc, void *pw, struct lwc_context_s *ctx, + dom_alloc alloc, void *pw, dom_events_default_action_fetcher daf, struct dom_document **doc); static dom_exception impl_implementation_get_feature( @@ -210,7 +210,7 @@ dom_exception impl_implementation_create_document_type( struct dom_string *qname, struct dom_string *public_id, struct dom_string *system_id, - dom_alloc alloc, void *pw, struct lwc_context_s *ctx, + dom_alloc alloc, void *pw, struct dom_document_type **doctype) { struct dom_document_type *d; @@ -232,7 +232,7 @@ dom_exception impl_implementation_create_document_type( /* Create the doctype */ err = dom_document_type_create(qname, public_id, system_id, - alloc, pw, ctx, &d); + alloc, pw, &d); if (err != DOM_NO_ERR) return err; @@ -286,7 +286,7 @@ dom_exception impl_implementation_create_document( struct dom_string *namespace, struct dom_string *qname, struct dom_document_type *doctype, - dom_alloc alloc, void *pw, struct lwc_context_s *ctx, + dom_alloc alloc, void *pw, dom_events_default_action_fetcher daf, struct dom_document **doc) { @@ -308,7 +308,7 @@ dom_exception impl_implementation_create_document( } /* Create document object */ - err = dom_document_create(impl, alloc, pw, ctx, daf, &d); + err = dom_document_create(impl, alloc, pw, daf, &d); if (err != DOM_NO_ERR) return err; diff --git a/src/core/document.c b/src/core/document.c index b15eef3..74fb534 100644 --- a/src/core/document.c +++ b/src/core/document.c @@ -75,7 +75,6 @@ static dom_exception dom_document_dup_node(dom_document *doc, * \param alloc Memory (de)allocation function * \param pw Pointer to client-specific private data * \param doc Pointer to location to receive created document - * \param ctx The intern string context of this document * \param daf The default action fetcher * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion. * @@ -84,7 +83,7 @@ static dom_exception dom_document_dup_node(dom_document *doc, * The returned document will already be referenced. */ dom_exception dom_document_create(struct dom_implementation *impl, - dom_alloc alloc, void *pw, struct lwc_context_s *ctx, + dom_alloc alloc, void *pw, dom_events_default_action_fetcher daf, struct dom_document **doc) { @@ -105,7 +104,7 @@ dom_exception dom_document_create(struct dom_implementation *impl, * reaches zero. Documents own themselves (this simplifies the * rest of the code, as it doesn't need to special case Documents) */ - err = _dom_document_initialise(d, impl, alloc, pw, ctx, daf); + err = _dom_document_initialise(d, impl, alloc, pw, daf); if (err != DOM_NO_ERR) { /* Clean up document */ alloc(d, 0, pw); @@ -120,10 +119,8 @@ dom_exception dom_document_create(struct dom_implementation *impl, /* Initialise the document */ dom_exception _dom_document_initialise(struct dom_document *doc, struct dom_implementation *impl, dom_alloc alloc, void *pw, - struct lwc_context_s *ctx, dom_events_default_action_fetcher daf) { - assert(ctx != NULL); assert(alloc != NULL); assert(impl != NULL); @@ -131,7 +128,7 @@ dom_exception _dom_document_initialise(struct dom_document *doc, lwc_string *name; lwc_error lerr; - lerr = lwc_context_intern(ctx, "#document", SLEN("#document"), &name); + lerr = lwc_intern_string("#document", SLEN("#document"), &name); if (lerr != lwc_error_ok) return _dom_exception_from_lwc_error(lerr); @@ -143,11 +140,10 @@ dom_exception _dom_document_initialise(struct dom_document *doc, /* Set up document allocation context - must be first */ doc->alloc = alloc; doc->pw = pw; - doc->context = lwc_context_ref(ctx); err = _dom_node_initialise(&doc->base, doc, DOM_DOCUMENT_NODE, name, NULL, NULL, NULL); - lwc_context_string_unref(ctx, name); + lwc_string_unref(name); list_init(&doc->pending_nodes); @@ -187,8 +183,7 @@ bool _dom_document_finalise(struct dom_document *doc) doc->nodelists = NULL; if (doc->id_name != NULL) - lwc_context_string_unref(doc->context, doc->id_name); - lwc_context_unref(doc->context); + lwc_string_unref(doc->id_name); _dom_document_event_internal_finalise(doc, &doc->dei); @@ -306,13 +301,12 @@ dom_exception _dom_document_create_element(struct dom_document *doc, if (_dom_validate_name(tag_name) == false) return DOM_INVALID_CHARACTER_ERR; - assert(doc->context != NULL); - err = _dom_string_intern(tag_name, doc->context, &name); + err = _dom_string_intern(tag_name, &name); if (err != DOM_NO_ERR) return err; err = _dom_element_create(doc, name, NULL, NULL, result); - lwc_context_string_unref(doc->context, name); + lwc_string_unref(name); return err; } @@ -335,15 +329,13 @@ dom_exception _dom_document_create_document_fragment(struct dom_document *doc, dom_exception err; lwc_error lerr; - assert(doc->context != NULL); - - lerr = lwc_context_intern(doc->context, "#document-fragment", + lerr = lwc_intern_string("#document-fragment", SLEN("#document-fragment"), &name); if (lerr != lwc_error_ok) return _dom_exception_from_lwc_error(lerr); err = _dom_document_fragment_create(doc, name, NULL, result); - lwc_context_string_unref(doc->context, name); + lwc_string_unref(name); return err; } @@ -367,14 +359,12 @@ dom_exception _dom_document_create_text_node(struct dom_document *doc, dom_exception err; lwc_error lerr; - assert(doc->context != NULL); - - lerr = lwc_context_intern(doc->context, "#text", SLEN("#text"), &name); + lerr = lwc_intern_string("#text", SLEN("#text"), &name); if (lerr != lwc_error_ok) return _dom_exception_from_lwc_error(lerr); err = _dom_text_create(doc, name, data, result); - lwc_context_string_unref(doc->context, name); + lwc_string_unref(name); return err; } @@ -398,15 +388,13 @@ dom_exception _dom_document_create_comment(struct dom_document *doc, dom_exception err; lwc_error lerr; - assert(doc->context != NULL); - - lerr = lwc_context_intern(doc->context, "#comment", SLEN("#comment"), + lerr = lwc_intern_string("#comment", SLEN("#comment"), &name); if (lerr != lwc_error_ok) return _dom_exception_from_lwc_error(lerr); err = _dom_comment_create(doc, name, data, result); - lwc_context_string_unref(doc->context, name); + lwc_string_unref(name); return err; } @@ -431,15 +419,13 @@ dom_exception _dom_document_create_cdata_section(struct dom_document *doc, dom_exception err; lwc_error lerr; - assert(doc->context != NULL); - - lerr = lwc_context_intern(doc->context, "#cdata-section", + lerr = lwc_intern_string("#cdata-section", SLEN("#cdata-section"), &name); if (lerr != lwc_error_ok) return _dom_exception_from_lwc_error(lerr); err = _dom_cdata_section_create(doc, name, data, result); - lwc_context_string_unref(doc->context, name); + lwc_string_unref(name); return err; } @@ -470,13 +456,12 @@ dom_exception _dom_document_create_processing_instruction( if (_dom_validate_name(target) == false) return DOM_INVALID_CHARACTER_ERR; - assert(doc->context != NULL); - err = _dom_string_intern(target, doc->context, &name); + err = _dom_string_intern(target, &name); if (err != DOM_NO_ERR) return err; err = _dom_processing_instruction_create(doc, name, data, result); - lwc_context_string_unref(doc->context, name); + lwc_string_unref(name); return err; } @@ -503,13 +488,12 @@ dom_exception _dom_document_create_attribute(struct dom_document *doc, if (_dom_validate_name(name) == false) return DOM_INVALID_CHARACTER_ERR; - assert(doc->context != NULL); - err = _dom_string_intern(name, doc->context, &n); + err = _dom_string_intern(name, &n); if (err != DOM_NO_ERR) return err; err = _dom_attr_create(doc, n, NULL, NULL, true, result); - lwc_context_string_unref(doc->context, n); + lwc_string_unref(n); return err; } @@ -537,13 +521,12 @@ dom_exception _dom_document_create_entity_reference(struct dom_document *doc, if (_dom_validate_name(name) == false) return DOM_INVALID_CHARACTER_ERR; - assert(doc->context != NULL); - err = _dom_string_intern(name, doc->context, &n); + err = _dom_string_intern(name, &n); if (err != DOM_NO_ERR) return err; err = _dom_entity_reference_create(doc, n, NULL, result); - lwc_context_string_unref(doc->context, n); + lwc_string_unref(n); return err; } @@ -565,15 +548,14 @@ dom_exception _dom_document_get_elements_by_tag_name(struct dom_document *doc, lwc_string *name; dom_exception err; - assert(doc->context != NULL); - err = _dom_string_intern(tagname, doc->context, &name); + err = _dom_string_intern(tagname, &name); if (err != DOM_NO_ERR) return err; err = _dom_document_get_nodelist(doc, DOM_NODELIST_BY_NAME, (struct dom_node_internal *) doc, name, NULL, NULL, result); - lwc_context_string_unref(doc->context, name); + lwc_string_unref(name); return err; } @@ -653,10 +635,9 @@ dom_exception _dom_document_create_element_ns(struct dom_document *doc, } /* Get the interned string from the dom_string */ - assert(doc->context != NULL); lwc_string *l = NULL, *n = NULL, *p = NULL; if (localname != NULL) { - err = _dom_string_intern(localname, doc->context, &l); + err = _dom_string_intern(localname, &l); if (err != DOM_NO_ERR) { dom_string_unref(localname); if (prefix != NULL) @@ -666,9 +647,9 @@ dom_exception _dom_document_create_element_ns(struct dom_document *doc, } } if (namespace != NULL) { - err = _dom_string_intern(namespace, doc->context, &n); + err = _dom_string_intern(namespace, &n); if (err != DOM_NO_ERR) { - lwc_context_string_unref(doc->context, l); + lwc_string_unref(l); dom_string_unref(localname); if (prefix != NULL) dom_string_unref(prefix); @@ -677,10 +658,10 @@ dom_exception _dom_document_create_element_ns(struct dom_document *doc, } } if (prefix != NULL) { - err = _dom_string_intern(prefix, doc->context, &p); + err = _dom_string_intern(prefix, &p); if (err != DOM_NO_ERR) { - lwc_context_string_unref(doc->context, l); - lwc_context_string_unref(doc->context, n); + lwc_string_unref(l); + lwc_string_unref(n); dom_string_unref(localname); if (prefix != NULL) dom_string_unref(prefix); @@ -695,14 +676,14 @@ dom_exception _dom_document_create_element_ns(struct dom_document *doc, /* Tidy up */ if (localname != NULL) { dom_string_unref(localname); - lwc_context_string_unref(doc->context, l); + lwc_string_unref(l); } if (prefix != NULL) { dom_string_unref(prefix); - lwc_context_string_unref(doc->context, p); + lwc_string_unref(p); } if (namespace != NULL) { - lwc_context_string_unref(doc->context, n); + lwc_string_unref(n); } return err; @@ -759,10 +740,9 @@ dom_exception _dom_document_create_attribute_ns(struct dom_document *doc, } /* Get the interned string from the dom_string */ - assert(doc->context != NULL); lwc_string *l = NULL, *n = NULL, *p = NULL; if (localname != NULL) { - err = _dom_string_intern(localname, doc->context, &l); + err = _dom_string_intern(localname, &l); if (err != DOM_NO_ERR) { dom_string_unref(localname); if (prefix != NULL) @@ -772,9 +752,9 @@ dom_exception _dom_document_create_attribute_ns(struct dom_document *doc, } } if (namespace != NULL) { - err = _dom_string_intern(namespace, doc->context, &n); + err = _dom_string_intern(namespace, &n); if (err != DOM_NO_ERR) { - lwc_context_string_unref(doc->context, l); + lwc_string_unref(l); dom_string_unref(localname); if (prefix != NULL) dom_string_unref(prefix); @@ -783,10 +763,10 @@ dom_exception _dom_document_create_attribute_ns(struct dom_document *doc, } } if (prefix != NULL) { - err = _dom_string_intern(prefix, doc->context, &p); + err = _dom_string_intern(prefix, &p); if (err != DOM_NO_ERR) { - lwc_context_string_unref(doc->context, l); - lwc_context_string_unref(doc->context, n); + lwc_string_unref(l); + lwc_string_unref(n); dom_string_unref(localname); if (prefix != NULL) dom_string_unref(prefix); @@ -800,14 +780,14 @@ dom_exception _dom_document_create_attribute_ns(struct dom_document *doc, /* Tidy up */ if (localname != NULL) { dom_string_unref(localname); - lwc_context_string_unref(doc->context, l); + lwc_string_unref(l); } if (prefix != NULL) { dom_string_unref(prefix); - lwc_context_string_unref(doc->context, p); + lwc_string_unref(p); } if (namespace != NULL) { - lwc_context_string_unref(doc->context, n); + lwc_string_unref(n); } return err; @@ -834,16 +814,15 @@ dom_exception _dom_document_get_elements_by_tag_name_ns( lwc_string *l = NULL, *n = NULL; /* Get the interned string from the dom_string */ - assert(doc->context != NULL); if (localname != NULL) { - err = _dom_string_intern(localname, doc->context, &l); + err = _dom_string_intern(localname, &l); if (err != DOM_NO_ERR) return err; } if (namespace != NULL) { - err = _dom_string_intern(namespace, doc->context, &n); + err = _dom_string_intern(namespace, &n); if (err != DOM_NO_ERR) { - lwc_context_string_unref(doc->context, l); + lwc_string_unref(l); return err; } } @@ -852,9 +831,9 @@ dom_exception _dom_document_get_elements_by_tag_name_ns( (struct dom_node_internal *) doc, NULL, n, l, result); if (l != NULL) - lwc_context_string_unref(doc->context, l); + lwc_string_unref(l); if (n != NULL) - lwc_context_string_unref(doc->context, n); + lwc_string_unref(n); return err; } @@ -880,8 +859,7 @@ dom_exception _dom_document_get_element_by_id(struct dom_document *doc, *result = NULL; - assert(doc->context != NULL); - err = _dom_string_intern(id, doc->context, &i); + err = _dom_string_intern(id, &i); if (err != DOM_NO_ERR) return err; @@ -1322,10 +1300,9 @@ dom_exception _dom_document_create_lwcstring(struct dom_document *doc, { lwc_error lerr; - assert(doc->context != NULL); + UNUSED(doc); - lerr = lwc_context_intern(doc->context, (const char *) data, len, - result); + lerr = lwc_intern_string((const char *) data, len, result); return _dom_exception_from_lwc_error(lerr); } @@ -1334,14 +1311,9 @@ dom_exception _dom_document_create_lwcstring(struct dom_document *doc, void _dom_document_unref_lwcstring(struct dom_document *doc, struct lwc_string_s *str) { - lwc_context_string_unref(doc->context, str); -} + UNUSED(doc); -/* Simple accessor for lwc_context of this document */ -struct lwc_context_s *_dom_document_get_intern_context( - struct dom_document *doc) -{ - return doc->context; + lwc_string_unref(str); } /* Get the resource manager from the document */ @@ -1350,7 +1322,6 @@ void _dom_document_get_resource_mgr( { rm->alloc = doc->alloc; rm->pw = doc->pw; - rm->ctx = doc->context; } /* Simple accessor for allocator data for this document */ @@ -1372,10 +1343,8 @@ dom_exception _dom_document_create_string_from_lwcstring( struct dom_document *doc, struct lwc_string_s *str, struct dom_string **result) { - assert(doc->context != NULL); - return _dom_string_create_from_lwcstring(doc->alloc, doc->pw, - doc->context, str, result); + str, result); } /** @@ -1680,14 +1649,11 @@ void _dom_document_try_destroy(struct dom_document *doc) * * \param doc The document object * \param name The ID name of the elements in this document - * - * @note: The lwc_context of the param 'name' must be the same one with - * document's, this should be assured by the client. */ void _dom_document_set_id_name(dom_document *doc, struct lwc_string_s *name) { if (doc->id_name != NULL) - lwc_context_string_unref(doc->context, doc->id_name); - doc->id_name = lwc_context_string_ref(doc->context, name); + lwc_string_unref(doc->id_name); + doc->id_name = lwc_string_ref(name); } diff --git a/src/core/document.h b/src/core/document.h index e421fe5..a7cab6d 100644 --- a/src/core/document.h +++ b/src/core/document.h @@ -54,8 +54,6 @@ struct dom_document { struct dom_string *uri; /**< The uri of this document */ - struct lwc_context_s *context; /**< The internment context */ - dom_alloc alloc; /**< Memory (de)allocation function */ void *pw; /**< Pointer to client data */ @@ -71,7 +69,6 @@ struct dom_document { /* Initialise the document */ dom_exception _dom_document_initialise(struct dom_document *doc, struct dom_implementation *impl, dom_alloc alloc, void *pw, - struct lwc_context_s *ctx, dom_events_default_action_fetcher daf); /* Finalise the document */ @@ -220,10 +217,6 @@ void _dom_document_try_destroy(struct dom_document *doc); /* (De)allocate memory */ void *_dom_document_alloc(struct dom_document *doc, void *ptr, size_t size); -/* Get the internment context */ -struct lwc_context_s *_dom_document_get_intern_context( - struct dom_document *doc); - /* Get the resource manager inside this document, a resource manager * is an object which contain the memory allocator/intern string context, * with which we can allocate strings or intern strings */ diff --git a/src/core/document_type.c b/src/core/document_type.c index fd59ef1..c8b3ff2 100644 --- a/src/core/document_type.c +++ b/src/core/document_type.c @@ -66,7 +66,7 @@ static struct dom_node_protect_vtable dt_protect_vtable = { */ dom_exception dom_document_type_create(struct dom_string *qname, struct dom_string *public_id, struct dom_string *system_id, - dom_alloc alloc, void *pw, struct lwc_context_s *ctx, + dom_alloc alloc, void *pw, struct dom_document_type **doctype) { struct dom_document_type *result; @@ -82,7 +82,7 @@ dom_exception dom_document_type_create(struct dom_string *qname, result->base.vtable = &dt_protect_vtable; err = _dom_document_type_initialise(result, qname, public_id, system_id, - alloc, pw, ctx); + alloc, pw); *doctype = result; @@ -111,8 +111,7 @@ void _dom_document_type_destroy(struct dom_node_internal *doctypenode) /* Initialise this document_type */ dom_exception _dom_document_type_initialise(struct dom_document_type *doctype, struct dom_string *qname, struct dom_string *public_id, - struct dom_string *system_id, dom_alloc alloc, void *pw, - struct lwc_context_s *ctx) + struct dom_string *system_id, dom_alloc alloc, void *pw) { dom_exception err; @@ -125,7 +124,7 @@ dom_exception _dom_document_type_initialise(struct dom_document_type *doctype, lwc_string *lprefix = NULL, *lname = NULL; if (prefix != NULL) { - err = _dom_string_intern(prefix, ctx, &lprefix); + err = _dom_string_intern(prefix, &lprefix); if (err != DOM_NO_ERR) { dom_string_unref(prefix); dom_string_unref(localname); @@ -135,12 +134,12 @@ dom_exception _dom_document_type_initialise(struct dom_document_type *doctype, } if (localname != NULL) { - err = _dom_string_intern(localname, ctx, &lname); + err = _dom_string_intern(localname, &lname); if (err != DOM_NO_ERR) { dom_string_unref(prefix); dom_string_unref(localname); if (lprefix != NULL) - lwc_context_string_unref(ctx, lprefix); + lwc_string_unref(lprefix); alloc(doctype, 0, pw); return err; } @@ -150,8 +149,7 @@ dom_exception _dom_document_type_initialise(struct dom_document_type *doctype, /* Initialise base node */ err = _dom_node_initialise_generic(&doctype->base, NULL, alloc, pw, - ctx, DOM_DOCUMENT_TYPE_NODE, lname, NULL, NULL, - lprefix); + DOM_DOCUMENT_TYPE_NODE, lname, NULL, NULL, lprefix); if (err != DOM_NO_ERR) { alloc(doctype, 0, pw); return err; @@ -174,7 +172,6 @@ dom_exception _dom_document_type_initialise(struct dom_document_type *doctype, /* Fill in allocation information */ doctype->res.alloc = alloc; doctype->res.pw = pw; - doctype->res.ctx = ctx; return DOM_NO_ERR; } @@ -190,7 +187,7 @@ void _dom_document_type_finalise(struct dom_document_type *doctype) assert(doctype->base.owner != NULL || doctype->base.user_data == NULL); _dom_node_finalise_generic(&doctype->base, doctype->res.alloc, - doctype->res.pw, doctype->res.ctx); + doctype->res.pw); } @@ -383,7 +380,6 @@ void _dom_document_type_get_resource_mgr( { rm->alloc = dt->res.alloc; rm->pw = dt->res.pw; - rm->ctx = dt->res.ctx; } /** diff --git a/src/core/document_type.h b/src/core/document_type.h index 649b027..50dd5ea 100644 --- a/src/core/document_type.h +++ b/src/core/document_type.h @@ -16,8 +16,7 @@ struct dom_implementation; void _dom_document_type_destroy(struct dom_node_internal *doctypenode); dom_exception _dom_document_type_initialise(struct dom_document_type *doctype, struct dom_string *qname, struct dom_string *public_id, - struct dom_string *system_id, dom_alloc alloc, void *pw, - struct lwc_context_s *ctx); + struct dom_string *system_id, dom_alloc alloc, void *pw); void _dom_document_type_finalise(struct dom_document_type *doctype); /* The virtual functions of DocumentType */ diff --git a/src/core/element.c b/src/core/element.c index eb76bc7..9c1263a 100644 --- a/src/core/element.c +++ b/src/core/element.c @@ -216,18 +216,15 @@ dom_exception _dom_element_initialise(struct dom_document *doc, */ void _dom_element_finalise(struct dom_document *doc, struct dom_element *ele) { - lwc_context *ctx = _dom_document_get_intern_context(doc); - assert (ctx != NULL); - /* Destroy attributes attached to this node */ if (ele->attributes != NULL) { - _dom_hash_destroy(ele->attributes, _key, ctx, _value, ctx); + _dom_hash_destroy(ele->attributes, _key, NULL, _value, doc); ele->attributes = NULL; } if (ele->ns_attributes != NULL) { - _dom_hash_destroy(ele->ns_attributes, _key, ctx, - _nsattributes, ctx); + _dom_hash_destroy(ele->ns_attributes, _key, NULL, + _nsattributes, doc); ele->ns_attributes = NULL; } @@ -411,14 +408,11 @@ dom_exception _dom_element_get_elements_by_tag_name( { dom_exception err; lwc_string *n; - lwc_context *ctx; dom_node_internal *base = (dom_node_internal *) element; assert(base->owner != NULL); - ctx = _dom_document_get_intern_context(base->owner); - assert(ctx != NULL); - err = _dom_string_intern(name, ctx, &n); + err = _dom_string_intern(name, &n); if (err != DOM_NO_ERR) return err; @@ -426,7 +420,7 @@ dom_exception _dom_element_get_elements_by_tag_name( (struct dom_node_internal *) element, n, NULL, NULL, result); - lwc_context_string_unref(ctx, n); + lwc_string_unref(n); return err; } @@ -738,17 +732,16 @@ dom_exception _dom_element_get_elements_by_tag_name_ns( /** \todo ensure XML feature is supported */ /* Get the interned string from the dom_string */ - assert(doc->context != NULL); lwc_string *l = NULL, *n = NULL; if (localname != NULL) { - err = _dom_string_intern(localname, doc->context, &l); + err = _dom_string_intern(localname, &l); if (err != DOM_NO_ERR) return err; } if (namespace != NULL) { - err = _dom_string_intern(namespace, doc->context, &n); + err = _dom_string_intern(namespace, &n); if (err != DOM_NO_ERR) { - lwc_context_string_unref(doc->context, l); + lwc_string_unref(l); return err; } @@ -760,9 +753,9 @@ dom_exception _dom_element_get_elements_by_tag_name_ns( result); if (localname != NULL) - lwc_context_string_unref(doc->context, l); + lwc_string_unref(l); if (namespace != NULL) - lwc_context_string_unref(doc->context, n); + lwc_string_unref(n); return err; } @@ -1023,20 +1016,15 @@ dom_exception _dom_element_is_default_namespace(dom_node_internal *node, struct dom_element *ele = (struct dom_element *) node; lwc_string *ns; dom_string *value; - dom_document *doc = node->owner; - lwc_context *ctx; dom_exception err; - assert(doc != NULL); err = _dom_node_get_intern_string(node, namespace, &ns); if (err != DOM_NO_ERR) { return err; } - ctx = _dom_document_get_intern_context(doc); - assert(ctx != NULL); if (node->prefix == NULL) { - lwc_context_string_isequal(ctx, node->namespace, ns, result); - lwc_context_string_unref(ctx, ns); + lwc_string_isequal(node->namespace, ns, result); + lwc_string_unref(ns); return DOM_NO_ERR; } @@ -1057,9 +1045,9 @@ dom_exception _dom_element_is_default_namespace(dom_node_internal *node, } if (ns2 != NULL) { - lwc_context_string_isequal(ctx, ns2, ns, result); - lwc_context_string_unref(ctx, ns); - lwc_context_string_unref(ctx, ns2); + lwc_string_isequal(ns2, ns, result); + lwc_string_unref(ns); + lwc_string_unref(ns2); dom_string_unref(value); return DOM_NO_ERR; } @@ -1161,7 +1149,6 @@ dom_exception _dom_element_copy(struct dom_node_internal *new, dom_element *oe = (dom_element *) old; dom_document *od, *nd; struct dom_hash_table *ht; - lwc_context *oc, *nc; dom_exception err; err = _dom_node_copy(new, old); @@ -1173,23 +1160,18 @@ dom_exception _dom_element_copy(struct dom_node_internal *new, assert(od != NULL); assert(nd != NULL); - oc = _dom_document_get_intern_context(od); - nc = _dom_document_get_intern_context(nd); - assert(oc != NULL); - assert(nc != NULL); - dom_alloc alloc; void *pw; _dom_document_get_allocator(nd, &alloc, &pw); /* Copy the hash tables */ - ht = _dom_hash_clone(oe->attributes, alloc, pw, _key, nc, + ht = _dom_hash_clone(oe->attributes, alloc, pw, _key, NULL, _value, nd); if (ht == NULL) return DOM_NO_MEM_ERR; ne->attributes = ht; - ht = _dom_hash_clone(oe->ns_attributes, alloc, pw, _key, nc, + ht = _dom_hash_clone(oe->ns_attributes, alloc, pw, _key, NULL, _nsattributes, nd); if (ht == NULL) return DOM_NO_MEM_ERR; @@ -2111,22 +2093,20 @@ void *_key(void *key, void *key_pw, dom_alloc alloc, void *pw, bool clone) { assert(key != NULL); - assert(key_pw != NULL); + UNUSED(key_pw); UNUSED(alloc); UNUSED(pw); if (clone == false) { - lwc_context_string_unref((lwc_context *) key_pw, - (lwc_string *) key); + lwc_string_unref((lwc_string *) key); return NULL; } else { lwc_error err; lwc_string *ret; const char *data = lwc_string_data((lwc_string *) key); size_t len = lwc_string_length((lwc_string *) key); - err = lwc_context_intern((lwc_context *) key_pw, data, len, - &ret); + err = lwc_intern_string(data, len, &ret); if (err != lwc_error_ok) return NULL; @@ -2143,7 +2123,6 @@ void *_value(void *value, void *value_pw, dom_alloc alloc, UNUSED(alloc); UNUSED(pw); - UNUSED(value_pw); if (clone == false) { dom_node_internal *a = (dom_node_internal *) value; @@ -2179,15 +2158,13 @@ void *_nsattributes(void *value, void *value_pw, dom_alloc alloc, return NULL; } else { dom_document *doc = (dom_document *) value_pw; - lwc_context *ctx = _dom_document_get_intern_context(doc); - assert(ctx != NULL); dom_alloc alloc; void *pw; struct dom_hash_table *ret = NULL; _dom_document_get_allocator(doc, &alloc, &pw); ret = _dom_hash_clone((struct dom_hash_table *) value, alloc, - pw, _key, ctx, _value, doc); + pw, _key, NULL, _value, doc); return ret; } diff --git a/src/core/implementation.c b/src/core/implementation.c index 30e1eb3..6713060 100644 --- a/src/core/implementation.c +++ b/src/core/implementation.c @@ -77,11 +77,11 @@ dom_exception dom_implementation_has_feature( dom_exception dom_implementation_create_document_type( struct dom_implementation *impl, struct dom_string *qname, struct dom_string *public_id, struct dom_string *system_id, - dom_alloc alloc, void *pw, struct lwc_context_s *ctx, + dom_alloc alloc, void *pw, struct dom_document_type **doctype) { return impl->create_document_type(impl, qname, public_id, system_id, - alloc, pw, ctx, doctype); + alloc, pw, doctype); } /** @@ -121,12 +121,12 @@ dom_exception dom_implementation_create_document( struct dom_implementation *impl, struct dom_string *namespace, struct dom_string *qname, struct dom_document_type *doctype, - dom_alloc alloc, void *pw, struct lwc_context_s *ctx, + dom_alloc alloc, void *pw, dom_events_default_action_fetcher daf, struct dom_document **doc) { return impl->create_document(impl, namespace, qname, doctype, alloc, - pw, ctx, daf, doc); + pw, daf, doc); } /** diff --git a/src/core/node.c b/src/core/node.c index 1bdcade..5f35f61 100644 --- a/src/core/node.c +++ b/src/core/node.c @@ -145,18 +145,13 @@ dom_exception _dom_node_initialise(dom_node_internal *node, struct lwc_string_s *name, struct dom_string *value, struct lwc_string_s *namespace, struct lwc_string_s *prefix) { - lwc_context *ctx; dom_alloc alloc; void *pw; dom_exception err; - ctx = _dom_document_get_intern_context(doc); - /* The lwc_context for a document never can be NULL */ - assert(ctx != NULL); - _dom_document_get_allocator(doc, &alloc, &pw); - err = _dom_node_initialise_generic(node, doc, alloc, pw, ctx, type, + err = _dom_node_initialise_generic(node, doc, alloc, pw, type, name, value, namespace, prefix); if (err != DOM_NO_ERR) return err; @@ -168,10 +163,9 @@ dom_exception _dom_node_initialise(dom_node_internal *node, * Initialise a DOM node * * \param node The node to initialise - * \param doc The document object + * \param doc The document object * \param alloc The memory allocator * \param pw The allocator private pointer data - * \param ctx The intern context * \param type The node type required * \param name The node (local) name, or NULL * \param value The node value, or NULL @@ -184,7 +178,7 @@ dom_exception _dom_node_initialise(dom_node_internal *node, */ dom_exception _dom_node_initialise_generic( struct dom_node_internal *node, struct dom_document *doc, - dom_alloc alloc, void *pw, struct lwc_context_s *ctx, + dom_alloc alloc, void *pw, dom_node_type type, struct lwc_string_s *name, struct dom_string *value, struct lwc_string_s *namespace, struct lwc_string_s *prefix) @@ -192,11 +186,10 @@ dom_exception _dom_node_initialise_generic( UNUSED(alloc); UNUSED(pw); - assert(ctx != NULL); node->owner = doc; if (name != NULL) - lwc_context_string_ref(ctx, name); + lwc_string_ref(name); node->name = name; if (value != NULL) @@ -231,12 +224,12 @@ dom_exception _dom_node_initialise_generic( */ if (namespace != NULL) { - lwc_context_string_ref(ctx, namespace); + lwc_string_ref(namespace); } node->namespace = namespace; if (prefix != NULL) { - lwc_context_string_ref(ctx, prefix); + lwc_string_ref(prefix); } node->prefix = prefix; @@ -264,17 +257,12 @@ dom_exception _dom_node_initialise_generic( */ void _dom_node_finalise(struct dom_document *doc, dom_node_internal *node) { - lwc_context *ctx; dom_alloc alloc; void *pw; - ctx = _dom_document_get_intern_context(doc); - /* The lwc_context for a document never can be NULL */ - assert(ctx != NULL); - _dom_document_get_allocator(doc, &alloc, &pw); - _dom_node_finalise_generic(node, alloc, pw, ctx); + _dom_node_finalise_generic(node, alloc, pw); } /** @@ -283,18 +271,15 @@ void _dom_node_finalise(struct dom_document *doc, dom_node_internal *node) * \param node The node to finalise * \param alloc The allocator * \param pw The allocator private data - * \param ctx The intern string context */ void _dom_node_finalise_generic(dom_node_internal *node, dom_alloc alloc, - void *pw, struct lwc_context_s *ctx) + void *pw) { struct dom_user_data *u, *v; UNUSED(alloc); UNUSED(pw); - assert(ctx != NULL); - /* Destroy user data */ for (u = node->user_data; u != NULL; u = v) { v = u->next; @@ -304,10 +289,10 @@ void _dom_node_finalise_generic(dom_node_internal *node, dom_alloc alloc, node->user_data = NULL; if (node->prefix != NULL) - lwc_context_string_unref(ctx, node->prefix); + lwc_string_unref(node->prefix); if (node->namespace != NULL) - lwc_context_string_unref(ctx, node->namespace); + lwc_string_unref(node->namespace); /* Destroy all the child nodes of this node */ struct dom_node_internal *p = node->first_child; @@ -330,7 +315,7 @@ void _dom_node_finalise_generic(dom_node_internal *node, dom_alloc alloc, dom_string_unref(node->value); if (node->name != NULL) - lwc_context_string_unref(ctx, node->name); + lwc_string_unref(node->name); /* If the node has no owner document, we need not to finalise its * dom_event_target_internal structure. @@ -1339,15 +1324,11 @@ dom_exception _dom_node_is_supported(dom_node_internal *node, dom_exception _dom_node_get_namespace(dom_node_internal *node, struct dom_string **result) { - lwc_context *ctx; - assert(node->owner != NULL); - ctx = _dom_document_get_intern_context(node->owner); - assert(ctx != NULL); /* If there is a namespace, increase its reference count */ if (node->namespace != NULL) - lwc_context_string_ref(ctx, node->namespace); + lwc_string_ref(node->namespace); return _dom_document_create_string_from_lwcstring(node->owner, node->namespace, result); @@ -1367,15 +1348,11 @@ dom_exception _dom_node_get_namespace(dom_node_internal *node, dom_exception _dom_node_get_prefix(dom_node_internal *node, struct dom_string **result) { - lwc_context *ctx; - assert(node->owner != NULL); - ctx = _dom_document_get_intern_context(node->owner); - assert(ctx != NULL); /* If there is a prefix, increase its reference count */ if (node->prefix != NULL) - lwc_context_string_ref(ctx, node->prefix); + lwc_string_ref(node->prefix); return _dom_document_create_string_from_lwcstring(node->owner, node->prefix, @@ -1410,10 +1387,6 @@ dom_exception _dom_node_set_prefix(dom_node_internal *node, { dom_exception err; lwc_string *str; - lwc_context *docctx; - - docctx = _dom_document_get_intern_context(node->owner); - assert(docctx != NULL); /* Only Element and Attribute nodes created using * namespace-aware methods may have a prefix */ @@ -1432,7 +1405,7 @@ dom_exception _dom_node_set_prefix(dom_node_internal *node, /* No longer want existing prefix */ if (node->prefix != NULL) { - lwc_context_string_unref(docctx, node->prefix); + lwc_string_unref(node->prefix); } /* Set the prefix */ @@ -1468,11 +1441,7 @@ dom_exception _dom_node_set_prefix(dom_node_internal *node, dom_exception _dom_node_get_local_name(dom_node_internal *node, struct dom_string **result) { - lwc_context *ctx; - assert(node->owner != NULL); - ctx = _dom_document_get_intern_context(node->owner); - assert(ctx != NULL); /* Only Element and Attribute nodes may have a local name */ if (node->type != DOM_ELEMENT_NODE && @@ -1483,7 +1452,7 @@ dom_exception _dom_node_get_local_name(dom_node_internal *node, /* The node may have a local name, reference it if so */ if (node->name != NULL) { - lwc_context_string_ref(ctx, node->name); + lwc_string_ref(node->name); } return _dom_document_create_string_from_lwcstring(node->owner, @@ -1740,7 +1709,6 @@ dom_exception _dom_node_is_equal(dom_node_internal *node, { dom_exception err; dom_string *s1, *s2; - lwc_context *c1, *c2; dom_namednodemap *m1, *m2; dom_nodelist *l1, *l2; @@ -1765,36 +1733,11 @@ dom_exception _dom_node_is_equal(dom_node_internal *node, return DOM_NO_ERR; } - c1 = _dom_document_get_intern_context(node->owner); - assert(c1 != NULL); - - c2 = _dom_document_get_intern_context(other->owner); - assert(c2 != NULL); - - if (c1 == c2) { - if (node->name != other->name || - node->namespace != other->namespace || - node->prefix != other->prefix) { - *result = false; - return DOM_NO_ERR; - } - } else { - if (_dom_lwc_string_compare_raw(node->name, other->name) != 0){ - *result = false; - return DOM_NO_ERR; - } - - if (_dom_lwc_string_compare_raw(node->namespace, - other->namespace) != 0){ - *result = false; - return DOM_NO_ERR; - } - - if (_dom_lwc_string_compare_raw(node->prefix, - other->prefix) != 0){ - *result = false; - return DOM_NO_ERR; - } + if (node->name != other->name || + node->namespace != other->namespace || + node->prefix != other->prefix) { + *result = false; + return DOM_NO_ERR; } if (dom_string_cmp(node->value, other->value) != 0) { @@ -1987,19 +1930,13 @@ dom_exception _dom_node_alloc(struct dom_document *doc, /* Copy the internal attributes of a Node from old to new */ dom_exception _dom_node_copy(dom_node_internal *new, dom_node_internal *old) { - lwc_context *nctx, *octx; dom_exception err; new->vtable = old->vtable; new->base.vtable = old->base.vtable; assert(old->owner != NULL); - octx = _dom_document_get_intern_context(old->owner); - assert(octx != NULL); - assert(new->owner != NULL); - nctx = _dom_document_get_intern_context(old->owner); - assert(nctx != NULL); new->type = old->type; new->parent = NULL; @@ -2009,51 +1946,13 @@ dom_exception _dom_node_copy(dom_node_internal *new, dom_node_internal *old) new->next = NULL; new->owner = old->owner; - if (octx == nctx) { - lwc_context_string_ref(octx, old->name); - new->name = old->name; + new->name = lwc_string_ref(old->name); - if (old->namespace != NULL) - lwc_context_string_ref(octx, old->namespace); - new->namespace = old->namespace; + if (old->namespace != NULL) + new->namespace = lwc_string_ref(old->namespace); - if (old->prefix != NULL) - lwc_context_string_ref(octx, old->prefix); - new->prefix = old->prefix; - } else { - lwc_string *str; - lwc_error lerr; - - lerr = lwc_context_intern(nctx, lwc_string_data(old->name), - lwc_string_length(old->name), &str); - if (lerr != lwc_error_ok) - return _dom_exception_from_lwc_error(lerr); - - new->name = str; - - if (old->namespace != NULL) { - lerr = lwc_context_intern(nctx, - lwc_string_data(old->namespace), - lwc_string_length(old->namespace), - &str); - if (lerr != lwc_error_ok) - return _dom_exception_from_lwc_error(lerr); - - new->namespace = str; - } else - new->namespace = NULL; - - if (old->prefix != NULL) { - lerr = lwc_context_intern(nctx, - lwc_string_data(old->prefix), - lwc_string_length(old->prefix), &str); - if (lerr != lwc_error_ok) - return _dom_exception_from_lwc_error(lerr); - - new->prefix = str; - } else - new->prefix = NULL; - } + if (old->prefix != NULL) + new->prefix = lwc_string_ref(old->prefix); dom_alloc al; void *pw; @@ -2351,32 +2250,6 @@ void _dom_node_replace(dom_node_internal *old, old->previous = old->next = old->parent = NULL; } -/** - * Migrate one lwc_string from one context to another, this function - * may be used when we import/adopt a Node between documents. - * - * \param old The source context - * \param new The new context - * \param string The lwc_string to migrate - * \return DOM_NO_ERR on success, appropriate dom_exception on failure. - */ -dom_exception _redocument_lwcstring(lwc_context *old, lwc_context *new, - lwc_string **string) -{ - lwc_string *str; - lwc_error lerr; - - lerr = lwc_context_intern(new, lwc_string_data(*string), - lwc_string_length(*string), &str); - if (lerr != lwc_error_ok) - return _dom_exception_from_lwc_error(lerr); - - lwc_context_string_unref(old, *string); - *string = str; - - return DOM_NO_ERR; -} - /** * Migrate one dom_string from one document to another, this function * may be used when we import/adopt a Node between documents. @@ -2437,7 +2310,7 @@ dom_exception _dom_merge_adjacent_text(dom_node_internal *p, } /** - * Intern a dom_string using the node's owner document's lwc_context + * Intern a dom_string * * \param node The node * \param str The dom_string to be interned @@ -2448,24 +2321,19 @@ dom_exception _dom_node_get_intern_string(dom_node_internal *node, dom_string *str, lwc_string **intern) { dom_exception err; - lwc_context *ctx, *docctx; lwc_string *ret; - assert(str != NULL); - assert(node->owner != NULL); + UNUSED(node); - docctx = _dom_document_get_intern_context(node->owner); - assert(docctx != NULL); + assert(str != NULL); - err = dom_string_get_intern(str, &ctx, &ret); + err = dom_string_get_intern(str, &ret); if (err != DOM_NO_ERR) return err; - if (ctx != docctx) { - err = _dom_string_intern(str, docctx, &ret); - if (err != DOM_NO_ERR) - return err; - } + err = _dom_string_intern(str, &ret); + if (err != DOM_NO_ERR) + return err; *intern = ret; @@ -2491,7 +2359,7 @@ void _dom_node_unref_intern_string(dom_node_internal *node, (dom_document_type *) node, &rm); } - lwc_context_string_unref(rm.ctx, intern); + lwc_string_unref(intern); } /** diff --git a/src/core/node.h b/src/core/node.h index c1a4192..4144b6e 100644 --- a/src/core/node.h +++ b/src/core/node.h @@ -92,14 +92,14 @@ dom_exception _dom_node_initialise(struct dom_node_internal *node, dom_exception _dom_node_initialise_generic( struct dom_node_internal *node, struct dom_document *doc, - dom_alloc alloc, void *pw, struct lwc_context_s *ctx, + dom_alloc alloc, void *pw, dom_node_type type, struct lwc_string_s *name, struct dom_string *value, struct lwc_string_s *namespace, struct lwc_string_s *prefix); void _dom_node_finalise(struct dom_document *doc, dom_node_internal *node); void _dom_node_finalise_generic(dom_node_internal *node, dom_alloc alloc, - void *pw, struct lwc_context_s *ctx); + void *pw); bool _dom_node_readonly(const dom_node_internal *node); @@ -275,8 +275,6 @@ static inline dom_exception dom_node_copy(struct dom_node_internal *new, #define dom_node_get_refcount(n) ((dom_node_internal *) (n))->refcnt -dom_exception _redocument_lwcstring(lwc_context *old, lwc_context *new, - lwc_string **string); dom_exception _redocument_domstring(struct dom_document *old, struct dom_document* new, struct dom_string **string); dom_exception _dom_merge_adjacent_text(dom_node_internal *p, diff --git a/src/core/nodelist.c b/src/core/nodelist.c index 2497619..755438a 100644 --- a/src/core/nodelist.c +++ b/src/core/nodelist.c @@ -71,10 +71,6 @@ dom_exception _dom_nodelist_create(struct dom_document *doc, nodelist_type type, struct dom_nodelist **list) { struct dom_nodelist *l; - lwc_context *ctx; - - ctx = _dom_document_get_intern_context(doc); - assert(ctx != NULL); l = _dom_document_alloc(doc, NULL, sizeof(struct dom_nodelist)); if (l == NULL) @@ -98,7 +94,7 @@ dom_exception _dom_nodelist_create(struct dom_document *doc, nodelist_type type, } } - lwc_context_string_ref(ctx, tagname); + lwc_string_ref(tagname); l->data.n.name = tagname; } else if (type == DOM_NODELIST_BY_NAMESPACE) { l->data.ns.any_localname = false; @@ -110,7 +106,7 @@ dom_exception _dom_nodelist_create(struct dom_document *doc, nodelist_type type, l->data.ns.any_localname = true; } } - lwc_context_string_ref(ctx, localname); + lwc_string_ref(localname); } if (namespace != NULL) { if (lwc_string_length(namespace) == 1) { @@ -119,7 +115,7 @@ dom_exception _dom_nodelist_create(struct dom_document *doc, nodelist_type type, l->data.ns.any_namespace = true; } } - lwc_context_string_ref(ctx, namespace); + lwc_string_ref(namespace); } l->data.ns.namespace = namespace; @@ -160,25 +156,19 @@ void dom_nodelist_unref(struct dom_nodelist *list) if (--list->refcnt == 0) { struct dom_node_internal *owner = (struct dom_node_internal *) list->owner; - lwc_context *ctx; - ctx = _dom_document_get_intern_context((dom_document *) owner); - assert(ctx != NULL); - switch (list->type) { case DOM_NODELIST_CHILDREN: /* Nothing to do */ break; case DOM_NODELIST_BY_NAMESPACE: if (list->data.ns.namespace != NULL) - lwc_context_string_unref(ctx, - list->data.ns.namespace); + lwc_string_unref(list->data.ns.namespace); if (list->data.ns.localname != NULL) - lwc_context_string_unref(ctx, - list->data.ns.localname); + lwc_string_unref(list->data.ns.localname); break; case DOM_NODELIST_BY_NAME: assert(list->data.n.name != NULL); - lwc_context_string_unref(ctx, list->data.n.name); + lwc_string_unref(list->data.n.name); break; } diff --git a/src/core/string.c b/src/core/string.c index 473363b..1a5b396 100644 --- a/src/core/string.c +++ b/src/core/string.c @@ -29,8 +29,6 @@ struct dom_string { lwc_string *intern; /**< The lwc_string of this string */ - lwc_context *context; /**< The lwc_context for the lwc_string */ - dom_alloc alloc; /**< Memory (de)allocation function */ void *pw; /**< Client-specific data */ @@ -41,7 +39,6 @@ static struct dom_string empty_string = { .ptr = NULL, .len = 0, .intern = NULL, - .context = NULL, .alloc = NULL, .pw = NULL, .refcnt = 1 @@ -75,8 +72,7 @@ void dom_string_unref(struct dom_string *str) if (--str->refcnt == 0) { if (str->intern != NULL) { - lwc_context_unref(str->context); - lwc_context_string_unref(str->context, str->intern); + lwc_string_unref(str->intern); str->alloc(str, 0, str->pw); } else if (str->alloc != NULL) { str->alloc(str->ptr, 0, str->pw); @@ -132,7 +128,6 @@ dom_exception dom_string_create(dom_alloc alloc, void *pw, ret->pw = pw; ret->intern = NULL; - ret->context = NULL; ret->refcnt = 1; @@ -166,7 +161,7 @@ dom_exception dom_string_clone(dom_alloc alloc, void *pw, if (str->intern != NULL) { return _dom_string_create_from_lwcstring(alloc, pw, - str->context, str->intern, ret); + str->intern, ret); } else { return dom_string_create(alloc, pw, str->ptr, str->len, ret); } @@ -175,13 +170,12 @@ dom_exception dom_string_clone(dom_alloc alloc, void *pw, /** * Create a dom_string from a lwc_string * - * \param ctx The lwc_context * \param str The lwc_string * \param ret The new dom_string * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion */ dom_exception _dom_string_create_from_lwcstring(dom_alloc alloc, void *pw, - lwc_context *ctx, lwc_string *str, struct dom_string **ret) + lwc_string *str, struct dom_string **ret) { dom_string *r; @@ -200,7 +194,6 @@ dom_exception _dom_string_create_from_lwcstring(dom_alloc alloc, void *pw, return DOM_NO_ERR; } - r->context = ctx; r->intern = str; r->ptr = (uint8_t *)lwc_string_data(str); r->len = lwc_string_length(str); @@ -211,8 +204,7 @@ dom_exception _dom_string_create_from_lwcstring(dom_alloc alloc, void *pw, r->refcnt = 1; /* Ref the lwc_string */ - lwc_context_ref(ctx); - lwc_context_string_ref(ctx, str); + lwc_string_ref(str); *ret = r; return DOM_NO_ERR; @@ -220,42 +212,30 @@ dom_exception _dom_string_create_from_lwcstring(dom_alloc alloc, void *pw, } /** - * Make the dom_string be interned in the lwc_context + * Make the dom_string be interned * * \param str The dom_string to be interned - * \param ctx The lwc_context to intern this dom_string * \param lwcstr The result lwc_string * \return DOM_NO_ERR on success, appropriate dom_exception on failure. */ dom_exception _dom_string_intern(struct dom_string *str, - struct lwc_context_s *ctx, struct lwc_string_s **lwcstr) + struct lwc_string_s **lwcstr) { lwc_string *ret; lwc_error lerr; - /* If this string is interned with the same context, do nothing */ - if (str->context != NULL && str->context == ctx) { - *lwcstr = str->intern; - lwc_context_ref(ctx); - lwc_context_string_ref(ctx, *lwcstr); + /* If this string is already interned, do nothing */ + if (str->intern != NULL) { + *lwcstr = lwc_string_ref(str->intern); return DOM_NO_ERR; } - lerr = lwc_context_intern(ctx, (const char *)str->ptr, str->len, &ret); + lerr = lwc_intern_string((const char *)str->ptr, str->len, &ret); if (lerr != lwc_error_ok) { return _dom_exception_from_lwc_error(lerr); } - if (str->context != NULL) { - lwc_context_unref(str->context); - lwc_context_string_unref(str->context, str->intern); - str->ptr = NULL; - } - - str->context = ctx; str->intern = ret; - lwc_context_ref(ctx); - lwc_context_string_ref(ctx, ret); if (str->ptr != NULL) { str->alloc(str->ptr, 0, str->pw); @@ -263,7 +243,7 @@ dom_exception _dom_string_intern(struct dom_string *str, str->ptr = (uint8_t *) lwc_string_data(ret); - *lwcstr = ret; + *lwcstr = lwc_string_ref(ret); return DOM_NO_ERR; } @@ -271,20 +251,16 @@ dom_exception _dom_string_intern(struct dom_string *str, * Get the internal lwc_string * * \param str The dom_string object - * \param ctx The lwc_context which intern this dom_string * \param lwcstr The lwc_string of this dom-string * \return DOM_NO_ERR on success, appropriate dom_exception on failure. */ dom_exception dom_string_get_intern(struct dom_string *str, - struct lwc_context_s **ctx, struct lwc_string_s **lwcstr) + struct lwc_string_s **lwcstr) { - *ctx = str->context; *lwcstr = str->intern; - if (*ctx != NULL) - lwc_context_ref(*ctx); if (*lwcstr != NULL) - lwc_context_string_ref(*ctx, *lwcstr); + lwc_string_ref(*lwcstr); return DOM_NO_ERR; } @@ -308,11 +284,8 @@ int dom_string_cmp(struct dom_string *s1, struct dom_string *s2) if (s2 == NULL) s2 = &empty_string; - if (s1->context == s2->context && s1->context != NULL) { - assert(s1->intern != NULL); - assert(s2->intern != NULL); - lwc_context_string_isequal(s1->context, s1->intern, - s2->intern, &ret); + if (s1->intern != NULL && s2->intern != NULL) { + lwc_string_isequal(s1->intern, s2->intern, &ret); if (ret == true) { return 0; } else { @@ -347,11 +320,8 @@ int dom_string_icmp(struct dom_string *s1, struct dom_string *s2) s2 = &empty_string; bool ret; - if (s1->context == s2->context && s1->context != NULL) { - assert(s1->intern != NULL); - assert(s2->intern != NULL); - lwc_context_string_caseless_isequal(s1->context, s1->intern, - s2->intern, &ret); + if (s1->intern != NULL && s2->intern != NULL) { + lwc_string_caseless_isequal(s1->intern, s2->intern, &ret); if (ret == true) { return 0; } else { @@ -606,7 +576,6 @@ dom_exception dom_string_concat(struct dom_string *s1, struct dom_string *s2, concat->alloc = alloc; concat->pw = pw; - concat->context = NULL; concat->intern = NULL; concat->refcnt = 1; @@ -757,7 +726,6 @@ dom_exception dom_string_insert(struct dom_string *target, res->alloc = target->alloc; res->pw = target->pw; res->intern = NULL; - res->context = NULL; res->refcnt = 1; @@ -864,7 +832,6 @@ dom_exception dom_string_replace(struct dom_string *target, res->alloc = target->alloc; res->pw = target->pw; res->intern = NULL; - res->context = NULL; res->refcnt = 1; @@ -891,7 +858,7 @@ dom_exception dom_string_dup(struct dom_string *str, { if (str->intern != NULL) { return _dom_string_create_from_lwcstring(str->alloc, str->pw, - str->context, str->intern, result); + str->intern, result); } else { return dom_string_create(str->alloc, str->pw, str->ptr, str->len, result); @@ -936,36 +903,14 @@ dom_exception _dom_exception_from_lwc_error(lwc_error err) return DOM_NO_MEM_ERR; case lwc_error_range: return DOM_INDEX_SIZE_ERR; + case lwc_error_initialised: + return DOM_NO_ERR; } assert ("Unknow lwc_error, can't convert to dom_exception"); /* Suppress compile errors */ return DOM_NO_ERR; } -/** - * Compare the raw data of two lwc_strings for equality when the two strings - * belong to different lwc_context - * - * \param s1 The first lwc_string - * \param s2 The second lwc_string - * \return 0 for equal, non-zero otherwise - */ -int _dom_lwc_string_compare_raw(struct lwc_string_s *s1, - struct lwc_string_s *s2) -{ - const char *rs1, *rs2; - size_t len; - - if (lwc_string_length(s1) != lwc_string_length(s2)) - return -1; - - len = lwc_string_length(s1); - rs1 = lwc_string_data(s1); - rs2 = lwc_string_data(s2); - - return memcmp(rs1, rs2, len); -} - /** * Get the raw character data of the dom_string. * diff --git a/src/core/string.h b/src/core/string.h index 46704d8..ef231be 100644 --- a/src/core/string.h +++ b/src/core/string.h @@ -13,17 +13,11 @@ /* Create a DOM string from a lwc_string * This function call mainly used for create a string from lwc_string */ dom_exception _dom_string_create_from_lwcstring(dom_alloc alloc, void *pw, - struct lwc_context_s *ctx, struct lwc_string_s *str, - struct dom_string **ret); + struct lwc_string_s *str, struct dom_string **ret); -/* Make the dom_string be interned in the lwc_context */ +/* Make the dom_string be interned */ dom_exception _dom_string_intern(struct dom_string *str, - struct lwc_context_s *ctx, struct lwc_string_s **lwcstr); - -/* Compare the raw data of two lwc_strings for equality when the two strings - * belong to different lwc_context */ -int _dom_lwc_string_compare_raw(struct lwc_string_s *s1, - struct lwc_string_s *s2); + struct lwc_string_s **lwcstr); /* Map the lwc_error to dom_exception */ dom_exception _dom_exception_from_lwc_error(lwc_error err); diff --git a/src/core/text.h b/src/core/text.h index e5de56c..44e09e7 100644 --- a/src/core/text.h +++ b/src/core/text.h @@ -16,7 +16,6 @@ struct dom_document; struct dom_string; -struct lwc_context_s; struct lwc_string_s; /** diff --git a/src/events/document_event.c b/src/events/document_event.c index 47afed6..6f18028 100644 --- a/src/events/document_event.c +++ b/src/events/document_event.c @@ -53,11 +53,12 @@ dom_exception _dom_document_event_internal_initialise(struct dom_document *doc, dom_events_default_action_fetcher actions) { lwc_error err; - lwc_context *ctx = _dom_document_get_intern_context(doc); int i = 0; + UNUSED(doc); + for (; i < DOM_EVENT_COUNT; i++) { - err = lwc_context_intern(ctx, __event_types[i], + err = lwc_intern_string(__event_types[i], SLEN(__event_types[i]), &dei->event_types[i]); if (err != lwc_error_ok) return _dom_exception_from_lwc_error(err); @@ -92,15 +93,13 @@ void _dom_document_event_internal_finalise(struct dom_document *doc, dom_exception _dom_document_event_create_event(dom_document_event *de, struct dom_string *type, struct dom_event **evt) { - lwc_context *ctx = NULL; lwc_string *t = NULL; dom_exception err; struct dom_document *doc = de; - dom_string_get_intern(type, &ctx, &t); + dom_string_get_intern(type, &t); if (t == NULL) { - ctx = _dom_document_get_intern_context(doc); - err = _dom_string_intern(type, ctx, &t); + err = _dom_string_intern(type, &t); if (err != DOM_NO_ERR) return err; } @@ -115,7 +114,7 @@ dom_exception _dom_document_event_create_event(dom_document_event *de, break; } } - lwc_context_string_unref(ctx, t); + lwc_string_unref(t); switch (et) { case DOM_EVENT: diff --git a/src/events/event.c b/src/events/event.c index 9330edf..6cd8d64 100644 --- a/src/events/event.c +++ b/src/events/event.c @@ -15,6 +15,7 @@ #include "core/string.h" #include "core/node.h" #include "core/document.h" +#include "utils/utils.h" static void _virtual_dom_event_destroy(struct dom_event *evt); @@ -68,14 +69,12 @@ dom_exception _dom_event_initialise(struct dom_document *doc, /* Finalise function */ void _dom_event_finalise(struct dom_document *doc, struct dom_event *evt) { - assert(doc != NULL); - lwc_context *ctx = _dom_document_get_intern_context(doc); - assert(ctx != NULL); + UNUSED(doc); if (evt->type != NULL) - lwc_context_string_unref(ctx, evt->type); + lwc_string_unref(evt->type); if (evt->namespace != NULL) - lwc_context_string_unref(ctx, evt->namespace); + lwc_string_unref(evt->namespace); evt->stop = false; evt->stop_now = false; @@ -250,11 +249,10 @@ dom_exception _dom_event_init(dom_event *evt, struct dom_string *type, bool bubble, bool cancelable) { assert(evt->doc != NULL); - lwc_context *ctx = _dom_document_get_intern_context(evt->doc); lwc_string *str = NULL; dom_exception err; - err = _dom_string_intern(type, ctx, &str); + err = _dom_string_intern(type, &str); if (err != DOM_NO_ERR) return err; @@ -343,16 +341,15 @@ dom_exception _dom_event_init_ns(dom_event *evt, struct dom_string *namespace, struct dom_string *type, bool bubble, bool cancelable) { assert(evt->doc != NULL); - lwc_context *ctx = _dom_document_get_intern_context(evt->doc); lwc_string *str = NULL; dom_exception err; - err = _dom_string_intern(type, ctx, &str); + err = _dom_string_intern(type, &str); if (err != DOM_NO_ERR) return err; evt->type = str; - err = _dom_string_intern(namespace, ctx, &str); + err = _dom_string_intern(namespace, &str); if (err != DOM_NO_ERR) return err; evt->namespace = str; diff --git a/src/events/event_target.c b/src/events/event_target.c index 8350224..e409e02 100644 --- a/src/events/event_target.c +++ b/src/events/event_target.c @@ -51,10 +51,8 @@ dom_exception _dom_event_target_internal_initialise(struct dom_document *doc, void _dom_event_target_internal_finalise(struct dom_document *doc, dom_event_target_internal *eti) { - lwc_context *ctx = _dom_document_get_intern_context(doc); - if (eti->listeners != NULL) - _dom_hash_destroy(eti->listeners, _key, ctx, _value, doc); + _dom_hash_destroy(eti->listeners, _key, NULL, _value, doc); /* TODO: Now, we did not support the EventListener with namespace, * when we support it, we should deal with the ns_listeners hash * table, too. @@ -83,7 +81,6 @@ dom_exception _dom_event_target_add_event_listener(dom_event_target *et, struct dom_event_target_internal *eti = &et->eti; lwc_string *t = NULL; - lwc_context *ctx = NULL; dom_exception err; /* If there is no hash table, we should create one firstly */ @@ -94,17 +91,16 @@ dom_exception _dom_event_target_add_event_listener(dom_event_target *et, return err; } - err = dom_string_get_intern(type, &ctx, &t); + err = dom_string_get_intern(type, &t); if (err != DOM_NO_ERR) return err; - ctx = _dom_document_get_intern_context(doc); if (t == NULL) { - err = _dom_string_intern(type, ctx, &t); + err = _dom_string_intern(type, &t); if (err != DOM_NO_ERR) return err; } else { - lwc_context_string_ref(ctx, t); + lwc_string_ref(t); } assert(t != NULL); @@ -158,20 +154,18 @@ dom_exception _dom_event_target_remove_event_listener(dom_event_target *et, struct dom_event_target_internal *eti = &et->eti; lwc_string *t = NULL; - lwc_context *ctx = NULL; dom_exception err; - err = dom_string_get_intern(type, &ctx, &t); + err = dom_string_get_intern(type, &t); if (err != DOM_NO_ERR) return err; - ctx = _dom_document_get_intern_context(doc); if (t == NULL) { - err = _dom_string_intern(type, ctx, &t); + err = _dom_string_intern(type, &t); if (err != DOM_NO_ERR) return err; } else { - lwc_context_string_ref(ctx, t); + lwc_string_ref(t); } assert(t != NULL); @@ -181,7 +175,7 @@ dom_exception _dom_event_target_remove_event_listener(dom_event_target *et, eti->listeners, t); if (item == NULL) { /* There is no such event listener */ - lwc_context_string_unref(ctx, t); + lwc_string_unref(t); return DOM_NO_ERR; } else { struct list_entry *i = item; @@ -262,11 +256,9 @@ dom_exception _dom_event_target_dispatch_event(dom_event_target *et, dom_string_unref(type); lwc_string *t = evt->type; - lwc_context *ctx = NULL; dom_event_target_entry list; dom_event_target *target = et; - ctx = _dom_document_get_intern_context(doc); assert(t != NULL); *success = true; @@ -349,8 +341,7 @@ dom_exception _dom_event_target_dispatch_event(dom_event_target *et, goto cleanup; } lwc_string *lnodename = NULL; - lwc_context *lctx = NULL; - err = dom_string_get_intern(nodename, &lctx, &lnodename); + err = dom_string_get_intern(nodename, &lnodename); if (err != DOM_NO_ERR) { dom_string_unref(nodename); ret = err; @@ -363,8 +354,7 @@ dom_exception _dom_event_target_dispatch_event(dom_event_target *et, } dom_string_unref(nodename); - lwc_context_string_unref(lctx, lnodename); - lwc_context_unref(lctx); + lwc_string_unref(lnodename); cleanup: if (evt->prevent_default == true) { @@ -441,6 +431,7 @@ dom_exception _dom_event_target_remove_event_listener_ns(dom_event_target *et, static void *_key(void *key, void *key_pw, dom_alloc alloc, void *pw, bool clone) { + UNUSED(key_pw); UNUSED(alloc); UNUSED(pw); /* There should never be the requirement of clone the event listener @@ -448,8 +439,7 @@ static void *_key(void *key, void *key_pw, dom_alloc alloc, void *pw, assert(clone == false); UNUSED(clone); - lwc_context *ctx = (lwc_context *) key_pw; - lwc_context_string_unref(ctx, (lwc_string *) key); + lwc_string_unref((lwc_string *) key); return NULL; } diff --git a/src/utils/resource_mgr.c b/src/utils/resource_mgr.c index c9c86d3..98270ee 100644 --- a/src/utils/resource_mgr.c +++ b/src/utils/resource_mgr.c @@ -13,6 +13,8 @@ #include #include "core/string.h" +#include "utils/utils.h" + /** * Allocate some memory with this allocator * @@ -55,10 +57,9 @@ dom_exception _dom_resource_mgr_create_lwcstring(struct dom_resource_mgr *res, { lwc_error lerr; - assert(res->ctx != NULL); + UNUSED(res); - lerr = lwc_context_intern(res->ctx, (const char *) data, len, - result); + lerr = lwc_intern_string((const char *) data, len, result); return _dom_exception_from_lwc_error(lerr); } @@ -75,9 +76,7 @@ dom_exception _dom_resource_mgr_create_string_from_lwcstring( struct dom_resource_mgr *res, struct lwc_string_s *str, struct dom_string **result) { - assert(res->ctx != NULL); - - return _dom_string_create_from_lwcstring(res->alloc, res->pw, res->ctx, + return _dom_string_create_from_lwcstring(res->alloc, res->pw, str, result); } diff --git a/src/utils/resource_mgr.h b/src/utils/resource_mgr.h index b58f665..608df53 100644 --- a/src/utils/resource_mgr.h +++ b/src/utils/resource_mgr.h @@ -13,7 +13,6 @@ #include "hashtable.h" -struct lwc_context_s; struct lwc_string_s; struct dom_string; @@ -23,7 +22,6 @@ struct dom_string; typedef struct dom_resource_mgr { dom_alloc alloc; void *pw; - struct lwc_context_s *ctx; } dom_resource_mgr; void *_dom_resource_mgr_alloc(struct dom_resource_mgr *res, void *ptr, diff --git a/test/DOMTSHandler.pm b/test/DOMTSHandler.pm index 4e9d304..bc86369 100644 --- a/test/DOMTSHandler.pm +++ b/test/DOMTSHandler.pm @@ -363,7 +363,6 @@ sub generate_main { #include dom_implementation *doc_impl; -lwc_context *ctx; int main(int argc, char **argv) { @@ -375,7 +374,7 @@ int main(int argc, char **argv) if (exp != DOM_NO_ERR) return exp; - lerr = lwc_create_context(myrealloc, NULL, &ctx); + lerr = lwc_initialise(myrealloc, NULL, 0); if (lerr != lwc_error_ok) return -1; @@ -701,9 +700,9 @@ sub generate_method { # Add the bootstrap params if (exists $bootstrap_api{$method}) { if ($method eq "dom_implementation_create_document") { - $params = $params.", myrealloc, NULL, ctx, NULL"; + $params = $params.", myrealloc, NULL, NULL"; } else { - $params = $params.", myrealloc, NULL, ctx"; + $params = $params.", myrealloc, NULL"; } } # Deal with the situation like diff --git a/test/testutils/domts.h b/test/testutils/domts.h index 14f4e9e..6aa8cc4 100644 --- a/test/testutils/domts.h +++ b/test/testutils/domts.h @@ -15,10 +15,6 @@ #include #include -struct lwc_context_s; - -extern struct lwc_context_s *ctx; - dom_document *load_xml(char *file, bool willBeModified); dom_document *load_html(char *file, bool willBeModified); diff --git a/test/testutils/load.c b/test/testutils/load.c index 66e4e4c..0028eb4 100644 --- a/test/testutils/load.c +++ b/test/testutils/load.c @@ -24,8 +24,6 @@ #include "utils.h" -extern lwc_context *ctx; - /** * Load the file as it is a XML file * @@ -44,7 +42,7 @@ dom_document *load_xml(char *file, bool willBeModified) UNUSED(willBeModified); parser = dom_xml_parser_create(NULL, NULL, - myrealloc, NULL, mymsg, NULL, ctx); + myrealloc, NULL, mymsg, NULL); if (parser == NULL) { fprintf(stderr, "Can't create XMLParser\n"); return NULL; @@ -105,8 +103,8 @@ dom_document *load_html(char *file, bool willBeModified) UNUSED(willBeModified); - parser = dom_hubbub_parser_create("data/Aliases", NULL, true, - myrealloc, NULL, mymsg, NULL, ctx); + parser = dom_hubbub_parser_create("../data/Aliases", NULL, true, + myrealloc, NULL, mymsg, NULL); if (parser == NULL) { fprintf(stderr, "Can't create Hubbub Parser\n"); return NULL; @@ -115,7 +113,7 @@ dom_document *load_html(char *file, bool willBeModified) handle = open(file, O_RDONLY); if (handle == -1) { dom_hubbub_parser_destroy(parser); - fprintf(stderr, "Can't open test input file: %s\n", file); + /* fprintf(stderr, "Can't open test input file: %s\n", file); */ return NULL; } -- cgit v1.2.3