summaryrefslogtreecommitdiff
path: root/src/utils/dict.c
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/utils/dict.c
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/utils/dict.c')
-rw-r--r--src/utils/dict.c39
1 files changed, 24 insertions, 15 deletions
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;
}
/**