Page MenuHomeFreeBSD

D58333.1796471530.diff
No OneTemporary

Authored By
Unknown
Size
11 KB
Referenced Files
None
Subscribers
None

D58333.1796471530.diff

diff --git a/contrib/libucl/CLAUDE.md b/contrib/libucl/CLAUDE.md
new file mode 100644
--- /dev/null
+++ b/contrib/libucl/CLAUDE.md
@@ -0,0 +1,82 @@
+# CLAUDE.md
+
+This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
+
+## Project Overview
+
+libucl is a C library for parsing UCL (Universal Configuration Language) — an nginx-inspired config format that is a superset of JSON. It also reads/writes MessagePack, emits YAML, and reads S-expressions. Version 0.9.4.
+
+## Build Commands
+
+```bash
+# Standard CMake build
+cmake -B build && cmake --build build
+
+# Build with sanitizers
+cmake -B build -DENABLE_SANITIZERS=ON -DSANITIZE_TYPE=address && cmake --build build
+
+# Build with utilities (ucl-tool, objdump, chargen)
+cmake -B build -DENABLE_UTILS=ON && cmake --build build
+
+# Build with Lua bindings
+cmake -B build -DENABLE_LUA=ON && cmake --build build
+```
+
+## Running Tests
+
+```bash
+# Run all tests via CTest
+cd build && ctest
+
+# Run a specific test (test names: test_basic, test_schema, test_msgpack, test_generate, test_speed)
+cd build && ctest -R test_basic
+
+# Run test binary directly (needs env vars)
+TEST_DIR=tests TEST_OUT_DIR=build/tests TEST_BINARY_DIR=build/tests ./tests/basic.test
+```
+
+Tests use shell wrapper scripts (`tests/*.test`) that invoke compiled test binaries. Basic tests parse `.in` files and compare output against `.res` files in `tests/basic/`. Schema tests run JSON Schema v4 test suites from `tests/schema/*.json`.
+
+## Architecture
+
+**Core source files** (all in `src/`):
+
+- `ucl_parser.c` — State-machine parser handling UCL, JSON, and msgpack input. The main parsing loop, macro processing (`.include`, `.priority`), and variable expansion live here. This is the largest and most complex file.
+- `ucl_emitter.c` — Tree-walking emitter dispatching to format-specific handlers (JSON, YAML, config, msgpack). Uses a context/ops pattern where `ucl_emitter_context` holds state and `ucl_emitter_operations` is a vtable of format callbacks.
+- `ucl_emitter_streamline.c` — Streaming emitter API that builds output incrementally without requiring a complete object tree.
+- `ucl_emitter_utils.c` — Shared emitter helpers: number formatting, string escaping, indentation.
+- `ucl_schema.c` — JSON Schema draft v4 validator. Recursive descent over schema keywords (type, properties, allOf/anyOf/oneOf, etc.).
+- `ucl_hash.c` — Hash table wrapping uthash with optional case-insensitive keys. Each `ucl_object_t` of type `UCL_OBJECT` stores children in one of these.
+- `ucl_util.c` — Object manipulation API (creation, lookup, iteration, type conversion), file I/O, and the `.include` macro implementation.
+- `ucl_msgpack.c` — MessagePack serialization/deserialization.
+- `ucl_sexp.c` — S-expression (canonical form) parser.
+
+**Key headers**:
+
+- `include/ucl.h` — Public C API. All external types and functions.
+- `include/ucl++.h` — C++ wrapper with `Ucl` class.
+- `src/ucl_internal.h` — Internal parser state, chunk management, macro structures.
+
+**Bundled dependencies** (header-only, in-tree):
+
+- `uthash/` — Hash table macros (uthash, utlist, utstring)
+- `klib/` — kvec (dynamic arrays)
+
+**Object model**: The central type is `ucl_object_t` (defined in `ucl.h`). Objects form a tree; each node has a type (int, float, string, boolean, object, array, null, userdata), a key, and a next pointer for implicit arrays (duplicate keys). Objects use reference counting (`ucl_object_ref`/`ucl_object_unref`).
+
+**Parser lifecycle**: Create with `ucl_parser_new()`, feed data with `ucl_parser_add_string()`/`ucl_parser_add_file()`/`ucl_parser_add_fd()`, retrieve result with `ucl_parser_get_object()`, free with `ucl_parser_free()`. The parser processes input in chunks and maintains a state stack.
+
+## Test Data Convention
+
+Basic parse tests: `tests/basic/N.in` (input) + `tests/basic/N.res` (expected output). To add a parse test, create a new `.in`/`.res` pair. The test harness also exercises FD-based parsing, JSON/YAML output modes, and comment/macro preservation modes on every input file.
+
+## Notable CMake Options
+
+| Option | Default | Purpose |
+|--------|---------|---------|
+| `ENABLE_SANITIZERS` | OFF | AddressSanitizer/UBSan/etc. |
+| `SANITIZE_TYPE` | address | Which sanitizer (address, thread, undefined, memory, leak) |
+| `ENABLE_URL_INCLUDE` | OFF | `.include` from URLs (needs libcurl or libfetch) |
+| `ENABLE_URL_SIGN` | OFF | Signature verification for includes (needs OpenSSL) |
+| `ENABLE_LUA` | OFF | Lua bindings (`lua/lua_ucl.c`) |
+| `BUILD_SHARED_LIBS` | OFF | Build shared instead of static library |
diff --git a/contrib/libucl/FREEBSD-upgrade b/contrib/libucl/FREEBSD-upgrade
--- a/contrib/libucl/FREEBSD-upgrade
+++ b/contrib/libucl/FREEBSD-upgrade
@@ -33,7 +33,7 @@
# 3. Merge vendor tree
#
# $ git subtree merge -P contrib/libucl vendor/libucl/<REF_BRANCH_TO_BE_IMPORTED>
-# $ sh -c 'for F in `cat FREEBSD-Xlist | grep -v FreeBSD`; do rm -rf ./$F ; done'
+# $ sh -c 'for F in `cat FREEBSD-Xlist | grep -v FreeBSD`; do git rm -rf ./$F ; done'
#
# Recheck if there were any new files were added which are not necessary in the
# contrib tree. If so, remove them and also add them to the FREEBSD-Xlist file.
diff --git a/contrib/libucl/include/ucl.h b/contrib/libucl/include/ucl.h
--- a/contrib/libucl/include/ucl.h
+++ b/contrib/libucl/include/ucl.h
@@ -861,6 +861,29 @@
#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
diff --git a/contrib/libucl/src/ucl_emitter.c b/contrib/libucl/src/ucl_emitter.c
--- a/contrib/libucl/src/ucl_emitter.c
+++ b/contrib/libucl/src/ucl_emitter.c
@@ -353,10 +353,16 @@
else {
/* Expand implicit arrays */
if (cur->next != NULL) {
- if (first_key) {
- ucl_add_tabs(func, ctx->indent, compact);
+ if (!first_key) {
+ if (compact) {
+ func->ucl_emitter_append_character(',', 1, func->ud);
+ }
+ else {
+ func->ucl_emitter_append_len(",\n", 2, func->ud);
+ }
}
- ucl_emitter_common_start_array(ctx, cur, first_key, true, compact);
+ ucl_add_tabs(func, ctx->indent, compact);
+ ucl_emitter_common_start_array(ctx, cur, true, true, compact);
ucl_emitter_common_end_array(ctx, cur, compact);
}
else {
diff --git a/contrib/libucl/src/ucl_hash.h b/contrib/libucl/src/ucl_hash.h
--- a/contrib/libucl/src/ucl_hash.h
+++ b/contrib/libucl/src/ucl_hash.h
@@ -97,6 +97,12 @@
*/
bool ucl_hash_iter_has_next(ucl_hash_t *hashlin, ucl_hash_iter_t iter);
+/**
+ * Free a hash iterator (used when iteration is abandoned early)
+ * @param iter iterator to free, may be NULL
+ */
+void ucl_hash_iterate_free(ucl_hash_iter_t iter);
+
/**
* Reserves space in hash
* @return true on sucess, false on failure (e.g. ENOMEM)
diff --git a/contrib/libucl/src/ucl_hash.c b/contrib/libucl/src/ucl_hash.c
--- a/contrib/libucl/src/ucl_hash.c
+++ b/contrib/libucl/src/ucl_hash.c
@@ -443,6 +443,14 @@
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)
@@ -610,6 +618,9 @@
void ucl_hash_sort(ucl_hash_t *hashlin, enum ucl_object_keys_sort_flags fl)
{
+ if (hashlin == NULL) {
+ return;
+ }
if (fl & UCL_SORT_KEYS_ICASE) {
DL_SORT(hashlin->head, ucl_hash_cmp_icase);
diff --git a/contrib/libucl/src/ucl_util.c b/contrib/libucl/src/ucl_util.c
--- a/contrib/libucl/src/ucl_util.c
+++ b/contrib/libucl/src/ucl_util.c
@@ -2435,9 +2435,7 @@
if (found == NULL) {
top->value.ov = ucl_hash_insert_object(top->value.ov, elt, false);
top->len++;
- if (replace) {
- ret = false;
- }
+ /* Key was inserted - return true regardless of replace flag */
}
else {
if (replace) {
@@ -2767,6 +2765,20 @@
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,
@@ -3028,6 +3040,16 @@
if (obj->type == UCL_ARRAY) {
UCL_ARRAY_GET(vec, obj);
+ if (vec == NULL) {
+ /* Allocate array storage if not present (e.g., copied empty array) */
+ vec = UCL_ALLOC(sizeof(*vec));
+ if (vec == NULL) {
+ return false;
+ }
+ kv_init(*vec);
+ obj->value.av = (void *)vec;
+ }
+
if (vec->m < reserved) {
/* Preallocate some space for arrays */
kv_resize_safe(ucl_object_t *, *vec, reserved, e0);
@@ -3657,8 +3679,9 @@
}
if (other->type == UCL_ARRAY || other->type == UCL_OBJECT) {
- /* reset old value */
+ /* reset old value and length since we will re-add elements below */
memset(&new->value, 0, sizeof(new->value));
+ new->len = 0;
while ((cur = ucl_object_iterate(other, &it, true)) != NULL) {
if (other->type == UCL_ARRAY) {
diff --git a/contrib/libucl/tests/CMakeLists.txt b/contrib/libucl/tests/CMakeLists.txt
--- a/contrib/libucl/tests/CMakeLists.txt
+++ b/contrib/libucl/tests/CMakeLists.txt
@@ -22,10 +22,14 @@
ENDIF()
endmacro()
-# Build test binaries always (not just for testing)
-add_ucl_test(test_basic test_basic.c basic.test)
-add_ucl_test(test_speed test_speed.c speed.test)
-add_ucl_test(test_schema test_schema.c schema.test)
+# Tests using POSIX APIs (mmap, STDIN_FILENO, etc.) - skip on Windows
+IF(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
+ add_ucl_test(test_basic test_basic.c basic.test)
+ add_ucl_test(test_speed test_speed.c speed.test)
+ add_ucl_test(test_schema test_schema.c schema.test)
+ENDIF()
+
+# Portable tests
add_ucl_test(test_msgpack test_msgpack.c msgpack.test)
add_ucl_test(test_generate test_generate.c generate.test)
diff --git a/contrib/libucl/tests/basic/issue312.in b/contrib/libucl/tests/basic/issue312.in
new file mode 100644
--- /dev/null
+++ b/contrib/libucl/tests/basic/issue312.in
@@ -0,0 +1,4 @@
+section_a { key_1 = "value_1"; }
+section_a { key_2 = "value_2"; }
+section_b { key_3 = "value_3"; }
+section_b { key_4 = "value_4"; }
diff --git a/contrib/libucl/tests/basic/issue312.res b/contrib/libucl/tests/basic/issue312.res
new file mode 100644
--- /dev/null
+++ b/contrib/libucl/tests/basic/issue312.res
@@ -0,0 +1,13 @@
+section_a {
+ key_1 = "value_1";
+}
+section_a {
+ key_2 = "value_2";
+}
+section_b {
+ key_3 = "value_3";
+}
+section_b {
+ key_4 = "value_4";
+}
+

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 5, 11:52 AM (9 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42229933
Default Alt Text
D58333.1796471530.diff (11 KB)

Event Timeline