#define ucl_iterate_object ucl_object_iterate
#define ucl_object_iterate(ob, it, ev) ucl_object_iterate_with_error((ob), (it), (ev), NULL)
+/**
+ * Free resources associated with an inline iterator when iteration is
+ * abandoned before completion. Only needed for UCL_OBJECT iteration where
+ * internal heap state is allocated. Safe to call with a NULL iterator or
+ * on non-object types.
+ *
+ * Example usage:
+ * ucl_object_iter_t it = NULL;
+ * while ((cur = ucl_iterate_object(obj, &it, true))) {
+ * if (error) {
+ * ucl_object_iterate_end(obj, &it);
+ * return;
+ * }
+ * }
+ *
+ * @param obj the object being iterated
+ * @param iter pointer to the iterator to free
+ */
+UCL_EXTERN void ucl_object_iterate_end(const ucl_object_t *obj,
+ ucl_object_iter_t *iter);
+
+#define ucl_iterate_object_end ucl_object_iterate_end
+
/**
* Create new safe iterator for the specified object
* @param obj object to iterate
return it->cur != NULL;
}
+void ucl_hash_iterate_free(ucl_hash_iter_t iter)
+{
+ struct ucl_hash_real_iter *it = (struct ucl_hash_real_iter *) (iter);
+
+ if (it != NULL) {
+ UCL_FREE(sizeof(*it), it);
+ }
+}
+
const ucl_object_t *
ucl_hash_search(ucl_hash_t *hashlin, const char *key, unsigned keylen)
*/
bool ucl_hash_iter_has_next (ucl_hash_t *hashlin, ucl_hash_iter_t iter);
+/**
+ * Free resources associated with an iterator when iteration is abandoned
+ * before completion. Safe to call with NULL iterator.
+ */
+void ucl_hash_iterate_free(ucl_hash_iter_t iter);
+
/**
* Reserves space in hash
* @return true on sucess, false on failure (e.g. ENOMEM)
return NULL;
}
+void ucl_object_iterate_end(const ucl_object_t *obj, ucl_object_iter_t *iter)
+{
+ if (iter == NULL || *iter == NULL) {
+ return;
+ }
+
+ if (obj != NULL && obj->type == UCL_OBJECT) {
+ ucl_hash_iterate_free(*iter);
+ }
+
+ *iter = NULL;
+}
+
enum ucl_safe_iter_flags {
UCL_ITERATE_FLAG_UNDEFINED = 0,
UCL_ITERATE_FLAG_INSIDE_ARRAY,