From 6c0e77c643e96436d85aebb9195c83cb403c25fa Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 9 Nov 2008 17:29:15 +0000 Subject: Return errors from dictionary constructor/destructor. Fix commentary copied from libcss svn path=/trunk/hubbub/; revision=5663 --- src/utils/dict.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'src/utils/dict.c') 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; } /** -- cgit v1.2.3