r3544 jmb - /trunk/dom/bindings/xml/xmlparser.c
by netsurf@semichrome.net
Author: jmb
Date: Mon Sep 17 01:12:56 2007
New Revision: 3544
URL: http://source.netsurf-browser.org?rev=3544&view=rev
Log:
Fix potential segfaults
Modified:
trunk/dom/bindings/xml/xmlparser.c
Modified: trunk/dom/bindings/xml/xmlparser.c
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlparser.c?rev=...
==============================================================================
--- trunk/dom/bindings/xml/xmlparser.c (original)
+++ trunk/dom/bindings/xml/xmlparser.c Mon Sep 17 01:12:56 2007
@@ -1092,7 +1092,8 @@
/* Create public ID for doctype */
err = dom_string_create_from_const_ptr(parser->doc,
dtd->ExternalID,
- strlen((const char *) dtd->ExternalID),
+ (dtd->ExternalID == NULL) ? 0
+ : strlen((const char *) dtd->ExternalID),
&public_id);
if (err != DOM_NO_ERR) {
dom_string_unref(qname);
@@ -1102,7 +1103,8 @@
/* Create system ID for doctype */
err = dom_string_create_from_const_ptr(parser->doc,
dtd->SystemID,
- strlen((const char *) dtd->SystemID),
+ (dtd->SystemID == NULL) ? 0
+ : strlen((const char *) dtd->SystemID),
&system_id);
if (err != DOM_NO_ERR) {
dom_string_unref(public_id);
16 years, 2 months
r3543 jmb - /trunk/dom/bindings/xml/xmlbinding.c
by netsurf@semichrome.net
Author: jmb
Date: Mon Sep 17 01:12:21 2007
New Revision: 3543
URL: http://source.netsurf-browser.org?rev=3543&view=rev
Log:
Implement xml-binding-specific dom_implementation_create_document
Modified:
trunk/dom/bindings/xml/xmlbinding.c
Modified: trunk/dom/bindings/xml/xmlbinding.c
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlbinding.c?rev...
==============================================================================
--- trunk/dom/bindings/xml/xmlbinding.c (original)
+++ trunk/dom/bindings/xml/xmlbinding.c Mon Sep 17 01:12:21 2007
@@ -7,6 +7,7 @@
#include <dom/bootstrap/implpriv.h>
#include <dom/bootstrap/implregistry.h>
+#include <dom/dom.h>
#include "functypes.h"
#include "xmlbinding.h"
@@ -270,15 +271,52 @@
struct dom_document **doc,
dom_alloc alloc, void *pw)
{
- UNUSED(impl);
- UNUSED(namespace);
- UNUSED(qname);
- UNUSED(doctype);
- UNUSED(doc);
- UNUSED(alloc);
- UNUSED(pw);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_document *d;
+ dom_exception err;
+
+ /* Create document object */
+ err = dom_document_create(impl, alloc, pw, &d);
+ if (err != DOM_NO_ERR)
+ return err;
+
+ /* Set its doctype, if necessary */
+ if (doctype != NULL) {
+ err = dom_document_set_doctype(d, doctype);
+ if (err != DOM_NO_ERR) {
+ dom_node_unref((struct dom_node *) d);
+ return err;
+ }
+ }
+
+ /* Create root element and attach it to document */
+ if (qname != NULL) {
+ struct dom_element *e;
+ struct dom_node *inserted;
+
+ err = dom_document_create_element_ns(d, namespace, qname, &e);
+ if (err != DOM_NO_ERR) {
+ dom_node_unref((struct dom_node *) d);
+ return err;
+ }
+
+ err = dom_node_append_child((struct dom_node *) d,
+ (struct dom_node *) e, &inserted);
+ if (err != DOM_NO_ERR) {
+ dom_node_unref((struct dom_node *) e);
+ dom_node_unref((struct dom_node *) d);
+ return err;
+ }
+
+ /* No longer interested in inserted node */
+ dom_node_unref(inserted);
+
+ /* Done with element */
+ dom_node_unref((struct dom_node *) e);
+ }
+
+ *doc = d;
+
+ return DOM_NO_ERR;
}
/**
16 years, 2 months
r3542 jmb - in /trunk/dom/src/core: document.c node.c
by netsurf@semichrome.net
Author: jmb
Date: Mon Sep 17 01:10:56 2007
New Revision: 3542
URL: http://source.netsurf-browser.org?rev=3542&view=rev
Log:
Make Document nodes own themselves (removes need for special case for Documents)
Fixup dom_node_destroy appropriately.
Implement dom_node_{set,get}_user_data.
Modified:
trunk/dom/src/core/document.c
trunk/dom/src/core/node.c
Modified: trunk/dom/src/core/document.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/document.c?rev=3542&...
==============================================================================
--- trunk/dom/src/core/document.c (original)
+++ trunk/dom/src/core/document.c Mon Sep 17 01:10:56 2007
@@ -140,8 +140,10 @@
/* Initialise base class -- the Document has no parent, so
* destruction will be attempted as soon as its reference count
- * reaches zero. */
- err = dom_node_initialise(&d->base, NULL, DOM_DOCUMENT_NODE,
+ * reaches zero. Documents own themselves (this simplifies the
+ * rest of the code, as it doesn't need to special case Documents)
+ */
+ err = dom_node_initialise(&d->base, d, DOM_DOCUMENT_NODE,
NULL, NULL);
if (err != DOM_NO_ERR) {
/* Clean up interned strings */
Modified: trunk/dom/src/core/node.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/node.c?rev=3542&r1=3...
==============================================================================
--- trunk/dom/src/core/node.c (original)
+++ trunk/dom/src/core/node.c Mon Sep 17 01:10:56 2007
@@ -39,14 +39,14 @@
void dom_node_destroy(struct dom_node *node)
{
struct dom_document *owner = node->owner;
+ bool document_node = (node->type == DOM_DOCUMENT_NODE);
/* This function simply acts as a central despatcher
* for type-specific destructors. */
- assert(owner != NULL ||
- (owner == NULL && node->type == DOM_DOCUMENT_NODE));
-
- if (owner != NULL) {
+ assert(owner != NULL);
+
+ if (!document_node) {
/* Claim a reference upon the owning document during
* destruction to ensure that the document doesn't get
* destroyed before its contents. */
@@ -96,7 +96,7 @@
break;
}
- if (owner != NULL) {
+ if (!document_node) {
/* Release the reference we claimed on the document. If this
* is the last reference held on the document and the list
* of nodes pending deletion is empty, then the document will
@@ -115,7 +115,7 @@
* \param value The node value, or NULL
* \return DOM_NO_ERR on success.
*
- * ::doc, ::name and ::value will have their reference counts increased.
+ * ::name and ::value will have their reference counts increased.
*/
dom_exception dom_node_initialise(struct dom_node *node,
struct dom_document *doc, dom_node_type type,
@@ -1105,13 +1105,62 @@
struct dom_string *key, void *data,
dom_user_data_handler handler, void **result)
{
- UNUSED(node);
- UNUSED(key);
- UNUSED(data);
- UNUSED(handler);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
+ struct dom_user_data *ud = NULL;
+ void *prevdata = NULL;
+
+ /* Search for user data */
+ for (ud = node->user_data; ud != NULL; ud = ud->next) {
+ if (dom_string_cmp(ud->key, key) == 0)
+ break;
+ };
+
+ /* Remove it, if found and no new data */
+ if (data == NULL && ud != NULL) {
+ dom_string_unref(ud->key);
+
+ if (ud->next != NULL)
+ ud->next->prev = ud->prev;
+ if (ud->prev != NULL)
+ ud->prev->next = ud->next;
+ else
+ node->user_data = ud->next;
+
+ *result = ud->data;
+
+ dom_document_alloc(node->owner, ud, 0);
+
+ 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));
+ if (ud == NULL)
+ return DOM_NO_MEM_ERR;
+
+ dom_string_ref(key);
+ ud->key = key;
+ ud->data = NULL;
+ ud->handler = NULL;
+
+ /* Insert into list */
+ ud->prev = NULL;
+ ud->next = node->user_data;
+ if (node->user_data)
+ node->user_data->prev = ud;
+ node->user_data = ud;
+ }
+
+ prevdata = ud->data;
+
+ /* And associate data with it */
+ ud->data = data;
+ ud->handler = handler;
+
+ *result = prevdata;
+
+ return DOM_NO_ERR;
}
/**
@@ -1125,9 +1174,19 @@
dom_exception dom_node_get_user_data(struct dom_node *node,
struct dom_string *key, void **result)
{
- UNUSED(node);
- UNUSED(key);
- UNUSED(result);
-
- return DOM_NOT_SUPPORTED_ERR;
-}
+ struct dom_user_data *ud = NULL;
+
+ /* Search for user data */
+ for (ud = node->user_data; ud != NULL; ud = ud->next) {
+ if (dom_string_cmp(ud->key, key) == 0)
+ break;
+ };
+
+ if (ud != NULL)
+ *result = ud->data;
+ else
+ *result = NULL;
+
+ return DOM_NO_ERR;
+}
+
16 years, 2 months
r3541 jmb - /trunk/dom/test/testutils.h
by netsurf@semichrome.net
Author: jmb
Date: Sun Sep 16 18:02:56 2007
New Revision: 3541
URL: http://source.netsurf-browser.org?rev=3541&view=rev
Log:
Fix testcases after change to xml_parser API (messaging callback)
Modified:
trunk/dom/test/testutils.h
Modified: trunk/dom/test/testutils.h
URL: http://source.netsurf-browser.org/trunk/dom/test/testutils.h?rev=3541&r1=...
==============================================================================
--- trunk/dom/test/testutils.h (original)
+++ trunk/dom/test/testutils.h Sun Sep 16 18:02:56 2007
@@ -1,6 +1,7 @@
#ifndef dom_test_testutils_h_
#define dom_test_testutils_h_
+#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -39,6 +40,19 @@
UNUSED(pw);
return realloc(ptr, len);
+}
+
+static void mymsg(uint32_t severity, void *ctx, const char *msg, ...)
+{
+ va_list l;
+
+ UNUSED(ctx);
+
+ va_start(l, msg);
+
+ fprintf(stderr, "%d: ", severity);
+ vfprintf(stderr, msg, l);
+ fprintf(stderr, "\n");
}
typedef struct TestObject {
@@ -82,7 +96,8 @@
if (ret == NULL)
return NULL;
- ret->parser = xml_parser_create(NULL, "UTF-8", myrealloc, NULL);
+ ret->parser = xml_parser_create(NULL, "UTF-8", myrealloc, NULL,
+ mymsg, NULL);
if (ret->parser == NULL) {
free(ret);
return NULL;
@@ -115,9 +130,9 @@
len) == XML_OK);
len = 0;
+ }
- assert(xml_parser_completed(ret->parser) == XML_OK);
- }
+ assert(xml_parser_completed(ret->parser) == XML_OK);
fclose(fp);
16 years, 2 months
r3540 jmb - in /trunk/dom/bindings/xml: functypes.h xmlparser.c xmlparser.h
by netsurf@semichrome.net
Author: jmb
Date: Sun Sep 16 18:02:20 2007
New Revision: 3540
URL: http://source.netsurf-browser.org?rev=3540&view=rev
Log:
Add callback for informational messaging (with variable severity, a la syslog)
Use it to log interesting things during parsing.
This needs to grow some i18n at some point.
Modified:
trunk/dom/bindings/xml/functypes.h
trunk/dom/bindings/xml/xmlparser.c
trunk/dom/bindings/xml/xmlparser.h
Modified: trunk/dom/bindings/xml/functypes.h
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/functypes.h?rev=...
==============================================================================
--- trunk/dom/bindings/xml/functypes.h (original)
+++ trunk/dom/bindings/xml/functypes.h Sun Sep 16 18:02:20 2007
@@ -13,4 +13,24 @@
*/
typedef void *(*xml_alloc)(void *ptr, size_t len, void *pw);
+/**
+ * Severity levels for xml_msg function, based on syslog(3)
+ */
+enum {
+ XML_MSG_DEBUG,
+ XML_MSG_INFO,
+ XML_MSG_NOTICE,
+ XML_MSG_WARNING,
+ XML_MSG_ERROR,
+ XML_MSG_CRITICAL,
+ XML_MSG_ALERT,
+ XML_MSG_EMERGENCY
+};
+
+/**
+ * Type of XML parser message function
+ */
+typedef void (*xml_msg)(uint32_t severity, void *ctx, const char *msg, ...);
+
#endif
+
Modified: trunk/dom/bindings/xml/xmlparser.c
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlparser.c?rev=...
==============================================================================
--- trunk/dom/bindings/xml/xmlparser.c (original)
+++ trunk/dom/bindings/xml/xmlparser.c Sun Sep 16 18:02:20 2007
@@ -6,7 +6,6 @@
*/
#include <stdbool.h>
-#include <stdio.h>
#include <string.h>
#include <libxml/parser.h>
@@ -95,44 +94,47 @@
xml_alloc alloc; /**< Memory (de)allocation function */
void *pw; /**< Pointer to client data */
+
+ xml_msg msg; /**< Informational message function */
+ void *mctx; /**< Pointer to client data */
};
/**
* SAX callback dispatch table
*/
static xmlSAXHandler sax_handler = {
- .internalSubset = xml_parser_internal_subset,
- .isStandalone = xml_parser_is_standalone,
- .hasInternalSubset = xml_parser_has_internal_subset,
- .hasExternalSubset = xml_parser_has_external_subset,
- .resolveEntity = xml_parser_resolve_entity,
- .getEntity = xml_parser_get_entity,
- .entityDecl = xml_parser_entity_decl,
- .notationDecl = xml_parser_notation_decl,
- .attributeDecl = xml_parser_attribute_decl,
- .elementDecl = xml_parser_element_decl,
- .unparsedEntityDecl = xml_parser_unparsed_entity_decl,
- .setDocumentLocator = xml_parser_set_document_locator,
- .startDocument = xml_parser_start_document,
- .endDocument = xml_parser_end_document,
- .startElement = NULL,
- .endElement = NULL,
- .reference = xml_parser_reference,
- .characters = xml_parser_characters,
- .ignorableWhitespace = xml_parser_characters,
- .processingInstruction = NULL,
- .comment = xml_parser_comment,
- .warning = NULL,
- .error = NULL,
- .fatalError = NULL,
- .getParameterEntity = xml_parser_get_parameter_entity,
- .cdataBlock = xml_parser_cdata_block,
- .externalSubset = xml_parser_external_subset,
- .initialized = XML_SAX2_MAGIC,
- ._private = NULL,
- .startElementNs = xml_parser_start_element_ns,
- .endElementNs = xml_parser_end_element_ns,
- .serror = NULL
+ .internalSubset = xml_parser_internal_subset,
+ .isStandalone = xml_parser_is_standalone,
+ .hasInternalSubset = xml_parser_has_internal_subset,
+ .hasExternalSubset = xml_parser_has_external_subset,
+ .resolveEntity = xml_parser_resolve_entity,
+ .getEntity = xml_parser_get_entity,
+ .entityDecl = xml_parser_entity_decl,
+ .notationDecl = xml_parser_notation_decl,
+ .attributeDecl = xml_parser_attribute_decl,
+ .elementDecl = xml_parser_element_decl,
+ .unparsedEntityDecl = xml_parser_unparsed_entity_decl,
+ .setDocumentLocator = xml_parser_set_document_locator,
+ .startDocument = xml_parser_start_document,
+ .endDocument = xml_parser_end_document,
+ .startElement = NULL,
+ .endElement = NULL,
+ .reference = xml_parser_reference,
+ .characters = xml_parser_characters,
+ .ignorableWhitespace = xml_parser_characters,
+ .processingInstruction = NULL,
+ .comment = xml_parser_comment,
+ .warning = NULL,
+ .error = NULL,
+ .fatalError = NULL,
+ .getParameterEntity = xml_parser_get_parameter_entity,
+ .cdataBlock = xml_parser_cdata_block,
+ .externalSubset = xml_parser_external_subset,
+ .initialized = XML_SAX2_MAGIC,
+ ._private = NULL,
+ .startElementNs = xml_parser_start_element_ns,
+ .endElementNs = xml_parser_end_element_ns,
+ .serror = NULL
};
/**
@@ -142,6 +144,8 @@
* \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
*
* Neither ::enc nor ::int_enc are used here.
@@ -149,7 +153,7 @@
* parser encoding is not yet implemented
*/
xml_parser *xml_parser_create(const char *enc, const char *int_enc,
- xml_alloc alloc, void *pw)
+ xml_alloc alloc, void *pw, xml_msg msg, void *mctx)
{
xml_parser *parser;
struct dom_string *features;
@@ -159,13 +163,16 @@
UNUSED(int_enc);
parser = alloc(NULL, sizeof(xml_parser), pw);
- if (parser == NULL)
+ if (parser == NULL) {
+ msg(XML_MSG_CRITICAL, mctx, "No memory for parser");
return NULL;
+ }
parser->xml_ctx =
xmlCreatePushParserCtxt(&sax_handler, parser, "", 0, NULL);
if (parser->xml_ctx == NULL) {
alloc(parser, 0, pw);
+ msg(XML_MSG_CRITICAL, mctx, "Failed to create XML parser");
return NULL;
}
@@ -180,6 +187,7 @@
if (err != DOM_NO_ERR) {
xmlFreeParserCtxt(parser->xml_ctx);
alloc(parser, 0, pw);
+ msg(XML_MSG_CRITICAL, mctx, "No memory for userdata key");
return NULL;
}
@@ -191,6 +199,7 @@
dom_string_unref(parser->udkey);
xmlFreeParserCtxt(parser->xml_ctx);
alloc(parser, 0, pw);
+ msg(XML_MSG_CRITICAL, mctx, "No memory for feature string");
return NULL;
}
@@ -202,6 +211,7 @@
dom_string_unref(parser->udkey);
xmlFreeParserCtxt(parser->xml_ctx);
alloc(parser, 0, pw);
+ msg(XML_MSG_ERROR, mctx, "No suitable DOMImplementation");
return NULL;
}
@@ -210,6 +220,9 @@
parser->alloc = alloc;
parser->pw = pw;
+
+ parser->msg = msg;
+ parser->mctx = mctx;
return parser;
}
@@ -248,8 +261,11 @@
xmlParserErrors err;
err = xmlParseChunk(parser->xml_ctx, (char *) data, len, 0);
- if (err != XML_ERR_OK)
+ if (err != XML_ERR_OK) {
+ parser->msg(XML_MSG_ERROR, parser->mctx,
+ "xmlParseChunk failed: %d", err);
return XML_LIBXML_ERR | err;
+ }
return XML_OK;
}
@@ -267,8 +283,11 @@
xmlParserErrors err;
err = xmlParseChunk(parser->xml_ctx, "", 0, 1);
- if (err != XML_ERR_OK)
+ if (err != XML_ERR_OK) {
+ parser->msg(XML_MSG_ERROR, parser->mctx,
+ "xmlParseChunk failed: %d", err);
return XML_LIBXML_ERR | err;
+ }
parser->complete = true;
@@ -311,6 +330,8 @@
(dom_alloc) parser->alloc,
parser->pw);
if (err != DOM_NO_ERR) {
+ parser->msg(XML_MSG_CRITICAL, parser->mctx,
+ "Failed creating document");
return;
}
@@ -342,8 +363,11 @@
xmlSAX2EndDocument(parser->xml_ctx);
/* If there is no document, we can't do anything */
- if (parser->doc == NULL)
- return;
+ if (parser->doc == NULL) {
+ parser->msg(XML_MSG_WARNING, parser->mctx,
+ "No document in end_document");
+ return;
+ }
/* We need to mirror any child nodes at the end of the list of
* children which occur after the last Element node in the list */
@@ -352,6 +376,8 @@
err = dom_node_get_user_data((struct dom_node *) parser->doc,
parser->udkey, (void **) &node);
if (err != DOM_NO_ERR) {
+ parser->msg(XML_MSG_WARNING, parser->mctx,
+ "Failed finding XML node");
return;
}
@@ -407,8 +433,11 @@
nb_defaulted, attributes);
/* If there is no document, we can't do anything */
- if (parser->doc == NULL)
- return;
+ if (parser->doc == NULL) {
+ parser->msg(XML_MSG_WARNING, parser->mctx,
+ "No document in start_element_ns");
+ return;
+ }
if (parent == NULL) {
/* No parent; use document */
@@ -471,8 +500,11 @@
xmlSAX2EndElementNs(parser->xml_ctx, localname, prefix, URI);
/* If there is no document, we can't do anything */
- if (parser->doc == NULL)
- return;
+ if (parser->doc == NULL) {
+ parser->msg(XML_MSG_WARNING, parser->mctx,
+ "No document in end_element_ns");
+ return;
+ }
/* We need to mirror any child nodes at the end of the list of
* children which occur after the last Element node in the list */
@@ -515,8 +547,11 @@
/* Register XML node as user data for DOM node */
err = dom_node_set_user_data(dom, parser->udkey, xml, NULL,
&prev_data);
- if (err != DOM_NO_ERR)
+ if (err != DOM_NO_ERR) {
+ parser->msg(XML_MSG_ERROR, parser->mctx,
+ "Failed setting user data: %d", err);
return err;
+ }
/* Register DOM node with the XML node */
xml->_private = dom;
@@ -579,7 +614,8 @@
xml_parser_add_document_type(parser, parent, child);
break;
default:
- fprintf(stderr, "Unsupported node type: %s\n",
+ parser->msg(XML_MSG_NOTICE, parser->mctx,
+ "Unsupported node type: %s",
node_types[child->type]);
}
}
Modified: trunk/dom/bindings/xml/xmlparser.h
URL: http://source.netsurf-browser.org/trunk/dom/bindings/xml/xmlparser.h?rev=...
==============================================================================
--- trunk/dom/bindings/xml/xmlparser.h (original)
+++ trunk/dom/bindings/xml/xmlparser.h Sun Sep 16 18:02:20 2007
@@ -20,7 +20,7 @@
/* Create an XML parser instance */
xml_parser *xml_parser_create(const char *enc, const char *int_enc,
- xml_alloc alloc, void *pw);
+ xml_alloc alloc, void *pw, xml_msg msg, void *mctx);
/* Destroy an XML parser instance */
void xml_parser_destroy(xml_parser *parser);
16 years, 2 months
r3539 jmb - /trunk/dom/test/transform/test-to-c.xsl
by netsurf@semichrome.net
Author: jmb
Date: Sun Sep 16 18:00:00 2007
New Revision: 3539
URL: http://source.netsurf-browser.org?rev=3539&view=rev
Log:
Move parameter declaration, as xsltproc (libxml 2.6.26, libxslt 1.1.21, libexslt 0.8.13) complains otherwise
Modified:
trunk/dom/test/transform/test-to-c.xsl
Modified: trunk/dom/test/transform/test-to-c.xsl
URL: http://source.netsurf-browser.org/trunk/dom/test/transform/test-to-c.xsl?...
==============================================================================
--- trunk/dom/test/transform/test-to-c.xsl (original)
+++ trunk/dom/test/transform/test-to-c.xsl Sun Sep 16 18:00:00 2007
@@ -470,7 +470,10 @@
<!-- the parameter's expected type -->
<xsl:param name="interface-type"/>
-
+
+ <!-- used for referencing DOMStrings -->
+ <xsl:param name="current-position"/>
+
<!-- the IDL type of $var-or-literal -->
<xsl:variable name="var-type">
<xsl:call-template name="guess-var-or-literal-type">
@@ -479,10 +482,7 @@
<xsl:with-param name="interface-type" select="$interface-type"/>
</xsl:call-template>
</xsl:variable>
-
- <!-- used for referencing DOMStrings -->
- <xsl:param name="current-position"/>
-
+
<xsl:choose>
<xsl:when test="$var-type = 'DOMString'">
<!--
16 years, 2 months
r3538 jmb - /trunk/dom/src/core/node.c
by netsurf@semichrome.net
Author: jmb
Date: Sun Sep 16 17:58:03 2007
New Revision: 3538
URL: http://source.netsurf-browser.org?rev=3538&view=rev
Log:
Fix bug in dom_node_destroy -- Document nodes have no owner, so attempting to ref/unref it is stupid
Modified:
trunk/dom/src/core/node.c
Modified: trunk/dom/src/core/node.c
URL: http://source.netsurf-browser.org/trunk/dom/src/core/node.c?rev=3538&r1=3...
==============================================================================
--- trunk/dom/src/core/node.c (original)
+++ trunk/dom/src/core/node.c Sun Sep 16 17:58:03 2007
@@ -4,6 +4,8 @@
* http://www.opensource.org/licenses/mit-license.php
* Copyright 2007 John-Mark Bell <jmb(a)netsurf-browser.org>
*/
+
+#include <assert.h>
#include <dom/core/document.h>
#include <dom/core/string.h>
@@ -41,10 +43,15 @@
/* This function simply acts as a central despatcher
* for type-specific destructors. */
- /* Claim a reference upon the owning document during destruction
- * to ensure that the document doesn't get destroyed before its
- * contents. */
- dom_node_ref((struct dom_node *) owner);
+ assert(owner != NULL ||
+ (owner == NULL && node->type == DOM_DOCUMENT_NODE));
+
+ if (owner != NULL) {
+ /* Claim a reference upon the owning document during
+ * destruction to ensure that the document doesn't get
+ * destroyed before its contents. */
+ dom_node_ref((struct dom_node *) owner);
+ }
switch (node->type) {
case DOM_ELEMENT_NODE:
@@ -89,10 +96,13 @@
break;
}
- /* Release the reference we claimed on the document. If this is
- * the last reference held on the document and the list of nodes
- * pending deletion is empty, then the document will be destroyed. */
- dom_node_unref((struct dom_node *) owner);
+ if (owner != NULL) {
+ /* Release the reference we claimed on the document. If this
+ * is the last reference held on the document and the list
+ * of nodes pending deletion is empty, then the document will
+ * be destroyed. */
+ dom_node_unref((struct dom_node *) owner);
+ }
}
/**
16 years, 2 months
r3537 dsilvers - in /trunk/netsurf: desktop/browser.c desktop/browser.h desktop/gesture_core.c desktop/gesture_core.h gtk/gtk_scaffolding.c makefile
by netsurf@semichrome.net
Author: dsilvers
Date: Fri Sep 14 19:33:32 2007
New Revision: 3537
URL: http://source.netsurf-browser.org?rev=3537&view=rev
Log:
Remove the old and crap gesture core
Removed:
trunk/netsurf/desktop/gesture_core.c
trunk/netsurf/desktop/gesture_core.h
Modified:
trunk/netsurf/desktop/browser.c
trunk/netsurf/desktop/browser.h
trunk/netsurf/gtk/gtk_scaffolding.c
trunk/netsurf/makefile
Modified: trunk/netsurf/desktop/browser.c
URL: http://source.netsurf-browser.org/trunk/netsurf/desktop/browser.c?rev=353...
==============================================================================
--- trunk/netsurf/desktop/browser.c (original)
+++ trunk/netsurf/desktop/browser.c Fri Sep 14 19:33:32 2007
@@ -48,7 +48,6 @@
#include "desktop/options.h"
#include "desktop/selection.h"
#include "desktop/textinput.h"
-#include "desktop/gesture_core.h"
#include "render/box.h"
#include "render/form.h"
#include "render/font.h"
@@ -184,11 +183,6 @@
else
bw->history = history_clone(clone->history);
- if (!clone || (clone && !clone->gesturer))
- bw->gesturer = NULL;
- else
- bw->gesturer = gesturer_clone(clone->gesturer);
-
/* window characteristics */
bw->sel = selection_create(bw);
bw->refresh_interval = -1;
Modified: trunk/netsurf/desktop/browser.h
URL: http://source.netsurf-browser.org/trunk/netsurf/desktop/browser.h?rev=353...
==============================================================================
--- trunk/netsurf/desktop/browser.h (original)
+++ trunk/netsurf/desktop/browser.h Fri Sep 14 19:33:32 2007
@@ -40,7 +40,6 @@
struct browser_window;
struct url_data;
struct bitmap;
-struct _gesturer_state;
typedef bool (*browser_caret_callback)(struct browser_window *bw,
@@ -61,9 +60,6 @@
/** Window history structure. */
struct history *history;
-
- /** Gesturer for this browser window */
- struct _gesturer_state *gesturer;
/** Selection state */
struct selection *sel;
Removed: trunk/netsurf/desktop/gesture_core.c
URL: http://source.netsurf-browser.org/trunk/netsurf/desktop/gesture_core.c?re...
==============================================================================
--- trunk/netsurf/desktop/gesture_core.c (original)
+++ trunk/netsurf/desktop/gesture_core.c (removed)
@@ -1,353 +1,0 @@
-/*
- * Copyright 2006 Daniel Silverstone <dsilvers(a)digital-scurf.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/** \file
- * Mouse gesture core (implementation)
- */
-
-#include "utils/log.h"
-#include "desktop/gesture_core.h"
-#include <string.h>
-#include <math.h>
-#include <stdlib.h>
-
-/** A gesture as used by the recognition machinery */
-struct _internal_gesture {
- struct _internal_gesture *next; /**< The next gesture in the list */
- int gesture_tag; /**< The tag to return for this gesture */
- int gesture_len; /**< The length of this gesture string */
- char *gesture; /**< The gesture string reversed for matching */
-};
-
-typedef struct _internal_gesture* InternalGesture;
-
-/** A recogniser state. Commonly one in the application. Could have
- * multiple (E.g. one for browser windows, one for the history window.
- */
-struct _gesture_recogniser {
- InternalGesture gestures; /**< The gestures registered */
- Gesturer gesture_users; /**< The users of the gesture engine */
- int max_len; /**< The maximum length the gestures in this recogniser */
- int min_distance; /**< The minimum distance the mouse should move */
- int max_nonmove; /**< The maximum number of data points before abort */
-};
-
-/** A gesturer state. Commonly one per browser window */
-struct _gesturer_state {
- GestureRecogniser recogniser; /**< The recogniser for this state */
- Gesturer next; /* Next gesture state */
- int last_x; /**< Last X coordinate fed to the gesture engine */
- int last_y; /**< Last Y coordinate fed to the gesture engine */
- int bored_count; /**< Num of boring recent add_point calls */
- int elements; /**< Number of elements in the current gesture */
- int nelements; /**< The max number of elements in this gesturer */
- char *gesture; /**< The in-progress gesture string */
-};
-
-static void gesturer_notify_recognition_change(Gesturer gesturer);
-
-/** Create a gesture recogniser.
- *
- * \return A new recogniser.
- */
-GestureRecogniser gesture_recogniser_create(void)
-{
- GestureRecogniser ret = malloc(sizeof(struct _gesture_recogniser));
- ret->gestures = NULL;
- ret->gesture_users = NULL;
- ret->max_len = 0;
- ret->min_distance = 1000000; /* Extremely unlikely */
- ret->max_nonmove = 1;
- return ret;
-}
-
-/** Add a gesture to the recogniser.
- *
- * \param recog The recogniser
- * \param gesture_str The gesture string to add
- * \param gesture_tag The tag to return for this gesture
- */
-void gesture_recogniser_add(GestureRecogniser recog,
- const char* gesture_str, int gesture_tag)
-{
- InternalGesture g = malloc(sizeof(struct _internal_gesture));
- InternalGesture g2,g3;
- int i;
- Gesturer gest = recog->gesture_users;
-
- g->gesture_tag = gesture_tag;
- g->gesture_len = strlen(gesture_str);
- g->gesture = malloc(g->gesture_len);
-
- for(i = 0; i < g->gesture_len; ++i)
- g->gesture[i] = gesture_str[g->gesture_len - i - 1];
-
- g2 = recog->gestures; g3 = NULL;
- while( g2 && g->gesture_len < g2->gesture_len ) g3=g3, g2 = g2->next;
- if( g3 == NULL ) {
- /* prev == NULL, this means we're inserting at the head */
- recog->gestures = g; g->next = g2;
- } else {
- /* prev == something; we're inserting somewhere */
- g3->next = g; g->next = g2;
- }
-
- if( recog->max_len < g->gesture_len ) recog->max_len = g->gesture_len;
-
- while( gest != NULL ) {
- gesturer_notify_recognition_change(gest);
- gest = gest->next;
- }
-}
-
-/** Destroy a gesture recogniser.
- *
- * Only call this after destroying all the gesturers for it.
- *
- * \param recog The recogniser to destroy.
- */
-void gesture_recogniser_destroy(GestureRecogniser recog)
-{
- if( recog->gesture_users ) {
- LOG(("Attempt to destroy a gesture recogniser with gesture users still registered."));
- return;
- }
- while( recog->gestures ) {
- InternalGesture g = recog->gestures;
- recog->gestures = g->next;
- free(g->gesture);
- free(g);
- }
- free(recog);
- return;
-}
-
-/** Set the min distance the mouse has to move in order to be
- * classed as having partaken of a gesture.
- *
- * \param recog The recogniser.
- * \param min_distance The minimum distance in pixels
- */
-void gesture_recogniser_set_distance_threshold(GestureRecogniser recog,
- int min_distance)
-{
- recog->min_distance = min_distance * min_distance;
-}
-
-/** Set the number of non-movement adds of points before the gesturer is
- * internally reset instead of continuing to accumulate a gesture.
- *
- * \param recog The recogniser.
- * \param max_nonmove The maximum number of non-movement adds.
- */
-void gesture_recogniser_set_count_threshold(GestureRecogniser recog,
- int max_nonmove)
-{
- recog->max_nonmove = max_nonmove;
-}
-
-/** Create a gesturer.
- *
- * \param recog The gesture recogniser for this gesturer.
- *
- * \return The new gesturer object
- */
-Gesturer gesturer_create(GestureRecogniser recog)
-{
- Gesturer ret = malloc(sizeof(struct _gesturer_state));
- ret->recogniser = recog;
- ret->next = recog->gesture_users;
- recog->gesture_users = ret;
- ret->last_x = 0;
- ret->last_y = 0;
- ret->bored_count = 0;
- ret->elements = 0;
- ret->nelements = recog->max_len;
- ret->gesture = calloc(recog->max_len+1, 1);
- return ret;
-}
-
-/** Clone a gesturer.
- *
- * \param gesturer The gesturer to clone
- *
- * \return A gesturer cloned from the parameter
- */
-Gesturer gesturer_clone(Gesturer gesturer)
-{
- return gesturer_create(gesturer->recogniser);
-}
-
-/** Remove this gesturer from its recogniser and destroy it.
- *
- * \param gesturer The gesturer to destroy.
- */
-void gesturer_destroy(Gesturer gesturer)
-{
- Gesturer g = gesturer->recogniser->gesture_users, g2 = NULL;
- while( g && g != gesturer ) g2 = g, g = g->next;
- if( g2 == NULL ) {
- /* This gesturer is first in the list */
- gesturer->recogniser->gesture_users = gesturer->next;
- } else {
- g2->next = gesturer->next;
- }
- free(gesturer->gesture);
- free(gesturer);
-}
-
-/** Notify a gesturer that its recogniser has changed in some way */
-static void gesturer_notify_recognition_change(Gesturer gesturer)
-{
- char *new_gesture = calloc(gesturer->recogniser->max_len+1, 1);
- int i;
- for(i = 0; i < gesturer->elements; ++i)
- new_gesture[i] = gesturer->gesture[i];
- free(gesturer->gesture);
- gesturer->gesture = new_gesture;
- gesturer->nelements = gesturer->recogniser->max_len;
-}
-
-/** Clear the points associated with this gesturer.
- *
- * You might call this if the gesturer should be cleared because a mouse
- * button was released or similar.
- *
- * \param gesturer The gesturer to clear.
- */
-void gesturer_clear_points(Gesturer gesturer)
-{
- memset(gesturer->gesture, 0, gesturer->elements);
- gesturer->elements = 0;
- gesturer->bored_count = 0;
-}
-
-#define M_PI_8 (M_PI_4 / 2)
-#define M_3_PI_8 (3 * M_PI_8)
-
-static struct {
- float lower, upper;
- bool x_neg, y_neg;
- char direction;
-} directions[12] = {
- /* MIN MAX X_NEG Y_NEG DIRECTION */
- { 0.0, M_PI_8, false, false, '1' }, /* Right */
- { M_PI_8, M_3_PI_8, false, false, '2' }, /* Up/Right */
- { M_3_PI_8, INFINITY, false, false, '3' }, /* Up */
- { M_3_PI_8, INFINITY, true, false, '3' }, /* Up */
- { M_PI_8, M_3_PI_8, true, false, '4' }, /* Up/Left */
- { 0.0, M_PI_8, true, false, '5' }, /* Left */
- { 0.0, M_PI_8, true, true, '5' }, /* Left */
- { M_PI_8, M_3_PI_8, true, true, '6' }, /* Down/Left */
- { M_3_PI_8, INFINITY, true, true, '7' }, /* Down */
- { M_3_PI_8, INFINITY, false, true, '7' }, /* Down */
- { M_PI_8, M_3_PI_8, false, true, '8' }, /* Down/Right */
- { 0.0, M_PI_8, false, true, '1' } /* Right */
-};
-
-#undef M_PI_8
-#undef M_3_PI_8
-
-static char gesturer_find_direction(Gesturer gesturer, int x, int y)
-{
- float dx = 0.0000000000001 + (x - gesturer->last_x);
- float dy = -(0.0000000000001 + (y - gesturer->last_y));
- float arc;
- bool x_neg = dx < 0;
- bool y_neg = dy < 0;
- int i;
-
- if( x_neg ) dx = -dx;
- if( y_neg ) dy = -dy;
- arc = atanf(dy/dx);
- for( i = 0; i < 12; ++i ) {
- if( directions[i].lower > arc || directions[i].upper <= arc )
- continue; /* Not within this entry */
- if( directions[i].x_neg != x_neg ||
- directions[i].y_neg != y_neg )
- continue; /* Signs not matching */
- return directions[i].direction;
- }
- LOG(("Erm, fell off the end of the direction calculator"));
- return 0; /* No direction */
-}
-
-/** Indicate to a gesturer that a new mouse sample is available.
- *
- * Call this to provide a new position sample to the gesturer.
- * If this is interesting, the gesturer will return a gesture tag
- * as per the gesture recogniser it was constructed with. Otherwise
- * it will return GESTURE_NONE which has the value -1.
- *
- * \param gesturer The gesturer to add the point to.
- * \param x The X coordinate of the mouse pointer.
- * \param y The Y coordinate of the mouse pointer.
- *
- * \return The gesture tag activated (or GESTURE_NONE if none)
- */
-int gesturer_add_point(Gesturer gesturer, int x, int y)
-{
- int distance = ((gesturer->last_x - x) * (gesturer->last_x - x)) +
- ((gesturer->last_y - y) * (gesturer->last_y - y));
- char last_direction = (gesturer->elements == 0) ? 0 :
- (gesturer->gesture[0]);
- char this_direction = gesturer_find_direction(gesturer, x, y);
- InternalGesture ig = gesturer->recogniser->gestures;
- int ret = GESTURE_NONE;
-
- if( distance < gesturer->recogniser->min_distance ) {
- gesturer->bored_count++;
- if( gesturer->elements &&
- (gesturer->bored_count >=
- gesturer->recogniser->max_nonmove) ) {
- LOG(("Bored now."));
- gesturer_clear_points(gesturer);
- }
- if( gesturer->elements &&
- gesturer->bored_count ==
- (gesturer->recogniser->max_nonmove >> 1)) {
- LOG(("Decided to look"));
- while( ig && ig->gesture_len <= gesturer->elements ) {
- if( strcmp(gesturer->gesture,
- ig->gesture) == 0 )
- ret = ig->gesture_tag;
- ig = ig->next;
- }
- }
- return ret; /* GESTURE_NONE or else a gesture found above */
- }
- /* We moved far enough that we care about the movement */
- gesturer->last_x = x;
- gesturer->last_y = y;
- gesturer->bored_count = 0;
- if( this_direction == last_direction ) {
- return GESTURE_NONE; /* Nothing */
- }
-
- /* Shunt the gesture one up */
- if( gesturer->elements ) {
- if( gesturer->elements == gesturer->nelements )
- gesturer->elements--;
- memmove(gesturer->gesture+1, gesturer->gesture,
- gesturer->elements);
- }
- gesturer->elements++;
- gesturer->gesture[0] = this_direction;
- LOG(("Gesture is currently: '%s'", gesturer->gesture));
- return GESTURE_NONE;
-}
Removed: trunk/netsurf/desktop/gesture_core.h
URL: http://source.netsurf-browser.org/trunk/netsurf/desktop/gesture_core.h?re...
==============================================================================
--- trunk/netsurf/desktop/gesture_core.h (original)
+++ trunk/netsurf/desktop/gesture_core.h (removed)
@@ -1,49 +1,0 @@
-/*
- * Copyright 2006 Daniel Silverstone <dsilvers(a)digital-scurf.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/** \file
- * Mouse gesture core (interface)
- */
-
-#ifndef _NETSURF_DESKTOP_GESTURE_CORE_H
-#define _NETSURF_DESKTOP_GESTURE_CORE_H_
-
-#include <stdbool.h>
-
-typedef struct _gesture_recogniser* GestureRecogniser;
-typedef struct _gesturer_state* Gesturer;
-
-GestureRecogniser gesture_recogniser_create(void);
-void gesture_recogniser_add(GestureRecogniser recog,
- const char* gesture_str, int gesture_tag);
-void gesture_recogniser_destroy(GestureRecogniser recog);
-void gesture_recogniser_set_distance_threshold(GestureRecogniser recog,
- int min_distance);
-void gesture_recogniser_set_count_threshold(GestureRecogniser recog,
- int max_nonmove);
-
-
-Gesturer gesturer_create(GestureRecogniser recog);
-Gesturer gesturer_clone(Gesturer gesturer);
-void gesturer_destroy(Gesturer gesturer);
-int gesturer_add_point(Gesturer gesturer, int x, int y);
-void gesturer_clear_points(Gesturer gesturer);
-
-#define GESTURE_NONE -1
-
-#endif
Modified: trunk/netsurf/gtk/gtk_scaffolding.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/gtk_scaffolding.c?rev...
==============================================================================
--- trunk/netsurf/gtk/gtk_scaffolding.c (original)
+++ trunk/netsurf/gtk/gtk_scaffolding.c Fri Sep 14 19:33:32 2007
@@ -31,7 +31,6 @@
#include "desktop/plotters.h"
#include "desktop/options.h"
#include "desktop/textinput.h"
-#include "desktop/gesture_core.h"
#include "gtk/gtk_gui.h"
#include "gtk/gtk_plotters.h"
#include "gtk/gtk_scaffolding.h"
Modified: trunk/netsurf/makefile
URL: http://source.netsurf-browser.org/trunk/netsurf/makefile?rev=3537&r1=3536...
==============================================================================
--- trunk/netsurf/makefile (original)
+++ trunk/netsurf/makefile Fri Sep 14 19:33:32 2007
@@ -33,7 +33,7 @@
OBJECTS_RISCOS = $(OBJECTS_COMMON) $(OBJECTS_IMAGE)
OBJECTS_RISCOS += browser.o frames.o history_core.o netsurf.o \
- selection.o textinput.o gesture_core.o # desktop/
+ selection.o textinput.o # desktop/
OBJECTS_RISCOS += 401login.o artworks.o assert.o awrender.o bitmap.o \
buffer.o cookies.o configure.o debugwin.o \
dialog.o download.o draw.o filetype.o font.o \
@@ -64,7 +64,7 @@
OBJECTS_GTK = $(OBJECTS_COMMON) $(OBJECTS_IMAGE)
OBJECTS_GTK += browser.o frames.o history_core.o netsurf.o \
- selection.o textinput.o gesture_core.o # desktop/
+ selection.o textinput.o # desktop/
OBJECTS_GTK += font_pango.o gtk_bitmap.o gtk_gui.o \
gtk_schedule.o gtk_thumbnail.o gtk_options.o \
gtk_plotters.o gtk_treeview.o gtk_scaffolding.o \
16 years, 2 months
r3536 rjek - /trunk/netsurf/image/mng.c
by netsurf@semichrome.net
Author: rjek
Date: Fri Sep 14 19:22:40 2007
New Revision: 3536
URL: http://source.netsurf-browser.org?rev=3536&view=rev
Log:
NetBSD doesn't have the timezone struct, either.
Modified:
trunk/netsurf/image/mng.c
Modified: trunk/netsurf/image/mng.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/mng.c?rev=3536&r1=3...
==============================================================================
--- trunk/netsurf/image/mng.c (original)
+++ trunk/netsurf/image/mng.c Fri Sep 14 19:22:40 2007
@@ -356,8 +356,8 @@
static bool start = true;
static time_t t0;
struct timeval tv;
-#if defined(__SVR4) && defined(__sun)
- /* Solaris doesn't have this structure, and ignores the second
+#if defined(__SVR4) && defined(__sun) || defined(__NetBSD__)
+ /* Solaris and NetBSD don't have this structure, and ignores the second
* parameter to gettimeofday()
*/
int tz;
16 years, 2 months