Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Import libucl 0.7.2
Baptiste Daroussin committed 11 years ago
commit 134801c6dd9216c1cb13430278413cea78397869
parent 4e92c66
11 files changed +75 -26
modified external/libucl/ChangeLog.md
@@ -28,3 +28,7 @@
### Libucl 0.7.1

- Added safe iterators API
+

+
### Libucl 0.7.2
+

+
- Fixed serious bugs in schema and arrays iteration
modified external/libucl/README.md
@@ -156,10 +156,10 @@ is converted to the following object:
```nginx
section {
	blah {
-
			key = value;
+
		key = value;
	}
	foo {
-
			key = value;
+
		key = value;
	}
}
```
@@ -177,9 +177,9 @@ is presented as:
```nginx    
section {
	blah {
-
			foo {
-
					key = value;
-
			}
+
		foo {
+
			key = value;
+
		}
	}
}
```
@@ -219,8 +219,8 @@ UCL supports external macros both multiline and single line ones:
```nginx
.macro "sometext";
.macro {
-
     Some long text
-
     ....
+
    Some long text
+
    ....
};
```

modified external/libucl/configure.ac
@@ -1,7 +1,7 @@
m4_define([maj_ver], [0])
m4_define([med_ver], [7])
-
m4_define([min_ver], [1])
-
m4_define([so_version], [5:0:0])
+
m4_define([min_ver], [2])
+
m4_define([so_version], [5:0:1])
m4_define([ucl_version], [maj_ver.med_ver.min_ver])

