return 0;
}
-KHASH_INIT (ucl_hash_node, const ucl_object_t *, struct ucl_hash_elt, 1,
+KHASH_INIT (ucl_hash_node, const ucl_object_t *, struct ucl_hash_elt *, 1,
ucl_hash_func, ucl_hash_equal)
static inline uint32_t
return false;
}
-KHASH_INIT (ucl_hash_caseless_node, const ucl_object_t *, struct ucl_hash_elt, 1,
+KHASH_INIT (ucl_hash_caseless_node, const ucl_object_t *, struct ucl_hash_elt *, 1,
ucl_hash_caseless_func, ucl_hash_caseless_equal)
ucl_hash_t*
void ucl_hash_destroy (ucl_hash_t* hashlin, ucl_hash_free_func func)
{
- const ucl_object_t *cur, *tmp;
if (hashlin == NULL) {
return;
khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *)
hashlin->hash;
khiter_t k;
+ const ucl_object_t *cur, *tmp;
for (k = kh_begin (h); k != kh_end (h); ++k) {
if (kh_exist (h, k)) {
- cur = (kh_value (h, k)).obj;
+ cur = (kh_value (h, k))->obj;
while (cur != NULL) {
tmp = cur->next;
func (__DECONST (ucl_object_t *, cur));
kh_destroy (ucl_hash_node, h);
}
+ struct ucl_hash_elt *cur, *tmp;
+
+ DL_FOREACH_SAFE(hashlin->head, cur, tmp) {
+ UCL_FREE(sizeof(*cur), cur);
+ }
+
UCL_FREE (sizeof (*hashlin), hashlin);
}
{
khiter_t k;
int ret;
- struct ucl_hash_elt *elt;
+ struct ucl_hash_elt **pelt, *elt;
if (hashlin == NULL) {
return false;
hashlin->hash;
k = kh_put (ucl_hash_caseless_node, h, obj, &ret);
if (ret > 0) {
- elt = &kh_value (h, k);
+ elt = UCL_ALLOC(sizeof(*elt));
+ pelt = &kh_value (h, k);
+ *pelt = elt;
DL_APPEND(hashlin->head, elt);
elt->obj = obj;
}
+ else if (ret < 0) {
+ goto e0;
+ }
}
else {
khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *)
hashlin->hash;
k = kh_put (ucl_hash_node, h, obj, &ret);
if (ret > 0) {
- elt = &kh_value (h, k);
+ elt = UCL_ALLOC(sizeof(*elt));
+ pelt = &kh_value (h, k);
+ *pelt = elt;
DL_APPEND(hashlin->head, elt);
elt->obj = obj;
} else if (ret < 0) {
{
khiter_t k;
int ret;
- struct ucl_hash_elt elt, *pelt;
+ struct ucl_hash_elt *elt, *nelt;
if (hashlin == NULL) {
return;
hashlin->hash;
k = kh_put (ucl_hash_caseless_node, h, old, &ret);
if (ret == 0) {
- elt = kh_value (h, k);
+ elt = kh_value(h, k);
kh_del (ucl_hash_caseless_node, h, k);
k = kh_put (ucl_hash_caseless_node, h, new, &ret);
- pelt = &kh_value (h, k);
- pelt->obj = new;
- DL_REPLACE_ELEM(hashlin->head, &elt, pelt);
+ nelt = UCL_ALLOC(sizeof(*nelt));
+ nelt->obj = new;
+ kh_value(h, k) = nelt;
+ DL_REPLACE_ELEM(hashlin->head, elt, nelt);
+ UCL_FREE(sizeof(*elt), elt);
}
}
else {
elt = kh_value (h, k);
kh_del (ucl_hash_node, h, k);
k = kh_put (ucl_hash_node, h, new, &ret);
- pelt = &kh_value (h, k);
- pelt->obj = new;
- DL_REPLACE_ELEM(hashlin->head, &elt, pelt);
+ nelt = UCL_ALLOC(sizeof(*nelt));
+ nelt->obj = new;
+ kh_value(h, k) = nelt;
+ DL_REPLACE_ELEM(hashlin->head, elt, nelt);
+ UCL_FREE(sizeof(*elt), elt);
}
}
}
k = kh_get (ucl_hash_caseless_node, h, &search);
if (k != kh_end (h)) {
- elt = &kh_value (h, k);
+ elt = kh_value (h, k);
ret = elt->obj;
}
}
hashlin->hash;
k = kh_get (ucl_hash_node, h, &search);
if (k != kh_end (h)) {
- elt = &kh_value (h, k);
+ elt = kh_value (h, k);
ret = elt->obj;
}
}
k = kh_get (ucl_hash_caseless_node, h, obj);
if (k != kh_end (h)) {
- elt = &kh_value (h, k);
+ elt = kh_value (h, k);
DL_DELETE(hashlin->head, elt);
kh_del (ucl_hash_caseless_node, h, k);
+ UCL_FREE(sizeof(*elt), elt);
}
}
else {
hashlin->hash;
k = kh_get (ucl_hash_node, h, obj);
if (k != kh_end (h)) {
- elt = &kh_value (h, k);
+ elt = kh_value (h, k);
DL_DELETE(hashlin->head, elt);
kh_del (ucl_hash_node, h, k);
+ UCL_FREE(sizeof(*elt), elt);
}
}
}