summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-11-09 17:29:15 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-11-09 17:29:15 +0000
commit6c0e77c643e96436d85aebb9195c83cb403c25fa (patch)
tree647f8a07a77abaf2cb1e692112f7777a3dd44de5 /src
parentf3c6e30f43c8e9feec891d68cc3eee99c3ef6264 (diff)
downloadlibhubbub-6c0e77c643e96436d85aebb9195c83cb403c25fa.tar.gz
libhubbub-6c0e77c643e96436d85aebb9195c83cb403c25fa.tar.bz2
Return errors from dictionary constructor/destructor.
Fix commentary copied from libcss svn path=/trunk/hubbub/; revision=5663
Diffstat (limited to 'src')
-rw-r--r--src/tokeniser/entities.c6
-rw-r--r--src/utils/dict.c39
-rw-r--r--src/utils/dict.h5
-rw-r--r--src/utils/parserutilserror.h4
4 files changed, 32 insertions, 22 deletions
diff --git a/src/tokeniser/entities.c b/src/tokeniser/entities.c
index 7cf1e56..23756a6 100644
--- a/src/tokeniser/entities.c
+++ b/src/tokeniser/entities.c
@@ -2171,9 +2171,9 @@ hubbub_error hubbub_entities_create(hubbub_alloc alloc, void *pw)
if (alloc == NULL)
return HUBBUB_BADPARM;
- dict = hubbub_dict_create(alloc, pw);
- if (dict == NULL)
- return HUBBUB_NOMEM;
+ error = hubbub_dict_create(alloc, pw, &dict);
+ if (error != HUBBUB_OK)
+ return error;
for (i = 0; i < sizeof(entities) / sizeof(entities[0]); i++) {
error = hubbub_dict_insert(dict, entities[i].name,
diff --git a/src/utils/dict.c b/src/utils/dict.c
index 5c40b19..7bd2df7 100644
--- a/src/utils/dict.c
+++ b/src/utils/dict.c
@@ -18,7 +18,7 @@ typedef struct hubbub_dict_node {
struct hubbub_dict_node *gt; /**< Subtree for data greater than
* split */
- const void *value; /**< Data for this node */
+ const void *value; /**< Data for this node */
} hubbub_dict_node;
/** Dictionary object */
@@ -41,40 +41,49 @@ static hubbub_dict_node *hubbub_dict_insert_internal(hubbub_dict *dict,
*
* \param alloc Memory (de)allocation function
* \param pw Pointer to client-specific private data (may be NULL)
- * \return Pointer to dictionary instance, or NULL on error
+ * \param dict Pointer to location to receive dictionary instance
+ * \return HUBBUB_OK on success,
+ * HUBBUB_BADPARM on bad parameters,
+ * HUBBUB_NOMEM on memory exhaustion
*/
-hubbub_dict *hubbub_dict_create(hubbub_alloc alloc, void *pw)
+hubbub_error hubbub_dict_create(hubbub_alloc alloc, void *pw,
+ hubbub_dict **dict)
{
- hubbub_dict *dict;
+ hubbub_dict *d;
- if (alloc == NULL)
- return NULL;
+ if (alloc == NULL || dict == NULL)
+ return HUBBUB_BADPARM;
- dict = alloc(NULL, sizeof(hubbub_dict), pw);
- if (dict == NULL)
- return NULL;
+ d = alloc(NULL, sizeof(hubbub_dict), pw);
+ if (d == NULL)
+ return HUBBUB_NOMEM;
+
+ d->dict = NULL;
- dict->dict = NULL;
+ d->alloc = alloc;
+ d->pw = pw;
- dict->alloc = alloc;
- dict->pw = pw;
+ *dict = d;
- return dict;
+ return HUBBUB_OK;
}
/**
* Destroy a dictionary
*
* \param dict Dictionary to destroy
+ * \return HUBBUB_OK on success, appropriate error otherwise
*/
-void hubbub_dict_destroy(hubbub_dict *dict)
+hubbub_error hubbub_dict_destroy(hubbub_dict *dict)
{
if (dict == NULL)
- return;
+ return HUBBUB_BADPARM;
hubbub_dict_destroy_internal(dict, dict->dict);
dict->alloc(dict, 0, dict->pw);
+
+ return HUBBUB_OK;
}
/**
diff --git a/src/utils/dict.h b/src/utils/dict.h
index 2cde01d..4ea4440 100644
--- a/src/utils/dict.h
+++ b/src/utils/dict.h
@@ -16,9 +16,10 @@
typedef struct hubbub_dict hubbub_dict;
/* Create a dictionary */
-hubbub_dict *hubbub_dict_create(hubbub_alloc alloc, void *pw);
+hubbub_error hubbub_dict_create(hubbub_alloc alloc, void *pw,
+ hubbub_dict **dict);
/* Destroy a dictionary */
-void hubbub_dict_destroy(hubbub_dict *dict);
+hubbub_error hubbub_dict_destroy(hubbub_dict *dict);
/* Insert a key-value pair into a dictionary */
hubbub_error hubbub_dict_insert(hubbub_dict *dict, const char *key,
diff --git a/src/utils/parserutilserror.h b/src/utils/parserutilserror.h
index 3e05524..9e0c8f5 100644
--- a/src/utils/parserutilserror.h
+++ b/src/utils/parserutilserror.h
@@ -13,10 +13,10 @@
#include <hubbub/errors.h>
/**
- * Convert a ParserUtils error into a LibCSS error
+ * Convert a ParserUtils error into a Hubbub error
*
* \param error The ParserUtils error to convert
- * \return The corresponding LibCSS error
+ * \return The corresponding Hubbub error
*/
static inline hubbub_error hubbub_error_from_parserutils_error(
parserutils_error error)