From cfad5e411a897bd30bf9f6014e58a25f1ecb69da Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 9 Nov 2008 20:06:20 +0000 Subject: Return errors from dictionary constructor/destructor svn path=/trunk/libparserutils/; revision=5673 --- src/utils/dict.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'src/utils') diff --git a/src/utils/dict.c b/src/utils/dict.c index 8b519ba..303389c 100644 --- a/src/utils/dict.c +++ b/src/utils/dict.c @@ -36,37 +36,46 @@ static void dict_del(void *key, void *value, void *pw); * \param pw Pointer to client-specific private data * \return Pointer to dictionary instance, or NULL on memory exhaustion */ -parserutils_dict *parserutils_dict_create(parserutils_alloc alloc, void *pw) +parserutils_error parserutils_dict_create(parserutils_alloc alloc, void *pw, + parserutils_dict **dict) { - parserutils_dict *dict; + parserutils_dict *d; - if (alloc == NULL) - return NULL; + if (alloc == NULL || dict == NULL) + return PARSERUTILS_BADPARM; - dict = alloc(NULL, sizeof(parserutils_dict), pw); - if (dict == NULL) - return NULL; + d = alloc(NULL, sizeof(parserutils_dict), pw); + if (d == NULL) + return PARSERUTILS_NOMEM; - memset(dict->table, 0, TABLE_SIZE * sizeof(parserutils_rbtree *)); + memset(d->table, 0, TABLE_SIZE * sizeof(parserutils_rbtree *)); - dict->alloc = alloc; - dict->pw = pw; + d->alloc = alloc; + d->pw = pw; - return dict; + *dict = d; + + return PARSERUTILS_OK; } /** * Destroy a dictionary * * \param dict The dictionary instance to destroy + * \return CSS_OK on success, appropriate error otherwise */ -void parserutils_dict_destroy(parserutils_dict *dict) +parserutils_error parserutils_dict_destroy(parserutils_dict *dict) { + if (dict == NULL) + return PARSERUTILS_BADPARM; + for (int i = 0; i < TABLE_SIZE; i++) { parserutils_rbtree_destroy(dict->table[i], dict_del, dict); } dict->alloc(dict, 0, dict->pw); + + return PARSERUTILS_OK; } /** -- cgit v1.2.3