Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Update with latest libucl
Baptiste Daroussin committed 11 years ago
commit c2196d41753c571a128ab7d1f93f133d48b8cc08
parent c2cea0b
8 files changed +114 -23
modified external/libucl/configure.ac
@@ -1,7 +1,7 @@
m4_define([maj_ver], [0])
m4_define([med_ver], [5])
-
m4_define([min_ver], [3])
-
m4_define([so_version], [2:0:2])
+
m4_define([min_ver], [4])
+
m4_define([so_version], [2:1:2])
m4_define([ucl_version], [maj_ver.med_ver.min_ver])

AC_INIT([libucl],[ucl_version],[https://github.com/vstakhov/libucl],[libucl])
modified external/libucl/include/ucl.h
@@ -171,9 +171,11 @@ typedef enum ucl_string_flags {
 * Basic flags for an object
 */
typedef enum ucl_object_flags {
-
	UCL_OBJECT_ALLOCATED_KEY = 1, /**< An object has key allocated internally */
-
	UCL_OBJECT_ALLOCATED_VALUE = 2, /**< An object has a string value allocated internally */
-
	UCL_OBJECT_NEED_KEY_ESCAPE = 4 /**< The key of an object need to be escaped on output */
+
	UCL_OBJECT_ALLOCATED_KEY = 0x1, /**< An object has key allocated internally */
+
	UCL_OBJECT_ALLOCATED_VALUE = 0x2, /**< An object has a string value allocated internally */
+
	UCL_OBJECT_NEED_KEY_ESCAPE = 0x4, /**< The key of an object need to be escaped on output */
+
	UCL_OBJECT_EPHEMERAL = 0x8, /**< Temporary object that does not need to be freed really */
+
	UCL_OBJECT_MULTILINE = 0x16 /**< String should be displayed as multiline string */
} ucl_object_flags_t;

/**
modified external/libucl/src/ucl_emitter.c
@@ -131,7 +131,7 @@ ucl_emitter_print_key (bool print_key, struct ucl_emitter_context *ctx,
		}
	}
	else if (ctx->id == UCL_EMIT_YAML) {
-
		if (obj->keylen > 0 && obj->flags & UCL_OBJECT_NEED_KEY_ESCAPE) {
+
		if (obj->keylen > 0 && (obj->flags & UCL_OBJECT_NEED_KEY_ESCAPE)) {
			ucl_elt_string_write_json (obj->key, obj->keylen, ctx);
		}
		else if (obj->keylen > 0) {
@@ -398,7 +398,12 @@ ucl_emitter_common_elt (struct ucl_emitter_context *ctx,
		break;
	case UCL_STRING:
		ucl_emitter_print_key (print_key, ctx, obj, compact);
-
		ucl_elt_string_write_json (obj->value.sv, obj->len, ctx);
+
		if (ctx->id == UCL_EMIT_CONFIG && ucl_maybe_long_string (obj)) {
+
			ucl_elt_string_write_multiline (obj->value.sv, obj->len, ctx);
+
		}
+
		else {
+
			ucl_elt_string_write_json (obj->value.sv, obj->len, ctx);
+
		}
		ucl_emitter_finish_object (ctx, obj, compact, !print_key);
		break;
	case UCL_NULL:
modified external/libucl/src/ucl_emitter_utils.c
@@ -138,6 +138,17 @@ ucl_elt_string_write_json (const char *str, size_t size,
	func->ucl_emitter_append_character ('"', 1, func->ud);
}

+
void
+
ucl_elt_string_write_multiline (const char *str, size_t size,
+
		struct ucl_emitter_context *ctx)
+
{
+
	const struct ucl_emitter_functions *func = ctx->func;
+

+
	func->ucl_emitter_append_len ("<<EOD\n", sizeof ("<<EOD\n") - 1, func->ud);
+
	func->ucl_emitter_append_len (str, size, func->ud);
+
	func->ucl_emitter_append_len ("\nEOD", sizeof ("\nEOD") - 1, func->ud);
+
}
+

/*
 * Generic utstring output
 */
@@ -458,3 +469,18 @@ ucl_object_emit_single_json (const ucl_object_t *obj)

	return res;
}
+

+
#define LONG_STRING_LIMIT 80
+

+
bool
+
ucl_maybe_long_string (const ucl_object_t *obj)
+
{
+
	if (obj->len > LONG_STRING_LIMIT || (obj->flags & UCL_OBJECT_MULTILINE)) {
+
		/* String is long enough, so search for newline characters in it */
+
		if (memchr (obj->value.sv, '\n', obj->len) != NULL) {
+
			return true;
+
		}
+
	}
+

+
	return false;
+
}
modified external/libucl/src/ucl_internal.h
@@ -358,7 +358,7 @@ const struct ucl_emitter_context *
ucl_emit_get_standard_context (enum ucl_emitter emit_type);

/**
-
 * Serialise string
+
 * Serialize string as JSON string
 * @param str string to emit
 * @param buf target buffer
 */
@@ -366,10 +366,27 @@ void ucl_elt_string_write_json (const char *str, size_t size,
		struct ucl_emitter_context *ctx);

/**
+
 * Write multiline string using `EOD` as string terminator
+
 * @param str
+
 * @param size
+
 * @param ctx
+
 */
+
void ucl_elt_string_write_multiline (const char *str, size_t size,
+
		struct ucl_emitter_context *ctx);
+

+
/**
 * Emit a single object to string
 * @param obj
 * @return
 */
unsigned char * ucl_object_emit_single_json (const ucl_object_t *obj);

+
/**
+
 * Check whether a specified string is long and should be likely printed in
+
 * multiline mode
+
 * @param obj
+
 * @return
+
 */
+
bool ucl_maybe_long_string (const ucl_object_t *obj);
+

#endif /* UCL_INTERNAL_H_ */
modified external/libucl/src/ucl_parser.c
@@ -1264,7 +1264,7 @@ ucl_parse_multiline_string (struct ucl_parser *parser,
		int term_len, unsigned char const **beg,
		bool *var_expand)
{
-
	const unsigned char *p, *c;
+
	const unsigned char *p, *c, *tend;
	bool newline = false;
	int len = 0;

@@ -1277,7 +1277,13 @@ ucl_parse_multiline_string (struct ucl_parser *parser,
			if (chunk->end - p < term_len) {
				return 0;
			}
-
			else if (memcmp (p, term, term_len) == 0 && (p[term_len] == '\n' || p[term_len] == '\r')) {
+
			else if (memcmp (p, term, term_len) == 0) {
+
				tend = p + term_len;
+
				if (*tend != '\n' && *tend != ';' && *tend != ',') {
+
					/* Incomplete terminator */
+
					ucl_chunk_skipc (chunk, p);
+
					continue;
+
				}
				len = p - c;
				chunk->remain -= term_len;
				chunk->pos = p + term_len;
modified external/libucl/src/ucl_util.c
@@ -143,15 +143,18 @@ ucl_object_dtor_free (ucl_object_t *obj)
	if (obj->trash_stack[UCL_TRASH_VALUE] != NULL) {
		UCL_FREE (obj->len, obj->trash_stack[UCL_TRASH_VALUE]);
	}
-
	if (obj->type != UCL_USERDATA) {
-
		UCL_FREE (sizeof (ucl_object_t), obj);
-
	}
-
	else {
-
		struct ucl_object_userdata *ud = (struct ucl_object_userdata *)obj;
-
		if (ud->dtor) {
-
			ud->dtor (obj->value.ud);
+
	/* Do not free ephemeral objects */
+
	if ((obj->flags & UCL_OBJECT_EPHEMERAL) == 0) {
+
		if (obj->type != UCL_USERDATA) {
+
			UCL_FREE (sizeof (ucl_object_t), obj);
+
		}
+
		else {
+
			struct ucl_object_userdata *ud = (struct ucl_object_userdata *)obj;
+
			if (ud->dtor) {
+
				ud->dtor (obj->value.ud);
+
			}
+
			UCL_FREE (sizeof (*ud), obj);
		}
-
		UCL_FREE (sizeof (*ud), obj);
	}
}

@@ -1911,12 +1914,22 @@ ucl_object_ref (const ucl_object_t *obj)
	ucl_object_t *res = NULL;

	if (obj != NULL) {
-
		res = __DECONST (ucl_object_t *, obj);
+
		if (obj->flags & UCL_OBJECT_EPHEMERAL) {
+
			/*
+
			 * Use deep copy for ephemeral objects, note that its refcount
+
			 * is NOT increased, since ephemeral objects does not need refcount
+
			 * at all
+
			 */
+
			res = ucl_object_copy (obj);
+
		}
+
		else {
+
			res = __DECONST (ucl_object_t *, obj);
#ifdef HAVE_ATOMIC_BUILTINS
-
		(void)__sync_add_and_fetch (&res->ref, 1);
+
			(void)__sync_add_and_fetch (&res->ref, 1);
#else
-
		res->ref ++;
+
			res->ref ++;
#endif
+
		}
	}
	return res;
}
@@ -1933,6 +1946,10 @@ ucl_object_copy_internal (const ucl_object_t *other, bool allow_array)

	if (new != NULL) {
		memcpy (new, other, sizeof (*new));
+
		if (other->flags & UCL_OBJECT_EPHEMERAL) {
+
			/* Copied object is always non ephemeral */
+
			new->flags &= ~UCL_OBJECT_EPHEMERAL;
+
		}
		new->ref = 1;
		/* Unlink from others */
		new->next = NULL;
modified external/libucl/tests/basic/4.res
@@ -10,7 +10,14 @@ licenses [
    "BSD",
]
flatsize = 60523;
-
desc = "pkgconf is a program which helps to configure compiler and linker flags for\ndevelopment frameworks. It is similar to pkg-config, but was written from\nscratch in Summer of 2011 to replace pkg-config, which now needs itself to build\nitself.\n\nWWW: https://github.com/pkgconf/pkgconf";
+
desc = <<EOD
+
pkgconf is a program which helps to configure compiler and linker flags for
+
development frameworks. It is similar to pkg-config, but was written from
+
scratch in Summer of 2011 to replace pkg-config, which now needs itself to build
+
itself.
+

+
WWW: https://github.com/pkgconf/pkgconf
+
EOD;
categories [
    "devel",
]
@@ -31,6 +38,17 @@ scripts {
    pre-deinstall = "cd /usr/local\nn";
    post-deinstall = "cd /usr/local\nn";
}
-
multiline-key = "test\ntest\ntest\\n\n/* comment like */\n# Some invalid endings\n EOD\nEOD   \nEOF\n# Valid ending + empty string\n";
+
multiline-key = <<EOD
+
test
+
test
+
test\n
+
/* comment like */
+
# Some invalid endings
+
 EOD
+
EOD   
+
EOF
+
# Valid ending + empty string
+

+
EOD;
normal-key = "<<EODnot";