AC_INIT([libucl],[ucl_version],[https://github.com/vstakhov/libucl],[libucl])
modified external/libucl/src/ucl_emitter_utils.c
@@ -289,6 +289,7 @@ ucl_fd_append_character (unsigned char c, size_t len, void *ud)
		else {
			memset (buf, c, len);
			if (write (fd, buf, len) == -1) {
+
				free(buf);
				return -1;
			}
			free (buf);
modified external/libucl/src/ucl_hash.c
@@ -123,6 +123,10 @@ void ucl_hash_destroy (ucl_hash_t* hashlin, ucl_hash_free_func *func)
{
	const ucl_object_t *cur, *tmp;

+
	if (hashlin == NULL) {
+
		return;
+
	}
+

	if (func != NULL) {
		/* Iterate over the hash first */
		khash_t(ucl_hash_node) *h = (khash_t(ucl_hash_node) *)
@@ -164,6 +168,10 @@ ucl_hash_insert (ucl_hash_t* hashlin, const ucl_object_t *obj,
	int ret;
	struct ucl_hash_elt *elt;

+
	if (hashlin == NULL) {
+
		return;
+
	}
+

	if (hashlin->caseless) {
		khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *)
				hashlin->hash;
@@ -195,6 +203,10 @@ void ucl_hash_replace (ucl_hash_t* hashlin, const ucl_object_t *old,
	int ret;
	struct ucl_hash_elt elt, *pelt;

+
	if (hashlin == NULL) {
+
		return;
+
	}
+

	if (hashlin->caseless) {
		khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *)
				hashlin->hash;
@@ -236,8 +248,9 @@ ucl_hash_iterate (ucl_hash_t *hashlin, ucl_hash_iter_t *iter)
	struct ucl_hash_real_iter *it = (struct ucl_hash_real_iter *)(*iter);
	const ucl_object_t *ret = NULL;

-
	if (hashlin == NULL)
+
	if (hashlin == NULL) {
		return NULL;
+
	}

	if (it == NULL) {
		it = UCL_ALLOC (sizeof (*it));
@@ -250,6 +263,8 @@ ucl_hash_iterate (ucl_hash_t *hashlin, ucl_hash_iter_t *iter)
	}
	else {
		UCL_FREE (sizeof (*it), it);
+
		*iter = NULL;
+
		return NULL;
	}

	*iter = it;
@@ -277,6 +292,10 @@ ucl_hash_search (ucl_hash_t* hashlin, const char *key, unsigned keylen)
	search.key = key;
	search.keylen = keylen;

+
	if (hashlin == NULL) {
+
		return NULL;
+
	}
+

	if (hashlin->caseless) {
		khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *)
						hashlin->hash;
@@ -306,6 +325,10 @@ ucl_hash_delete (ucl_hash_t* hashlin, const ucl_object_t *obj)
	khiter_t k;
	struct ucl_hash_elt *elt;

+
	if (hashlin == NULL) {
+
		return;
+
	}
+

	if (hashlin->caseless) {
		khash_t(ucl_hash_caseless_node) *h = (khash_t(ucl_hash_caseless_node) *)
			hashlin->hash;
modified external/libucl/src/ucl_parser.c
@@ -1364,6 +1364,10 @@ ucl_get_value_object (struct ucl_parser *parser)
{
	ucl_object_t *t, *obj = NULL;

+
	if (parser == NULL || parser->stack == NULL || parser->stack->obj == NULL) {
+
		return NULL;
+
	}
+

	if (parser->stack->obj->type == UCL_ARRAY) {
		/* Object must be allocated */
		obj = ucl_object_new_full (UCL_NULL, parser->chunks->priority);
modified external/libucl/src/ucl_schema.c
@@ -525,15 +525,16 @@ ucl_schema_validate_array (const ucl_object_t *schema,
	ucl_object_iter_t iter = NULL, piter = NULL;
	bool ret = true, allow_additional = true, need_unique = false;
	int64_t minmax;
+
	unsigned int idx = 0;

	while (ret && (elt = ucl_iterate_object (schema, &iter, true)) != NULL) {
		if (strcmp (ucl_object_key (elt), "items") == 0) {
			if (elt->type == UCL_ARRAY) {
-
				found = obj->value.av;
+
				found = ucl_array_head (obj);
				while (ret && (it = ucl_iterate_object (elt, &piter, true)) != NULL) {
					if (found) {
						ret = ucl_schema_validate (it, found, false, err, root);
-
						found = found->next;
+
						found = ucl_array_find_index (obj, ++idx);
					}
				}
				if (found != NULL) {
@@ -608,14 +609,14 @@ ucl_schema_validate_array (const ucl_object_t *schema,
					ret = false;
				}
				else if (additional_schema != NULL) {
-
					elt = first_unvalidated;
+
					elt = ucl_array_find_index (obj, idx);
					while (elt) {
						if (!ucl_schema_validate (additional_schema, elt, false,
								err, root)) {
							ret = false;
							break;
						}
-
						elt = elt->next;
+
						elt = ucl_array_find_index (obj, idx ++);
					}
				}
			}
@@ -741,7 +742,7 @@ ucl_schema_resolve_ref_component (const ucl_object_t *cur,
					"reference %s is invalid, invalid item number", refc);
			return NULL;
		}
-
		res = cur->value.av;
+
		res = ucl_array_head (cur);
		i = 0;
		while (res != NULL) {
			if (i == num) {
modified external/libucl/src/ucl_util.c
@@ -26,7 +26,9 @@
#include "ucl_chartable.h"
#include "kvec.h"

+
#ifndef _WIN32
#include <glob.h>
+
#endif

#ifdef HAVE_LIBGEN_H
#include <libgen.h> /* For dirname */
@@ -74,6 +76,11 @@ typedef kvec_t(ucl_object_t *) ucl_array_t;
#define MAP_FAILED      ((void *) -1)
#endif

+
#ifdef _WIN32
+
#include <limits.h>
+
#define NBBY CHAR_BIT
+
#endif
+

static void *ucl_mmap(char *addr, size_t length, int prot, int access, int fd, off_t offset)
{
	void *map = NULL;
@@ -960,10 +967,10 @@ ucl_include_file (const unsigned char *data, size_t len,
	const unsigned char *p = data, *end = data + len;
	bool need_glob = false;
	int cnt = 0;
-
	glob_t globbuf;
	char glob_pattern[PATH_MAX];
	size_t i;

+
#ifndef _WIN32
	if (!allow_glob) {
		return ucl_include_file_single (data, len, parser, check_signature,
			must_exist, priority);
@@ -978,6 +985,7 @@ ucl_include_file (const unsigned char *data, size_t len,
			p ++;
		}
		if (need_glob) {
+
			glob_t globbuf;
			memset (&globbuf, 0, sizeof (globbuf));
			ucl_strlcpy (glob_pattern, (const char *)data, sizeof (glob_pattern));
			if (glob (glob_pattern, 0, NULL, &globbuf) != 0) {
@@ -1005,7 +1013,13 @@ ucl_include_file (const unsigned char *data, size_t len,
				must_exist, priority);
		}
	}
-

+
#else
+
	/* Win32 compilers do not support globbing. Therefore, for Win32,
+
	   treat allow_glob/need_glob as a NOOP and just return */
+
	return ucl_include_file_single (data, len, parser, check_signature,
+
		must_exist, priority);
+
#endif
+
	
	return true;
}

@@ -2447,7 +2461,7 @@ ucl_object_compare (const ucl_object_t *o1, const ucl_object_t *o2)

	switch (o1->type) {
	case UCL_STRING:
-
		if (o1->len == o2->len) {
+
		if (o1->len == o2->len && o1->len > 0) {
			ret = strcmp (ucl_object_tostring(o1), ucl_object_tostring(o2));
		}
		else {
@@ -2463,9 +2477,9 @@ ucl_object_compare (const ucl_object_t *o1, const ucl_object_t *o2)
		ret = ucl_object_toboolean (o1) - ucl_object_toboolean (o2);
		break;
	case UCL_ARRAY:
-
		if (o1->len == o2->len) {
+
		if (o1->len == o2->len && o1->len > 0) {
			UCL_ARRAY_GET (vec1, o1);
-
			UCL_ARRAY_GET (vec2, o1);
+
			UCL_ARRAY_GET (vec2, o2);
			unsigned i;

			/* Compare all elements in both arrays */
@@ -2492,7 +2506,7 @@ ucl_object_compare (const ucl_object_t *o1, const ucl_object_t *o2)
		}
		break;
	case UCL_OBJECT:
-
		if (o1->len == o2->len) {
+
		if (o1->len == o2->len && o1->len > 0) {
			while ((it1 = ucl_iterate_object (o1, &iter, true)) != NULL) {
				it2 = ucl_object_find_key (o2, ucl_object_key (it1));
				if (it2 == NULL) {
modified external/libucl/tests/schema.test
@@ -5,5 +5,5 @@ rm /tmp/_ucl_test_schema.out ||true
for i in ${TEST_DIR}/schema/*.json ; do
	_name=`basename $i`
	printf "running schema test suite $_name... "
-
	$PROG >> /tmp/_ucl_test_schema.out < $i && ( echo "OK" ) || ( echo "Fail" )
+
	$PROG >> /tmp/_ucl_test_schema.out < $i && ( echo "OK" ) || ( echo "Fail" ; exit 1 )
done
modified external/libucl/tests/test_schema.c
@@ -79,6 +79,8 @@ perform_test (const ucl_object_t *schema, const ucl_object_t *obj,
				ucl_object_tostring (description),
				ucl_object_toboolean (valid) ? "valid" : "invalid",
						err->msg);
+
		fprintf (stdout, "%s\n", ucl_object_emit (data, UCL_EMIT_CONFIG));
+
		fprintf (stdout, "%s\n", ucl_object_emit (schema, UCL_EMIT_CONFIG));
		return false;
	}

modified external/libucl/uthash/utstring.h
@@ -39,7 +39,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdarg.h>

#ifndef oom
-
#define oom() exit(-1)
+
#define oom abort
#endif

typedef struct {
@@ -54,8 +54,8 @@ do { \
  if (((s)->n - (s)->i) < (size_t)(amt)) {                 \
     (s)->d = (char*)realloc((s)->d, (s)->n + amt);        \
     if ((s)->d == NULL) oom();                            \
-
     (s)->n += amt;                                        \
-
     if ((s)->pd) *((s)->pd) = (s)->d;                     \
+
     else {(s)->n += amt;                                  \
+
     if ((s)->pd) *((s)->pd) = (s)->d;}                    \
  }                                                        \
} while(0)

@@ -82,7 +82,7 @@ do { \
do {                                                       \
   s = (UT_string*)calloc(1, sizeof(UT_string));          \
   if (!s) oom();                                          \
-
   utstring_init(s);                                       \
+
   else utstring_init(s);                                  \
} while(0)

#define utstring_renew(s)                                  \