Lines Matching defs:obj

137 typedef void (*ucl_object_dtor) (ucl_object_t *obj);
138 static void ucl_object_free_internal (ucl_object_t *obj, bool allow_rec,
140 static void ucl_object_dtor_unref (ucl_object_t *obj);
143 ucl_object_dtor_free (ucl_object_t *obj)
145 if (obj->trash_stack[UCL_TRASH_KEY] != NULL) {
146 UCL_FREE (obj->hh.keylen, obj->trash_stack[UCL_TRASH_KEY]);
148 if (obj->trash_stack[UCL_TRASH_VALUE] != NULL) {
149 UCL_FREE (obj->len, obj->trash_stack[UCL_TRASH_VALUE]);
151 UCL_FREE (sizeof (ucl_object_t), obj);
160 ucl_object_dtor_unref_single (ucl_object_t *obj)
162 if (obj != NULL) {
164 unsigned int rc = __sync_sub_and_fetch (&obj->ref, 1);
167 if (--obj->ref == 0) {
169 ucl_object_free_internal (obj, false, ucl_object_dtor_unref);
175 ucl_object_dtor_unref (ucl_object_t *obj)
177 if (obj->ref == 0) {
178 ucl_object_dtor_free (obj);
182 ucl_object_dtor_unref_single (obj);
187 ucl_object_free_internal (ucl_object_t *obj, bool allow_rec, ucl_object_dtor dtor)
191 while (obj != NULL) {
192 if (obj->type == UCL_ARRAY) {
193 sub = obj->value.av;
200 else if (obj->type == UCL_OBJECT) {
201 if (obj->value.ov != NULL) {
202 ucl_hash_destroy (obj->value.ov, (ucl_hash_free_func *)dtor);
205 tmp = obj->next;
206 dtor (obj);
207 obj = tmp;
216 ucl_object_free (ucl_object_t *obj)
218 ucl_object_free_internal (obj, true, ucl_object_dtor_free);
327 ucl_copy_key_trash (const ucl_object_t *obj)
331 if (obj == NULL) {
334 if (obj->trash_stack[UCL_TRASH_KEY] == NULL && obj->key != NULL) {
335 deconst = __DECONST (ucl_object_t *, obj);
336 deconst->trash_stack[UCL_TRASH_KEY] = malloc (obj->keylen + 1);
338 memcpy (deconst->trash_stack[UCL_TRASH_KEY], obj->key, obj->keylen);
339 deconst->trash_stack[UCL_TRASH_KEY][obj->keylen] = '\0';
341 deconst->key = obj->trash_stack[UCL_TRASH_KEY];
345 return obj->trash_stack[UCL_TRASH_KEY];
349 ucl_copy_value_trash (const ucl_object_t *obj)
353 if (obj == NULL) {
356 if (obj->trash_stack[UCL_TRASH_VALUE] == NULL) {
357 deconst = __DECONST (ucl_object_t *, obj);
358 if (obj->type == UCL_STRING) {
361 deconst->trash_stack[UCL_TRASH_VALUE] = malloc (obj->len + 1);
363 memcpy (deconst->trash_stack[UCL_TRASH_VALUE], obj->value.sv, obj->len);
364 deconst->trash_stack[UCL_TRASH_VALUE][obj->len] = '\0';
365 deconst->value.sv = obj->trash_stack[UCL_TRASH_VALUE];
370 deconst->trash_stack[UCL_TRASH_VALUE] = ucl_object_emit_single_json (obj);
371 deconst->len = strlen (obj->trash_stack[UCL_TRASH_VALUE]);
375 return obj->trash_stack[UCL_TRASH_VALUE];
1018 ucl_object_t *obj;
1027 obj = ucl_object_new ();
1028 if (obj) {
1052 obj->type = UCL_STRING;
1099 obj->value.sv = dst;
1100 obj->trash_stack[UCL_TRASH_VALUE] = dst;
1101 obj->len = escaped_len;
1108 obj->value.sv = dst;
1109 obj->trash_stack[UCL_TRASH_VALUE] = dst;
1110 obj->len = end - start;
1116 if (!ucl_maybe_parse_boolean (obj, dst, obj->len) && (flags & UCL_STRING_PARSE_NUMBER)) {
1117 ucl_maybe_parse_number (obj, dst, dst + obj->len, &pos,
1124 ucl_maybe_parse_number (obj, dst, dst + obj->len, &pos,
1132 return obj;
1314 ucl_object_find_keyl (const ucl_object_t *obj, const char *key, size_t klen)
1319 if (obj == NULL || obj->type != UCL_OBJECT || key == NULL) {
1325 ret = ucl_hash_search_obj (obj->value.ov, &srch);
1331 ucl_object_find_key (const ucl_object_t *obj, const char *key)
1336 return ucl_object_find_keyl (obj, key, strlen(key));
1340 ucl_iterate_object (const ucl_object_t *obj, ucl_object_iter_t *iter, bool expand_values)
1344 if (obj == NULL || iter == NULL) {
1349 switch (obj->type) {
1351 return (const ucl_object_t*)ucl_hash_iterate (obj->value.ov, iter);
1356 elt = obj->value.av;
1361 else if (elt == obj->value.av) {
1364 *iter = elt->next ? elt->next : obj->value.av;
1374 elt = obj;
1379 else if (elt == obj) {
1382 *iter = __DECONST (void *, elt->next ? elt->next : obj);
1469 ucl_object_type (const ucl_object_t *obj)
1471 return obj->type;
1489 ucl_object_t *obj;
1491 obj = ucl_object_new ();
1492 if (obj != NULL) {
1493 obj->type = UCL_INT;
1494 obj->value.iv = iv;
1497 return obj;
1503 ucl_object_t *obj;
1505 obj = ucl_object_new ();
1506 if (obj != NULL) {
1507 obj->type = UCL_FLOAT;
1508 obj->value.dv = dv;
1511 return obj;
1517 ucl_object_t *obj;
1519 obj = ucl_object_new ();
1520 if (obj != NULL) {
1521 obj->type = UCL_BOOLEAN;
1522 obj->value.iv = bv;
1525 return obj;
1683 ucl_object_todouble_safe (const ucl_object_t *obj, double *target)
1685 if (obj == NULL || target == NULL) {
1688 switch (obj->type) {
1690 *target = obj->value.iv; /* Probaly could cause overflow */
1694 *target = obj->value.dv;
1704 ucl_object_todouble (const ucl_object_t *obj)
1708 ucl_object_todouble_safe (obj, &result);
1713 ucl_object_toint_safe (const ucl_object_t *obj, int64_t *target)
1715 if (obj == NULL || target == NULL) {
1718 switch (obj->type) {
1720 *target = obj->value.iv;
1724 *target = obj->value.dv; /* Loosing of decimal points */
1734 ucl_object_toint (const ucl_object_t *obj)
1738 ucl_object_toint_safe (obj, &result);
1743 ucl_object_toboolean_safe (const ucl_object_t *obj, bool *target)
1745 if (obj == NULL || target == NULL) {
1748 switch (obj->type) {
1750 *target = (obj->value.iv == true);
1760 ucl_object_toboolean (const ucl_object_t *obj)
1764 ucl_object_toboolean_safe (obj, &result);
1769 ucl_object_tostring_safe (const ucl_object_t *obj, const char **target)
1771 if (obj == NULL || target == NULL) {
1775 switch (obj->type) {
1777 *target = ucl_copy_value_trash (obj);
1787 ucl_object_tostring (const ucl_object_t *obj)
1791 ucl_object_tostring_safe (obj, &result);
1796 ucl_object_tostring_forced (const ucl_object_t *obj)
1798 return ucl_copy_value_trash (obj);
1802 ucl_object_tolstring_safe (const ucl_object_t *obj, const char **target, size_t *tlen)
1804 if (obj == NULL || target == NULL) {
1807 switch (obj->type) {
1809 *target = obj->value.sv;
1811 *tlen = obj->len;
1822 ucl_object_tolstring (const ucl_object_t *obj, size_t *tlen)
1826 ucl_object_tolstring_safe (obj, &result, tlen);
1831 ucl_object_key (const ucl_object_t *obj)
1833 return ucl_copy_key_trash (obj);
1837 ucl_object_keyl (const ucl_object_t *obj, size_t *len)
1839 if (len == NULL || obj == NULL) {
1842 *len = obj->keylen;
1843 return obj->key;
1847 ucl_object_ref (const ucl_object_t *obj)
1851 if (obj != NULL) {
1852 res = __DECONST (ucl_object_t *, obj);
1863 ucl_object_unref (ucl_object_t *obj)
1865 if (obj != NULL) {
1867 unsigned int rc = __sync_sub_and_fetch (&obj->ref, 1);
1870 if (--obj->ref == 0) {
1872 ucl_object_free_internal (obj, true, ucl_object_dtor_unref);