r12442 jmb - in /branches/jmb/dom-alloc-purge/src: core/implementation.c html/html_document.h
by netsurf@semichrome.net
Author: jmb
Date: Sun May 22 17:31:08 2011
New Revision: 12442
URL: http://source.netsurf-browser.org?rev=12442&view=rev
Log:
Make implementation.c compile
Modified:
branches/jmb/dom-alloc-purge/src/core/implementation.c
branches/jmb/dom-alloc-purge/src/html/html_document.h
Modified: branches/jmb/dom-alloc-purge/src/core/implementation.c
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/i...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/implementation.c (original)
+++ branches/jmb/dom-alloc-purge/src/core/implementation.c Sun May 22 17:31:08 2011
@@ -53,9 +53,6 @@
* Document does not support XML
* namespaces.
*
- * Any memory allocated by this call should be allocated using
- * the provided memory (de)allocation function.
- *
* The doctype will be referenced, so the client need not do this
* explicitly. The client must unref the doctype once it has
* finished with it.
@@ -63,7 +60,6 @@
dom_exception dom_implementation_create_document_type(
const char *qname, const char *public_id,
const char *system_id,
- dom_alloc alloc, void *pw,
struct dom_document_type **doctype)
{
struct dom_document_type *d;
@@ -72,7 +68,7 @@
dom_exception err;
if (qname != NULL) {
- err = dom_string_create(alloc, pw, (const uint8_t *) qname,
+ err = dom_string_create((const uint8_t *) qname,
strlen(qname), &qname_s);
if (err != DOM_NO_ERR)
return err;
@@ -99,7 +95,7 @@
}
if (public_id != NULL) {
- err = dom_string_create(alloc, pw, (const uint8_t *) public_id,
+ err = dom_string_create((const uint8_t *) public_id,
strlen(public_id), &public_id_s);
if (err != DOM_NO_ERR) {
dom_string_unref(lname);
@@ -110,7 +106,7 @@
}
if (system_id != NULL) {
- err = dom_string_create(alloc, pw, (const uint8_t *) system_id,
+ err = dom_string_create((const uint8_t *) system_id,
strlen(system_id), &system_id_s);
if (err != DOM_NO_ERR) {
dom_string_unref(public_id_s);
@@ -122,8 +118,7 @@
}
/* Create the doctype */
- err = _dom_document_type_create(qname_s, public_id_s, system_id_s,
- alloc, pw, &d);
+ err = _dom_document_type_create(qname_s, public_id_s, system_id_s, &d);
if (err == DOM_NO_ERR)
*doctype = d;
@@ -163,9 +158,6 @@
* Document does not support XML
* namespaces.
*
- * Any memory allocated by this call should be allocated using
- * the provided memory (de)allocation function.
- *
* The document will be referenced, so the client need not do this
* explicitly. The client must unref the document once it has
* finished with it.
@@ -174,7 +166,6 @@
uint32_t impl_type,
const char *namespace, const char *qname,
struct dom_document_type *doctype,
- dom_alloc alloc, void *pw,
dom_events_default_action_fetcher daf,
struct dom_document **doc)
{
@@ -183,14 +174,14 @@
dom_exception err;
if (namespace != NULL) {
- err = dom_string_create(alloc, pw, (const uint8_t *) namespace,
+ err = dom_string_create((const uint8_t *) namespace,
strlen(namespace), &namespace_s);
if (err != DOM_NO_ERR)
return err;
}
if (qname != NULL) {
- err = dom_string_create(alloc, pw, (const uint8_t *) qname,
+ err = dom_string_create((const uint8_t *) qname,
strlen(qname), &qname_s);
if (err != DOM_NO_ERR) {
dom_string_unref(namespace_s);
@@ -226,7 +217,7 @@
if (impl_type == DOM_IMPLEMENTATION_HTML) {
dom_html_document *html_doc;
- err = dom_html_document_create(alloc, pw, NULL, NULL,
+ err = dom_html_document_create(NULL, NULL,
daf, NULL, DOM_HTML_PARSER, &html_doc);
d = (dom_document *) html_doc;
@@ -235,7 +226,7 @@
UNUSED(impl_type);
#endif
{
- err = _dom_document_create(alloc, pw, daf, &d);
+ err = _dom_document_create(daf, &d);
}
if (err != DOM_NO_ERR) {
Modified: branches/jmb/dom-alloc-purge/src/html/html_document.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/html/h...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/html/html_document.h (original)
+++ branches/jmb/dom-alloc-purge/src/html/html_document.h Sun May 22 17:31:08 2011
@@ -35,7 +35,7 @@
/* 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 */
11 years, 8 months
r12441 jmb - in /branches/jmb/dom-alloc-purge/src/core: document.h element.c element.h
by netsurf@semichrome.net
Author: jmb
Date: Sun May 22 06:17:26 2011
New Revision: 12441
URL: http://source.netsurf-browser.org?rev=12441&view=rev
Log:
Make element.c compile again
Modified:
branches/jmb/dom-alloc-purge/src/core/document.h
branches/jmb/dom-alloc-purge/src/core/element.c
branches/jmb/dom-alloc-purge/src/core/element.h
Modified: branches/jmb/dom-alloc-purge/src/core/document.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/d...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/document.h (original)
+++ branches/jmb/dom-alloc-purge/src/core/document.h Sun May 22 06:17:26 2011
@@ -56,7 +56,7 @@
struct list_entry pending_nodes;
/**< The deletion pending list */
- struct lwc_string_s *id_name; /**< The ID attribute's name */
+ dom_string *id_name; /**< The ID attribute's name */
dom_document_event_internal dei;
/**< The DocumentEVent interface */
@@ -240,8 +240,8 @@
/* Get a nodelist, creating one if necessary */
dom_exception _dom_document_get_nodelist(struct dom_document *doc,
nodelist_type type, struct dom_node_internal *root,
- struct lwc_string_s *tagname, struct lwc_string_s *namespace,
- struct lwc_string_s *localname, struct dom_nodelist **list);
+ dom_string *tagname, dom_string *namespace,
+ dom_string *localname, struct dom_nodelist **list);
/* Remove a nodelist */
void _dom_document_remove_nodelist(struct dom_document *doc,
struct dom_nodelist *list);
Modified: branches/jmb/dom-alloc-purge/src/core/element.c
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/e...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/element.c (original)
+++ branches/jmb/dom-alloc-purge/src/core/element.c Sun May 22 06:17:26 2011
@@ -180,14 +180,14 @@
assert(doc != NULL);
err = _dom_document_create_hashtable(doc, CHAINS_ATTRIBUTES,
- _dom_hash_hash_lwcstring, &el->attributes);
+ (dom_hash_func) dom_string_hash, &el->attributes);
if (err != DOM_NO_ERR) {
free(el);
return err;
}
err = _dom_document_create_hashtable(doc, CHAINS_NAMESPACE,
- _dom_hash_hash_lwcstring, &el->ns_attributes);
+ (dom_hash_func) dom_string_hash, &el->ns_attributes);
if (err != DOM_NO_ERR) {
free(el->attributes);
free(el);
@@ -214,20 +214,19 @@
/**
* Finalise a dom_element
*
- * \param doc The document
* \param ele The element
*/
-void _dom_element_finalise(struct dom_document *doc, struct dom_element *ele)
+void _dom_element_finalise(struct dom_element *ele)
{
/* Destroy attributes attached to this node */
if (ele->attributes != NULL) {
- _dom_hash_destroy(ele->attributes, _key, NULL, _value, doc);
+ _dom_hash_destroy(ele->attributes, _key, NULL, _value, NULL);
ele->attributes = NULL;
}
if (ele->ns_attributes != NULL) {
_dom_hash_destroy(ele->ns_attributes, _key, NULL,
- _nsattributes, doc);
+ _nsattributes, NULL);
ele->ns_attributes = NULL;
}
@@ -242,15 +241,13 @@
/**
* Destroy an element
*
- * \param doc The owning document
* \param element The element to destroy
*
* The contents of ::element will be destroyed and ::element will be freed.
*/
-void _dom_element_destroy(struct dom_document *doc,
- struct dom_element *element)
-{
- _dom_element_finalise(doc, element);
+void _dom_element_destroy(struct dom_element *element)
+{
+ _dom_element_finalise(element);
/* Free the element */
free(element);
@@ -442,19 +439,12 @@
dom_string *namespace, dom_string *localname,
dom_string **value)
{
- lwc_string *str;
- dom_exception err;
struct dom_hash_table *attrs;
if (namespace == NULL)
return _dom_element_get_attribute(element, localname, value);
- err = _dom_node_get_intern_string(&element->base, namespace, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- attrs = (struct dom_hash_table *) _dom_hash_get(element->ns_attributes,
- str);
+ attrs = _dom_hash_get(element->ns_attributes, namespace);
/* The element has no such namespace */
if (attrs == NULL) {
*value = NULL;
@@ -497,7 +487,6 @@
dom_string *namespace, dom_string *qname,
dom_string *value)
{
- lwc_string *str;
dom_exception err;
struct dom_hash_table *attrs;
bool added;
@@ -524,23 +513,18 @@
return err;
}
- err = _dom_node_get_intern_string(&element->base, namespace, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- attrs = (struct dom_hash_table *) _dom_hash_get(element->ns_attributes,
- str);
+ attrs = _dom_hash_get(element->ns_attributes, namespace);
/* The element has no such namespace */
if (attrs == NULL) {
dom_document *doc;
doc = dom_node_get_owner(element);
assert(doc != NULL);
err = _dom_document_create_hashtable(doc, CHAINS_NS_ATTRIBUTES,
- _dom_hash_hash_lwcstring, &attrs);
+ (dom_hash_func) dom_string_hash, &attrs);
if (err != DOM_NO_ERR)
return err;
- added = _dom_hash_add(element->ns_attributes, str, attrs,
+ added = _dom_hash_add(element->ns_attributes, namespace, attrs,
false);
if (added == false)
return DOM_NO_MEM_ERR;
@@ -566,19 +550,12 @@
dom_exception _dom_element_remove_attribute_ns(struct dom_element *element,
dom_string *namespace, dom_string *localname)
{
- lwc_string *str;
- dom_exception err;
struct dom_hash_table *attrs;
if (namespace != NULL)
return _dom_element_remove_attribute(element, localname);
- err = _dom_node_get_intern_string(&element->base, namespace, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- attrs = (struct dom_hash_table *) _dom_hash_get(element->ns_attributes,
- str);
+ attrs = _dom_hash_get(element->ns_attributes, namespace);
/* The element has no such namespace */
if (attrs == NULL) {
return DOM_NO_ERR;
@@ -608,8 +585,6 @@
dom_string *namespace, dom_string *localname,
struct dom_attr **result)
{
- lwc_string *str;
- dom_exception err;
struct dom_hash_table *attrs;
if (namespace == NULL) {
@@ -617,12 +592,7 @@
result);
}
- err = _dom_node_get_intern_string(&element->base, namespace, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- attrs = (struct dom_hash_table *) _dom_hash_get(element->ns_attributes,
- str);
+ attrs = _dom_hash_get(element->ns_attributes, namespace);
/* The element has no such namespace */
if (attrs == NULL) {
*result = NULL;
@@ -657,7 +627,6 @@
dom_exception _dom_element_set_attribute_node_ns(struct dom_element *element,
struct dom_attr *attr, struct dom_attr **result)
{
- lwc_string *str;
dom_exception err;
struct dom_hash_table *attrs;
bool added;
@@ -670,23 +639,18 @@
if (namespace == NULL)
return _dom_element_set_attribute_node(element, attr, result);
- err = _dom_node_get_intern_string(&element->base, namespace, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- attrs = (struct dom_hash_table *) _dom_hash_get(element->ns_attributes,
- str);
+ attrs = _dom_hash_get(element->ns_attributes, namespace);
/* The element has no such namespace */
if (attrs == NULL) {
dom_document *doc;
doc = dom_node_get_owner(element);
assert(doc != NULL);
err = _dom_document_create_hashtable(doc, CHAINS_NS_ATTRIBUTES,
- _dom_hash_hash_lwcstring, &attrs);
+ (dom_hash_func) dom_string_hash, &attrs);
if (err != DOM_NO_ERR)
return err;
- added = _dom_hash_add(element->ns_attributes, str, attrs,
+ added = _dom_hash_add(element->ns_attributes, namespace, attrs,
false);
if (added == false)
return DOM_NO_MEM_ERR;
@@ -728,31 +692,11 @@
/** \todo ensure XML feature is supported */
- /* Get the interned string from the dom_string */
- lwc_string *l = NULL, *n = NULL;
- if (localname != NULL) {
- err = _dom_string_intern(localname, &l);
- if (err != DOM_NO_ERR)
- return err;
- }
- if (namespace != NULL) {
- err = _dom_string_intern(namespace, &n);
- if (err != DOM_NO_ERR) {
- lwc_string_unref(l);
-
- return err;
- }
- }
-
err = _dom_document_get_nodelist(element->base.owner,
DOM_NODELIST_BY_NAMESPACE,
- (struct dom_node_internal *) element, NULL, n, l,
+ (struct dom_node_internal *) element, NULL,
+ namespace, localname,
result);
-
- if (localname != NULL)
- lwc_string_unref(l);
- if (namespace != NULL)
- lwc_string_unref(n);
return err;
}
@@ -790,19 +734,12 @@
dom_string *namespace, dom_string *localname,
bool *result)
{
- lwc_string *str;
- dom_exception err;
struct dom_hash_table *attrs;
if (namespace == NULL)
return _dom_element_has_attribute(element, localname, result);
- err = _dom_node_get_intern_string(&element->base, namespace, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- attrs = (struct dom_hash_table *) _dom_hash_get(element->ns_attributes,
- str);
+ attrs = _dom_hash_get(element->ns_attributes, namespace);
/* The element has no such namespace */
if (attrs == NULL) {
*result = false;
@@ -872,24 +809,18 @@
{
struct dom_hash_table *hs;
dom_exception err;
- lwc_string *ns;
if (namespace == NULL)
return _dom_element_set_id_attribute(element, localname, is_id);
- err = _dom_node_get_intern_string(&element->base, namespace, &ns);
+ hs = _dom_hash_get(element->ns_attributes, namespace);
+ assert(hs != NULL);
+
+ err = _dom_element_set_id_attr(element, hs, localname, is_id);
if (err != DOM_NO_ERR)
return err;
- hs = (struct dom_hash_table *) _dom_hash_get(element->ns_attributes,
- ns);
- assert(hs != NULL);
-
- err = _dom_element_set_id_attr(element, hs, localname, is_id);
- if (err != DOM_NO_ERR)
- return err;
-
- element->id_ns = ns;
+ element->id_ns = dom_string_ref(namespace);
return DOM_NO_ERR;
}
@@ -910,7 +841,6 @@
{
struct dom_hash_table *hs;
dom_exception err;
- lwc_string *ns;
dom_string *namespace;
dom_string *localname;
@@ -921,19 +851,14 @@
if (err != DOM_NO_ERR)
return err;
- err = _dom_node_get_intern_string(&element->base, namespace, &ns);
+ hs = _dom_hash_get(element->ns_attributes, namespace);
+ assert(hs != NULL);
+
+ err = _dom_element_set_id_attr(element, hs, localname, is_id);
if (err != DOM_NO_ERR)
return err;
- hs = (struct dom_hash_table *) _dom_hash_get(element->ns_attributes,
- ns);
- assert(hs != NULL);
-
- err = _dom_element_set_id_attr(element, hs, localname, is_id);
- if (err != DOM_NO_ERR)
- return err;
-
- element->id_ns = ns;
+ element->id_ns = namespace;
return DOM_NO_ERR;
@@ -1011,17 +936,11 @@
dom_string *namespace, bool *result)
{
struct dom_element *ele = (struct dom_element *) node;
- lwc_string *ns;
dom_string *value;
dom_exception err;
- err = _dom_node_get_intern_string(node, namespace, &ns);
- if (err != DOM_NO_ERR) {
- return err;
- }
if (node->prefix == NULL) {
- lwc_string_isequal(node->namespace, ns, result);
- lwc_string_unref(ns);
+ *result = dom_string_isequal(node->namespace, namespace);
return DOM_NO_ERR;
}
@@ -1032,23 +951,16 @@
return err;
if (has == true) {
- return dom_element_get_attribute(ele, xmlns, &value);
- }
-
- lwc_string *ns2;
- err = _dom_node_get_intern_string(node, value, &ns2);
- if (err != DOM_NO_ERR) {
- return err;
- }
-
- if (ns2 != NULL) {
- lwc_string_isequal(ns2, ns, result);
- lwc_string_unref(ns);
- lwc_string_unref(ns2);
+ err = dom_element_get_attribute(ele, xmlns, &value);
+ if (err != DOM_NO_ERR)
+ return err;
+
+ *result = dom_string_isequal(value, namespace);
+
dom_string_unref(value);
+
return DOM_NO_ERR;
}
-
return dom_node_is_default_namespace(node->parent, namespace, result);
}
@@ -1064,25 +976,17 @@
dom_exception _dom_element_lookup_namespace(dom_node_internal *node,
dom_string *prefix, dom_string **result)
{
- lwc_string *pf;
dom_exception err;
- err = _dom_node_get_intern_string(node, prefix, &pf);
- if (err != DOM_NO_ERR)
- return err;
-
- /* To some extent, directly compare the two lwc_string pointer
- * is better */
- if (node->namespace != NULL && node->prefix == pf) {
- assert(node->owner != NULL);
- return _dom_document_create_string_from_lwcstring(node->owner,
- pf, result);
+ if (node->namespace != NULL &&
+ dom_string_isequal(node->prefix, prefix)) {
+ *result = dom_string_ref(node->namespace);
+ return DOM_NO_ERR;
}
bool has;
dom_string *xmlns = _dom_namespace_get_xmlns_prefix();
- err = dom_element_has_attribute_ns(node,
- dom_namespaces[DOM_NAMESPACE_XMLNS], prefix, &has);
+ err = dom_element_has_attribute_ns(node, xmlns, prefix, &has);
if (err != DOM_NO_ERR)
return err;
@@ -1147,26 +1051,7 @@
/* The destroy virtual function of dom_element */
void __dom_element_destroy(struct dom_node_internal *node)
{
- struct dom_document *doc = dom_node_get_owner(node);
-
- _dom_element_destroy(doc, (struct dom_element *) node);
-}
-
-/* The memory allocator of this class */
-dom_exception _dom_element_alloc(dom_document *doc, struct dom_node_internal *n,
- struct dom_node_internal **ret)
-{
- dom_element *e;
- UNUSED(n);
-
- e = _dom_document_alloc(doc, NULL, sizeof(struct dom_element));
- if (e == NULL)
- return DOM_NO_MEM_ERR;
-
- *ret = (dom_node_internal *) e;
- dom_node_set_owner(*ret, doc);
-
- return DOM_NO_ERR;
+ _dom_element_destroy((struct dom_element *) node);
}
/* TODO: How to deal with default attribue:
@@ -1177,45 +1062,42 @@
* are all specified. For the methods like importNode and adoptNode,
* this will make _dom_element_copy can be used in them.
*/
-dom_exception _dom_element_copy(struct dom_node_internal *new,
- struct dom_node_internal *old)
-{
- dom_element *ne = (dom_element *) new;
- dom_element *oe = (dom_element *) old;
- dom_document *od, *nd;
+dom_exception _dom_element_copy(dom_node_internal *old,
+ dom_node_internal **copy)
+{
+ dom_element *olde = (dom_element *) old;
+ dom_element *e;
struct dom_hash_table *ht;
dom_exception err;
-
- err = _dom_node_copy(new, old);
- if (err != DOM_NO_ERR)
- return err;
- od = dom_node_get_owner(old);
- nd = dom_node_get_owner(new);
- assert(od != NULL);
- assert(nd != NULL);
-
- dom_alloc alloc;
- void *pw;
- _dom_document_get_allocator(nd, &alloc, &pw);
-
+ e = malloc(sizeof(dom_element));
+ if (e == NULL)
+ return DOM_NO_MEM_ERR;
+
+ err = dom_node_copy_internal(old, e);
+ if (err != DOM_NO_ERR) {
+ free(e);
+ return err;
+ }
+
/* Copy the hash tables */
- ht = _dom_hash_clone(oe->attributes, alloc, pw, _key, NULL,
- _value, nd);
+ ht = _dom_hash_clone(olde->attributes, _key, NULL, _value, NULL);
if (ht == NULL)
return DOM_NO_MEM_ERR;
- ne->attributes = ht;
-
- ht = _dom_hash_clone(oe->ns_attributes, alloc, pw, _key, NULL,
- _nsattributes, nd);
+ e->attributes = ht;
+
+ ht = _dom_hash_clone(olde->ns_attributes, _key, NULL,
+ _nsattributes, NULL);
if (ht == NULL)
return DOM_NO_MEM_ERR;
- ne->ns_attributes = ht;
-
- ne->id_ns = NULL;
- ne->id_name = NULL;
+ e->ns_attributes = ht;
+
+ e->id_ns = NULL;
+ e->id_name = NULL;
/* TODO: deal with dom_type_info, it get no definition ! */
+
+ *copy = (dom_node_internal *) e;
return DOM_NO_ERR;
}
@@ -1241,14 +1123,10 @@
{
void *a;
dom_exception err = DOM_NO_ERR;
- lwc_string *str;
-
- /* Looking for name */
- err = _dom_node_get_intern_string(&element->base, name, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- a = _dom_hash_get(hs, str);
+
+ UNUSED(element);
+
+ a = _dom_hash_get(hs, name);
/* Fill in value */
if (a == NULL) {
@@ -1274,8 +1152,6 @@
dom_string *value)
{
void *a;
- dom_exception err;
- lwc_string *str;
bool added;
dom_node_internal *e = (dom_node_internal *) element;
@@ -1286,12 +1162,7 @@
if (_dom_node_readonly(e))
return DOM_NO_MODIFICATION_ALLOWED_ERR;
- /* Looking for name */
- err = _dom_node_get_intern_string(&element->base, name, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- a = _dom_hash_get(hs, str);
+ a = _dom_hash_get(hs, name);
if (a != NULL) {
/* Found an existing attribute, so replace its value */
@@ -1327,7 +1198,7 @@
dom_exception err;
struct dom_attr *attr;
- err = _dom_attr_create(e->owner, str, NULL, NULL, true, &attr);
+ err = _dom_attr_create(e->owner, name, NULL, NULL, true, &attr);
if (err != DOM_NO_ERR)
return err;
@@ -1364,7 +1235,7 @@
return err;
}
- added = _dom_hash_add(hs, str, attr, false);
+ added = _dom_hash_add(hs, name, attr, false);
if (added == false) {
/* If we failed at this step, there must be no memory */
dom_node_set_parent(attr, NULL);
@@ -1398,19 +1269,13 @@
{
void *a;
dom_exception err;
- lwc_string *str;
dom_node_internal *e = (dom_node_internal *) element;
/* Ensure element can be written to */
if (_dom_node_readonly(e))
return DOM_NO_MODIFICATION_ALLOWED_ERR;
- /* Looking for name */
- err = _dom_node_get_intern_string(&element->base, name, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- a = (dom_node_internal *) _dom_hash_get(hs, str);
+ a = _dom_hash_get(hs, name);
/* Detach attr node from list */
if (a != NULL) {
@@ -1425,7 +1290,7 @@
return err;
/* Delete the attribute node */
- _dom_hash_del(hs, str);
+ _dom_hash_del(hs, name);
/* Claim a reference for later event dispatch */
dom_node_ref(a);
@@ -1479,15 +1344,10 @@
struct dom_attr **result)
{
void *a;
- dom_exception err;
- lwc_string *str;
-
- /* Looking for name */
- err = _dom_node_get_intern_string(&element->base, name, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- a = _dom_hash_get(hs, str);
+
+ UNUSED(element);
+
+ a = _dom_hash_get(hs, name);
/* Fill in value */
if (a == NULL) {
@@ -1522,7 +1382,6 @@
struct dom_attr **result)
{
dom_exception err;
- lwc_string *str = NULL;
dom_string *name = NULL;
bool added;
dom_node_internal *e = (dom_node_internal *) element;
@@ -1546,12 +1405,7 @@
if (err != DOM_NO_ERR)
return err;
- /* Looking for name */
- err = _dom_node_get_intern_string(&element->base, name, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- a = _dom_hash_get(hs, str);
+ a = _dom_hash_get(hs, name);
*result = NULL;
if (a != NULL) {
@@ -1564,11 +1418,10 @@
DOM_MUTATION_REMOVAL, &success);
if (err != DOM_NO_ERR) {
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
return err;
}
- _dom_hash_del(hs, str);
+ _dom_hash_del(hs, name);
dom_node_ref(a);
*result = (dom_attr *) a;
dom_node_set_parent(a, NULL);
@@ -1584,7 +1437,6 @@
if (err != DOM_NO_ERR && err != DOM_NOT_SUPPORTED_ERR) {
dom_node_unref(a);
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
return err;
}
err = _dom_dispatch_attr_modified_event(doc, e, old, NULL,
@@ -1593,7 +1445,6 @@
dom_string_unref(old);
if (err != DOM_NO_ERR) {
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
return err;
}
@@ -1602,15 +1453,13 @@
(dom_event_target *) e, &success);
if (err != DOM_NO_ERR) {
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
return err;
}
}
- added = _dom_hash_add(hs, str, attr, false);
+ added = _dom_hash_add(hs, name, attr, false);
if (added == false) {
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
/* If we failed at this step, there must be no memory */
return DOM_NO_MEM_ERR;
}
@@ -1633,7 +1482,6 @@
/* Cleanup */
dom_string_unref(new);
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
if (err != DOM_NO_ERR) {
return err;
}
@@ -1674,7 +1522,6 @@
{
void *a;
dom_exception err;
- lwc_string *str;
dom_string *name;
dom_node_internal *e = (dom_node_internal *) element;
@@ -1686,18 +1533,12 @@
if (err != DOM_NO_ERR)
return err;
- /* Looking for name */
- err = _dom_node_get_intern_string(&element->base, name, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- a = _dom_hash_get(hs, str);
+ a = _dom_hash_get(hs, name);
/** \todo defaulted attribute handling */
if (a == NULL || a != (void *) attr) {
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
return DOM_NOT_FOUND_ERR;
}
@@ -1709,17 +1550,15 @@
&success);
if (err != DOM_NO_ERR) {
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
return err;
}
/* Delete the attribute node */
- _dom_hash_del(hs, str);
+ _dom_hash_del(hs, name);
dom_node_ref(a);
- /* Now, cleaup the dom_string and lwc_string */
+ /* Now, cleaup the dom_string */
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
/* Dispatch a DOMAttrModified event */
dom_string *old = NULL;
@@ -1771,15 +1610,10 @@
bool *result)
{
void *a;
- dom_exception err;
- lwc_string *str;
-
- /* Looking for name */
- err = _dom_node_get_intern_string(&element->base, name, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- a = _dom_hash_get(hs, str);
+
+ UNUSED(element);
+
+ a = _dom_hash_get(hs, name);
/* Fill in value */
if (a == NULL) {
@@ -1804,16 +1638,9 @@
struct dom_hash_table *hs, dom_string *name, bool is_id)
{
dom_attr *attr;
- lwc_string *str;
- dom_exception err;
struct dom_hash_table *oh;
- /* Looking for name */
- err = _dom_node_get_intern_string(&element->base, name, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- attr = (dom_attr *) _dom_hash_get(hs, str);
+ attr = _dom_hash_get(hs, name);
if (attr == NULL)
return DOM_NOT_FOUND_ERR;
@@ -1821,15 +1648,15 @@
/* Firstly, clear the previous id attribute if there is one */
if (element->id_ns != NULL) {
assert(element->id_name != NULL);
- oh = (struct dom_hash_table *) _dom_hash_get(
- element->ns_attributes, element->id_ns);
+ oh = _dom_hash_get(element->ns_attributes,
+ element->id_ns);
} else {
oh = element->attributes;
}
assert(oh != NULL);
if (element->id_name != NULL) {
- attr = (dom_attr *) _dom_hash_get(oh, element->id_name);
+ attr = _dom_hash_get(oh, element->id_name);
assert(attr != NULL);
_dom_attr_set_isid(attr, false);
}
@@ -1837,7 +1664,7 @@
_dom_attr_set_isid(attr, is_id);
- element->id_name = str;
+ element->id_name = dom_string_ref(name);
return DOM_NO_ERR;
}
@@ -1849,7 +1676,7 @@
* \param id The ID of this element
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
-dom_exception _dom_element_get_id(struct dom_element *ele, lwc_string **id)
+dom_exception _dom_element_get_id(struct dom_element *ele, dom_string **id)
{
dom_exception err;
dom_string *ret = NULL;
@@ -1862,32 +1689,13 @@
doc = dom_node_get_owner(ele);
assert(doc != NULL);
- dom_string *namespace, *name;
- err = _dom_document_create_string_from_lwcstring(doc,
- ele->id_ns, &namespace);
- if (err != DOM_NO_ERR)
- return err;
-
- err = _dom_document_create_string_from_lwcstring(doc,
- ele->id_name, &name);
+ err = _dom_element_get_attribute_ns(ele, ele->id_ns,
+ ele->id_name, &ret);
if (err != DOM_NO_ERR) {
- dom_string_unref(namespace);
return err;
}
- err = _dom_element_get_attribute_ns(ele, namespace, name, &ret);
- if (err != DOM_NO_ERR) {
- dom_string_unref(namespace);
- dom_string_unref(name);
- return err;
- }
-
- dom_string_unref(namespace);
- dom_string_unref(name);
-
- err = _dom_node_get_intern_string((dom_node_internal *) ele,
- ret, id);
- dom_string_unref(ret);
+ *id = ret;
return err;
}
@@ -1897,37 +1705,24 @@
dom_string *name;
if (ele->id_name != NULL) {
- err = _dom_document_create_string_from_lwcstring(doc,
- ele->id_name, &name);
- if (err != DOM_NO_ERR) {
- return err;
- }
+ name = ele->id_name;
} else {
- lwc_string *id_name = _dom_document_get_id_name(doc);
- if (id_name == NULL) {
+ name = _dom_document_get_id_name(doc);
+
+ if (name == NULL) {
/* No ID attribute at all, just return NULL */
*id = NULL;
return DOM_NO_ERR;
}
- err = _dom_document_create_string_from_lwcstring(doc, id_name,
- &name);
- if (err != DOM_NO_ERR) {
- return err;
- }
}
err = _dom_element_get_attribute(ele, name, &ret);
if (err != DOM_NO_ERR) {
- dom_string_unref(name);
- return err;
- }
-
- dom_string_unref(name);
+ return err;
+ }
if (ret != NULL) {
- err = _dom_node_get_intern_string((dom_node_internal *) ele,
- ret, id);
- dom_string_unref(ret);
+ *id = ret;
} else {
*id = NULL;
}
@@ -2130,40 +1925,26 @@
/*------------------ End of namednodemap functions -----------------------*/
/* The key_func of the hash table, see utils/hashtable.h for details */
-void *_key(void *key, void *key_pw, dom_alloc alloc, void *pw,
- bool clone)
+void *_key(void *key, void *key_pw, bool clone)
{
assert(key != NULL);
UNUSED(key_pw);
- UNUSED(alloc);
- UNUSED(pw);
if (clone == false) {
- lwc_string_unref((lwc_string *) key);
+ dom_string_unref((dom_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_intern_string(data, len, &ret);
- if (err != lwc_error_ok)
- return NULL;
-
- return ret;
+ return dom_string_ref((dom_string *) key);
}
}
/* The value_func of the hash table, see utils/hashtable.h for details */
-void *_value(void *value, void *value_pw, dom_alloc alloc,
- void *pw, bool clone)
+void *_value(void *value, void *value_pw, bool clone)
{
assert(value != NULL);
- assert(value_pw != NULL);
-
- UNUSED(alloc);
- UNUSED(pw);
+
+ UNUSED(value_pw);
if (clone == false) {
dom_node_internal *a = (dom_node_internal *) value;
@@ -2174,8 +1955,7 @@
dom_exception err;
dom_node *node;
- err = dom_document_import_node((dom_document *) value_pw, value,
- true, &node);
+ err = dom_node_clone_node(value, true, &node);
if (err != DOM_NO_ERR)
return NULL;
@@ -2184,28 +1964,21 @@
}
/* The value_func of the hash table, see utils/hashtable.h for details */
-void *_nsattributes(void *value, void *value_pw, dom_alloc alloc,
- void *pw, bool clone)
+void *_nsattributes(void *value, void *value_pw, bool clone)
{
assert(value != NULL);
- assert(value_pw != NULL);
-
- UNUSED(alloc);
- UNUSED(pw);
+
+ UNUSED(value_pw);
if (clone == false) {
_dom_hash_destroy((struct dom_hash_table *) value, _key,
- value_pw, _value, value_pw);
+ NULL, _value, NULL);
return NULL;
} else {
- dom_document *doc = (dom_document *) value_pw;
- 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, NULL, _value, doc);
+
+ ret = _dom_hash_clone((struct dom_hash_table *) value,
+ _key, NULL, _value, NULL);
return ret;
}
Modified: branches/jmb/dom-alloc-purge/src/core/element.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/e...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/element.h (original)
+++ branches/jmb/dom-alloc-purge/src/core/element.h Sun May 22 06:17:26 2011
@@ -48,10 +48,9 @@
struct dom_element *el, dom_string *name,
dom_string *namespace, dom_string *prefix);
-void _dom_element_finalise(struct dom_document *doc, struct dom_element *ele);
-
-void _dom_element_destroy(struct dom_document *doc,
- struct dom_element *element);
+void _dom_element_finalise(struct dom_element *ele);
+
+void _dom_element_destroy(struct dom_element *element);
/* The virtual functions of dom_element */
11 years, 8 months
r12440 jmb - in /branches/jmb/dom-alloc-purge/src/utils: hashtable.c hashtable.h
by netsurf@semichrome.net
Author: jmb
Date: Sun May 22 05:10:33 2011
New Revision: 12440
URL: http://source.netsurf-browser.org?rev=12440&view=rev
Log:
Clean up hashtable
Modified:
branches/jmb/dom-alloc-purge/src/utils/hashtable.c
branches/jmb/dom-alloc-purge/src/utils/hashtable.h
Modified: branches/jmb/dom-alloc-purge/src/utils/hashtable.c
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/utils/...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/utils/hashtable.c (original)
+++ branches/jmb/dom-alloc-purge/src/utils/hashtable.c Sun May 22 05:10:33 2011
@@ -30,10 +30,7 @@
unsigned int nchains; /**< The chains number */
dom_hash_func hash; /**< The hash function */
struct _dom_hash_entry **chain; /**< The chain head */
- unsigned int number; /**< The enries in this table */
-
- dom_alloc alloc; /**< Memory allocation function */
- void *ptr; /**< The private data for the memory allocator */
+ unsigned int number; /**< The entries in this table */
};
@@ -45,16 +42,12 @@
* should be a prime number, and ideally a prime number just
* over a power of two, for best performance and distribution
* \param hash The hash function
- * \param alloc The memory allocator
- * \param ptr The private pointer for the allocator
* \return struct dom_hash_table containing the context of this hash table or
* NULL if there is insufficent memory to create it and its chains.
*/
-struct dom_hash_table *_dom_hash_create(unsigned int chains, dom_hash_func hash,
- dom_alloc alloc, void *ptr)
-{
- struct dom_hash_table *r = alloc(NULL, sizeof(struct dom_hash_table),
- ptr);
+struct dom_hash_table *_dom_hash_create(unsigned int chains, dom_hash_func hash)
+{
+ struct dom_hash_table *r = malloc(sizeof(struct dom_hash_table));
if (r == NULL) {
return NULL;
@@ -62,18 +55,10 @@
r->nchains = chains;
r->hash = hash;
- r->alloc = alloc;
- r->ptr = ptr;
- r->chain = (struct _dom_hash_entry **)alloc(NULL,
- chains*sizeof(struct _dom_hash_entry *), ptr);
r->number = 0;
-
- unsigned int i;
- for (i = 0; i < chains; i++)
- r->chain[i] = NULL;
-
+ r->chain = calloc(chains, sizeof(struct _dom_hash_entry *));
if (r->chain == NULL) {
- alloc(r, 0, ptr);
+ free(r);
return NULL;
}
@@ -84,8 +69,6 @@
* Clone a hash table.
*
* \param ht Hash table to clone.
- * \param alloc The allocator.
- * \param pw The private data for the allocator.
* \param kf The function pointer used to copy the key.
* \param key_pw The private data for the key cloner.
* \param vf The function pointer used to copy the value.
@@ -94,12 +77,12 @@
* \return The cloned hash table.
*/
struct dom_hash_table *_dom_hash_clone(struct dom_hash_table *ht,
- dom_alloc alloc, void *pw, dom_key_func kf, void *key_pw,
+ dom_key_func kf, void *key_pw,
dom_value_func vf, void *value_pw)
{
struct dom_hash_table *ret;
- ret = _dom_hash_create(ht->nchains, ht->hash, alloc, pw);
+ ret = _dom_hash_create(ht->nchains, ht->hash);
if (ret == NULL)
return NULL;
@@ -107,16 +90,16 @@
void *value = NULL, *nvalue = NULL;
unsigned int c1, *c2 = NULL;
while ( (key = _dom_hash_iterate(ht, &c1, &c2)) != NULL) {
- nkey = kf(key, key_pw, alloc, pw, true);
+ nkey = kf(key, key_pw, true);
if (nkey == NULL) {
_dom_hash_destroy(ret, kf, key_pw, vf, value_pw);
return NULL;
}
value = _dom_hash_get(ht, key);
- nvalue = vf(value, value_pw, alloc, pw, true);
+ nvalue = vf(value, value_pw, true);
if (nvalue == NULL) {
- kf(nkey, key_pw, alloc, pw, false);
+ kf(nkey, key_pw, false);
_dom_hash_destroy(ret, kf, key_pw, vf, value_pw);
return NULL;
}
@@ -148,29 +131,25 @@
if (ht == NULL)
return;
- assert(ht->alloc != NULL);
-
for (i = 0; i < ht->nchains; i++) {
if (ht->chain[i] != NULL) {
struct _dom_hash_entry *e = ht->chain[i];
while (e) {
struct _dom_hash_entry *n = e->next;
if (kf != NULL) {
- kf(e->key, key_pw, ht->alloc,
- ht->ptr, false);
+ kf(e->key, key_pw, false);
}
if (vf != NULL) {
- vf(e->value, value_pw, ht->alloc,
- ht->ptr, false);
+ vf(e->value, value_pw, false);
}
- ht->alloc(e, 0, ht->ptr);
+ free(e);
e = n;
}
}
}
- ht->alloc(ht->chain, 0, ht->ptr);
- ht->alloc(ht, 0, ht->ptr);
+ free(ht->chain);
+ free(ht);
}
/**
@@ -204,9 +183,7 @@
}
}
- assert(ht->alloc != NULL);
-
- e = ht->alloc(NULL, sizeof(struct _dom_hash_entry), ht->ptr);
+ e = malloc(sizeof(struct _dom_hash_entry));
if (e == NULL) {
return false;
}
@@ -264,8 +241,6 @@
h = ht->hash(key);
c = h % ht->nchains;
-
- assert(ht->alloc != NULL);
p = ht->chain[c];
for (e = p; e; p = e, e = e->next)
@@ -278,7 +253,7 @@
}
ret = e->value;
- ht->alloc(e, 0, ht->ptr);
+ free(e);
ht->number --;
return ret;
}
@@ -356,13 +331,6 @@
}
/*-----------------------------------------------------------------------*/
-/* The hash function for lwc_string type */
-unsigned int _dom_hash_hash_lwcstring(void *key)
-{
- lwc_string *lstr = (lwc_string *) key;
-
- return lwc_string_hash_value(lstr);
-}
/* A simple test rig. To compile, use:
* gcc -g -o hashtest -I../ -I../../include -DTEST_RIG hashtable.c
Modified: branches/jmb/dom-alloc-purge/src/utils/hashtable.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/utils/...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/utils/hashtable.h (original)
+++ branches/jmb/dom-alloc-purge/src/utils/hashtable.h Sun May 22 05:10:33 2011
@@ -13,6 +13,7 @@
#include <dom/functypes.h>
typedef struct dom_hash_table dom_hash_table;
+
/* The hash function */
typedef unsigned int (*dom_hash_func)(void *key);
/* Function to clone/delete key */
@@ -37,7 +38,4 @@
unsigned int _dom_hash_get_chains(struct dom_hash_table *ht);
dom_hash_func _dom_hash_get_func(struct dom_hash_table *ht);
-/*-----------------------------------------------------------------------*/
-unsigned int _dom_hash_hash_lwcstring(void *key);
-
#endif
11 years, 8 months
r12439 jmb - in /branches/jmb/dom-alloc-purge: bindings/hubbub/ bindings/xml/ include/dom/ include/dom/core/ include/dom/html/ src/ src/core/ src/utils/
by netsurf@semichrome.net
Author: jmb
Date: Fri May 20 02:37:44 2011
New Revision: 12439
URL: http://source.netsurf-browser.org?rev=12439&view=rev
Log:
Begin to restore sanity:
1) dom_string is now a sensible shape
2) lwc_strings should never be stored outside a dom_string wrapper
3) Remove library initialisation and resource manager stuff
4) Objects now have proper copy constructors, and not some bizarre two-step copy approach
5) dom_alloc disappears and we just use malloc/free
Note: the above changes have not yet been applied to all source files, so it won't compile yet
Removed:
branches/jmb/dom-alloc-purge/src/dom.c
branches/jmb/dom-alloc-purge/src/utils/resource_mgr.c
branches/jmb/dom-alloc-purge/src/utils/resource_mgr.h
Modified:
branches/jmb/dom-alloc-purge/bindings/hubbub/parser.c
branches/jmb/dom-alloc-purge/bindings/hubbub/parser.h
branches/jmb/dom-alloc-purge/bindings/xml/xmlparser.c
branches/jmb/dom-alloc-purge/bindings/xml/xmlparser.h
branches/jmb/dom-alloc-purge/include/dom/core/implementation.h
branches/jmb/dom-alloc-purge/include/dom/core/string.h
branches/jmb/dom-alloc-purge/include/dom/dom.h
branches/jmb/dom-alloc-purge/include/dom/functypes.h
branches/jmb/dom-alloc-purge/include/dom/html/html_document.h
branches/jmb/dom-alloc-purge/src/Makefile
branches/jmb/dom-alloc-purge/src/core/attr.c
branches/jmb/dom-alloc-purge/src/core/attr.h
branches/jmb/dom-alloc-purge/src/core/characterdata.c
branches/jmb/dom-alloc-purge/src/core/characterdata.h
branches/jmb/dom-alloc-purge/src/core/document.h
branches/jmb/dom-alloc-purge/src/core/document_type.h
branches/jmb/dom-alloc-purge/src/core/element.c
branches/jmb/dom-alloc-purge/src/core/element.h
branches/jmb/dom-alloc-purge/src/core/node.c
branches/jmb/dom-alloc-purge/src/core/node.h
branches/jmb/dom-alloc-purge/src/core/string.c
branches/jmb/dom-alloc-purge/src/core/string.h
branches/jmb/dom-alloc-purge/src/utils/Makefile
branches/jmb/dom-alloc-purge/src/utils/hashtable.h
branches/jmb/dom-alloc-purge/src/utils/namespace.h
Modified: branches/jmb/dom-alloc-purge/bindings/hubbub/parser.c
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/bindings/h...
==============================================================================
--- branches/jmb/dom-alloc-purge/bindings/hubbub/parser.c (original)
+++ branches/jmb/dom-alloc-purge/bindings/hubbub/parser.c Fri May 20 02:37:44 2011
@@ -37,9 +37,6 @@
const char *encoding; /**< The document's encoding */
bool complete; /**< Indicate stream completion */
-
- dom_alloc alloc; /**< Memory (de)allocation function */
- void *pw; /**< Pointer to client data */
dom_msg msg; /**< Informational messaging function */
void *mctx; /**< Pointer to client data */
@@ -97,27 +94,40 @@
NULL
};
+static void *dom_hubbub_alloc(void *ptr, size_t len, void *pw)
+{
+ UNUSED(pw);
+
+ if (ptr == NULL)
+ return len > 0 ? malloc(len) : NULL;
+
+ if (len == 0) {
+ free(ptr);
+ return NULL;
+ }
+
+ return realloc(ptr, len);
+}
+
/**
* Create a Hubbub parser instance
*
* \param enc Source charset, or NULL
* \param fix_enc Whether fix the encoding
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data
* \param msg Informational message function
* \param mctx Pointer to client-specific private data
* \return Pointer to instance, or NULL on memory exhaustion
*/
dom_hubbub_parser *dom_hubbub_parser_create(
const char *enc, bool fix_enc,
- dom_alloc alloc, void *pw, dom_msg msg, void *mctx)
+ dom_msg msg, void *mctx)
{
dom_hubbub_parser *parser;
hubbub_parser_optparams params;
hubbub_error error;
dom_exception err;
- parser = alloc(NULL, sizeof(dom_hubbub_parser), pw);
+ parser = dom_hubbub_alloc(NULL, sizeof(dom_hubbub_parser), NULL);
if (parser == NULL) {
msg(DOM_MSG_CRITICAL, mctx, "No memory for parsing context");
return NULL;
@@ -130,14 +140,13 @@
: ENCODING_SOURCE_DETECTED;
parser->complete = false;
- parser->alloc = alloc;
- parser->pw = pw;
parser->msg = msg;
parser->mctx = mctx;
- error = hubbub_parser_create(enc, fix_enc, alloc, pw, &parser->parser);
+ error = hubbub_parser_create(enc, fix_enc, dom_hubbub_alloc, NULL,
+ &parser->parser);
if (error != HUBBUB_OK) {
- parser->alloc(parser, 0, parser->pw);
+ dom_hubbub_alloc(parser, 0, NULL);
msg(DOM_MSG_CRITICAL, mctx, "Can't create parser");
return NULL;
}
@@ -147,10 +156,10 @@
* Netsurf */
err = dom_implementation_create_document(DOM_IMPLEMENTATION_HTML,
NULL, NULL, NULL,
- alloc, pw, NULL, &parser->doc);
+ NULL, &parser->doc);
if (err != DOM_NO_ERR) {
hubbub_parser_destroy(parser->parser);
- alloc(parser, 0, pw);
+ dom_hubbub_alloc(parser, 0, NULL);
msg(DOM_MSG_ERROR, mctx, "Can't create DOM document");
return NULL;
}
@@ -185,7 +194,7 @@
parser->doc = NULL;
}
- parser->alloc(parser, 0, parser->pw);
+ dom_hubbub_alloc(parser, 0, NULL);
}
/**
@@ -288,8 +297,7 @@
*result = NULL;
- err = dom_string_create(dom_parser->alloc, dom_parser->pw, data->ptr,
- data->len, &str);
+ err = dom_string_create(data->ptr, data->len, &str);
if (err != DOM_NO_ERR) {
dom_parser->msg(DOM_MSG_CRITICAL, dom_parser->mctx,
"Can't create comment node text");
@@ -355,8 +363,7 @@
}
err = dom_implementation_create_document_type(qname,
- public_id, system_id, dom_parser->alloc,
- dom_parser->pw, &dtype);
+ public_id, system_id, &dtype);
if (err != DOM_NO_ERR) {
dom_parser->msg(DOM_MSG_CRITICAL, dom_parser->mctx,
"Can't create the document type");
@@ -392,8 +399,7 @@
*result = NULL;
- err = dom_string_create(dom_parser->alloc, dom_parser->pw,
- tag->name.ptr, tag->name.len, &name);
+ err = dom_string_create(tag->name.ptr, tag->name.len, &name);
if (err != DOM_NO_ERR) {
dom_parser->msg(DOM_MSG_CRITICAL, dom_parser->mctx,
"Can't create element name");
@@ -448,8 +454,7 @@
*result = NULL;
- err = dom_string_create(dom_parser->alloc, dom_parser->pw, data->ptr,
- data->len, &str);
+ err = dom_string_create(data->ptr, data->len, &str);
if (err != DOM_NO_ERR) {
dom_parser->msg(DOM_MSG_CRITICAL, dom_parser->mctx,
"Can't create text '%.*s'", data->len,
@@ -691,8 +696,7 @@
for (i = 0; i < n_attributes; i++) {
dom_string *name, *value;
- err = dom_string_create(dom_parser->alloc, dom_parser->pw,
- attributes[i].name.ptr,
+ err = dom_string_create(attributes[i].name.ptr,
attributes[i].name.len, &name);
if (err != DOM_NO_ERR) {
dom_parser->msg(DOM_MSG_CRITICAL, dom_parser->mctx,
@@ -700,8 +704,7 @@
goto fail;
}
- err = dom_string_create(dom_parser->alloc, dom_parser->pw,
- attributes[i].value.ptr,
+ err = dom_string_create(attributes[i].value.ptr,
attributes[i].value.len, &value);
if (err != DOM_NO_ERR) {
dom_parser->msg(DOM_MSG_CRITICAL, dom_parser->mctx,
Modified: branches/jmb/dom-alloc-purge/bindings/hubbub/parser.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/bindings/h...
==============================================================================
--- branches/jmb/dom-alloc-purge/bindings/hubbub/parser.h (original)
+++ branches/jmb/dom-alloc-purge/bindings/hubbub/parser.h Fri May 20 02:37:44 2011
@@ -50,7 +50,7 @@
/* Create a Hubbub parser instance */
dom_hubbub_parser *dom_hubbub_parser_create(
const char *enc, bool fix_enc,
- dom_alloc alloc, void *pw, dom_msg msg, void *mctx);
+ dom_msg msg, void *mctx);
/* Destroy a Hubbub parser instance */
void dom_hubbub_parser_destroy(dom_hubbub_parser *parser);
Modified: branches/jmb/dom-alloc-purge/bindings/xml/xmlparser.c
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/bindings/x...
==============================================================================
--- branches/jmb/dom-alloc-purge/bindings/xml/xmlparser.c (original)
+++ branches/jmb/dom-alloc-purge/bindings/xml/xmlparser.c Fri May 20 02:37:44 2011
@@ -95,9 +95,6 @@
bool complete; /**< Indicate stream completion */
dom_string *udkey; /**< Key for DOM node user data */
-
- dom_alloc alloc; /**< Memory (de)allocation function */
- void *pw; /**< Pointer to client data */
dom_msg msg; /**< Informational message function */
void *mctx; /**< Pointer to client data */
@@ -141,13 +138,26 @@
.serror = NULL
};
+static void *dom_xml_alloc(void *ptr, size_t len, void *pw)
+{
+ UNUSED(pw);
+
+ if (ptr == NULL)
+ return len > 0 ? malloc(len) : NULL;
+
+ if (len == 0) {
+ free(ptr);
+ return NULL;
+ }
+
+ return realloc(ptr, len);
+}
+
/**
* Create an XML parser instance
*
* \param enc Source charset, or NULL
* \param int_enc Desired charset of document buffer (UTF-8 or UTF-16)
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data
* \param msg Informational message function
* \param mctx Pointer to client-specific private data
* \return Pointer to instance, or NULL on memory exhaustion
@@ -157,7 +167,7 @@
* 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)
+ dom_msg msg, void *mctx)
{
dom_xml_parser *parser;
dom_exception err;
@@ -166,7 +176,7 @@
UNUSED(enc);
UNUSED(int_enc);
- parser = alloc(NULL, sizeof(dom_xml_parser), pw);
+ parser = dom_xml_alloc(NULL, sizeof(dom_xml_parser), NULL);
if (parser == NULL) {
msg(DOM_MSG_CRITICAL, mctx, "No memory for parser");
return NULL;
@@ -175,7 +185,7 @@
parser->xml_ctx =
xmlCreatePushParserCtxt(&sax_handler, parser, "", 0, NULL);
if (parser->xml_ctx == NULL) {
- alloc(parser, 0, pw);
+ dom_xml_alloc(parser, 0, NULL);
msg(DOM_MSG_CRITICAL, mctx, "Failed to create XML parser");
return NULL;
}
@@ -190,19 +200,15 @@
parser->complete = false;
/* Create key for user data registration */
- err = dom_string_create((dom_alloc) alloc, pw,
- (const uint8_t *) "__xmlnode", SLEN("__xmlnode"),
- &parser->udkey);
+ err = dom_string_create((const uint8_t *) "__xmlnode",
+ SLEN("__xmlnode"), &parser->udkey);
if (err != DOM_NO_ERR) {
xmlFreeParserCtxt(parser->xml_ctx);
- alloc(parser, 0, pw);
+ dom_xml_alloc(parser, 0, NULL);
msg(DOM_MSG_CRITICAL, mctx, "No memory for userdata key");
return NULL;
}
- parser->alloc = alloc;
- parser->pw = pw;
-
parser->msg = msg;
parser->mctx = mctx;
@@ -222,7 +228,7 @@
xmlFreeDoc(parser->xml_ctx->myDoc);
- parser->alloc(parser, 0, parser->pw);
+ dom_xml_alloc(parser, 0, NULL);
}
/**
@@ -319,7 +325,7 @@
/* namespace */ NULL,
/* qname */ NULL,
/* doctype */ NULL,
- parser->alloc, parser->pw, NULL,
+ NULL,
&doc);
if (err != DOM_NO_ERR) {
parser->msg(DOM_MSG_CRITICAL, parser->mctx,
@@ -1181,7 +1187,7 @@
/* Create doctype */
err = dom_implementation_create_document_type(
qname, public_id, system_id,
- parser->alloc, parser->pw, &doctype);
+ &doctype);
if (err != DOM_NO_ERR) {
parser->msg(DOM_MSG_CRITICAL, parser->mctx,
"Failed to create document type");
Modified: branches/jmb/dom-alloc-purge/bindings/xml/xmlparser.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/bindings/x...
==============================================================================
--- branches/jmb/dom-alloc-purge/bindings/xml/xmlparser.h (original)
+++ branches/jmb/dom-alloc-purge/bindings/xml/xmlparser.h Fri May 20 02:37:44 2011
@@ -21,7 +21,7 @@
/* 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);
+ dom_msg msg, void *mctx);
/* Destroy an XML parser instance */
void dom_xml_parser_destroy(dom_xml_parser *parser);
Modified: branches/jmb/dom-alloc-purge/include/dom/core/implementation.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/include/do...
==============================================================================
--- branches/jmb/dom-alloc-purge/include/dom/core/implementation.h (original)
+++ branches/jmb/dom-alloc-purge/include/dom/core/implementation.h Fri May 20 02:37:44 2011
@@ -36,14 +36,12 @@
dom_exception dom_implementation_create_document_type(
const char *qname,
const char *public_id, const char *system_id,
- dom_alloc alloc, void *pw,
struct dom_document_type **doctype);
dom_exception dom_implementation_create_document(
uint32_t impl_type,
const char *namespace, const char *qname,
struct dom_document_type *doctype,
- dom_alloc alloc, void *pw,
dom_events_default_action_fetcher daf,
struct dom_document **doc);
Modified: branches/jmb/dom-alloc-purge/include/dom/core/string.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/include/do...
==============================================================================
--- branches/jmb/dom-alloc-purge/include/dom/core/string.h (original)
+++ branches/jmb/dom-alloc-purge/include/dom/core/string.h Fri May 20 02:37:44 2011
@@ -19,26 +19,22 @@
typedef struct dom_string dom_string;
/* Claim a reference on a DOM string */
-void dom_string_ref(dom_string *str);
+dom_string *dom_string_ref(dom_string *str);
/* Release a reference on a DOM string */
void dom_string_unref(dom_string *str);
/* Create a DOM string from a string of characters */
-dom_exception dom_string_create(dom_alloc alloc, void *pw,
- const uint8_t *ptr, size_t len, dom_string **str);
+dom_exception dom_string_create(const uint8_t *ptr, size_t len,
+ dom_string **str);
-/* Clone a dom_string */
-dom_exception dom_string_clone(dom_alloc alloc, void *pw,
- dom_string *str, dom_string **ret);
-
-/* Get the internal lwc_string */
-dom_exception dom_string_get_intern(dom_string *str,
+/* Obtain an interned representation of a dom string */
+dom_exception dom_string_intern(dom_string *str,
struct lwc_string_s **lwcstr);
/* Case sensitively compare two DOM strings */
-int dom_string_cmp(dom_string *s1, dom_string *s2);
+bool dom_string_isequal(dom_string *s1, dom_string *s2);
/* Case insensitively compare two DOM strings */
-int dom_string_icmp(dom_string *s1, dom_string *s2);
+bool dom_string_caseless_isequal(dom_string *s1, dom_string *s2);
/* Get the index of the first occurrence of a character in a dom string */
uint32_t dom_string_index(dom_string *str, uint32_t chr);
@@ -72,10 +68,6 @@
dom_string *source, uint32_t i1, uint32_t i2,
dom_string **result);
-/* Duplicate a dom string */
-dom_exception dom_string_dup(dom_string *str,
- dom_string **result);
-
/* Calculate a hash value from a dom string */
uint32_t dom_string_hash(dom_string *str);
Modified: branches/jmb/dom-alloc-purge/include/dom/dom.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/include/do...
==============================================================================
--- branches/jmb/dom-alloc-purge/include/dom/dom.h (original)
+++ branches/jmb/dom-alloc-purge/include/dom/dom.h Fri May 20 02:37:44 2011
@@ -54,7 +54,4 @@
extern dom_string *dom_namespaces[DOM_NAMESPACE_COUNT];
-dom_exception dom_initialise(dom_alloc alloc, void *pw);
-dom_exception dom_finalise(void);
-
#endif
Modified: branches/jmb/dom-alloc-purge/include/dom/functypes.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/include/do...
==============================================================================
--- branches/jmb/dom-alloc-purge/include/dom/functypes.h (original)
+++ branches/jmb/dom-alloc-purge/include/dom/functypes.h Fri May 20 02:37:44 2011
@@ -10,11 +10,6 @@
#include <stddef.h>
#include <inttypes.h>
-
-/**
- * Type of allocation function for DOM implementation
- */
-typedef void *(*dom_alloc)(void *ptr, size_t size, void *pw);
/**
* Severity levels for dom_msg function, based on syslog(3)
Modified: branches/jmb/dom-alloc-purge/include/dom/html/html_document.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/include/do...
==============================================================================
--- branches/jmb/dom-alloc-purge/include/dom/html/html_document.h (original)
+++ branches/jmb/dom-alloc-purge/include/dom/html/html_document.h Fri May 20 02:37:44 2011
@@ -41,8 +41,7 @@
typedef struct dom_ui_handler dom_ui_handler;
/* 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);
Modified: branches/jmb/dom-alloc-purge/src/Makefile
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/Makefi...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/Makefile (original)
+++ branches/jmb/dom-alloc-purge/src/Makefile Fri May 20 02:37:44 2011
@@ -1,3 +1,1 @@
-DIR_SOURCES := dom.c
-
include build/makefiles/Makefile.subdir
Modified: branches/jmb/dom-alloc-purge/src/core/attr.c
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/a...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/attr.c (original)
+++ branches/jmb/dom-alloc-purge/src/core/attr.c Fri May 20 02:37:44 2011
@@ -6,9 +6,10 @@
* Copyright 2009 Bo Yang <struggleyb.nku(a)gmail.com>
*/
+#include <assert.h>
#include <stddef.h>
+#include <stdlib.h>
#include <string.h>
-#include <assert.h>
#include <dom/core/attr.h>
#include <dom/core/document.h>
@@ -84,15 +85,15 @@
* The returned attribute will already be referenced.
*/
dom_exception _dom_attr_create(struct dom_document *doc,
- struct lwc_string_s *name, struct lwc_string_s *namespace,
- struct lwc_string_s *prefix, bool specified,
+ dom_string *name, dom_string *namespace,
+ dom_string *prefix, bool specified,
struct dom_attr **result)
{
struct dom_attr *a;
dom_exception err;
/* Allocate the attribute node */
- a = _dom_document_alloc(doc, NULL, sizeof(struct dom_attr));
+ a = malloc(sizeof(struct dom_attr));
if (a == NULL)
return DOM_NO_MEM_ERR;
@@ -104,9 +105,10 @@
err = _dom_attr_initialise(a, doc, name, namespace, prefix, specified,
result);
if (err != DOM_NO_ERR) {
- _dom_document_alloc(doc, a, 0);
- return err;
- }
+ free(a);
+ return err;
+ }
+
return DOM_NO_ERR;
}
@@ -123,8 +125,8 @@
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception _dom_attr_initialise(dom_attr *a,
- struct dom_document *doc, struct lwc_string_s *name,
- struct lwc_string_s *namespace, struct lwc_string_s *prefix,
+ struct dom_document *doc, dom_string *name,
+ dom_string *namespace, dom_string *prefix,
bool specified, struct dom_attr **result)
{
dom_exception err;
@@ -150,10 +152,9 @@
/**
* The destructor of dom_attr
*
- * \param doc The owner document
* \param attr The attribute
*/
-void _dom_attr_finalise(dom_document *doc, dom_attr *attr)
+void _dom_attr_finalise(dom_attr *attr)
{
/* Now, clean up this node and destroy it */
@@ -161,22 +162,21 @@
/** \todo destroy schema type info */
}
- _dom_node_finalise(doc, &attr->base);
+ _dom_node_finalise(&attr->base);
}
/**
* Destroy an attribute node
*
- * \param doc The owning document
* \param attr The attribute to destroy
*
* The contents of ::attr will be destroyed and ::attr will be freed
*/
-void _dom_attr_destroy(struct dom_document *doc, struct dom_attr *attr)
-{
- _dom_attr_finalise(doc, attr);
-
- _dom_document_alloc(doc, attr, 0);
+void _dom_attr_destroy(struct dom_attr *attr)
+{
+ _dom_attr_finalise(attr);
+
+ free(attr);
}
/*-----------------------------------------------------------------------*/
@@ -749,51 +749,43 @@
/* The virtual destroy function of this class */
void __dom_attr_destroy(dom_node_internal *node)
{
- dom_document *doc = node->owner;
-
- assert(doc != NULL);
- _dom_attr_destroy(doc, (dom_attr *) node);
+ _dom_attr_destroy((dom_attr *) node);
}
/* The memory allocator of this class */
-dom_exception _dom_attr_alloc(struct dom_document *doc,
- struct dom_node_internal *n, struct dom_node_internal **ret)
-{
- UNUSED(n);
+dom_exception _dom_attr_copy(dom_node_internal *n, dom_node_internal **copy)
+{
+ dom_attr *old = (dom_attr *) n;
dom_attr *a;
-
- a = _dom_document_alloc(doc, NULL, sizeof(struct dom_attr));
+ dom_exception err;
+
+ a = malloc(sizeof(struct dom_attr));
if (a == NULL)
return DOM_NO_MEM_ERR;
-
- *ret = (dom_node_internal *) a;
- dom_node_set_owner(*ret, doc);
-
- return DOM_NO_ERR;
-}
-
-/* The copy constructor of this class */
-dom_exception _dom_attr_copy(struct dom_node_internal *new,
- struct dom_node_internal *old)
-{
- dom_attr *na = (dom_attr *) new;
- dom_attr *oa = (dom_attr *) old;
-
- na->specified = oa->specified;
+
+ err = dom_node_copy_internal(n, a);
+ if (err != DOM_NO_ERR) {
+ free(a);
+ return err;
+ }
+
+ a->specified = old->specified;
/* TODO: deal with dom_type_info, it get no definition ! */
- na->schema_type_info = NULL;
-
- na->is_id = oa->is_id;
-
- na->type = oa->type;
-
- na->value = oa->value;
+ a->schema_type_info = NULL;
+
+ a->is_id = old->is_id;
+
+ a->type = old->type;
+
+ a->value = old->value;
/* TODO: is this correct? */
- na->read_only = false;
-
- return _dom_node_copy(new, old);
+ a->read_only = false;
+
+ *copy = (dom_node_internal *) a;
+
+ return DOM_NO_ERR;
}
Modified: branches/jmb/dom-alloc-purge/src/core/attr.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/a...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/attr.h (original)
+++ branches/jmb/dom-alloc-purge/src/core/attr.h Fri May 20 02:37:44 2011
@@ -12,18 +12,17 @@
struct dom_document;
struct dom_type_info;
-struct lwc_string_s;
dom_exception _dom_attr_create(struct dom_document *doc,
- struct lwc_string_s *name, struct lwc_string_s *namespace,
- struct lwc_string_s *prefix, bool specified,
+ dom_string *name, dom_string *namespace,
+ dom_string *prefix, bool specified,
struct dom_attr **result);
-void _dom_attr_destroy(struct dom_document *doc, struct dom_attr *attr);
+void _dom_attr_destroy(struct dom_attr *attr);
dom_exception _dom_attr_initialise(struct dom_attr *a,
- struct dom_document *doc, struct lwc_string_s *name,
- struct lwc_string_s *namespace, struct lwc_string_s *prefix,
+ struct dom_document *doc, dom_string *name,
+ dom_string *namespace, dom_string *prefix,
bool specified, struct dom_attr **result);
-void _dom_attr_finalise(struct dom_document *doc, struct dom_attr *attr);
+void _dom_attr_finalise(struct dom_attr *attr);
/* Virtual functions for dom_attr */
dom_exception _dom_attr_get_name(struct dom_attr *attr,
@@ -103,14 +102,11 @@
/* The protected virtual functions */
void __dom_attr_destroy(dom_node_internal *node);
-dom_exception _dom_attr_alloc(struct dom_document *doc,
- struct dom_node_internal *n, struct dom_node_internal **ret);
-dom_exception _dom_attr_copy(struct dom_node_internal *new,
- struct dom_node_internal *old);
+dom_exception _dom_attr_copy(dom_node_internal *old,
+ dom_node_internal **copy);
#define DOM_ATTR_PROTECT_VTABLE \
__dom_attr_destroy, \
- _dom_attr_alloc, \
_dom_attr_copy
Modified: branches/jmb/dom-alloc-purge/src/core/characterdata.c
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/c...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/characterdata.c (original)
+++ branches/jmb/dom-alloc-purge/src/core/characterdata.c Fri May 20 02:37:44 2011
@@ -7,6 +7,7 @@
*/
#include <assert.h>
+#include <stdlib.h>
#include <dom/core/characterdata.h>
#include <dom/core/string.h>
@@ -29,11 +30,9 @@
/* Create a DOM characterdata node and compose the vtable */
-dom_characterdata *_dom_characterdata_create(struct dom_document *doc)
-{
- dom_characterdata *cdata = _dom_document_alloc(doc, NULL,
- sizeof(struct dom_characterdata));
-
+dom_characterdata *_dom_characterdata_create(void)
+{
+ dom_characterdata *cdata = malloc(sizeof(struct dom_characterdata));
if (cdata == NULL)
return NULL;
@@ -57,7 +56,7 @@
*/
dom_exception _dom_characterdata_initialise(struct dom_characterdata *cdata,
struct dom_document *doc, dom_node_type type,
- lwc_string *name, dom_string *value)
+ dom_string *name, dom_string *value)
{
return _dom_node_initialise(&cdata->base, doc, type,
name, value, NULL, NULL);
@@ -66,15 +65,13 @@
/**
* Finalise a character data node
*
- * \param doc The owning document
* \param cdata The node to finalise
*
* The contents of ::cdata will be cleaned up. ::cdata will not be freed.
*/
-void _dom_characterdata_finalise(struct dom_document *doc,
- struct dom_characterdata *cdata)
-{
- _dom_node_finalise(doc, &cdata->base);
+void _dom_characterdata_finalise(struct dom_characterdata *cdata)
+{
+ _dom_node_finalise(&cdata->base);
}
@@ -462,23 +459,11 @@
UNUSED(node);
}
-/* The memory allocator of this class */
-dom_exception _dom_characterdata_alloc(struct dom_document *doc,
- struct dom_node_internal *n, struct dom_node_internal **ret)
-{
- assert("Should never be here" == NULL);
- UNUSED(doc);
- UNUSED(n);
- UNUSED(ret);
-
- return DOM_NO_ERR;
-}
-
/* The copy constructor of this class
* The sub-class of characterdata should call this API */
-dom_exception _dom_characterdata_copy(struct dom_node_internal *new,
- struct dom_node_internal *old)
-{
- return _dom_node_copy(new, old);
-}
-
+dom_exception _dom_characterdata_copy(dom_node_internal *old,
+ dom_node_internal **copy)
+{
+ return _dom_node_copy(old, copy);
+}
+
Modified: branches/jmb/dom-alloc-purge/src/core/characterdata.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/c...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/characterdata.h (original)
+++ branches/jmb/dom-alloc-purge/src/core/characterdata.h Fri May 20 02:37:44 2011
@@ -21,13 +21,12 @@
/* The CharacterData is a intermediate node type, so the following function
* may never be used */
-dom_characterdata *_dom_characterdata_create(struct dom_document *doc);
+dom_characterdata *_dom_characterdata_create(void);
dom_exception _dom_characterdata_initialise(struct dom_characterdata *cdata,
struct dom_document *doc, dom_node_type type,
- struct lwc_string_s *name, dom_string *value);
+ dom_string *name, dom_string *value);
-void _dom_characterdata_finalise(struct dom_document *doc,
- struct dom_characterdata *cdata);
+void _dom_characterdata_finalise(struct dom_characterdata *cdata);
/* The virtual functions for dom_characterdata */
dom_exception _dom_characterdata_get_data(struct dom_characterdata *cdata,
@@ -63,15 +62,12 @@
*
* Only the _copy function can be used by sub-class of this.
*/
-void _dom_characterdata_destroy(struct dom_node_internal *node);
-dom_exception _dom_characterdata_alloc(struct dom_document *doc,
- struct dom_node_internal *n, struct dom_node_internal **ret);
-dom_exception _dom_characterdata_copy(struct dom_node_internal *new,
- struct dom_node_internal *old);
+void _dom_characterdata_destroy(dom_node_internal *node);
+dom_exception _dom_characterdata_copy(dom_node_internal *old,
+ dom_node_internal **copy);
#define DOM_CHARACTERDATA_PROTECT_VTABLE \
_dom_characterdata_destroy, \
- _dom_characterdata_alloc, \
_dom_characterdata_copy
extern struct dom_characterdata_vtable characterdata_vtable;
Modified: branches/jmb/dom-alloc-purge/src/core/document.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/d...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/document.h (original)
+++ branches/jmb/dom-alloc-purge/src/core/document.h Fri May 20 02:37:44 2011
@@ -20,7 +20,6 @@
#include "core/nodelist.h"
#include "utils/hashtable.h"
-#include "utils/resource_mgr.h"
#include "utils/list.h"
#include "events/document_event.h"
@@ -54,9 +53,6 @@
dom_string *uri; /**< The uri of this document */
- dom_alloc alloc; /**< Memory (de)allocation function */
- void *pw; /**< Pointer to client data */
-
struct list_entry pending_nodes;
/**< The deletion pending list */
@@ -67,13 +63,11 @@
};
/* Create a DOM document */
-dom_exception _dom_document_create(dom_alloc alloc, void *pw,
- dom_events_default_action_fetcher daf,
+dom_exception _dom_document_create(dom_events_default_action_fetcher daf,
struct dom_document **doc);
/* Initialise the document */
dom_exception _dom_document_initialise(struct dom_document *doc,
- dom_alloc alloc, void *pw,
dom_events_default_action_fetcher daf);
/* Finalise the document */
@@ -224,14 +218,11 @@
/* Following comes the protected vtable */
void _dom_document_destroy(struct dom_node_internal *node);
-dom_exception __dom_document_alloc(struct dom_document *doc,
- struct dom_node_internal *n, struct dom_node_internal **ret);
dom_exception _dom_document_copy(struct dom_node_internal *new,
struct dom_node_internal *old);
#define DOM_DOCUMENT_PROTECT_VTABLE \
_dom_document_destroy, \
- __dom_document_alloc, \
_dom_document_copy
@@ -241,18 +232,6 @@
* When the refcnt is zero and the pending list is empty, we can destroy this
* document. */
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 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 */
-void _dom_document_get_resource_mgr(
- struct dom_document *doc, struct dom_resource_mgr *rm);
-
-/* Get the internal allocator and its pointer */
-void _dom_document_get_allocator(struct dom_document *doc,
- dom_alloc *al, void **pw);
/* Create a hash_table */
dom_exception _dom_document_create_hashtable(struct dom_document *doc,
Modified: branches/jmb/dom-alloc-purge/src/core/document_type.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/d...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/document_type.h (original)
+++ branches/jmb/dom-alloc-purge/src/core/document_type.h Fri May 20 02:37:44 2011
@@ -9,19 +9,17 @@
#define dom_internal_core_document_type_h_
struct dom_document_type;
-struct dom_resource_mgr;
/* Create a DOM document type */
dom_exception _dom_document_type_create(dom_string *qname,
dom_string *public_id,
dom_string *system_id,
- dom_alloc alloc, void *pw,
struct dom_document_type **doctype);
/* Destroy a document type */
void _dom_document_type_destroy(struct dom_node_internal *doctypenode);
dom_exception _dom_document_type_initialise(struct dom_document_type *doctype,
dom_string *qname, dom_string *public_id,
- dom_string *system_id, dom_alloc alloc, void *pw);
+ dom_string *system_id);
void _dom_document_type_finalise(struct dom_document_type *doctype);
/* The virtual functions of DocumentType */
@@ -53,18 +51,11 @@
/* Following comes the protected vtable */
void _dom_dt_destroy(struct dom_node_internal *node);
-dom_exception _dom_dt_alloc(struct dom_document *doc,
- struct dom_node_internal *n, struct dom_node_internal **ret);
dom_exception _dom_dt_copy(struct dom_node_internal *new,
struct dom_node_internal *old);
#define DOM_DT_PROTECT_VTABLE \
_dom_dt_destroy, \
- _dom_dt_alloc, \
_dom_dt_copy
-/* Helper functions */
-void _dom_document_type_get_resource_mgr(
- struct dom_document_type *dt, struct dom_resource_mgr *rm);
-
#endif
Modified: branches/jmb/dom-alloc-purge/src/core/element.c
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/e...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/element.c (original)
+++ branches/jmb/dom-alloc-purge/src/core/element.c Fri May 20 02:37:44 2011
@@ -6,9 +6,10 @@
* Copyright 2009 Bo Yang <struggleyb.nku(a)gmail.com>
*/
+#include <assert.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-#include <assert.h>
#include <dom/dom.h>
#include <dom/core/attr.h>
@@ -110,12 +111,9 @@
attributes_equal
};
-static void *_key(void *key, void *key_pw, dom_alloc alloc, void *pw,
- bool clone);
-static void *_value(void *value, void *value_pw, dom_alloc alloc,
- void *pw, bool clone);
-static void *_nsattributes(void *value, void *value_pw, dom_alloc alloc,
- void *pw, bool clone);
+static void *_key(void *key, void *key_pw, bool clone);
+static void *_value(void *value, void *value_pw, bool clone);
+static void *_nsattributes(void *value, void *value_pw, bool clone);
/*----------------------------------------------------------------------*/
@@ -139,11 +137,11 @@
* The returned element will already be referenced.
*/
dom_exception _dom_element_create(struct dom_document *doc,
- struct lwc_string_s *name, struct lwc_string_s *namespace,
- struct lwc_string_s *prefix, struct dom_element **result)
+ dom_string *name, dom_string *namespace,
+ dom_string *prefix, struct dom_element **result)
{
/* Allocate the element */
- *result = _dom_document_alloc(doc, NULL, sizeof(struct dom_element));
+ *result = malloc(sizeof(struct dom_element));
if (*result == NULL)
return DOM_NO_MEM_ERR;
@@ -174,8 +172,8 @@
* The returned element will already be referenced.
*/
dom_exception _dom_element_initialise(struct dom_document *doc,
- struct dom_element *el, struct lwc_string_s *name,
- struct lwc_string_s *namespace, struct lwc_string_s *prefix)
+ struct dom_element *el, dom_string *name,
+ dom_string *namespace, dom_string *prefix)
{
dom_exception err;
@@ -184,22 +182,24 @@
err = _dom_document_create_hashtable(doc, CHAINS_ATTRIBUTES,
_dom_hash_hash_lwcstring, &el->attributes);
if (err != DOM_NO_ERR) {
- _dom_document_alloc(doc, el, 0);
+ free(el);
return err;
}
err = _dom_document_create_hashtable(doc, CHAINS_NAMESPACE,
_dom_hash_hash_lwcstring, &el->ns_attributes);
if (err != DOM_NO_ERR) {
- _dom_document_alloc(doc, el, 0);
- _dom_document_alloc(doc, el->attributes, 0);
+ free(el->attributes);
+ free(el);
return err;
}
/* Initialise the base class */
err = _dom_node_initialise(&el->base, doc, DOM_ELEMENT_NODE,
name, NULL, namespace, prefix);
if (err != DOM_NO_ERR) {
- _dom_document_alloc(doc, el, 0);
+ free(el->ns_attributes);
+ free(el->attributes);
+ free(el);
return err;
}
@@ -236,7 +236,7 @@
}
/* Finalise base class */
- _dom_node_finalise(doc, &ele->base);
+ _dom_node_finalise(&ele->base);
}
/**
@@ -253,7 +253,7 @@
_dom_element_finalise(doc, element);
/* Free the element */
- _dom_document_alloc(doc, element, 0);
+ free(element);
}
/*----------------------------------------------------------------------*/
@@ -410,20 +410,14 @@
struct dom_nodelist **result)
{
dom_exception err;
- lwc_string *n;
dom_node_internal *base = (dom_node_internal *) element;
assert(base->owner != NULL);
- err = _dom_string_intern(name, &n);
- if (err != DOM_NO_ERR)
- return err;
-
err = _dom_document_get_nodelist(base->owner, DOM_NODELIST_BY_NAME,
- (struct dom_node_internal *) element, n, NULL,
+ (struct dom_node_internal *) element, name, NULL,
NULL, result);
- lwc_string_unref(n);
return err;
}
Modified: branches/jmb/dom-alloc-purge/src/core/element.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/e...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/element.h (original)
+++ branches/jmb/dom-alloc-purge/src/core/element.h Fri May 20 02:37:44 2011
@@ -33,20 +33,20 @@
struct dom_hash_table *ns_attributes;
/**< Attributes with prefix */
- struct lwc_string_s *id_ns; /**< The id attribute's namespace */
-
- struct lwc_string_s *id_name; /**< The id attribute's name */
+ dom_string *id_ns; /**< The id attribute's namespace */
+
+ dom_string *id_name; /**< The id attribute's name */
struct dom_type_info *schema_type_info; /**< Type information */
};
dom_exception _dom_element_create(struct dom_document *doc,
- struct lwc_string_s *name, struct lwc_string_s *namespace,
- struct lwc_string_s *prefix, struct dom_element **result);
+ dom_string *name, dom_string *namespace,
+ dom_string *prefix, struct dom_element **result);
dom_exception _dom_element_initialise(struct dom_document *doc,
- struct dom_element *el, struct lwc_string_s *name,
- struct lwc_string_s *namespace, struct lwc_string_s *prefix);
+ struct dom_element *el, dom_string *name,
+ dom_string *namespace, dom_string *prefix);
void _dom_element_finalise(struct dom_document *doc, struct dom_element *ele);
@@ -212,22 +212,18 @@
dom_string *name, dom_string *value,
dom_string **parsed);
void __dom_element_destroy(dom_node_internal *node);
-dom_exception _dom_element_alloc(struct dom_document *doc,
- struct dom_node_internal *n, struct dom_node_internal **ret);
-dom_exception _dom_element_copy(struct dom_node_internal *new,
- struct dom_node_internal *old);
+dom_exception _dom_element_copy(dom_node_internal *old,
+ dom_node_internal **copy);
#define DOM_ELEMENT_PROTECT_VTABLE \
_dom_element_parse_attribute
#define DOM_NODE_PROTECT_VTABLE_ELEMENT \
__dom_element_destroy, \
- _dom_element_alloc, \
_dom_element_copy
/* Helper functions*/
-dom_exception _dom_element_get_id(struct dom_element *ele,
- struct lwc_string_s **id);
+dom_exception _dom_element_get_id(struct dom_element *ele, dom_string **id);
extern struct dom_element_vtable _dom_element_vtable;
Modified: branches/jmb/dom-alloc-purge/src/core/node.c
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/n...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/node.c (original)
+++ branches/jmb/dom-alloc-purge/src/core/node.c Fri May 20 02:37:44 2011
@@ -9,6 +9,7 @@
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
+#include <stdlib.h>
#include <dom/core/attr.h>
#include <dom/core/text.h>
@@ -33,7 +34,6 @@
#include "core/pi.h"
#include "core/text.h"
#include "utils/utils.h"
-#include "utils/resource_mgr.h"
#include "events/mutation_event.h"
static bool _dom_node_permitted_child(const dom_node_internal *parent,
@@ -68,11 +68,9 @@
/* The constructor and destructor of this object */
/* Create a DOM node and compose the vtable */
-dom_node_internal * _dom_node_create(struct dom_document *doc)
-{
- dom_node_internal *node = _dom_document_alloc(doc, NULL,
- sizeof(struct dom_node_internal));
-
+dom_node_internal * _dom_node_create(void)
+{
+ dom_node_internal *node = malloc(sizeof(struct dom_node_internal));
if (node == NULL)
return NULL;
@@ -111,7 +109,7 @@
}
/* Finalise this node, this should also destroy all the child nodes. */
- _dom_node_finalise(owner, node);
+ _dom_node_finalise(node);
if (!null_owner_permitted) {
/* Release the reference we claimed on the document. If this
@@ -122,7 +120,7 @@
}
/* Release our memory */
- _dom_document_alloc(owner, node, 0);
+ free(node);
}
/**
@@ -142,59 +140,20 @@
*/
dom_exception _dom_node_initialise(dom_node_internal *node,
struct dom_document *doc, dom_node_type type,
- struct lwc_string_s *name, dom_string *value,
- struct lwc_string_s *namespace, struct lwc_string_s *prefix)
-{
- dom_alloc alloc;
- void *pw;
- dom_exception err;
-
- _dom_document_get_allocator(doc, &alloc, &pw);
-
- err = _dom_node_initialise_generic(node, doc, alloc, pw, type,
- name, value, namespace, prefix);
- if (err != DOM_NO_ERR)
- return err;
-
- return DOM_NO_ERR;
-}
-
-/**
- * Initialise a DOM node
- *
- * \param node The node to initialise
- * \param doc The document object
- * \param alloc The memory allocator
- * \param pw The allocator private pointer data
- * \param type The node type required
- * \param name The node (local) name, or NULL
- * \param value The node value, or NULL
- * \param namespace Namespace URI to use for node, or NULL
- * \param prefix Namespace prefix to use for node, or NULL
- * \return DOM_NO_ERR on success.
- *
- * ::name, ::value, ::namespace, and ::prefix will have their reference
- * counts increased.
- */
-dom_exception _dom_node_initialise_generic(
- struct dom_node_internal *node, struct dom_document *doc,
- dom_alloc alloc, void *pw,
- dom_node_type type, struct lwc_string_s *name,
- dom_string *value, struct lwc_string_s *namespace,
- struct lwc_string_s *prefix)
-{
- UNUSED(alloc);
- UNUSED(pw);
-
+ dom_string *name, dom_string *value,
+ dom_string *namespace, dom_string *prefix)
+{
node->owner = doc;
if (name != NULL)
- lwc_string_ref(name);
- node->name = name;
+ node->name = dom_string_ref(name);
+ else
+ node->name = NULL;
if (value != NULL)
- dom_string_ref(value);
- node->value = value;
+ node->value = dom_string_ref(value);
+ else
+ node->value = NULL;
node->type = type;
@@ -223,15 +182,15 @@
* those nodes (and their sub-trees) in use by client code.
*/
- if (namespace != NULL) {
- lwc_string_ref(namespace);
- }
- node->namespace = namespace;
-
- if (prefix != NULL) {
- lwc_string_ref(prefix);
- }
- node->prefix = prefix;
+ if (namespace != NULL)
+ node->namespace = dom_string_ref(namespace);
+ else
+ node->namespace = NULL;
+
+ if (prefix != NULL)
+ node->prefix = dom_string_ref(prefix);
+ else
+ node->prefix = NULL;
node->user_data = NULL;
@@ -249,50 +208,28 @@
/**
* Finalise a DOM node
*
- * \param doc The owning document (or NULL if it's a standalone DocumentType)
* \param node The node to finalise
*
* The contents of ::node will be cleaned up. ::node will not be freed.
* All children of ::node should have been removed prior to finalisation.
*/
-void _dom_node_finalise(struct dom_document *doc, dom_node_internal *node)
-{
- dom_alloc alloc;
- void *pw;
-
- _dom_document_get_allocator(doc, &alloc, &pw);
-
- _dom_node_finalise_generic(node, alloc, pw);
-}
-
-/**
- * Finalise a DOM node
- *
- * \param node The node to finalise
- * \param alloc The allocator
- * \param pw The allocator private data
- */
-void _dom_node_finalise_generic(dom_node_internal *node, dom_alloc alloc,
- void *pw)
+void _dom_node_finalise(dom_node_internal *node)
{
struct dom_user_data *u, *v;
-
- UNUSED(alloc);
- UNUSED(pw);
/* Destroy user data */
for (u = node->user_data; u != NULL; u = v) {
v = u->next;
dom_string_unref(u->key);
- alloc(u, 0, pw);
+ free(u);
}
node->user_data = NULL;
if (node->prefix != NULL)
- lwc_string_unref(node->prefix);
+ dom_string_unref(node->prefix);
if (node->namespace != NULL)
- lwc_string_unref(node->namespace);
+ dom_string_unref(node->namespace);
/* Destroy all the child nodes of this node */
struct dom_node_internal *p = node->first_child;
@@ -315,7 +252,7 @@
dom_string_unref(node->value);
if (node->name != NULL)
- lwc_string_unref(node->name);
+ dom_string_unref(node->name);
/* If the node has no owner document, we need not to finalise its
* dom_event_target_internal structure.
@@ -393,7 +330,6 @@
dom_string *node_name, *temp;
dom_document *doc;
dom_exception err;
- struct dom_resource_mgr rm;
doc = node->owner;
/* Document Node and DocumentType Node can have no owner */
@@ -403,72 +339,39 @@
assert(node->name != NULL);
- if (doc != NULL) {
- _dom_document_get_resource_mgr(doc, &rm);
- } else if (node->type == DOM_DOCUMENT_TYPE_NODE) {
- _dom_document_type_get_resource_mgr(
- (dom_document_type *) node, &rm);
- }
-
/* If this node was created using a namespace-aware method and
* has a defined prefix, then nodeName is a QName comprised
* of prefix:name. */
- if(node->prefix != NULL) {
+ if (node->prefix != NULL) {
dom_string *colon;
- err = _dom_resource_mgr_create_string(&rm,
- (const uint8_t *) ":", SLEN(":"), &colon);
+ err = dom_string_create((const uint8_t *) ":", SLEN(":"),
+ &colon);
if (err != DOM_NO_ERR) {
return err;
}
- /* Make a temp prefix dom_string */
- err = _dom_resource_mgr_create_string_from_lwcstring(&rm,
- node->prefix, &temp);
+ /* Prefix + : */
+ err = dom_string_concat(node->prefix, colon, &temp);
if (err != DOM_NO_ERR) {
dom_string_unref(colon);
return err;
}
- /* Prefix + : */
- err = dom_string_concat(temp, colon, &node_name);
+ /* Finished with colon */
+ dom_string_unref(colon);
+
+ /* Prefix + : + Localname */
+ err = dom_string_concat(temp, node->name, &node_name);
if (err != DOM_NO_ERR) {
dom_string_unref(temp);
- dom_string_unref(colon);
return err;
}
- /*Finished with temp*/
- dom_string_unref(temp);
-
- /* Finished with colon */
- dom_string_unref(colon);
-
- /* Make a temp name dom_string */
- err = _dom_resource_mgr_create_string_from_lwcstring(&rm,
- node->name, &temp);
- if (err != DOM_NO_ERR) {
- return err;
- }
- /* Prefix + : + Localname */
- err = dom_string_concat(node_name, temp, &colon);
- if (err != DOM_NO_ERR) {
- dom_string_unref(temp);
- dom_string_unref(node_name);
- return err;
- }
/* Finished with temp */
dom_string_unref(temp);
- /* Finished with intermediate node name */
- dom_string_unref(node_name);
-
- node_name = colon;
} else {
- err = _dom_resource_mgr_create_string_from_lwcstring(&rm,
- node->name, &node_name);
- if (err != DOM_NO_ERR) {
- return err;
- }
+ node_name = dom_string_ref(node->name);
}
*result = node_name;
@@ -1190,13 +1093,8 @@
doc = node->owner;
assert(doc != NULL);
- err = dom_node_alloc(doc, node, &n);
- if (err != DOM_NO_ERR)
- return err;
-
- err = dom_node_copy(n, node);
+ err = dom_node_copy(node, &n);
if (err != DOM_NO_ERR) {
- _dom_document_alloc(doc, n, 0);
return err;
}
@@ -1325,10 +1223,11 @@
/* If there is a namespace, increase its reference count */
if (node->namespace != NULL)
- lwc_string_ref(node->namespace);
-
- return _dom_document_create_string_from_lwcstring(node->owner,
- node->namespace, result);
+ *result = dom_string_ref(node->namespace);
+ else
+ *result = NULL;
+
+ return DOM_NO_ERR;
}
/**
@@ -1349,11 +1248,11 @@
/* If there is a prefix, increase its reference count */
if (node->prefix != NULL)
- lwc_string_ref(node->prefix);
-
- return _dom_document_create_string_from_lwcstring(node->owner,
- node->prefix,
- result);
+ *result = dom_string_ref(node->prefix);
+ else
+ *result = NULL;
+
+ return DOM_NO_ERR;
}
/**
@@ -1382,9 +1281,6 @@
dom_exception _dom_node_set_prefix(dom_node_internal *node,
dom_string *prefix)
{
- dom_exception err;
- lwc_string *str;
-
/* Only Element and Attribute nodes created using
* namespace-aware methods may have a prefix */
if ((node->type != DOM_ELEMENT_NODE &&
@@ -1402,7 +1298,7 @@
/* No longer want existing prefix */
if (node->prefix != NULL) {
- lwc_string_unref(node->prefix);
+ dom_string_unref(node->prefix);
}
/* Set the prefix */
@@ -1411,11 +1307,7 @@
if (dom_string_length(prefix) == 0) {
node->prefix = NULL;
} else {
- err = _dom_node_get_intern_string(node, prefix, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- node->prefix = str;
+ node->prefix = dom_string_ref(prefix);
}
} else {
node->prefix = NULL;
@@ -1448,12 +1340,12 @@
}
/* The node may have a local name, reference it if so */
- if (node->name != NULL) {
- lwc_string_ref(node->name);
- }
-
- return _dom_document_create_string_from_lwcstring(node->owner,
- node->name, result);
+ if (node->name != NULL)
+ *result = dom_string_ref(node->name);
+ else
+ *result = NULL;
+
+ return DOM_NO_ERR;
}
/**
@@ -1725,7 +1617,7 @@
if (err != DOM_NO_ERR)
return err;
- if (dom_string_cmp(s1, s2) != 0) {
+ if (dom_string_isequal(s1, s2) == false) {
*result = false;
return DOM_NO_ERR;
}
@@ -1737,7 +1629,7 @@
return DOM_NO_ERR;
}
- if (dom_string_cmp(node->value, other->value) != 0) {
+ if (dom_string_isequal(node->value, other->value) == false) {
*result = false;
return DOM_NO_ERR;
}
@@ -1824,7 +1716,7 @@
/* Search for user data */
for (ud = node->user_data; ud != NULL; ud = ud->next) {
- if (dom_string_cmp(ud->key, key) == 0)
+ if (dom_string_isequal(ud->key, key))
break;
};
@@ -1841,15 +1733,14 @@
*result = ud->data;
- _dom_document_alloc(node->owner, ud, 0);
+ free(ud);
return DOM_NO_ERR;
}
/* Otherwise, create a new user data object if one wasn't found */
if (ud == NULL) {
- ud = _dom_document_alloc(node->owner, NULL,
- sizeof(struct dom_user_data));
+ ud = malloc(sizeof(struct dom_user_data));
if (ud == NULL)
return DOM_NO_MEM_ERR;
@@ -1892,7 +1783,7 @@
/* Search for user data */
for (ud = node->user_data; ud != NULL; ud = ud->next) {
- if (dom_string_cmp(ud->key, key) == 0)
+ if (dom_string_isequal(ud->key, key))
break;
};
@@ -1909,27 +1800,34 @@
/* The protected virtual functions */
-/* We should never call this pure-virtual function directly */
-dom_exception _dom_node_alloc(struct dom_document *doc,
- struct dom_node_internal *n, struct dom_node_internal **ret)
-{
- UNUSED(doc);
- UNUSED(n);
- UNUSED(ret);
-
- return DOM_NOT_SUPPORTED_ERR;
-}
-
-
/* Copy the internal attributes of a Node from old to new */
-dom_exception _dom_node_copy(dom_node_internal *new, dom_node_internal *old)
-{
+dom_exception _dom_node_copy(dom_node_internal *old, dom_node_internal **copy)
+{
+ dom_node_internal *new_node;
dom_exception err;
+ new_node = malloc(sizeof(dom_node_internal));
+ if (new_node == NULL)
+ return DOM_NO_MEM_ERR;
+
+ err = _dom_node_copy_internal(old, new_node);
+ if (err != DOM_NO_ERR) {
+ free(new_node);
+ return err;
+ }
+
+ *copy = new_node;
+
+ return DOM_NO_ERR;
+}
+
+dom_exception _dom_node_copy_internal(dom_node_internal *old,
+ dom_node_internal *new)
+{
new->base.vtable = old->base.vtable;
new->vtable = old->vtable;
- new->name = lwc_string_ref(old->name);
+ new->name = dom_string_ref(old->name);
/* Value - see below */
@@ -1945,12 +1843,12 @@
new->owner = old->owner;
if (old->namespace != NULL)
- new->namespace = lwc_string_ref(old->namespace);
+ new->namespace = dom_string_ref(old->namespace);
else
new->namespace = NULL;
if (old->prefix != NULL)
- new->prefix = lwc_string_ref(old->prefix);
+ new->prefix = dom_string_ref(old->prefix);
else
new->prefix = NULL;
@@ -1961,16 +1859,9 @@
/* Value */
if (old->value != NULL) {
- dom_alloc al;
- void *pw;
-
- _dom_document_get_allocator(new->owner, &al, &pw);
- dom_string *value;
- err = dom_string_clone(al, pw, old->value, &value);
- if (err != DOM_NO_ERR)
- return err;
-
- new->value = value;
+ dom_string_ref(old->value);
+
+ new->value = old->value;
} else {
new->value = NULL;
}
@@ -2257,36 +2148,6 @@
}
/**
- * Migrate one dom_string from one document to another, this function
- * may be used when we import/adopt a Node between documents.
- *
- * \param old The source document
- * \param new The new document
- * \param string The dom_string to migrate
- * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
- */
-dom_exception _redocument_domstring(dom_document *old, dom_document* new,
- dom_string **string)
-{
- dom_exception err;
- dom_string *str;
-
- UNUSED(old);
- err = _dom_document_create_string(new, NULL, 0, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- err = dom_string_dup(*string, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- dom_string_unref(*string);
- *string = str;
-
- return DOM_NO_ERR;
-}
-
-/**
* Merge two adjacent text nodes into one text node.
*
* \param p The first text node
@@ -2313,78 +2174,6 @@
dom_string_unref(str);
return DOM_NO_ERR;
-}
-
-/**
- * Intern a dom_string
- *
- * \param node The node
- * \param str The dom_string to be interned
- * \param intern The returned interned string
- * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
- */
-dom_exception _dom_node_get_intern_string(dom_node_internal *node,
- dom_string *str, lwc_string **intern)
-{
- dom_exception err;
- lwc_string *ret;
-
- UNUSED(node);
-
- assert(str != NULL);
-
- err = dom_string_get_intern(str, &ret);
- if (err != DOM_NO_ERR)
- return err;
-
- err = _dom_string_intern(str, &ret);
- if (err != DOM_NO_ERR)
- return err;
-
- *intern = ret;
-
- return DOM_NO_ERR;
-}
-
-/**
- * Unref a lwc_string used in this node
- *
- * \param node The node
- * \param intern The lwc_string to unref
- */
-void _dom_node_unref_intern_string(dom_node_internal *node,
- struct lwc_string_s *intern)
-{
- struct dom_resource_mgr rm;
- struct dom_document *doc = node->owner;
-
- if (doc != NULL) {
- _dom_document_get_resource_mgr(doc, &rm);
- } else if (node->type == DOM_DOCUMENT_TYPE_NODE) {
- _dom_document_type_get_resource_mgr(
- (dom_document_type *) node, &rm);
- }
-
- lwc_string_unref(intern);
-}
-
-/**
- * Create a lwc_string using the node's owner's lwc_context
- *
- * \param node The node object
- * \param data The string data
- * \param len The length of the string data
- * \param str The returned lwc_string
- * \return DOM_NO_ERR on success, appropirate dom_exception on failure.
- */
-dom_exception _dom_node_create_lwcstring(dom_node_internal *node,
- const uint8_t *data, size_t len, struct lwc_string_s **str)
-{
- dom_document *doc = dom_node_get_owner(node);
-
- assert(doc != NULL);
-
- return _dom_document_create_lwcstring(doc, data, len, str);
}
/**
Modified: branches/jmb/dom-alloc-purge/src/core/node.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/n...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/node.h (original)
+++ branches/jmb/dom-alloc-purge/src/core/node.h Fri May 20 02:37:44 2011
@@ -41,10 +41,7 @@
void (*destroy)(dom_node_internal *n);
/**< The destroy virtual function, it
* should be private to client */
- dom_exception (*alloc)(struct dom_document *doc,
- dom_node_internal *n, dom_node_internal **ret);
- /**< Allocate the memory of the new Node */
- dom_exception (*copy)(dom_node_internal *new, dom_node_internal *old);
+ dom_exception (*copy)(dom_node_internal *old, dom_node_internal **copy);
/**< Copy the old to new as well as
* all its attributes, but not its children */
} dom_node_protect_vtable;
@@ -58,10 +55,10 @@
struct dom_node base; /**< The vtable base */
void *vtable; /**< The protected vtable */
- struct lwc_string_s *name; /**< Node name (this is the local part
+ dom_string *name; /**< Node name (this is the local part
* of a QName in the cases where a
* namespace exists) */
- dom_string *value; /**< Node value */
+ dom_string *value; /**< Node value */
dom_node_type type; /**< Node type */
dom_node_internal *parent; /**< Parent node */
dom_node_internal *first_child; /**< First child node */
@@ -71,8 +68,8 @@
struct dom_document *owner; /**< Owning document */
- struct lwc_string_s *namespace; /**< Namespace URI */
- struct lwc_string_s *prefix; /**< Namespace prefix */
+ dom_string *namespace; /**< Namespace URI */
+ dom_string *prefix; /**< Namespace prefix */
struct dom_user_data *user_data; /**< User data list */
@@ -83,23 +80,14 @@
dom_event_target_internal eti; /**< The EventTarget interface */
};
-dom_node_internal * _dom_node_create(struct dom_document *doc);
+dom_node_internal * _dom_node_create(void);
dom_exception _dom_node_initialise(struct dom_node_internal *node,
struct dom_document *doc, dom_node_type type,
- struct lwc_string_s *name, dom_string *value,
- struct lwc_string_s *namespace, struct lwc_string_s *prefix);
-
-dom_exception _dom_node_initialise_generic(
- struct dom_node_internal *node, struct dom_document *doc,
- dom_alloc alloc, void *pw,
- dom_node_type type, struct lwc_string_s *name,
- 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);
+ dom_string *name, dom_string *value,
+ dom_string *namespace, dom_string *prefix);
+
+void _dom_node_finalise(dom_node_internal *node);
bool _dom_node_readonly(const dom_node_internal *node);
@@ -225,14 +213,11 @@
/* Following comes the protected vtable */
void _dom_node_destroy(struct dom_node_internal *node);
-dom_exception _dom_node_alloc(struct dom_document *doc,
- struct dom_node_internal *n, struct dom_node_internal **ret);
-dom_exception _dom_node_copy(struct dom_node_internal *new,
- struct dom_node_internal *old);
+dom_exception _dom_node_copy(struct dom_node_internal *old,
+ struct dom_node_internal **copy);
#define DOM_NODE_PROTECT_VTABLE \
_dom_node_destroy, \
- _dom_node_alloc, \
_dom_node_copy
@@ -243,26 +228,21 @@
}
#define dom_node_destroy(n) dom_node_destroy((dom_node_internal *) (n))
-/* Allocate the Node */
-static inline dom_exception dom_node_alloc(struct dom_document *doc,
- struct dom_node_internal *n, struct dom_node_internal **ret)
+/* Copy the Node old to new */
+static inline dom_exception dom_node_copy(struct dom_node_internal *old,
+ struct dom_node_internal **copy)
{
- return ((dom_node_protect_vtable *) n->vtable)->alloc(doc, n, ret);
+ return ((dom_node_protect_vtable *) old->vtable)->copy(old, copy);
}
-#define dom_node_alloc(d,n,r) dom_node_alloc((struct dom_document *) (d), \
- (dom_node_internal *) (n), (dom_node_internal **) (r))
-
-
-/* Copy the Node old to new */
-static inline dom_exception dom_node_copy(struct dom_node_internal *new,
- struct dom_node_internal *old)
-{
- return ((dom_node_protect_vtable *) old->vtable)->copy(new, old);
-}
-#define dom_node_copy(n,o) dom_node_copy((dom_node_internal *) (n), \
- (dom_node_internal *) (o))
+#define dom_node_copy(o,c) dom_node_copy((dom_node_internal *) (o), \
+ (dom_node_internal **) (c))
/* Following are some helper functions */
+dom_exception _dom_node_copy_internal(dom_node_internal *old,
+ dom_node_internal *new);
+#define dom_node_copy_internal(o, n) _dom_node_copy_internal( \
+ (dom_node_internal *) (o), (dom_node_internal *) (n))
+
#define dom_node_get_owner(n) ((dom_node_internal *) (n))->owner
#define dom_node_set_owner(n, d) ((dom_node_internal *) (n))->owner = \
@@ -275,19 +255,8 @@
#define dom_node_get_refcount(n) ((dom_node_internal *) (n))->refcnt
-dom_exception _redocument_domstring(struct dom_document *old,
- struct dom_document* new, dom_string **string);
dom_exception _dom_merge_adjacent_text(dom_node_internal *p,
dom_node_internal *n);
-/* Used to extract the lwc_string from dom_string.
- * If there is no lwc_string inside the param, create one use the node->owner
- * as document */
-dom_exception _dom_node_get_intern_string(dom_node_internal *node,
- dom_string *str, struct lwc_string_s **intern);
-void _dom_node_unref_intern_string(dom_node_internal *node,
- struct lwc_string_s *inter);
-dom_exception _dom_node_create_lwcstring(dom_node_internal *node,
- const uint8_t *data, size_t len, struct lwc_string_s **str);
/* Try to destroy the node, if its refcnt is not zero, then append it to the
* owner document's pending list */
Modified: branches/jmb/dom-alloc-purge/src/core/string.c
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/s...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/string.c (original)
+++ branches/jmb/dom-alloc-purge/src/core/string.c Fri May 20 02:37:44 2011
@@ -9,6 +9,7 @@
#include <assert.h>
#include <ctype.h>
#include <inttypes.h>
+#include <stdlib.h>
#include <string.h>
#include <parserutils/charset/utf8.h>
@@ -18,43 +19,42 @@
#include "utils/utils.h"
/**
+ * Type of a DOM string
+ */
+enum dom_string_type {
+ DOM_STRING_CDATA = 0,
+ DOM_STRING_INTERNED = 1
+};
+
+/**
* A DOM string
*
* Strings are reference counted so destruction is performed correctly.
*/
struct dom_string {
- uint8_t *ptr; /**< Pointer to string data */
-
- size_t len; /**< Byte length of string */
-
- lwc_string *intern; /**< The lwc_string of this string */
-
- dom_alloc alloc; /**< Memory (de)allocation function */
- void *pw; /**< Client-specific data */
-
- uint32_t refcnt; /**< Reference count */
+ union {
+ lwc_string *intern; /**< Interned string */
+ struct {
+ uint8_t *ptr; /**< Pointer to string data */
+ size_t len; /**< Byte length of string */
+ } cdata;
+ } data;
+
+ unsigned int refcnt : 31, /**< Reference count */
+ type : 1; /**< String type */
};
-static dom_string empty_string = {
- .ptr = NULL,
- .len = 0,
- .intern = NULL,
- .alloc = NULL,
- .pw = NULL,
- .refcnt = 1
-};
-
-
-
/**
* Claim a reference on a DOM string
*
* \param str The string to claim a reference on
- */
-void dom_string_ref(dom_string *str)
-{
- if (str != NULL)
- str->refcnt++;
+ * \return \a str
+ */
+dom_string *dom_string_ref(dom_string *str)
+{
+ str->refcnt++;
+
+ return str;
}
/**
@@ -67,25 +67,25 @@
*/
void dom_string_unref(dom_string *str)
{
- if (str == NULL)
- return;
-
if (--str->refcnt == 0) {
- if (str->intern != NULL) {
- lwc_string_unref(str->intern);
- str->alloc(str, 0, str->pw);
- } else if (str->alloc != NULL) {
- str->alloc(str->ptr, 0, str->pw);
- str->alloc(str, 0, str->pw);
- }
+ switch (str->type) {
+ case DOM_STRING_INTERNED:
+ if (str->data.intern != NULL) {
+ lwc_string_unref(str->data.intern);
+ }
+ break;
+ case DOM_STRING_CDATA:
+ free(str->data.cdata.ptr);
+ break;
+ }
+
+ free(str);
}
}
/**
* Create a DOM string from a string of characters
*
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data
* \param ptr Pointer to string of characters
* \param len Length, in bytes, of string of characters
* \param str Pointer to location to receive result
@@ -97,74 +97,37 @@
* The string of characters passed in will be copied for use by the
* returned DOM string.
*/
-dom_exception dom_string_create(dom_alloc alloc, void *pw,
- const uint8_t *ptr, size_t len, dom_string **str)
+dom_exception dom_string_create(const uint8_t *ptr, size_t len,
+ dom_string **str)
{
dom_string *ret;
if (ptr == NULL || len == 0) {
- dom_string_ref(&empty_string);
-
- *str = &empty_string;
-
- return DOM_NO_ERR;
- }
-
- ret = alloc(NULL, sizeof(dom_string), pw);
+ ptr = (const uint8_t *) "";
+ len = 0;
+ }
+
+ ret = malloc(sizeof(dom_string));
if (ret == NULL)
return DOM_NO_MEM_ERR;
- ret->ptr = alloc(NULL, len, pw);
- if (ret->ptr == NULL) {
- alloc(ret, 0, pw);
- return DOM_NO_MEM_ERR;
- }
-
- memcpy(ret->ptr, ptr, len);
-
- ret->len = len;
-
- ret->alloc = alloc;
- ret->pw = pw;
-
- ret->intern = NULL;
+ ret->data.cdata.ptr = malloc(len);
+ if (ret->data.cdata.ptr == NULL) {
+ free(ret);
+ return DOM_NO_MEM_ERR;
+ }
+
+ memcpy(ret->data.cdata.ptr, ptr, len);
+
+ ret->data.cdata.len = len;
ret->refcnt = 1;
+ ret->type = DOM_STRING_CDATA;
+
*str = ret;
return DOM_NO_ERR;
-}
-
-/**
- * Clone a dom_string if necessary. This method is used to create a new string
- * with a new allocator, but if the allocator is the same with the paramter
- * str, just ref the string.
- *
- * \param alloc The new allocator for this string
- * \param pw The new pw for this string
- * \param str The source dom_string
- * \param ret The cloned dom_string
- * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
- *
- * @note: When both the alloc and pw are the same as the str's, we need no
- * real clone, just ref the source string is ok.
- */
-dom_exception dom_string_clone(dom_alloc alloc, void *pw,
- dom_string *str, dom_string **ret)
-{
- if (alloc == str->alloc && pw == str->pw) {
- *ret = str;
- dom_string_ref(str);
- return DOM_NO_ERR;
- }
-
- if (str->intern != NULL) {
- return _dom_string_create_from_lwcstring(alloc, pw,
- str->intern, ret);
- } else {
- return dom_string_create(alloc, pw, str->ptr, str->len, ret);
- }
}
/**
@@ -174,8 +137,8 @@
* \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_string *str, dom_string **ret)
+dom_exception _dom_string_create_from_lwcstring(lwc_string *str,
+ dom_string **ret)
{
dom_string *r;
@@ -184,27 +147,15 @@
return DOM_NO_ERR;
}
- r = alloc(NULL, sizeof(dom_string), pw);
+ r = malloc(sizeof(dom_string));
if (r == NULL)
return DOM_NO_MEM_ERR;
- if (str == NULL) {
- *ret = &empty_string;
- dom_string_ref(*ret);
- return DOM_NO_ERR;
- }
-
- r->intern = str;
- r->ptr = (uint8_t *)lwc_string_data(str);
- r->len = lwc_string_length(str);
-
- r->alloc = alloc;
- r->pw = pw;
+ r->data.intern = lwc_string_ref(str);
r->refcnt = 1;
- /* Ref the lwc_string */
- lwc_string_ref(str);
+ r->type = DOM_STRING_INTERNED;
*ret = r;
return DOM_NO_ERR;
@@ -218,49 +169,28 @@
* \param lwcstr The result lwc_string
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
-dom_exception _dom_string_intern(dom_string *str,
+dom_exception dom_string_intern(dom_string *str,
struct lwc_string_s **lwcstr)
{
- lwc_string *ret;
- lwc_error lerr;
-
/* If this string is already interned, do nothing */
- if (str->intern != NULL) {
- *lwcstr = lwc_string_ref(str->intern);
- return DOM_NO_ERR;
- }
-
- lerr = lwc_intern_string((const char *)str->ptr, str->len, &ret);
- if (lerr != lwc_error_ok) {
- return _dom_exception_from_lwc_error(lerr);
- }
-
- str->intern = ret;
-
- if (str->ptr != NULL) {
- str->alloc(str->ptr, 0, str->pw);
- }
-
- str->ptr = (uint8_t *) lwc_string_data(ret);
-
- *lwcstr = lwc_string_ref(ret);
- return DOM_NO_ERR;
-}
-
-/**
- * Get the internal lwc_string
- *
- * \param str The dom_string object
- * \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(dom_string *str,
- struct lwc_string_s **lwcstr)
-{
- *lwcstr = str->intern;
-
- if (*lwcstr != NULL)
- lwc_string_ref(*lwcstr);
+ if (str->type != DOM_STRING_INTERNED) {
+ lwc_string *ret;
+ lwc_error lerr;
+
+ lerr = lwc_intern_string((const char *) str->data.cdata.ptr,
+ str->data.cdata.len, &ret);
+ if (lerr != lwc_error_ok) {
+ return _dom_exception_from_lwc_error(lerr);
+ }
+
+ free(str->data.cdata.ptr);
+
+ str->data.intern = ret;
+
+ str->type = DOM_STRING_INTERNED;
+ }
+
+ *lwcstr = lwc_string_ref(str->data.intern);
return DOM_NO_ERR;
}
@@ -270,33 +200,34 @@
*
* \param s1 The first string to compare
* \param s2 The second string to compare
- * \return 0 if strings match, non-0 otherwise
- *
- * NULL and "" will match.
- */
-int dom_string_cmp(dom_string *s1, dom_string *s2)
-{
- bool ret;
-
- if (s1 == NULL)
- s1 = &empty_string;
-
- if (s2 == NULL)
- s2 = &empty_string;
-
- if (s1->intern != NULL && s2->intern != NULL) {
- lwc_string_isequal(s1->intern, s2->intern, &ret);
- if (ret == true) {
- return 0;
- } else {
- return -1;
- }
- }
-
- if (s1->len != s2->len)
- return 1;
-
- return memcmp(s1->ptr, s2->ptr, s1->len);
+ * \return true if strings match, false otherwise
+ */
+bool dom_string_isequal(dom_string *s1, dom_string *s2)
+{
+ if (s1->type == DOM_STRING_INTERNED &&
+ s2->type == DOM_STRING_INTERNED) {
+ bool match;
+
+ lwc_string_isequal(s1->data.intern, s2->data.intern, &match);
+
+ return match;
+ }
+
+ if (s1->data.cdata.len != s2->data.cdata.len)
+ return false;
+
+ return 0 == memcmp(s1->data.cdata.ptr, s2->data.cdata.ptr,
+ s1->data.cdata.len);
+}
+
+/**
+ * Trivial locale-agnostic lower case convertor
+ */
+static inline uint8_t dolower(const uint8_t c)
+{
+ if ('A' <= c && c <= 'Z')
+ return c + 'a' - 'A';
+ return c;
}
/**
@@ -304,62 +235,41 @@
*
* \param s1 The first string to compare
* \param s2 The second string to compare
- * \return 0 if strings match, non-0 otherwise
- *
- * NULL and "" will match.
- */
-int dom_string_icmp(dom_string *s1, dom_string *s2)
+ * \return true if strings match, false otherwise
+ */
+bool dom_string_caseless_isequal(dom_string *s1, dom_string *s2)
{
const uint8_t *d1 = NULL;
const uint8_t *d2 = NULL;
- size_t l1, l2;
-
- if (s1 == NULL)
- s1 = &empty_string;
- if (s2 == NULL)
- s2 = &empty_string;
-
- bool ret;
- if (s1->intern != NULL && s2->intern != NULL) {
- lwc_string_caseless_isequal(s1->intern, s2->intern, &ret);
- if (ret == true) {
- return 0;
- } else {
- return -1;
- }
- }
-
- d1 = s1->ptr;
- d2 = s2->ptr;
- l1 = s1->len;
- l2 = s2->len;
-
- while (l1 > 0 && l2 > 0) {
- uint32_t c1, c2;
- size_t cl1, cl2;
- parserutils_error err;
-
- err = parserutils_charset_utf8_to_ucs4(d1, l1, &c1, &cl1);
- if (err != PARSERUTILS_OK) {
- }
-
- err = parserutils_charset_utf8_to_ucs4(d2, l2, &c2, &cl2);
- if (err != PARSERUTILS_OK) {
- }
-
- /** \todo improved lower-casing algorithm */
- if (tolower(c1) != tolower(c2)) {
- return (int)(tolower(c1) - tolower(c2));
- }
-
- d1 += cl1;
- d2 += cl2;
-
- l1 -= cl1;
- l2 -= cl2;
- }
-
- return (int)(l1 - l2);
+ size_t len;
+
+ if (s1->type == DOM_STRING_INTERNED &&
+ s2->type == DOM_STRING_INTERNED) {
+ bool match;
+
+ lwc_string_caseless_isequal(s1->data.intern, s2->data.intern,
+ &match);
+
+ return match;
+ }
+
+ if (s1->data.cdata.len != s2->data.cdata.len)
+ return false;
+
+ d1 = s1->data.cdata.ptr;
+ d2 = s2->data.cdata.ptr;
+ len = s1->data.cdata.len;
+
+ while (len > 0) {
+ if (dolower(*d1) != dolower(*d2))
+ return false;
+
+ d1++;
+ d2++;
+ len--;
+ }
+
+ return true;
}
/**
@@ -376,11 +286,8 @@
uint32_t c, index;
parserutils_error err;
- if (str == NULL)
- str = &empty_string;
-
- s = str->ptr;
- slen = str->len;
+ s = (const uint8_t *) _dom_string_data(str);
+ slen = _dom_string_byte_length(str);
index = 0;
@@ -416,11 +323,8 @@
uint32_t c, coff, index;
parserutils_error err;
- if (str == NULL)
- str = &empty_string;
-
- s = str->ptr;
- slen = str->len;
+ s = (const uint8_t *) _dom_string_data(str);
+ slen = _dom_string_byte_length(str);
index = dom_string_length(str);
@@ -455,13 +359,14 @@
*/
uint32_t dom_string_length(dom_string *str)
{
- size_t clen;
+ const uint8_t *s;
+ size_t slen, clen;
parserutils_error err;
- if (str == NULL)
- str = &empty_string;
-
- err = parserutils_charset_utf8_length(str->ptr, str->len, &clen);
+ s = (const uint8_t *) _dom_string_data(str);
+ slen = _dom_string_byte_length(str);
+
+ err = parserutils_charset_utf8_length(s, slen, &clen);
if (err != PARSERUTILS_OK) {
return 0;
}
@@ -484,11 +389,8 @@
uint32_t c, i;
parserutils_error err;
- if (str == NULL)
- str = &empty_string;
-
- s = str->ptr;
- slen = str->len;
+ s = (const uint8_t *) _dom_string_data(str);
+ slen = _dom_string_byte_length(str);
i = 0;
@@ -527,58 +429,46 @@
* \param result Pointer to location to receive result
* \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
*
- * The returned string will be allocated using the allocation details
- * stored in ::s1.
- *
- * The returned string will have its reference count increased. The client
+ * The returned string will be referenced. The client
* should dereference it once it has finished with it.
*/
dom_exception dom_string_concat(dom_string *s1, dom_string *s2,
dom_string **result)
{
dom_string *concat;
- dom_alloc alloc;
- void *pw;
+ const uint8_t *s1ptr, *s2ptr;
+ size_t s1len, s2len;
assert(s1 != NULL);
assert(s2 != NULL);
- if (s1->alloc != NULL) {
- alloc = s1->alloc;
- pw = s1->pw;
- } else if (s2->alloc != NULL) {
- alloc = s2->alloc;
- pw = s2->pw;
- } else {
- /* s1 == s2 == empty_string */
- *result = &empty_string;
- return DOM_NO_ERR;
- }
-
- concat = alloc(NULL, sizeof(dom_string), pw);
+ s1ptr = (const uint8_t *) _dom_string_data(s1);
+ s2ptr = (const uint8_t *) _dom_string_data(s2);
+ s1len = _dom_string_byte_length(s1);
+ s2len = _dom_string_byte_length(s2);
+
+ concat = malloc(sizeof(dom_string));
if (concat == NULL) {
return DOM_NO_MEM_ERR;
}
- concat->ptr = alloc(NULL, s1->len + s2->len, pw);
- if (concat->ptr == NULL) {
- alloc(concat, 0, pw);
-
- return DOM_NO_MEM_ERR;
- }
-
- memcpy(concat->ptr, s1->ptr, s1->len);
-
- memcpy(concat->ptr + s1->len, s2->ptr, s2->len);
-
- concat->len = s1->len + s2->len;
-
- concat->alloc = alloc;
- concat->pw = pw;
- concat->intern = NULL;
+ concat->data.cdata.ptr = malloc(s1len + s2len);
+ if (concat->data.cdata.ptr == NULL) {
+ free(concat);
+
+ return DOM_NO_MEM_ERR;
+ }
+
+ memcpy(concat->data.cdata.ptr, s1ptr, s1len);
+
+ memcpy(concat->data.cdata.ptr + s1len, s2ptr, s2len);
+
+ concat->data.cdata.len = s1len + s2len;
concat->refcnt = 1;
+
+ concat->type = DOM_STRING_CDATA;
*result = concat;
@@ -594,17 +484,14 @@
* \param result Pointer to location to receive result
* \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
*
- * The returned string will be allocated using the allocation details
- * stored in ::str.
- *
* The returned string will have its reference count increased. The client
* should dereference it once it has finished with it.
*/
dom_exception dom_string_substr(dom_string *str,
uint32_t i1, uint32_t i2, dom_string **result)
{
- const uint8_t *s = str->ptr;
- size_t slen = str->len;
+ const uint8_t *s = (const uint8_t *) _dom_string_data(str);
+ size_t slen = _dom_string_byte_length(str);
uint32_t b1, b2;
parserutils_error err;
@@ -637,7 +524,7 @@
}
/* Create a string from the specified byte range */
- return dom_string_create(str->alloc, str->pw, s + b1, b2 - b1, result);
+ return dom_string_create(s + b1, b2 - b1, result);
}
/**
@@ -651,9 +538,6 @@
* DOM_NO_MEM_ERR on memory exhaustion,
* DOM_INDEX_SIZE_ERR if ::offset > len(::target).
*
- * The returned string will be allocated using the allocation details
- * stored in ::target.
- *
* The returned string will have its reference count increased. The client
* should dereference it once it has finished with it.
*/
@@ -667,10 +551,10 @@
uint32_t ins = 0;
parserutils_error err;
- t = target->ptr;
- tlen = target->len;
- s = source->ptr;
- slen = source->len;
+ t = (const uint8_t *) _dom_string_data(target);
+ tlen = _dom_string_byte_length(target);
+ s = (const uint8_t *) _dom_string_data(source);
+ slen = _dom_string_byte_length(source);
clen = dom_string_length(target);
@@ -696,38 +580,36 @@
}
/* Allocate result string */
- res = target->alloc(NULL, sizeof(dom_string), target->pw);
+ res = malloc(sizeof(dom_string));
if (res == NULL) {
return DOM_NO_MEM_ERR;
}
/* Allocate data buffer for result contents */
- res->ptr = target->alloc(NULL, tlen + slen, target->pw);
- if (res->ptr == NULL) {
- target->alloc(res, 0, target->pw);
+ res->data.cdata.ptr = malloc(tlen + slen);
+ if (res->data.cdata.ptr == NULL) {
+ free(res);
return DOM_NO_MEM_ERR;
}
/* Copy initial portion of target, if any, into result */
if (ins > 0) {
- memcpy(res->ptr, t, ins);
+ memcpy(res->data.cdata.ptr, t, ins);
}
/* Copy inserted data into result */
- memcpy(res->ptr + ins, s, slen);
+ memcpy(res->data.cdata.ptr + ins, s, slen);
/* Copy remainder of target, if any, into result */
if (tlen - ins > 0) {
- memcpy(res->ptr + ins + slen, t + ins, tlen - ins);
- }
-
- res->len = tlen + slen;
-
- res->alloc = target->alloc;
- res->pw = target->pw;
- res->intern = NULL;
-
+ memcpy(res->data.cdata.ptr + ins + slen, t + ins, tlen - ins);
+ }
+
+ res->data.cdata.len = tlen + slen;
+
res->refcnt = 1;
+
+ res->type = DOM_STRING_CDATA;
*result = res;
@@ -744,9 +626,6 @@
* \param result Pointer to location to receive result
* \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion.
*
- * The returned string will be allocated using the allocation details
- * stored in ::target.
- *
* The returned string will have its reference count increased. The client
* should dereference it once it has finished with it.
*/
@@ -760,13 +639,10 @@
uint32_t b1, b2;
parserutils_error err;
- if (source == NULL)
- source = &empty_string;
-
- t = target->ptr;
- tlen = target->len;
- s = source->ptr;
- slen = source->len;
+ t = (const uint8_t *) _dom_string_data(target);
+ tlen = _dom_string_byte_length(target);
+ s = (const uint8_t *) _dom_string_data(source);
+ slen = _dom_string_byte_length(source);
/* Initialise the byte index of the start to 0 */
b1 = 0;
@@ -799,70 +675,42 @@
}
/* Allocate result string */
- res = target->alloc(NULL, sizeof(dom_string), target->pw);
-
+ res = malloc(sizeof(dom_string));
if (res == NULL) {
return DOM_NO_MEM_ERR;
}
/* Allocate data buffer for result contents */
- res->ptr = target->alloc(NULL, tlen + slen - (b2 - b1), target->pw);
- if (res->ptr == NULL) {
- target->alloc(res, 0, target->pw);
+ res->data.cdata.ptr = malloc(tlen + slen - (b2 - b1));
+ if (res->data.cdata.ptr == NULL) {
+ free(res);
return DOM_NO_MEM_ERR;
}
/* Copy initial portion of target, if any, into result */
if (b1 > 0) {
- memcpy(res->ptr, t, b1);
+ memcpy(res->data.cdata.ptr, t, b1);
}
/* Copy replacement data into result */
if (slen > 0) {
- memcpy(res->ptr + b1, s, slen);
+ memcpy(res->data.cdata.ptr + b1, s, slen);
}
/* Copy remainder of target, if any, into result */
if (tlen - b2 > 0) {
- memcpy(res->ptr + b1 + slen, t + b2, tlen - b2);
- }
-
- res->len = tlen + slen - (b2 - b1);
-
- res->alloc = target->alloc;
- res->pw = target->pw;
- res->intern = NULL;
+ memcpy(res->data.cdata.ptr + b1 + slen, t + b2, tlen - b2);
+ }
+
+ res->data.cdata.len = tlen + slen - (b2 - b1);
res->refcnt = 1;
+ res->type = DOM_STRING_CDATA;
+
*result = res;
return DOM_NO_ERR;
-}
-
-/**
- * Duplicate a dom string
- *
- * \param str The string to duplicate
- * \param result Pointer to location to receive result
- * \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion
- *
- * The returned string will be allocated using the allocation details
- * stored in ::str.
- *
- * The returned string will have its reference count increased. The client
- * should dereference it once it has finished with it.
- */
-dom_exception dom_string_dup(dom_string *str,
- dom_string **result)
-{
- if (str->intern != NULL) {
- return _dom_string_create_from_lwcstring(str->alloc, str->pw,
- str->intern, result);
- } else {
- return dom_string_create(str->alloc, str->pw, str->ptr,
- str->len, result);
- }
}
/**
@@ -873,9 +721,9 @@
*/
uint32_t dom_string_hash(dom_string *str)
{
- const uint8_t *s = str->ptr;
- size_t slen = str->len;
- uint32_t hash = 0x01000193;
+ const uint8_t *s = (const uint8_t *) _dom_string_data(str);
+ size_t slen = _dom_string_byte_length(str);
+ uint32_t hash = 0x811c9dc5;
while (slen > 0) {
hash *= 0x01000193;
@@ -897,15 +745,14 @@
dom_exception _dom_exception_from_lwc_error(lwc_error err)
{
switch (err) {
- case lwc_error_ok:
- return DOM_NO_ERR;
- case lwc_error_oom:
- return DOM_NO_MEM_ERR;
- case lwc_error_range:
- return DOM_INDEX_SIZE_ERR;
- }
- assert ("Unknow lwc_error, can't convert to dom_exception");
- /* Suppress compile errors */
+ case lwc_error_ok:
+ return DOM_NO_ERR;
+ case lwc_error_oom:
+ return DOM_NO_MEM_ERR;
+ case lwc_error_range:
+ return DOM_INDEX_SIZE_ERR;
+ }
+
return DOM_NO_ERR;
}
@@ -913,22 +760,30 @@
* Get the raw character data of the dom_string.
*
* \param str The dom_string object
- * \return The C string pointer
+ * \return The C string pointer
*
* @note: This function is just provided for the convenience of accessing the
* raw C string character, no change on the result string is allowed.
*/
-char *_dom_string_data(dom_string *str)
-{
- return (char *) str->ptr;
-}
-
-/* Get the string length of this dom_string
+const char *_dom_string_data(dom_string *str)
+{
+ if (str->type == DOM_STRING_CDATA) {
+ return (const char *) str->data.cdata.ptr;
+ } else {
+ return lwc_string_data(str->data.intern);
+ }
+}
+
+/* Get the byte length of this dom_string
*
* \param str The dom_string object
*/
-size_t _dom_string_length(dom_string *str)
-{
- return str->len;
-}
-
+size_t _dom_string_byte_length(dom_string *str)
+{
+ if (str->type == DOM_STRING_CDATA) {
+ return str->data.cdata.len;
+ } else {
+ return lwc_string_length(str->data.intern);
+ }
+}
+
Modified: branches/jmb/dom-alloc-purge/src/core/string.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/s...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/string.h (original)
+++ branches/jmb/dom-alloc-purge/src/core/string.h Fri May 20 02:37:44 2011
@@ -1,3 +1,4 @@
+
/*
* This file is part of libdom.
* Licensed under the MIT License,
@@ -10,14 +11,9 @@
#include <dom/core/string.h>
-/* 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_string_s *str, dom_string **ret);
-
-/* Make the dom_string be interned */
-dom_exception _dom_string_intern(dom_string *str,
- struct lwc_string_s **lwcstr);
+/* Create a DOM string from a lwc_string */
+dom_exception _dom_string_create_from_lwcstring(struct lwc_string_s *str,
+ dom_string **ret);
/* Map the lwc_error to dom_exception */
dom_exception _dom_exception_from_lwc_error(lwc_error err);
@@ -27,10 +23,10 @@
* @note: This function is just provided for the convenience of accessing the
* raw C string character, no change on the result string is allowed.
*/
-char *_dom_string_data(dom_string *str);
+const char *_dom_string_data(dom_string *str);
-/* Get the string length of this dom_string */
-size_t _dom_string_length(dom_string *str);
+/* Get the byte length of this dom_string */
+size_t _dom_string_byte_length(dom_string *str);
#endif
Removed: branches/jmb/dom-alloc-purge/src/dom.c
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/dom.c?...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/dom.c (original)
+++ branches/jmb/dom-alloc-purge/src/dom.c (removed)
@@ -1,69 +1,0 @@
-/*
- * This file is part of libdom.
- * Licensed under the MIT License,
- * http://www.opensource.org/licenses/mit-license.php
- * Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
- */
-
-#include <stdbool.h>
-
-#include <dom/dom.h>
-
-#include "utils/namespace.h"
-
-static bool __initialised;
-
-/**
- * Initialise the dom library
- *
- * \param alloc Pointer to memory (de)allocation function
- * \param pw Pointer to client-specific private data
- * \return DOM_NO_ERR on success.
- *
- * This must be the first DOM library method called.
- */
-dom_exception dom_initialise(dom_alloc alloc, void *pw)
-{
- dom_exception err;
-
- /* Ensure we only initialise once */
- if (__initialised) {
- return DOM_NO_ERR;
- }
-
- err = _dom_namespace_initialise(alloc, pw);
- if (err != DOM_NO_ERR) {
- return err;
- }
-
- __initialised = true;
-
- return DOM_NO_ERR;
-}
-
-/**
- * Finalise the dom library
- *
- * \return DOM_NO_ERR on success.
- *
- * This must be the last DOM library method called.
- */
-dom_exception dom_finalise(void)
-{
- dom_exception err;
-
- /* Ensure we only finalise once */
- if (__initialised == false) {
- return DOM_NO_ERR;
- }
-
- err = _dom_namespace_finalise();
- if (err != DOM_NO_ERR) {
- return err;
- }
-
- __initialised = false;
-
- return DOM_NO_ERR;
-}
-
Modified: branches/jmb/dom-alloc-purge/src/utils/Makefile
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/utils/...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/utils/Makefile (original)
+++ branches/jmb/dom-alloc-purge/src/utils/Makefile Fri May 20 02:37:44 2011
@@ -1,5 +1,4 @@
# Sources
-DIR_SOURCES := namespace.c hashtable.c resource_mgr.c character_valid.c \
- validate.c
+DIR_SOURCES := namespace.c hashtable.c character_valid.c validate.c
include build/makefiles/Makefile.subdir
Modified: branches/jmb/dom-alloc-purge/src/utils/hashtable.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/utils/...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/utils/hashtable.h (original)
+++ branches/jmb/dom-alloc-purge/src/utils/hashtable.h Fri May 20 02:37:44 2011
@@ -16,16 +16,14 @@
/* The hash function */
typedef unsigned int (*dom_hash_func)(void *key);
/* Function to clone/delete key */
-typedef void *(*dom_key_func)(void *key, void *pw, dom_alloc alloc,
- void *alloc_pw, bool clone);
+typedef void *(*dom_key_func)(void *key, void *pw, bool clone);
/* Function to clone/delete value */
-typedef void *(*dom_value_func)(void *value, void *pw, dom_alloc alloc,
- void *alloc_pw, bool clone);
+typedef void *(*dom_value_func)(void *value, void *pw, bool clone);
-struct dom_hash_table *_dom_hash_create(unsigned int chains, dom_hash_func hash,
- dom_alloc alloc, void *ptr);
+struct dom_hash_table *_dom_hash_create(unsigned int chains,
+ dom_hash_func hash);
struct dom_hash_table *_dom_hash_clone(struct dom_hash_table *ht,
- dom_alloc alloc, void *pw, dom_key_func kf, void *key_pw,
+ dom_key_func kf, void *key_pw,
dom_value_func vf, void *value_pw);
void _dom_hash_destroy(struct dom_hash_table *ht, dom_key_func kf, void *key_pw,
dom_value_func vf, void *value_pw);
Modified: branches/jmb/dom-alloc-purge/src/utils/namespace.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/utils/...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/utils/namespace.h (original)
+++ branches/jmb/dom-alloc-purge/src/utils/namespace.h Fri May 20 02:37:44 2011
@@ -13,12 +13,6 @@
#include <dom/core/string.h>
struct dom_document;
-
-/* Initialise the namespace component */
-dom_exception _dom_namespace_initialise(dom_alloc alloc, void *pw);
-
-/* Finalise the namespace component */
-dom_exception _dom_namespace_finalise(void);
/* Ensure a QName is valid */
dom_exception _dom_namespace_validate_qname(dom_string *qname,
Removed: branches/jmb/dom-alloc-purge/src/utils/resource_mgr.c
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/utils/...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/utils/resource_mgr.c (original)
+++ branches/jmb/dom-alloc-purge/src/utils/resource_mgr.c (removed)
@@ -1,104 +1,0 @@
-/*
- * This file is part of libdom.
- * Licensed under the MIT License,
- * http://www.opensource.org/licenses/mit-license.php
- * Copyright 2009 Bo Yang <struggleyb.nku(a)gmail.com>
- */
-
-#include "resource_mgr.h"
-
-#include <string.h>
-#include <assert.h>
-
-#include <libwapcaplet/libwapcaplet.h>
-#include "core/string.h"
-
-#include "utils/utils.h"
-
-/**
- * Allocate some memory with this allocator
- *
- * \param res The resource manager
- * \param size The size of memory to allocate
- * \return the allocated memory pointer.
- */
-void *_dom_resource_mgr_alloc(struct dom_resource_mgr *res, void *ptr,
- size_t size)
-{
- return res->alloc(ptr, size, res->pw);
-}
-
-/**
- * Create a dom_string using this resource manager
- *
- * \param res The resource manager
- * \param data The data pointer
- * \param len The length of data
- * \param result The returned dom_string
- * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
- */
-dom_exception _dom_resource_mgr_create_string(struct dom_resource_mgr *res,
- const uint8_t *data, size_t len, dom_string **result)
-{
- return dom_string_create(res->alloc, res->pw, data, len, result);
-}
-
-/**
- * Create a lwc_string using this resource manager
- *
- * \param res The resource manager
- * \param data The data pointer
- * \param len The length of the data
- * \param result The returned lwc_string
- * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
- */
-dom_exception _dom_resource_mgr_create_lwcstring(struct dom_resource_mgr *res,
- const uint8_t *data, size_t len, struct lwc_string_s **result)
-{
- lwc_error lerr;
-
- UNUSED(res);
-
- lerr = lwc_intern_string((const char *) data, len, result);
-
- return _dom_exception_from_lwc_error(lerr);
-}
-
-/**
- * Create a dom_string from a lwc_string using this resource manager
- *
- * \param res The resource manager
- * \param str The dom_string to intern
- * \param result The returned lwc_string
- * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
- */
-dom_exception _dom_resource_mgr_create_string_from_lwcstring(
- struct dom_resource_mgr *res, struct lwc_string_s *str,
- dom_string **result)
-{
- return _dom_string_create_from_lwcstring(res->alloc, res->pw,
- str, result);
-}
-
-/**
- * Create a hash table using this resource manager
- *
- * \param res The resource manager
- * \param chains The number of buckets of the hash table
- * \param f The hash function
- * \param ht The returned hash table
- * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
- */
-dom_exception _dom_resource_mgr_create_hashtable(struct dom_resource_mgr *res,
- size_t chains, dom_hash_func f, struct dom_hash_table **ht)
-{
- struct dom_hash_table *ret;
-
- ret = _dom_hash_create(chains, f, res->alloc, res->pw);
- if (ret == NULL)
- return DOM_NO_MEM_ERR;
-
- *ht = ret;
- return DOM_NO_ERR;
-}
-
Removed: branches/jmb/dom-alloc-purge/src/utils/resource_mgr.h
URL: http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/utils/...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/utils/resource_mgr.h (original)
+++ branches/jmb/dom-alloc-purge/src/utils/resource_mgr.h (removed)
@@ -1,43 +1,0 @@
-/*
- * This file is part of libdom.
- * Licensed under the MIT License,
- * http://www.opensource.org/licenses/mit-license.php
- * Copyright 2009 Bo Yang <struggleyb.nku(a)gmail.com>
- */
-
-#ifndef dom_utils_resource_mgr_h_
-#define dom_utils_resource_mgr_h_
-
-#include <dom/functypes.h>
-#include <dom/core/exceptions.h>
-#include <dom/core/string.h>
-
-#include "hashtable.h"
-
-struct lwc_string_s;
-
-/**
- * Resource manager
- */
-typedef struct dom_resource_mgr {
- dom_alloc alloc;
- void *pw;
-} dom_resource_mgr;
-
-void *_dom_resource_mgr_alloc(struct dom_resource_mgr *res, void *ptr,
- size_t size);
-
-dom_exception _dom_resource_mgr_create_string(struct dom_resource_mgr *res,
- const uint8_t *data, size_t len, dom_string **result);
-
-dom_exception _dom_resource_mgr_create_lwcstring(struct dom_resource_mgr *res,
- const uint8_t *data, size_t len, struct lwc_string_s **result);
-
-dom_exception _dom_resource_mgr_create_string_from_lwcstring(
- struct dom_resource_mgr *res, struct lwc_string_s *str,
- dom_string **result);
-
-dom_exception _dom_resource_mgr_create_hashtable(struct dom_resource_mgr *res,
- size_t chains, dom_hash_func f, struct dom_hash_table **ht);
-
-#endif
11 years, 8 months
r12436 jmb - /trunk/netsurf/content/fetchers/curl.c
by netsurf@semichrome.net
Author: jmb
Date: Thu May 19 17:35:41 2011
New Revision: 12436
URL: http://source.netsurf-browser.org?rev=12436&view=rev
Log:
Log CA options
Modified:
trunk/netsurf/content/fetchers/curl.c
Modified: trunk/netsurf/content/fetchers/curl.c
URL: http://source.netsurf-browser.org/trunk/netsurf/content/fetchers/curl.c?r...
==============================================================================
--- trunk/netsurf/content/fetchers/curl.c (original)
+++ trunk/netsurf/content/fetchers/curl.c Thu May 19 17:35:41 2011
@@ -200,10 +200,14 @@
SETOPT(CURLOPT_NOSIGNAL, 1L);
SETOPT(CURLOPT_CONNECTTIMEOUT, 30L);
- if (option_ca_bundle && strcmp(option_ca_bundle, ""))
+ if (option_ca_bundle && strcmp(option_ca_bundle, "")) {
+ LOG(("option_ca_bundle: '%s'", option_ca_bundle));
SETOPT(CURLOPT_CAINFO, option_ca_bundle);
- if (option_ca_path && strcmp(option_ca_path, ""))
+ }
+ if (option_ca_path && strcmp(option_ca_path, "")) {
+ LOG(("option_ca_path: '%s'", option_ca_path));
SETOPT(CURLOPT_CAPATH, option_ca_path);
+ }
/* Detect whether the SSL CTX function API works */
curl_with_openssl = true;
11 years, 8 months
r12435 swdr - in /trunk/netsurf/cocoa: NetSurfAppDelegate.m res/NetSurf-Info.plist
by netsurf@semichrome.net
Author: swdr
Date: Thu May 19 11:04:54 2011
New Revision: 12435
URL: http://source.netsurf-browser.org?rev=12435&view=rev
Log:
Netsurf now appears in the 'Open with' menu for HTML files.
Modified:
trunk/netsurf/cocoa/NetSurfAppDelegate.m
trunk/netsurf/cocoa/res/NetSurf-Info.plist
Modified: trunk/netsurf/cocoa/NetSurfAppDelegate.m
URL: http://source.netsurf-browser.org/trunk/netsurf/cocoa/NetSurfAppDelegate....
==============================================================================
--- trunk/netsurf/cocoa/NetSurfAppDelegate.m (original)
+++ trunk/netsurf/cocoa/NetSurfAppDelegate.m Thu May 19 11:04:54 2011
@@ -122,5 +122,12 @@
forEventClass:kInternetEventClass andEventID:kAEGetURL];
}
+- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
+{
+ NSURL *url = [NSURL fileURLWithPath: filename];
+ browser_window_create( [[url absoluteString] UTF8String], NULL, NULL, true, false );
+ return YES;
+}
+
@end
Modified: trunk/netsurf/cocoa/res/NetSurf-Info.plist
URL: http://source.netsurf-browser.org/trunk/netsurf/cocoa/res/NetSurf-Info.pl...
==============================================================================
--- trunk/netsurf/cocoa/res/NetSurf-Info.plist (original)
+++ trunk/netsurf/cocoa/res/NetSurf-Info.plist Thu May 19 11:04:54 2011
@@ -5,7 +5,22 @@
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
- <array/>
+ <array>
+ <dict>
+ <key>CFBundleTypeExtensions</key>
+ <array/>
+ <key>CFBundleTypeMIMETypes</key>
+ <array/>
+ <key>CFBundleTypeName</key>
+ <string>HTML</string>
+ <key>CFBundleTypeRole</key>
+ <string>Viewer</string>
+ <key>LSItemContentTypes</key>
+ <array>
+ <string>public.html</string>
+ </array>
+ </dict>
+ </array>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
11 years, 8 months
r12434 swdr - /trunk/netsurf/cocoa/res/NetSurf-Info.plist
by netsurf@semichrome.net
Author: swdr
Date: Thu May 19 11:04:11 2011
New Revision: 12434
URL: http://source.netsurf-browser.org?rev=12434&view=rev
Log:
Importing UTI types for HTML and CSS.
Modified:
trunk/netsurf/cocoa/res/NetSurf-Info.plist
Modified: trunk/netsurf/cocoa/res/NetSurf-Info.plist
URL: http://source.netsurf-browser.org/trunk/netsurf/cocoa/res/NetSurf-Info.pl...
==============================================================================
--- trunk/netsurf/cocoa/res/NetSurf-Info.plist (original)
+++ trunk/netsurf/cocoa/res/NetSurf-Info.plist Thu May 19 11:04:11 2011
@@ -4,6 +4,8 @@
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
+ <key>CFBundleDocumentTypes</key>
+ <array/>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
@@ -20,14 +22,6 @@
<string>${NETSURF_VERSION}</string>
<key>CFBundleSignature</key>
<string>????</string>
- <key>CFBundleVersion</key>
- <string>${NETSURF_SHORT_VERSION}</string>
- <key>LSMinimumSystemVersion</key>
- <string>${MACOSX_DEPLOYMENT_TARGET}</string>
- <key>NSMainNibFile</key>
- <string>MainMenu</string>
- <key>NSPrincipalClass</key>
- <string>NetSurfApp</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
@@ -40,5 +34,63 @@
</array>
</dict>
</array>
+ <key>CFBundleVersion</key>
+ <string>${NETSURF_SHORT_VERSION}</string>
+ <key>LSMinimumSystemVersion</key>
+ <string>${MACOSX_DEPLOYMENT_TARGET}</string>
+ <key>NSMainNibFile</key>
+ <string>MainMenu</string>
+ <key>NSPrincipalClass</key>
+ <string>NetSurfApp</string>
+ <key>NSServices</key>
+ <array/>
+ <key>UTExportedTypeDeclarations</key>
+ <array/>
+ <key>UTImportedTypeDeclarations</key>
+ <array>
+ <dict>
+ <key>UTTypeConformsTo</key>
+ <array>
+ <string>public.text</string>
+ </array>
+ <key>UTTypeDescription</key>
+ <string>HTML</string>
+ <key>UTTypeIdentifier</key>
+ <string>public.html</string>
+ <key>UTTypeTagSpecification</key>
+ <dict>
+ <key>public.filename-extension</key>
+ <array>
+ <string>html</string>
+ <string>htm</string>
+ </array>
+ <key>public.mime-type</key>
+ <array>
+ <string>text/html</string>
+ </array>
+ </dict>
+ </dict>
+ <dict>
+ <key>UTTypeConformsTo</key>
+ <array>
+ <string>public.source-code</string>
+ </array>
+ <key>UTTypeDescription</key>
+ <string>CSS</string>
+ <key>UTTypeIdentifier</key>
+ <string>org.w3.css</string>
+ <key>UTTypeTagSpecification</key>
+ <dict>
+ <key>public.filename-extension</key>
+ <array>
+ <string>css</string>
+ </array>
+ <key>public.mime-type</key>
+ <array>
+ <string>text/css</string>
+ </array>
+ </dict>
+ </dict>
+ </array>
</dict>
</plist>
11 years, 8 months
r12433 swdr - /trunk/netsurf/cocoa/apple_image.m
by netsurf@semichrome.net
Author: swdr
Date: Thu May 19 08:18:01 2011
New Revision: 12433
URL: http://source.netsurf-browser.org?rev=12433&view=rev
Log:
Handling animations in apple_image.m. Loop counts are ignored for now
Modified:
trunk/netsurf/cocoa/apple_image.m
Modified: trunk/netsurf/cocoa/apple_image.m
URL: http://source.netsurf-browser.org/trunk/netsurf/cocoa/apple_image.m?rev=1...
==============================================================================
--- trunk/netsurf/cocoa/apple_image.m (original)
+++ trunk/netsurf/cocoa/apple_image.m Thu May 19 08:18:01 2011
@@ -26,9 +26,13 @@
#include "desktop/plotters.h"
#include "utils/talloc.h"
#include "utils/utils.h"
+#include "utils/schedule.h"
typedef struct apple_image_content {
struct content base;
+ NSUInteger frames;
+ NSUInteger currentFrame;
+ int *frameTimes;
} apple_image_content;
static nserror apple_image_create(const content_handler *handler,
@@ -126,6 +130,28 @@
return NSERROR_OK;
}
+
+static void animate_image_cb( void *ptr )
+{
+ struct apple_image_content *ai = ptr;
+ ++ai->currentFrame;
+ if (ai->currentFrame >= ai->frames) ai->currentFrame = 0;
+
+ [(NSBitmapImageRep *)ai->base.bitmap setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: ai->currentFrame]];
+ bitmap_modified( ai->base.bitmap );
+
+ union content_msg_data data;
+ data.redraw.full_redraw = true;
+ data.redraw.x = data.redraw.object_x = 0;
+ data.redraw.y = data.redraw.object_y = 0;
+ data.redraw.width = data.redraw.object_width = ai->base.width;
+ data.redraw.height = data.redraw.object_height = ai->base.height;
+ data.redraw.object = &ai->base;
+ content_broadcast( &ai->base, CONTENT_MSG_REDRAW, data );
+
+ schedule( ai->frameTimes[ai->currentFrame], animate_image_cb, ai );
+}
+
/**
* Convert a CONTENT_APPLE_IMAGE for display.
*/
@@ -156,6 +182,20 @@
content_set_ready(c);
content_set_done(c);
content_set_status(c, "");
+
+ struct apple_image_content *ai = (struct apple_image_content *)c;
+ NSUInteger frames = [[image valueForProperty: NSImageFrameCount] unsignedIntegerValue];
+ if (frames > 1) {
+ ai->frames = frames;
+ ai->currentFrame = 0;
+ ai->frameTimes = talloc_zero_array( ai, int, ai->frames );
+ for (NSUInteger i = 0; i < frames; i++) {
+ [image setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: i]];
+ ai->frameTimes[i] = 100 * [[image valueForProperty: NSImageCurrentFrameDuration] floatValue];
+ }
+ [image setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: 0]];
+ schedule( ai->frameTimes[0], animate_image_cb, ai );
+ }
return true;
}
@@ -165,6 +205,7 @@
{
[(id)c->bitmap release];
c->bitmap = NULL;
+ schedule_remove( animate_image_cb, c );
}
11 years, 8 months