]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Backport security fixes from libucl 0.9.3
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 9 Dec 2025 20:03:55 +0000 (20:03 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 9 Dec 2025 20:03:55 +0000 (20:03 +0000)
Backported critical fixes from upstream libucl:
- Fix heap-buffer-overflow in ucl_parse_multiline_string
- Fix heap-buffer-overflow in ucl_maybe_parse_number
- Fix Use-After-Free in ucl_parser_process_object_element
- Fix C-style comment parser bugs
- Fix invalid JSON emission when merging objects
- Add API misuse detection in ucl_object_emit_streamline_start_container

contrib/libucl/ucl.h
contrib/libucl/ucl_emitter.c
contrib/libucl/ucl_emitter_streamline.c
contrib/libucl/ucl_parser.c

index a91e5fb014bf19307777c75f4a755d3cacaa2f5e..65361ae19252ae81c9cd6b8e5242dc8849f1d024 100644 (file)
@@ -49,9 +49,9 @@
 #include <stdio.h>
 
 #ifdef _WIN32
-# define UCL_EXTERN __declspec(dllexport)
+#define UCL_EXTERN __declspec(dllexport)
 #else
-# define UCL_EXTERN
+#define UCL_EXTERN
 #endif
 
 /**
@@ -74,7 +74,7 @@
  * JSON with less strict rules that make it more comfortable for
  * using as a configuration language
  */
-#ifdef  __cplusplus
+#ifdef __cplusplus
 extern "C" {
 #endif
 /*
@@ -103,15 +103,15 @@ static inline char *ucl_strdup_impl(const char *s)
 #define UCL_STRDUP(str) ucl_strdup_impl(str)
 #endif
 
-#if    __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
-#define UCL_WARN_UNUSED_RESULT               \
-  __attribute__((warn_unused_result))
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+#define UCL_WARN_UNUSED_RESULT \
+       __attribute__((warn_unused_result))
 #else
 #define UCL_WARN_UNUSED_RESULT
 #endif
 
 #ifdef __GNUC__
-#define UCL_DEPRECATED(func) func __attribute__ ((deprecated))
+#define UCL_DEPRECATED(func) func __attribute__((deprecated))
 #elif defined(_MSC_VER)
 #define UCL_DEPRECATED(func) __declspec(deprecated) func
 #else
@@ -129,16 +129,16 @@ static inline char *ucl_strdup_impl(const char *s)
  * The common error codes returned by ucl parser
  */
 typedef enum ucl_error {
-       UCL_EOK = 0, /**< No error */
-       UCL_ESYNTAX, /**< Syntax error occurred during parsing */
-       UCL_EIO, /**< IO error occurred during parsing */
-       UCL_ESTATE, /**< Invalid state machine state */
-       UCL_ENESTED, /**< Input has too many recursion levels */
+       UCL_EOK = 0,   /**< No error */
+       UCL_ESYNTAX,   /**< Syntax error occurred during parsing */
+       UCL_EIO,       /**< IO error occurred during parsing */
+       UCL_ESTATE,    /**< Invalid state machine state */
+       UCL_ENESTED,   /**< Input has too many recursion levels */
        UCL_EUNPAIRED, /**< Input has too many recursion levels */
-       UCL_EMACRO, /**< Error processing a macro */
+       UCL_EMACRO,    /**< Error processing a macro */
        UCL_EINTERNAL, /**< Internal unclassified error */
-       UCL_ESSL, /**< SSL error */
-       UCL_EMERGE /**< A merge error occurred */
+       UCL_ESSL,      /**< SSL error */
+       UCL_EMERGE     /**< A merge error occurred */
 } ucl_error_t;
 
 /**
@@ -149,26 +149,26 @@ typedef enum ucl_error {
  */
 typedef enum ucl_type {
        UCL_OBJECT = 0, /**< UCL object - key/value pairs */
-       UCL_ARRAY, /**< UCL array */
-       UCL_INT, /**< Integer number */
-       UCL_FLOAT, /**< Floating point number */
-       UCL_STRING, /**< Null terminated string */
-       UCL_BOOLEAN, /**< Boolean value */
-       UCL_TIME, /**< Time value (floating point number of seconds) */
-       UCL_USERDATA, /**< Opaque userdata pointer (may be used in macros) */
-       UCL_NULL /**< Null value */
+       UCL_ARRAY,      /**< UCL array */
+       UCL_INT,        /**< Integer number */
+       UCL_FLOAT,      /**< Floating point number */
+       UCL_STRING,     /**< Null terminated string */
+       UCL_BOOLEAN,    /**< Boolean value */
+       UCL_TIME,       /**< Time value (floating point number of seconds) */
+       UCL_USERDATA,   /**< Opaque userdata pointer (may be used in macros) */
+       UCL_NULL        /**< Null value */
 } ucl_type_t;
 
 /**
  * You can use one of these types to serialise #ucl_object_t by using ucl_object_emit().
  */
 typedef enum ucl_emitter {
-       UCL_EMIT_JSON = 0, /**< Emit fine formatted JSON */
+       UCL_EMIT_JSON = 0,     /**< Emit fine formatted JSON */
        UCL_EMIT_JSON_COMPACT, /**< Emit compacted JSON */
-       UCL_EMIT_CONFIG, /**< Emit human readable config format */
-       UCL_EMIT_YAML, /**< Emit embedded YAML format */
-       UCL_EMIT_MSGPACK, /**< Emit msgpack output */
-       UCL_EMIT_MAX /**< Unsupported emitter type */
+       UCL_EMIT_CONFIG,       /**< Emit human readable config format */
+       UCL_EMIT_YAML,         /**< Emit embedded YAML format */
+       UCL_EMIT_MSGPACK,      /**< Emit msgpack output */
+       UCL_EMIT_MAX           /**< Unsupported emitter type */
 } ucl_emitter_t;
 
 /**
@@ -178,36 +178,36 @@ typedef enum ucl_emitter {
  * UCL still has to perform copying implicitly.
  */
 typedef enum ucl_parser_flags {
-       UCL_PARSER_DEFAULT = 0,       /**< No special flags */
-       UCL_PARSER_KEY_LOWERCASE = (1 << 0), /**< Convert all keys to lower case */
-       UCL_PARSER_ZEROCOPY = (1 << 1), /**< Parse input in zero-copy mode if possible */
-       UCL_PARSER_NO_TIME = (1 << 2), /**< Do not parse time and treat time values as strings */
+       UCL_PARSER_DEFAULT = 0,                   /**< No special flags */
+       UCL_PARSER_KEY_LOWERCASE = (1 << 0),      /**< Convert all keys to lower case */
+       UCL_PARSER_ZEROCOPY = (1 << 1),           /**< Parse input in zero-copy mode if possible */
+       UCL_PARSER_NO_TIME = (1 << 2),            /**< Do not parse time and treat time values as strings */
        UCL_PARSER_NO_IMPLICIT_ARRAYS = (1 << 3), /** Create explicit arrays instead of implicit ones */
-       UCL_PARSER_SAVE_COMMENTS = (1 << 4), /** Save comments in the parser context */
-       UCL_PARSER_DISABLE_MACRO = (1 << 5), /** Treat macros as comments */
-       UCL_PARSER_NO_FILEVARS = (1 << 6) /** Do not set file vars */
+       UCL_PARSER_SAVE_COMMENTS = (1 << 4),      /** Save comments in the parser context */
+       UCL_PARSER_DISABLE_MACRO = (1 << 5),      /** Treat macros as comments */
+       UCL_PARSER_NO_FILEVARS = (1 << 6)         /** Do not set file vars */
 } ucl_parser_flags_t;
 
-#define UCL_PARSER_SAFE_FLAGS (UCL_PARSER_NO_TIME | \
-       UCL_PARSER_NO_IMPLICIT_ARRAYS | \
-       UCL_PARSER_DISABLE_MACRO | \
-       UCL_PARSER_NO_FILEVARS)
+#define UCL_PARSER_SAFE_FLAGS (UCL_PARSER_NO_TIME |            \
+                                                          UCL_PARSER_NO_IMPLICIT_ARRAYS | \
+                                                          UCL_PARSER_DISABLE_MACRO |      \
+                                                          UCL_PARSER_NO_FILEVARS)
 /**
  * String conversion flags, that are used in #ucl_object_fromstring_common function.
  */
 typedef enum ucl_string_flags {
-       UCL_STRING_RAW = 0x0,     /**< Treat string as is */
-       UCL_STRING_ESCAPE = (1 << 0),  /**< Perform JSON escape */
-       UCL_STRING_TRIM = (1 << 1),    /**< Trim leading and trailing whitespaces */
-       UCL_STRING_PARSE_BOOLEAN = (1 << 2),    /**< Parse passed string and detect boolean */
-       UCL_STRING_PARSE_INT = (1 << 3),    /**< Parse passed string and detect integer number */
-       UCL_STRING_PARSE_DOUBLE = (1 << 4),    /**< Parse passed string and detect integer or float number */
-       UCL_STRING_PARSE_TIME = (1 << 5), /**< Parse time strings */
-       UCL_STRING_PARSE_NUMBER =  UCL_STRING_PARSE_INT|UCL_STRING_PARSE_DOUBLE|UCL_STRING_PARSE_TIME,  /**<
+       UCL_STRING_RAW = 0x0,                                                                             /**< Treat string as is */
+       UCL_STRING_ESCAPE = (1 << 0),                                                                     /**< Perform JSON escape */
+       UCL_STRING_TRIM = (1 << 1),                                                                       /**< Trim leading and trailing whitespaces */
+       UCL_STRING_PARSE_BOOLEAN = (1 << 2),                                                              /**< Parse passed string and detect boolean */
+       UCL_STRING_PARSE_INT = (1 << 3),                                                                  /**< Parse passed string and detect integer number */
+       UCL_STRING_PARSE_DOUBLE = (1 << 4),                                                               /**< Parse passed string and detect integer or float number */
+       UCL_STRING_PARSE_TIME = (1 << 5),                                                                 /**< Parse time strings */
+       UCL_STRING_PARSE_NUMBER = UCL_STRING_PARSE_INT | UCL_STRING_PARSE_DOUBLE | UCL_STRING_PARSE_TIME, /**<
                                                                        Parse passed string and detect number */
-       UCL_STRING_PARSE =  UCL_STRING_PARSE_BOOLEAN|UCL_STRING_PARSE_NUMBER,   /**<
+       UCL_STRING_PARSE = UCL_STRING_PARSE_BOOLEAN | UCL_STRING_PARSE_NUMBER,                            /**<
                                                                        Parse passed string (and detect booleans and numbers) */
-       UCL_STRING_PARSE_BYTES = (1 << 6)  /**< Treat numbers as bytes */
+       UCL_STRING_PARSE_BYTES = (1 << 6)                                                                 /**< Treat numbers as bytes */
 } ucl_string_flags_t;
 
 /**
@@ -215,15 +215,15 @@ typedef enum ucl_string_flags {
  * for priorities)
  */
 typedef enum ucl_object_flags {
-       UCL_OBJECT_ALLOCATED_KEY = (1 << 0), /**< An object has key allocated internally */
+       UCL_OBJECT_ALLOCATED_KEY = (1 << 0),   /**< An object has key allocated internally */
        UCL_OBJECT_ALLOCATED_VALUE = (1 << 1), /**< An object has a string value allocated internally */
        UCL_OBJECT_NEED_KEY_ESCAPE = (1 << 2), /**< The key of an object need to be escaped on output */
-       UCL_OBJECT_EPHEMERAL = (1 << 3), /**< Temporary object that does not need to be freed really */
-       UCL_OBJECT_MULTILINE = (1 << 4), /**< String should be displayed as multiline string */
-       UCL_OBJECT_MULTIVALUE = (1 << 5), /**< Object is a key with multiple values */
-       UCL_OBJECT_INHERITED = (1 << 6), /**< Object has been inherited from another */
-       UCL_OBJECT_BINARY = (1 << 7), /**< Object contains raw binary data */
-       UCL_OBJECT_SQUOTED = (1 << 8) /**< Object has been enclosed in single quotes */
+       UCL_OBJECT_EPHEMERAL = (1 << 3),       /**< Temporary object that does not need to be freed really */
+       UCL_OBJECT_MULTILINE = (1 << 4),       /**< String should be displayed as multiline string */
+       UCL_OBJECT_MULTIVALUE = (1 << 5),      /**< Object is a key with multiple values */
+       UCL_OBJECT_INHERITED = (1 << 6),       /**< Object has been inherited from another */
+       UCL_OBJECT_BINARY = (1 << 7),          /**< Object contains raw binary data */
+       UCL_OBJECT_SQUOTED = (1 << 8)          /**< Object has been enclosed in single quotes */
 } ucl_object_flags_t;
 
 /**
@@ -231,9 +231,9 @@ typedef enum ucl_object_flags {
  */
 enum ucl_duplicate_strategy {
        UCL_DUPLICATE_APPEND = 0, /**< Default policy to merge based on priorities */
-       UCL_DUPLICATE_MERGE,     /**< Merge new object with old one */
-       UCL_DUPLICATE_REWRITE,   /**< Rewrite old keys */
-       UCL_DUPLICATE_ERROR      /**< Stop parsing on duplicate found */
+       UCL_DUPLICATE_MERGE,      /**< Merge new object with old one */
+       UCL_DUPLICATE_REWRITE,    /**< Rewrite old keys */
+       UCL_DUPLICATE_ERROR       /**< Stop parsing on duplicate found */
 };
 
 /**
@@ -242,8 +242,8 @@ enum ucl_duplicate_strategy {
 enum ucl_parse_type {
        UCL_PARSE_UCL = 0, /**< Default ucl format */
        UCL_PARSE_MSGPACK, /**< Message pack input format */
-       UCL_PARSE_CSEXP, /**< Canonical S-expressions */
-       UCL_PARSE_AUTO /**< Try to detect parse type */
+       UCL_PARSE_CSEXP,   /**< Canonical S-expressions */
+       UCL_PARSE_AUTO     /**< Try to detect parse type */
 };
 
 /**
@@ -255,22 +255,22 @@ typedef struct ucl_object_s {
         * Variant value type
         */
        union {
-               int64_t iv;                                                     /**< Int value of an object */
-               const char *sv;                                         /**< String value of an object */
-               double dv;                                                      /**< Double value of an object */
-               void *av;                                                       /**< Array                                      */
-               void *ov;                                                       /**< Object                                     */
-               void* ud;                                                       /**< Opaque user data           */
+               int64_t iv;     /**< Int value of an object */
+               const char *sv; /**< String value of an object */
+               double dv;      /**< Double value of an object */
+               void *av;       /**< Array                                      */
+               void *ov;       /**< Object                                     */
+               void *ud;       /**< Opaque user data           */
        } value;
-       const char *key;                                                /**< Key of an object           */
-       struct ucl_object_s *next;                              /**< Array handle                       */
-       struct ucl_object_s *prev;                              /**< Array handle                       */
-       uint32_t keylen;                                                /**< Length of a key            */
-       uint32_t len;                                                   /**< Size of an object          */
-       uint32_t ref;                                                   /**< Reference count            */
-       uint16_t flags;                                                 /**< Object flags                       */
-       uint16_t type;                                                  /**< Real type                          */
-       unsigned char* trash_stack[2];                  /**< Pointer to allocated chunks */
+       const char *key;               /**< Key of an object            */
+       struct ucl_object_s *next;     /**< Array handle                        */
+       struct ucl_object_s *prev;     /**< Array handle                        */
+       uint32_t keylen;               /**< Length of a key             */
+       uint32_t len;                  /**< Size of an object           */
+       uint32_t ref;                  /**< Reference count             */
+       uint16_t flags;                /**< Object flags                        */
+       uint16_t type;                 /**< Real type                           */
+       unsigned char *trash_stack[2]; /**< Pointer to allocated chunks */
 } ucl_object_t;
 
 /**
@@ -278,7 +278,7 @@ typedef struct ucl_object_s {
  * @param ud user specified data pointer
  */
 typedef void (*ucl_userdata_dtor)(void *ud);
-typedef const char(*ucl_userdata_emitter)(void *ud);
+typedef const char *(*ucl_userdata_emitter)(void *ud);
 
 /** @} */
 
@@ -293,27 +293,27 @@ typedef const char* (*ucl_userdata_emitter)(void *ud);
  * @param obj CL object
  * @return zero terminated key
  */
-UCL_EXTERN char* ucl_copy_key_trash (const ucl_object_t *obj);
+UCL_EXTERN char *ucl_copy_key_trash(const ucl_object_t *obj);
 
 /**
  * Copy and return a string value of an object, returned key is zero-terminated
  * @param obj CL object
  * @return zero terminated string representation of object value
  */
-UCL_EXTERN char* ucl_copy_value_trash (const ucl_object_t *obj);
+UCL_EXTERN char *ucl_copy_value_trash(const ucl_object_t *obj);
 
 /**
  * Creates a new object
  * @return new object
  */
-UCL_EXTERN ucl_object_t* ucl_object_new (void) UCL_WARN_UNUSED_RESULT;
+UCL_EXTERN ucl_object_t *ucl_object_new(void) UCL_WARN_UNUSED_RESULT;
 
 /**
  * Create new object with type specified
  * @param type type of a new object
  * @return new object
  */
-UCL_EXTERN ucl_object_t* ucl_object_typed_new (ucl_type_t type) UCL_WARN_UNUSED_RESULT;
+UCL_EXTERN ucl_object_t *ucl_object_typed_new(ucl_type_t type) UCL_WARN_UNUSED_RESULT;
 
 /**
  * Create new object with type and priority specified
@@ -321,7 +321,7 @@ UCL_EXTERN ucl_object_t* ucl_object_typed_new (ucl_type_t type) UCL_WARN_UNUSED_
  * @param priority priority of an object
  * @return new object
  */
-UCL_EXTERN ucl_object_t* ucl_object_new_full (ucl_type_t type, unsigned priority)
+UCL_EXTERN ucl_object_t *ucl_object_new_full(ucl_type_t type, unsigned priority)
        UCL_WARN_UNUSED_RESULT;
 
 /**
@@ -331,29 +331,29 @@ UCL_EXTERN ucl_object_t* ucl_object_new_full (ucl_type_t type, unsigned priority
  * @param ptr opaque pointer
  * @return new object
  */
-UCL_EXTERN ucl_object_t* ucl_object_new_userdata (ucl_userdata_dtor dtor,
-               ucl_userdata_emitter emitter, void *ptr) UCL_WARN_UNUSED_RESULT;
+UCL_EXTERN ucl_object_t *ucl_object_new_userdata(ucl_userdata_dtor dtor,
+                                                                                                ucl_userdata_emitter emitter, void *ptr) UCL_WARN_UNUSED_RESULT;
 
 /**
  * Perform deep copy of an object copying everything
  * @param other object to copy
  * @return new object with refcount equal to 1
  */
-UCL_EXTERN ucl_object_t * ucl_object_copy (const ucl_object_t *other)
+UCL_EXTERN ucl_object_t *ucl_object_copy(const ucl_object_t *other)
        UCL_WARN_UNUSED_RESULT;
 
 /**
  * Return the type of an object
  * @return the object type
  */
-UCL_EXTERN ucl_type_t ucl_object_type (const ucl_object_t *obj);
+UCL_EXTERN ucl_type_t ucl_object_type(const ucl_object_t *obj);
 
 /**
  * Converts ucl object type to its string representation
  * @param type type of object
  * @return constant string describing type
  */
-UCL_EXTERN const char * ucl_object_type_to_string (ucl_type_t type);
+UCL_EXTERN const char *ucl_object_type_to_string(ucl_type_t type);
 
 /**
  * Converts string that represents ucl type to real ucl type enum
@@ -361,7 +361,7 @@ UCL_EXTERN const char * ucl_object_type_to_string (ucl_type_t type);
  * @param res resulting target
  * @return true if `input` is a name of type stored in `res`
  */
-UCL_EXTERN bool ucl_object_string_to_type (const char *input, ucl_type_t *res);
+UCL_EXTERN bool ucl_object_string_to_type(const char *input, ucl_type_t *res);
 
 /**
  * Convert any string to an ucl object making the specified transformations
@@ -370,15 +370,15 @@ UCL_EXTERN bool ucl_object_string_to_type (const char *input, ucl_type_t *res);
  * @param flags conversion flags
  * @return new object
  */
-UCL_EXTERN ucl_object_t * ucl_object_fromstring_common (const char *str, size_t len,
-               enum ucl_string_flags flags) UCL_WARN_UNUSED_RESULT;
+UCL_EXTERN ucl_object_t *ucl_object_fromstring_common(const char *str, size_t len,
+                                                                                                         enum ucl_string_flags flags) UCL_WARN_UNUSED_RESULT;
 
 /**
  * Create a UCL object from the specified string
  * @param str NULL terminated string, will be json escaped
  * @return new object
  */
-UCL_EXTERN ucl_object_t *ucl_object_fromstring (const char *str) UCL_WARN_UNUSED_RESULT;
+UCL_EXTERN ucl_object_t *ucl_object_fromstring(const char *str) UCL_WARN_UNUSED_RESULT;
 
 /**
  * Create a UCL object from the specified string
@@ -386,29 +386,29 @@ UCL_EXTERN ucl_object_t *ucl_object_fromstring (const char *str) UCL_WARN_UNUSED
  * @param len length of a string
  * @return new object
  */
-UCL_EXTERN ucl_object_t *ucl_object_fromlstring (const char *str,
-               size_t len) UCL_WARN_UNUSED_RESULT;
+UCL_EXTERN ucl_object_t *ucl_object_fromlstring(const char *str,
+                                                                                               size_t len) UCL_WARN_UNUSED_RESULT;
 
 /**
  * Create an object from an integer number
  * @param iv number
  * @return new object
  */
-UCL_EXTERN ucl_object_t* ucl_object_fromint (int64_t iv) UCL_WARN_UNUSED_RESULT;
+UCL_EXTERN ucl_object_t *ucl_object_fromint(int64_t iv) UCL_WARN_UNUSED_RESULT;
 
 /**
  * Create an object from a float number
  * @param dv number
  * @return new object
  */
-UCL_EXTERN ucl_object_t* ucl_object_fromdouble (double dv) UCL_WARN_UNUSED_RESULT;
+UCL_EXTERN ucl_object_t *ucl_object_fromdouble(double dv) UCL_WARN_UNUSED_RESULT;
 
 /**
  * Create an object from a boolean
  * @param bv bool value
  * @return new object
  */
-UCL_EXTERN ucl_object_t* ucl_object_frombool (bool bv) UCL_WARN_UNUSED_RESULT;
+UCL_EXTERN ucl_object_t *ucl_object_frombool(bool bv) UCL_WARN_UNUSED_RESULT;
 
 /**
  * Insert a object 'elt' to the hash 'top' and associate it with key 'key'
@@ -419,8 +419,8 @@ UCL_EXTERN ucl_object_t* ucl_object_frombool (bool bv) UCL_WARN_UNUSED_RESULT;
  * @param copy_key make an internal copy of key
  * @return true if key has been inserted
  */
-UCL_EXTERN bool ucl_object_insert_key (ucl_object_t *top, ucl_object_t *elt,
-               const char *key, size_t keylen, bool copy_key);
+UCL_EXTERN bool ucl_object_insert_key(ucl_object_t *top, ucl_object_t *elt,
+                                                                         const char *key, size_t keylen, bool copy_key);
 
 /**
  * Replace a object 'elt' to the hash 'top' and associate it with key 'key', old object will be unrefed,
@@ -432,8 +432,8 @@ UCL_EXTERN bool ucl_object_insert_key (ucl_object_t *top, ucl_object_t *elt,
  * @param copy_key make an internal copy of key
  * @return true if key has been inserted
  */
-UCL_EXTERN bool ucl_object_replace_key (ucl_object_t *top, ucl_object_t *elt,
-               const char *key, size_t keylen, bool copy_key);
+UCL_EXTERN bool ucl_object_replace_key(ucl_object_t *top, ucl_object_t *elt,
+                                                                          const char *key, size_t keylen, bool copy_key);
 
 /**
  * Merge the keys from one object to another object. Overwrite on conflict
@@ -442,7 +442,7 @@ UCL_EXTERN bool ucl_object_replace_key (ucl_object_t *top, ucl_object_t *elt,
  * @param copy copy rather than reference the elements
  * @return true if all keys have been merged
  */
-UCL_EXTERN bool ucl_object_merge (ucl_object_t *top, ucl_object_t *elt, bool copy);
+UCL_EXTERN bool ucl_object_merge(ucl_object_t *top, ucl_object_t *elt, bool copy);
 
 /**
  * Delete a object associated with key 'key', old object will be unrefered,
@@ -450,16 +450,16 @@ UCL_EXTERN bool ucl_object_merge (ucl_object_t *top, ucl_object_t *elt, bool cop
  * @param key key associated to the object to remove
  * @param keylen length of the key (or 0 for NULL terminated keys)
  */
-UCL_EXTERN bool ucl_object_delete_keyl (ucl_object_t *top,
-               const char *key, size_t keylen);
+UCL_EXTERN bool ucl_object_delete_keyl(ucl_object_t *top,
+                                                                          const char *key, size_t keylen);
 
 /**
  * Delete a object associated with key 'key', old object will be unrefered,
  * @param top object
  * @param key key associated to the object to remove
  */
-UCL_EXTERN bool ucl_object_delete_key (ucl_object_t *top,
-               const char *key);
+UCL_EXTERN bool ucl_object_delete_key(ucl_object_t *top,
+                                                                         const char *key);
 
 
 /**
@@ -471,8 +471,8 @@ UCL_EXTERN bool ucl_object_delete_key (ucl_object_t *top,
  * @param keylen length of the key (or 0 for NULL terminated keys)
  * @return removed object or NULL if object has not been found
  */
-UCL_EXTERN ucl_object_t* ucl_object_pop_keyl (ucl_object_t *top, const char *key,
-               size_t keylen) UCL_WARN_UNUSED_RESULT;
+UCL_EXTERN ucl_object_t *ucl_object_pop_keyl(ucl_object_t *top, const char *key,
+                                                                                        size_t keylen) UCL_WARN_UNUSED_RESULT;
 
 /**
  * Removes `key` from `top` object returning the object that was removed. This
@@ -482,7 +482,7 @@ UCL_EXTERN ucl_object_t* ucl_object_pop_keyl (ucl_object_t *top, const char *key
  * @param key key to remove
  * @return removed object or NULL if object has not been found
  */
-UCL_EXTERN ucl_object_t* ucl_object_pop_key (ucl_object_t *top, const char *key)
+UCL_EXTERN ucl_object_t *ucl_object_pop_key(ucl_object_t *top, const char *key)
        UCL_WARN_UNUSED_RESULT;
 
 /**
@@ -495,8 +495,8 @@ UCL_EXTERN ucl_object_t* ucl_object_pop_key (ucl_object_t *top, const char *key)
  * @param copy_key make an internal copy of key
  * @return true if key has been inserted
  */
-UCL_EXTERN bool ucl_object_insert_key_merged (ucl_object_t *top, ucl_object_t *elt,
-               const char *key, size_t keylen, bool copy_key);
+UCL_EXTERN bool ucl_object_insert_key_merged(ucl_object_t *top, ucl_object_t *elt,
+                                                                                        const char *key, size_t keylen, bool copy_key);
 
 /**
  * Reserve space in ucl array or object for `elt` elements
@@ -504,7 +504,7 @@ UCL_EXTERN bool ucl_object_insert_key_merged (ucl_object_t *top, ucl_object_t *e
  * @param reserved size to reserve in an object
  * @return 0 on success, -1 on failure (i.e. ENOMEM)
  */
-UCL_EXTERN bool ucl_object_reserve (ucl_object_t *obj, size_t reserved);
+UCL_EXTERN bool ucl_object_reserve(ucl_object_t *obj, size_t reserved);
 
 /**
  * Append an element to the end of array object
@@ -512,8 +512,8 @@ UCL_EXTERN bool ucl_object_reserve (ucl_object_t *obj, size_t reserved);
  * @param elt element to append (must NOT be NULL)
  * @return true if value has been inserted
  */
-UCL_EXTERN bool ucl_array_append (ucl_object_t *top,
-               ucl_object_t *elt);
+UCL_EXTERN bool ucl_array_append(ucl_object_t *top,
+                                                                ucl_object_t *elt);
 
 /**
  * Append an element to the start of array object
@@ -521,8 +521,8 @@ UCL_EXTERN bool ucl_array_append (ucl_object_t *top,
  * @param elt element to append (must NOT be NULL)
  * @return true if value has been inserted
  */
-UCL_EXTERN bool ucl_array_prepend (ucl_object_t *top,
-               ucl_object_t *elt);
+UCL_EXTERN bool ucl_array_prepend(ucl_object_t *top,
+                                                                 ucl_object_t *elt);
 
 /**
  * Merge all elements of second array into the first array
@@ -531,8 +531,8 @@ UCL_EXTERN bool ucl_array_prepend (ucl_object_t *top,
  * @param copy copy elements instead of referencing them
  * @return true if arrays were merged
  */
-UCL_EXTERN bool ucl_array_merge (ucl_object_t *top, ucl_object_t *elt,
-               bool copy);
+UCL_EXTERN bool ucl_array_merge(ucl_object_t *top, ucl_object_t *elt,
+                                                               bool copy);
 
 /**
  * Removes an element `elt` from the array `top`, returning the object that was
@@ -542,22 +542,22 @@ UCL_EXTERN bool ucl_array_merge (ucl_object_t *top, ucl_object_t *elt,
  * @param elt element to remove
  * @return removed element or NULL if `top` is NULL or not an array
  */
-UCL_EXTERN ucl_object_t* ucl_array_delete (ucl_object_t *top,
-               ucl_object_t *elt);
+UCL_EXTERN ucl_object_t *ucl_array_delete(ucl_object_t *top,
+                                                                                 ucl_object_t *elt);
 
 /**
  * Returns the first element of the array `top`
  * @param top array ucl object
  * @return element or NULL if `top` is NULL or not an array
  */
-UCL_EXTERN const ucl_object_t* ucl_array_head (const ucl_object_t *top);
+UCL_EXTERN const ucl_object_t *ucl_array_head(const ucl_object_t *top);
 
 /**
  * Returns the last element of the array `top`
  * @param top array ucl object
  * @return element or NULL if `top` is NULL or not an array
  */
-UCL_EXTERN const ucl_object_t* ucl_array_tail (const ucl_object_t *top);
+UCL_EXTERN const ucl_object_t *ucl_array_tail(const ucl_object_t *top);
 
 /**
  * Removes the last element from the array `top`, returning the object that was
@@ -566,7 +566,7 @@ UCL_EXTERN const ucl_object_t* ucl_array_tail (const ucl_object_t *top);
  * @param top array ucl object
  * @return removed element or NULL if `top` is NULL or not an array
  */
-UCL_EXTERN ucl_object_t* ucl_array_pop_last (ucl_object_t *top);
+UCL_EXTERN ucl_object_t *ucl_array_pop_last(ucl_object_t *top);
 
 /**
  * Removes the first element from the array `top`, returning the object that was
@@ -575,14 +575,14 @@ UCL_EXTERN ucl_object_t* ucl_array_pop_last (ucl_object_t *top);
  * @param top array ucl object
  * @return removed element or NULL if `top` is NULL or not an array
  */
-UCL_EXTERN ucl_object_t* ucl_array_pop_first (ucl_object_t *top);
+UCL_EXTERN ucl_object_t *ucl_array_pop_first(ucl_object_t *top);
 
 /**
  * Return size of the array `top`
  * @param top object to get size from (must be of type UCL_ARRAY)
  * @return size of the array
  */
-UCL_EXTERN unsigned int ucl_array_size (const ucl_object_t *top);
+UCL_EXTERN unsigned int ucl_array_size(const ucl_object_t *top);
 
 /**
  * Return object identified by index of the array `top`
@@ -590,8 +590,8 @@ UCL_EXTERN unsigned int ucl_array_size (const ucl_object_t *top);
  * @param index array index to return
  * @return object at the specified index or NULL if index is not found
  */
-UCL_EXTERN const ucl_object_t* ucl_array_find_index (const ucl_object_t *top,
-               unsigned int index);
+UCL_EXTERN const ucl_object_t *ucl_array_find_index(const ucl_object_t *top,
+                                                                                                       unsigned int index);
 
 /**
  * Return the index of `elt` in the array `top`
@@ -599,8 +599,8 @@ UCL_EXTERN const ucl_object_t* ucl_array_find_index (const ucl_object_t *top,
  * @param elt element to find index of (must NOT be NULL)
  * @return index of `elt` in the array `top or (unsigned int)-1 if `elt` is not found
  */
-UCL_EXTERN unsigned int ucl_array_index_of (ucl_object_t *top,
-               ucl_object_t *elt);
+UCL_EXTERN unsigned int ucl_array_index_of(ucl_object_t *top,
+                                                                                  ucl_object_t *elt);
 
 /**
  * Replace an element in an array with a different element, returning the object
@@ -612,8 +612,8 @@ UCL_EXTERN unsigned int ucl_array_index_of (ucl_object_t *top,
  * @return object that was replaced or NULL if index is not found
  */
 ucl_object_t *
-ucl_array_replace_index (ucl_object_t *top, ucl_object_t *elt,
-       unsigned int index);
+ucl_array_replace_index(ucl_object_t *top, ucl_object_t *elt,
+                                               unsigned int index);
 
 /**
  * Append a element to another element forming an implicit array
@@ -621,8 +621,8 @@ ucl_array_replace_index (ucl_object_t *top, ucl_object_t *elt,
  * @param elt new element
  * @return the new implicit array
  */
-UCL_EXTERN ucl_object_t * ucl_elt_append (ucl_object_t *head,
-               ucl_object_t *elt);
+UCL_EXTERN ucl_object_t *ucl_elt_append(ucl_object_t *head,
+                                                                               ucl_object_t *elt);
 
 /**
  * Converts an object to double value
@@ -630,14 +630,14 @@ UCL_EXTERN ucl_object_t * ucl_elt_append (ucl_object_t *head,
  * @param target target double variable
  * @return true if conversion was successful
  */
-UCL_EXTERN bool ucl_object_todouble_safe (const ucl_object_t *obj, double *target);
+UCL_EXTERN bool ucl_object_todouble_safe(const ucl_object_t *obj, double *target);
 
 /**
  * Unsafe version of \ref ucl_obj_todouble_safe
  * @param obj CL object
  * @return double value
  */
-UCL_EXTERN double ucl_object_todouble (const ucl_object_t *obj);
+UCL_EXTERN double ucl_object_todouble(const ucl_object_t *obj);
 
 /**
  * Converts an object to integer value
@@ -645,14 +645,14 @@ UCL_EXTERN double ucl_object_todouble (const ucl_object_t *obj);
  * @param target target integer variable
  * @return true if conversion was successful
  */
-UCL_EXTERN bool ucl_object_toint_safe (const ucl_object_t *obj, int64_t *target);
+UCL_EXTERN bool ucl_object_toint_safe(const ucl_object_t *obj, int64_t *target);
 
 /**
  * Unsafe version of \ref ucl_obj_toint_safe
  * @param obj CL object
  * @return int value
  */
-UCL_EXTERN int64_t ucl_object_toint (const ucl_object_t *obj);
+UCL_EXTERN int64_t ucl_object_toint(const ucl_object_t *obj);
 
 /**
  * Converts an object to boolean value
@@ -660,14 +660,14 @@ UCL_EXTERN int64_t ucl_object_toint (const ucl_object_t *obj);
  * @param target target boolean variable
  * @return true if conversion was successful
  */
-UCL_EXTERN bool ucl_object_toboolean_safe (const ucl_object_t *obj, bool *target);
+UCL_EXTERN bool ucl_object_toboolean_safe(const ucl_object_t *obj, bool *target);
 
 /**
  * Unsafe version of \ref ucl_obj_toboolean_safe
  * @param obj CL object
  * @return boolean value
  */
-UCL_EXTERN bool ucl_object_toboolean (const ucl_object_t *obj);
+UCL_EXTERN bool ucl_object_toboolean(const ucl_object_t *obj);
 
 /**
  * Converts an object to string value
@@ -675,21 +675,21 @@ UCL_EXTERN bool ucl_object_toboolean (const ucl_object_t *obj);
  * @param target target string variable, no need to free value
  * @return true if conversion was successful
  */
-UCL_EXTERN bool ucl_object_tostring_safe (const ucl_object_t *obj, const char **target);
+UCL_EXTERN bool ucl_object_tostring_safe(const ucl_object_t *obj, const char **target);
 
 /**
  * Unsafe version of \ref ucl_obj_tostring_safe
  * @param obj CL object
  * @return string value
  */
-UCL_EXTERN const char* ucl_object_tostring (const ucl_object_t *obj);
+UCL_EXTERN const char *ucl_object_tostring(const ucl_object_t *obj);
 
 /**
  * Convert any object to a string in JSON notation if needed
  * @param obj CL object
  * @return string value
  */
-UCL_EXTERN const char* ucl_object_tostring_forced (const ucl_object_t *obj);
+UCL_EXTERN const char *ucl_object_tostring_forced(const ucl_object_t *obj);
 
 /**
  * Return string as char * and len, string may be not zero terminated, more efficient that \ref ucl_obj_tostring as it
@@ -699,15 +699,15 @@ UCL_EXTERN const char* ucl_object_tostring_forced (const ucl_object_t *obj);
  * @param tlen target length
  * @return true if conversion was successful
  */
-UCL_EXTERN bool ucl_object_tolstring_safe (const ucl_object_t *obj,
-               const char **target, size_t *tlen);
+UCL_EXTERN bool ucl_object_tolstring_safe(const ucl_object_t *obj,
+                                                                                 const char **target, size_t *tlen);
 
 /**
  * Unsafe version of \ref ucl_obj_tolstring_safe
  * @param obj CL object
  * @return string value
  */
-UCL_EXTERN const char* ucl_object_tolstring (const ucl_object_t *obj, size_t *tlen);
+UCL_EXTERN const char *ucl_object_tolstring(const ucl_object_t *obj, size_t *tlen);
 
 /**
  * Return object identified by a key in the specified object
@@ -715,8 +715,8 @@ UCL_EXTERN const char* ucl_object_tolstring (const ucl_object_t *obj, size_t *tl
  * @param key key to search
  * @return object matching the specified key or NULL if key was not found
  */
-UCL_EXTERN const ucl_object_t* ucl_object_lookup (const ucl_object_t *obj,
-               const char *key);
+UCL_EXTERN const ucl_object_t *ucl_object_lookup(const ucl_object_t *obj,
+                                                                                                const char *key);
 #define ucl_object_find_key ucl_object_lookup
 
 /**
@@ -729,8 +729,8 @@ UCL_EXTERN const ucl_object_t* ucl_object_lookup (const ucl_object_t *obj,
  * @param ... list of alternative keys to search (NULL terminated)
  * @return object matching the specified key or NULL if key was not found
  */
-UCL_EXTERN const ucl_object_t* ucl_object_lookup_any (const ucl_object_t *obj,
-               const char *key, ...);
+UCL_EXTERN const ucl_object_t *ucl_object_lookup_any(const ucl_object_t *obj,
+                                                                                                        const char *key, ...);
 #define ucl_object_find_any_key ucl_object_lookup_any
 
 /**
@@ -740,8 +740,8 @@ UCL_EXTERN const ucl_object_t* ucl_object_lookup_any (const ucl_object_t *obj,
  * @param klen length of a key
  * @return object matching the specified key or NULL if key was not found
  */
-UCL_EXTERN const ucl_object_t* ucl_object_lookup_len (const ucl_object_t *obj,
-               const char *key, size_t klen);
+UCL_EXTERN const ucl_object_t *ucl_object_lookup_len(const ucl_object_t *obj,
+                                                                                                        const char *key, size_t klen);
 #define ucl_object_find_keyl ucl_object_lookup_len
 
 /**
@@ -750,8 +750,8 @@ UCL_EXTERN const ucl_object_t* ucl_object_lookup_len (const ucl_object_t *obj,
  * @param path dot.notation.path to the path to lookup. May use numeric .index on arrays
  * @return object matched the specified path or NULL if path is not found
  */
-UCL_EXTERN const ucl_object_t *ucl_object_lookup_path (const ucl_object_t *obj,
-               const char *path);
+UCL_EXTERN const ucl_object_t *ucl_object_lookup_path(const ucl_object_t *obj,
+                                                                                                         const char *path);
 #define ucl_lookup_path ucl_object_lookup_path
 
 /**
@@ -761,8 +761,8 @@ UCL_EXTERN const ucl_object_t *ucl_object_lookup_path (const ucl_object_t *obj,
  * @param sep the sepatorator to use in place of . (incase keys have . in them)
  * @return object matched the specified path or NULL if path is not found
  */
-UCL_EXTERN const ucl_object_t *ucl_object_lookup_path_char (const ucl_object_t *obj,
-               const char *path, char sep);
+UCL_EXTERN const ucl_object_t *ucl_object_lookup_path_char(const ucl_object_t *obj,
+                                                                                                                  const char *path, char sep);
 #define ucl_lookup_path_char ucl_object_lookup_path_char
 
 /**
@@ -770,7 +770,7 @@ UCL_EXTERN const ucl_object_t *ucl_object_lookup_path_char (const ucl_object_t *
  * @param obj CL object
  * @return key or NULL if there is no key
  */
-UCL_EXTERN const char* ucl_object_key (const ucl_object_t *obj);
+UCL_EXTERN const char *ucl_object_key(const ucl_object_t *obj);
 
 /**
  * Returns a key of an object as a fixed size string (may be more efficient)
@@ -778,26 +778,26 @@ UCL_EXTERN const char* ucl_object_key (const ucl_object_t *obj);
  * @param len target key length
  * @return key pointer
  */
-UCL_EXTERN const char* ucl_object_keyl (const ucl_object_t *obj, size_t *len);
+UCL_EXTERN const char *ucl_object_keyl(const ucl_object_t *obj, size_t *len);
 
 /**
  * Increase reference count for an object
  * @param obj object to ref
  * @return the referenced object
  */
-UCL_EXTERN ucl_object_t* ucl_object_ref (const ucl_object_t *obj);
+UCL_EXTERN ucl_object_t *ucl_object_ref(const ucl_object_t *obj);
 
 /**
  * Free ucl object
  * @param obj ucl object to free
  */
-UCL_DEPRECATED(UCL_EXTERN void ucl_object_free (ucl_object_t *obj));
+UCL_DEPRECATED(UCL_EXTERN void ucl_object_free(ucl_object_t *obj));
 
 /**
  * Decrease reference count for an object
  * @param obj object to unref
  */
-UCL_EXTERN void ucl_object_unref (ucl_object_t *obj);
+UCL_EXTERN void ucl_object_unref(ucl_object_t *obj);
 
 /**
  * Compare objects `o1` and `o2`
@@ -809,8 +809,8 @@ UCL_EXTERN void ucl_object_unref (ucl_object_t *obj);
  * 2) Size of objects
  * 3) Content of objects
  */
-UCL_EXTERN int ucl_object_compare (const ucl_object_t *o1,
-               const ucl_object_t *o2);
+UCL_EXTERN int ucl_object_compare(const ucl_object_t *o1,
+                                                                 const ucl_object_t *o2);
 
 /**
  * Compare objects `o1` and `o2` useful for sorting
@@ -822,16 +822,16 @@ UCL_EXTERN int ucl_object_compare (const ucl_object_t *o1,
  * 2) Size of objects
  * 3) Content of objects
  */
-UCL_EXTERN int ucl_object_compare_qsort (const ucl_object_t **o1,
-               const ucl_object_t **o2);
+UCL_EXTERN int ucl_object_compare_qsort(const ucl_object_t **o1,
+                                                                               const ucl_object_t **o2);
 
 /**
  * Sort UCL array using `cmp` compare function
  * @param ar
  * @param cmp
  */
-UCL_EXTERN void ucl_object_array_sort (ucl_object_t *ar,
-               int (*cmp)(const ucl_object_t **o1, const ucl_object_t **o2));
+UCL_EXTERN void ucl_object_array_sort(ucl_object_t *ar,
+                                                                         int (*cmp)(const ucl_object_t **o1, const ucl_object_t **o2));
 
 enum ucl_object_keys_sort_flags {
        UCL_SORT_KEYS_DEFAULT = 0,
@@ -843,28 +843,28 @@ enum ucl_object_keys_sort_flags {
  * @param obj
  * @param how
  */
-UCL_EXTERN void ucl_object_sort_keys (ucl_object_t *obj,
-               enum ucl_object_keys_sort_flags how);
+UCL_EXTERN void ucl_object_sort_keys(ucl_object_t *obj,
+                                                                        enum ucl_object_keys_sort_flags how);
 
 /**
  * Get the priority for specific UCL object
  * @param obj any ucl object
  * @return priority of an object
  */
-UCL_EXTERN unsigned int ucl_object_get_priority (const ucl_object_t *obj);
+UCL_EXTERN unsigned int ucl_object_get_priority(const ucl_object_t *obj);
 
 /**
  * Set explicit priority of an object.
  * @param obj any ucl object
  * @param priority new priroity value (only 4 least significant bits are considred)
  */
-UCL_EXTERN void ucl_object_set_priority (ucl_object_t *obj,
-               unsigned int priority);
+UCL_EXTERN void ucl_object_set_priority(ucl_object_t *obj,
+                                                                               unsigned int priority);
 
 /**
  * Opaque iterator object
  */
-typedef voiducl_object_iter_t;
+typedef void *ucl_object_iter_t;
 
 /**
  * Get next key from an object
@@ -875,8 +875,8 @@ typedef void* ucl_object_iter_t;
  * @param ep pointer record exception (such as ENOMEM), could be NULL
  * @return the next object or NULL
  */
-UCL_EXTERN const ucl_object_t* ucl_object_iterate_with_error (const ucl_object_t *obj,
-               ucl_object_iter_t *iter, bool expand_values, int *ep);
+UCL_EXTERN const ucl_object_t *ucl_object_iterate_with_error(const ucl_object_t *obj,
+                                                                                                                        ucl_object_iter_t *iter, bool expand_values, int *ep);
 
 #define ucl_iterate_object ucl_object_iterate
 #define ucl_object_iterate(ob, it, ev) ucl_object_iterate_with_error((ob), (it), (ev), NULL)
@@ -886,7 +886,7 @@ UCL_EXTERN const ucl_object_t* ucl_object_iterate_with_error (const ucl_object_t
  * @param obj object to iterate
  * @return new iterator object that should be used with safe iterators API only
  */
-UCL_EXTERN ucl_object_iter_t ucl_object_iterate_new (const ucl_object_t *obj)
+UCL_EXTERN ucl_object_iter_t ucl_object_iterate_new(const ucl_object_t *obj)
        UCL_WARN_UNUSED_RESULT;
 /**
  * Check safe iterator object after performing some operations on it
@@ -902,8 +902,8 @@ UCL_EXTERN bool ucl_object_iter_chk_excpn(ucl_object_iter_t *it);
  * @param obj new object to iterate
  * @return modified iterator object
  */
-UCL_EXTERN ucl_object_iter_t ucl_object_iterate_reset (ucl_object_iter_t it,
-               const ucl_object_t *obj);
+UCL_EXTERN ucl_object_iter_t ucl_object_iterate_reset(ucl_object_iter_t it,
+                                                                                                         const ucl_object_t *obj);
 
 /**
  * Get the next object from the `obj`. This function iterates over arrays, objects
@@ -912,15 +912,15 @@ UCL_EXTERN ucl_object_iter_t ucl_object_iterate_reset (ucl_object_iter_t it,
  * @param expand_values expand explicit arrays and objects
  * @return the next object in sequence
  */
-UCL_EXTERN const ucl_object_t* ucl_object_iterate_safe (ucl_object_iter_t iter,
-               bool expand_values);
+UCL_EXTERN const ucl_object_t *ucl_object_iterate_safe(ucl_object_iter_t iter,
+                                                                                                          bool expand_values);
 /**
  * Iteration type enumerator
  */
 enum ucl_iterate_type {
-       UCL_ITERATE_EXPLICIT = 1 << 0, /**< Iterate just explicit arrays and objects */
-       UCL_ITERATE_IMPLICIT = 1 << 1,  /**< Iterate just implicit arrays */
-       UCL_ITERATE_BOTH = (1 << 0) | (1 << 1),   /**< Iterate both explicit and implicit arrays*/
+       UCL_ITERATE_EXPLICIT = 1 << 0,          /**< Iterate just explicit arrays and objects */
+       UCL_ITERATE_IMPLICIT = 1 << 1,          /**< Iterate just implicit arrays */
+       UCL_ITERATE_BOTH = (1 << 0) | (1 << 1), /**< Iterate both explicit and implicit arrays*/
 };
 
 /**
@@ -930,14 +930,14 @@ enum ucl_iterate_type {
  * @param
  * @return the next object in sequence
  */
-UCL_EXTERN const ucl_object_t* ucl_object_iterate_full (ucl_object_iter_t iter,
-               enum ucl_iterate_type type);
+UCL_EXTERN const ucl_object_t *ucl_object_iterate_full(ucl_object_iter_t iter,
+                                                                                                          enum ucl_iterate_type type);
 
 /**
  * Free memory associated with the safe iterator
  * @param it safe iterator object
  */
-UCL_EXTERN void ucl_object_iterate_free (ucl_object_iter_t it);
+UCL_EXTERN void ucl_object_iterate_free(ucl_object_iter_t it);
 
 /** @} */
 
@@ -958,9 +958,9 @@ UCL_EXTERN void ucl_object_iterate_free (ucl_object_iter_t it);
  * @param err error pointer
  * @return true if macro has been parsed
  */
-typedef bool (*ucl_macro_handler) (const unsigned char *data, size_t len,
-               const ucl_object_t *arguments,
-               void* ud);
+typedef bool (*ucl_macro_handler)(const unsigned char *data, size_t len,
+                                                                 const ucl_object_t *arguments,
+                                                                 void *ud);
 
 /**
  * Context dependent macro handler for a parser
@@ -972,10 +972,10 @@ typedef bool (*ucl_macro_handler) (const unsigned char *data, size_t len,
  * @param err error pointer
  * @return true if macro has been parsed
  */
-typedef bool (*ucl_context_macro_handler) (const unsigned char *data, size_t len,
-               const ucl_object_t *arguments,
-               const ucl_object_t *context,
-               void* ud);
+typedef bool (*ucl_context_macro_handler)(const unsigned char *data, size_t len,
+                                                                                 const ucl_object_t *arguments,
+                                                                                 const ucl_object_t *context,
+                                                                                 void *ud);
 
 /* Opaque parser */
 struct ucl_parser;
@@ -985,7 +985,7 @@ struct ucl_parser;
  * @param pool pool to allocate memory from
  * @return new parser object
  */
-UCL_EXTERN struct ucl_parser* ucl_parser_new (int flags);
+UCL_EXTERN struct ucl_parser *ucl_parser_new(int flags);
 
 /**
  * Sets the default priority for the parser applied to chunks that do not
@@ -994,15 +994,15 @@ UCL_EXTERN struct ucl_parser* ucl_parser_new (int flags);
  * @param prio default priority (0 .. 16)
  * @return true if parser's default priority was set
  */
-UCL_EXTERN bool ucl_parser_set_default_priority (struct ucl_parser *parser,
-               unsigned prio);
+UCL_EXTERN bool ucl_parser_set_default_priority(struct ucl_parser *parser,
+                                                                                               unsigned prio);
 /**
  * Gets the default priority for the parser applied to chunks that do not
  * specify priority explicitly
  * @param parser parser object
  * @return true default priority (0 .. 16), -1 for failure
  */
-UCL_EXTERN int ucl_parser_get_default_priority (struct ucl_parser *parser);
+UCL_EXTERN int ucl_parser_get_default_priority(struct ucl_parser *parser);
 
 /**
  * Register new handler for a macro
@@ -1012,9 +1012,9 @@ UCL_EXTERN int ucl_parser_get_default_priority (struct ucl_parser *parser);
  * @param ud opaque user data for a handler
  * @return true on success, false on failure (i.e. ENOMEM)
  */
-UCL_EXTERN bool ucl_parser_register_macro (struct ucl_parser *parser,
-               const char *macro,
-               ucl_macro_handler handler, void* ud);
+UCL_EXTERN bool ucl_parser_register_macro(struct ucl_parser *parser,
+                                                                                 const char *macro,
+                                                                                 ucl_macro_handler handler, void *ud);
 
 /**
  * Register new context dependent handler for a macro
@@ -1024,10 +1024,10 @@ UCL_EXTERN bool ucl_parser_register_macro (struct ucl_parser *parser,
  * @param ud opaque user data for a handler
  * @return true on success, false on failure (i.e. ENOMEM)
  */
-UCL_EXTERN bool ucl_parser_register_context_macro (struct ucl_parser *parser,
-               const char *macro,
-               ucl_context_macro_handler handler,
-               void* ud);
+UCL_EXTERN bool ucl_parser_register_context_macro(struct ucl_parser *parser,
+                                                                                                 const char *macro,
+                                                                                                 ucl_context_macro_handler handler,
+                                                                                                 void *ud);
 
 /**
  * Handler to detect unregistered variables
@@ -1039,8 +1039,8 @@ UCL_EXTERN bool ucl_parser_register_context_macro (struct ucl_parser *parser,
  * @param ud opaque userdata
  * @return true if variable
  */
-typedef bool (*ucl_variable_handler) (const unsigned char *data, size_t len,
-               unsigned char **replace, size_t *replace_len, bool *need_free, void* ud);
+typedef bool (*ucl_variable_handler)(const unsigned char *data, size_t len,
+                                                                        unsigned char **replace, size_t *replace_len, bool *need_free, void *ud);
 
 /**
  * Register new parser variable
@@ -1048,8 +1048,8 @@ typedef bool (*ucl_variable_handler) (const unsigned char *data, size_t len,
  * @param var variable name
  * @param value variable value
  */
-UCL_EXTERN void ucl_parser_register_variable (struct ucl_parser *parser, const char *var,
-               const char *value);
+UCL_EXTERN void ucl_parser_register_variable(struct ucl_parser *parser, const char *var,
+                                                                                        const char *value);
 
 /**
  * Set handler for unknown variables
@@ -1057,8 +1057,8 @@ UCL_EXTERN void ucl_parser_register_variable (struct ucl_parser *parser, const c
  * @param handler desired handler
  * @param ud opaque data for the handler
  */
-UCL_EXTERN void ucl_parser_set_variables_handler (struct ucl_parser *parser,
-               ucl_variable_handler handler, void *ud);
+UCL_EXTERN void ucl_parser_set_variables_handler(struct ucl_parser *parser,
+                                                                                                ucl_variable_handler handler, void *ud);
 
 /**
  * Load new chunk to a parser
@@ -1067,8 +1067,8 @@ UCL_EXTERN void ucl_parser_set_variables_handler (struct ucl_parser *parser,
  * @param len the length of a chunk
  * @return true if chunk has been added and false in case of error
  */
-UCL_EXTERN bool ucl_parser_add_chunk (struct ucl_parser *parser,
-               const unsigned char *data, size_t len);
+UCL_EXTERN bool ucl_parser_add_chunk(struct ucl_parser *parser,
+                                                                        const unsigned char *data, size_t len);
 
 /**
  * Load new chunk to a parser with the specified priority
@@ -1079,8 +1079,8 @@ UCL_EXTERN bool ucl_parser_add_chunk (struct ucl_parser *parser,
  * are considered for this parameter)
  * @return true if chunk has been added and false in case of error
  */
-UCL_EXTERN bool ucl_parser_add_chunk_priority (struct ucl_parser *parser,
-               const unsigned char *data, size_t len, unsigned priority);
+UCL_EXTERN bool ucl_parser_add_chunk_priority(struct ucl_parser *parser,
+                                                                                         const unsigned char *data, size_t len, unsigned priority);
 
 /**
  * Insert new chunk to a parser (must have previously processed data with an existing top object)
@@ -1089,8 +1089,8 @@ UCL_EXTERN bool ucl_parser_add_chunk_priority (struct ucl_parser *parser,
  * @param len the length of a chunk
  * @return true if chunk has been added and false in case of error
  */
-UCL_EXTERN bool ucl_parser_insert_chunk (struct ucl_parser *parser,
-               const unsigned char *data, size_t len);
+UCL_EXTERN bool ucl_parser_insert_chunk(struct ucl_parser *parser,
+                                                                               const unsigned char *data, size_t len);
 
 /**
  * Full version of ucl_add_chunk with priority and duplicate strategy
@@ -1103,9 +1103,9 @@ UCL_EXTERN bool ucl_parser_insert_chunk (struct ucl_parser *parser,
  * @param parse_type input format
  * @return true if chunk has been added and false in case of error
  */
-UCL_EXTERN bool ucl_parser_add_chunk_full (struct ucl_parser *parser,
-               const unsigned char *data, size_t len, unsigned priority,
-               enum ucl_duplicate_strategy strat, enum ucl_parse_type parse_type);
+UCL_EXTERN bool ucl_parser_add_chunk_full(struct ucl_parser *parser,
+                                                                                 const unsigned char *data, size_t len, unsigned priority,
+                                                                                 enum ucl_duplicate_strategy strat, enum ucl_parse_type parse_type);
 
 /**
  * Load ucl object from a string
@@ -1114,8 +1114,8 @@ UCL_EXTERN bool ucl_parser_add_chunk_full (struct ucl_parser *parser,
  * @param len the length of the string, if `len` is 0 then `data` must be zero-terminated string
  * @return true if string has been added and false in case of error
  */
-UCL_EXTERN bool ucl_parser_add_string (struct ucl_parser *parser,
-               const char *data, size_t len);
+UCL_EXTERN bool ucl_parser_add_string(struct ucl_parser *parser,
+                                                                         const char *data, size_t len);
 
 /**
  * Load ucl object from a string
@@ -1126,8 +1126,8 @@ UCL_EXTERN bool ucl_parser_add_string (struct ucl_parser *parser,
  * are considered for this parameter)
  * @return true if string has been added and false in case of error
  */
-UCL_EXTERN bool ucl_parser_add_string_priority (struct ucl_parser *parser,
-               const char *data, size_t len, unsigned priority);
+UCL_EXTERN bool ucl_parser_add_string_priority(struct ucl_parser *parser,
+                                                                                          const char *data, size_t len, unsigned priority);
 
 /**
  * Load and add data from a file
@@ -1136,8 +1136,8 @@ UCL_EXTERN bool ucl_parser_add_string_priority (struct ucl_parser *parser,
  * @param err if *err is NULL it is set to parser error
  * @return true if chunk has been added and false in case of error
  */
-UCL_EXTERN bool ucl_parser_add_file (struct ucl_parser *parser,
-               const char *filename);
+UCL_EXTERN bool ucl_parser_add_file(struct ucl_parser *parser,
+                                                                       const char *filename);
 
 /**
  * Load and add data from a file
@@ -1148,8 +1148,8 @@ UCL_EXTERN bool ucl_parser_add_file (struct ucl_parser *parser,
  * are considered for this parameter)
  * @return true if chunk has been added and false in case of error
  */
-UCL_EXTERN bool ucl_parser_add_file_priority (struct ucl_parser *parser,
-               const char *filename, unsigned priority);
+UCL_EXTERN bool ucl_parser_add_file_priority(struct ucl_parser *parser,
+                                                                                        const char *filename, unsigned priority);
 
 /**
  * Load and add data from a file
@@ -1161,9 +1161,9 @@ UCL_EXTERN bool ucl_parser_add_file_priority (struct ucl_parser *parser,
  * @param parse_type Parser type to use while parsing this file
  * @return true if chunk has been added and false in case of error
  */
-UCL_EXTERN bool ucl_parser_add_file_full (struct ucl_parser *parser, const char *filename,
-               unsigned priority, enum ucl_duplicate_strategy strat,
-               enum ucl_parse_type parse_type);
+UCL_EXTERN bool ucl_parser_add_file_full(struct ucl_parser *parser, const char *filename,
+                                                                                unsigned priority, enum ucl_duplicate_strategy strat,
+                                                                                enum ucl_parse_type parse_type);
 
 /**
  * Load and add data from a file descriptor
@@ -1172,8 +1172,8 @@ UCL_EXTERN bool ucl_parser_add_file_full (struct ucl_parser *parser, const char
  * @param err if *err is NULL it is set to parser error
  * @return true if chunk has been added and false in case of error
  */
-UCL_EXTERN bool ucl_parser_add_fd (struct ucl_parser *parser,
-               int fd);
+UCL_EXTERN bool ucl_parser_add_fd(struct ucl_parser *parser,
+                                                                 int fd);
 
 /**
  * Load and add data from a file descriptor
@@ -1184,8 +1184,8 @@ UCL_EXTERN bool ucl_parser_add_fd (struct ucl_parser *parser,
  * are considered for this parameter)
  * @return true if chunk has been added and false in case of error
  */
-UCL_EXTERN bool ucl_parser_add_fd_priority (struct ucl_parser *parser,
-               int fd, unsigned priority);
+UCL_EXTERN bool ucl_parser_add_fd_priority(struct ucl_parser *parser,
+                                                                                  int fd, unsigned priority);
 
 /**
  * Load and add data from a file descriptor
@@ -1198,9 +1198,9 @@ UCL_EXTERN bool ucl_parser_add_fd_priority (struct ucl_parser *parser,
  * @param parse_type Parser type to use while parsing this file
  * @return true if chunk has been added and false in case of error
  */
-UCL_EXTERN bool ucl_parser_add_fd_full (struct ucl_parser *parser, int fd,
-               unsigned priority, enum ucl_duplicate_strategy strat,
-               enum ucl_parse_type parse_type);
+UCL_EXTERN bool ucl_parser_add_fd_full(struct ucl_parser *parser, int fd,
+                                                                          unsigned priority, enum ucl_duplicate_strategy strat,
+                                                                          enum ucl_parse_type parse_type);
 
 /**
  * Provide a UCL_ARRAY of paths to search for include files. The object is
@@ -1209,8 +1209,8 @@ UCL_EXTERN bool ucl_parser_add_fd_full (struct ucl_parser *parser, int fd,
  * @param paths UCL_ARRAY of paths to search
  * @return true if the path search array was replaced in the parser
  */
-UCL_EXTERN bool ucl_set_include_path (struct ucl_parser *parser,
-               ucl_object_t *paths);
+UCL_EXTERN bool ucl_set_include_path(struct ucl_parser *parser,
+                                                                        ucl_object_t *paths);
 
 /**
  * Get a top object for a parser (refcount is increased)
@@ -1218,7 +1218,7 @@ UCL_EXTERN bool ucl_set_include_path (struct ucl_parser *parser,
  * @param err if *err is NULL it is set to parser error
  * @return top parser object or NULL
  */
-UCL_EXTERN ucl_object_t* ucl_parser_get_object (struct ucl_parser *parser);
+UCL_EXTERN ucl_object_t *ucl_parser_get_object(struct ucl_parser *parser);
 
 /**
  * Get the current stack object as stack accessor function for use in macro
@@ -1227,61 +1227,61 @@ UCL_EXTERN ucl_object_t* ucl_parser_get_object (struct ucl_parser *parser);
  * @param depth depth of stack to retrieve (top is 0)
  * @return current stack object or NULL
  */
-UCL_EXTERN ucl_object_t* ucl_parser_get_current_stack_object (struct ucl_parser *parser, unsigned int depth);
+UCL_EXTERN ucl_object_t *ucl_parser_get_current_stack_object(struct ucl_parser *parser, unsigned int depth);
 
 /**
  * Peek at the character at the current chunk position
  * @param parser parser structure
  * @return current chunk position character
  */
-UCL_EXTERN unsigned char ucl_parser_chunk_peek (struct ucl_parser *parser);
+UCL_EXTERN unsigned char ucl_parser_chunk_peek(struct ucl_parser *parser);
 
 /**
  * Skip the character at the current chunk position
  * @param parser parser structure
  * @return success boolean
  */
-UCL_EXTERN bool ucl_parser_chunk_skip (struct ucl_parser *parser);
+UCL_EXTERN bool ucl_parser_chunk_skip(struct ucl_parser *parser);
 
 /**
  * Get the error string if parsing has been failed
  * @param parser parser object
  * @return error description
  */
-UCL_EXTERN const char *ucl_parser_get_error (struct ucl_parser *parser);
+UCL_EXTERN const char *ucl_parser_get_error(struct ucl_parser *parser);
 
 /**
  * Get the code of the last error
  * @param parser parser object
  * @return error code
  */
-UCL_EXTERN int ucl_parser_get_error_code (struct ucl_parser *parser);
+UCL_EXTERN int ucl_parser_get_error_code(struct ucl_parser *parser);
 
 /**
  * Get the current column number within parser
  * @param parser parser object
  * @return current column number
  */
-UCL_EXTERN unsigned ucl_parser_get_column (struct ucl_parser *parser);
+UCL_EXTERN unsigned ucl_parser_get_column(struct ucl_parser *parser);
 
 /**
  * Get the current line number within parser
  * @param parser parser object
  * @return current line number
  */
-UCL_EXTERN unsigned ucl_parser_get_linenum (struct ucl_parser *parser);
+UCL_EXTERN unsigned ucl_parser_get_linenum(struct ucl_parser *parser);
 
 /**
  * Clear the error in the parser
  * @param parser parser object
  */
-UCL_EXTERN void ucl_parser_clear_error (struct ucl_parser *parser);
+UCL_EXTERN void ucl_parser_clear_error(struct ucl_parser *parser);
 
 /**
  * Free ucl parser object
  * @param parser parser object
  */
-UCL_EXTERN void ucl_parser_free (struct ucl_parser *parser);
+UCL_EXTERN void ucl_parser_free(struct ucl_parser *parser);
 
 /**
  * Get constant opaque pointer to comments structure for this parser. Increase
@@ -1289,7 +1289,7 @@ UCL_EXTERN void ucl_parser_free (struct ucl_parser *parser);
  * @param parser parser structure
  * @return ucl comments pointer or NULL
  */
-UCL_EXTERN const ucl_object_t * ucl_parser_get_comments (struct ucl_parser *parser);
+UCL_EXTERN const ucl_object_t *ucl_parser_get_comments(struct ucl_parser *parser);
 
 /**
  * Utility function to find a comment object for the specified object in the input
@@ -1297,8 +1297,8 @@ UCL_EXTERN const ucl_object_t * ucl_parser_get_comments (struct ucl_parser *pars
  * @param srch search object
  * @return string comment enclosed in ucl_object_t
  */
-UCL_EXTERN const ucl_object_t * ucl_comments_find (const ucl_object_t *comments,
-               const ucl_object_t *srch);
+UCL_EXTERN const ucl_object_t *ucl_comments_find(const ucl_object_t *comments,
+                                                                                                const ucl_object_t *srch);
 
 /**
  * Move comment from `from` object to `to` object
@@ -1307,8 +1307,8 @@ UCL_EXTERN const ucl_object_t * ucl_comments_find (const ucl_object_t *comments,
  * @param with destination object
  * @return `true` if `from` has comment and it has been moved to `to`
  */
-UCL_EXTERN bool ucl_comments_move (ucl_object_t *comments,
-               const ucl_object_t *from, const ucl_object_t *to);
+UCL_EXTERN bool ucl_comments_move(ucl_object_t *comments,
+                                                                 const ucl_object_t *from, const ucl_object_t *to);
 
 /**
  * Adds a new comment for an object
@@ -1316,8 +1316,8 @@ UCL_EXTERN bool ucl_comments_move (ucl_object_t *comments,
  * @param obj object to add comment to
  * @param comment string representation of a comment
  */
-UCL_EXTERN void ucl_comments_add (ucl_object_t *comments,
-               const ucl_object_t *obj, const char *comment);
+UCL_EXTERN void ucl_comments_add(ucl_object_t *comments,
+                                                                const ucl_object_t *obj, const char *comment);
 
 /**
  * Add new public key to parser for signatures check
@@ -1327,8 +1327,8 @@ UCL_EXTERN void ucl_comments_add (ucl_object_t *comments,
  * @param err if *err is NULL it is set to parser error
  * @return true if a key has been successfully added
  */
-UCL_EXTERN bool ucl_parser_pubkey_add (struct ucl_parser *parser,
-               const unsigned char *key, size_t len);
+UCL_EXTERN bool ucl_parser_pubkey_add(struct ucl_parser *parser,
+                                                                         const unsigned char *key, size_t len);
 
 /**
  * Set FILENAME and CURDIR variables in parser
@@ -1337,23 +1337,23 @@ UCL_EXTERN bool ucl_parser_pubkey_add (struct ucl_parser *parser,
  * @param need_expand perform realpath() if this variable is true and filename is not NULL
  * @return true if variables has been set
  */
-UCL_EXTERN bool ucl_parser_set_filevars (struct ucl_parser *parser, const char *filename,
-               bool need_expand);
+UCL_EXTERN bool ucl_parser_set_filevars(struct ucl_parser *parser, const char *filename,
+                                                                               bool need_expand);
 
 /**
  * Returns current file for the parser
  * @param parser parser object
  * @return current file or NULL if parsing memory
  */
-UCL_EXTERN const char *ucl_parser_get_cur_file (struct ucl_parser *parser);
+UCL_EXTERN const char *ucl_parser_get_cur_file(struct ucl_parser *parser);
 
 /**
  * Defines special handler for certain types of data (identified by magic)
  */
-typedef bool (*ucl_parser_special_handler_t) (struct ucl_parser *parser,
-               const unsigned char *source, size_t source_len,
-               unsigned char **destination, size_t *dest_len,
-               void *user_data);
+typedef bool (*ucl_parser_special_handler_t)(struct ucl_parser *parser,
+                                                                                        const unsigned char *source, size_t source_len,
+                                                                                        unsigned char **destination, size_t *dest_len,
+                                                                                        void *user_data);
 
 /**
  * Special handler flags
@@ -1371,7 +1371,7 @@ struct ucl_parser_special_handler {
        size_t magic_len;
        enum ucl_special_handler_flags flags;
        ucl_parser_special_handler_t handler;
-       void (*free_function) (unsigned char *data, size_t len, void *user_data);
+       void (*free_function)(unsigned char *data, size_t len, void *user_data);
        void *user_data;
        struct ucl_parser_special_handler *next; /* Used internally */
 };
@@ -1381,8 +1381,8 @@ struct ucl_parser_special_handler {
  * @param parser parser structure
  * @param handler handler structure
  */
-UCL_EXTERN void ucl_parser_add_special_handler (struct ucl_parser *parser,
-               struct ucl_parser_special_handler *handler);
+UCL_EXTERN void ucl_parser_add_special_handler(struct ucl_parser *parser,
+                                                                                          struct ucl_parser_special_handler *handler);
 
 /**
  * Handler for include traces:
@@ -1393,12 +1393,12 @@ UCL_EXTERN void ucl_parser_add_special_handler (struct ucl_parser *parser,
  * @param pathlen length of the path
  * @param user_data opaque userdata
  */
-typedef void (ucl_include_trace_func_t) (struct ucl_parser *parser,
-               const ucl_object_t *parent,
-               const ucl_object_t *args,
-               const char *path,
-               size_t pathlen,
-               void *user_data);
+typedef void(ucl_include_trace_func_t)(struct ucl_parser *parser,
+                                                                          const ucl_object_t *parent,
+                                                                          const ucl_object_t *args,
+                                                                          const char *path,
+                                                                          size_t pathlen,
+                                                                          void *user_data);
 
 /**
  * Register trace function for an include handler
@@ -1406,9 +1406,9 @@ typedef void (ucl_include_trace_func_t) (struct ucl_parser *parser,
  * @param func function to trace includes
  * @param user_data opaque data
  */
-UCL_EXTERN void ucl_parser_set_include_tracer (struct ucl_parser *parser,
-                                                                                          ucl_include_trace_func_t func,
-                                                                                          void *user_data);
+UCL_EXTERN void ucl_parser_set_include_tracer(struct ucl_parser *parser,
+                                                                                         ucl_include_trace_func_t func,
+                                                                                         void *user_data);
 
 /** @} */
 
@@ -1425,13 +1425,13 @@ struct ucl_emitter_context;
  */
 struct ucl_emitter_functions {
        /** Append a single character */
-       int (*ucl_emitter_append_character) (unsigned char c, size_t nchars, void *ud);
+       int (*ucl_emitter_append_character)(unsigned char c, size_t nchars, void *ud);
        /** Append a string of a specified length */
-       int (*ucl_emitter_append_len) (unsigned const char *str, size_t len, void *ud);
+       int (*ucl_emitter_append_len)(unsigned const char *str, size_t len, void *ud);
        /** Append a 64 bit integer */
-       int (*ucl_emitter_append_int) (int64_t elt, void *ud);
+       int (*ucl_emitter_append_int)(int64_t elt, void *ud);
        /** Append floating point element */
-       int (*ucl_emitter_append_double) (double elt, void *ud);
+       int (*ucl_emitter_append_double)(double elt, void *ud);
        /** Free userdata */
        void (*ucl_emitter_free_func)(void *ud);
        /** Opaque userdata pointer */
@@ -1440,19 +1440,19 @@ struct ucl_emitter_functions {
 
 struct ucl_emitter_operations {
        /** Write a primitive element */
-       void (*ucl_emitter_write_elt) (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj, bool first, bool print_key);
+       void (*ucl_emitter_write_elt)(struct ucl_emitter_context *ctx,
+                                                                 const ucl_object_t *obj, bool first, bool print_key);
        /** Start ucl object */
-       void (*ucl_emitter_start_object) (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj, bool print_key);
+       void (*ucl_emitter_start_object)(struct ucl_emitter_context *ctx,
+                                                                        const ucl_object_t *obj, bool print_key);
        /** End ucl object */
-       void (*ucl_emitter_end_object) (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj);
+       void (*ucl_emitter_end_object)(struct ucl_emitter_context *ctx,
+                                                                  const ucl_object_t *obj);
        /** Start ucl array */
-       void (*ucl_emitter_start_array) (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj, bool print_key);
-       void (*ucl_emitter_end_array) (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj);
+       void (*ucl_emitter_start_array)(struct ucl_emitter_context *ctx,
+                                                                       const ucl_object_t *obj, bool print_key);
+       void (*ucl_emitter_end_array)(struct ucl_emitter_context *ctx,
+                                                                 const ucl_object_t *obj);
 };
 
 /**
@@ -1482,8 +1482,8 @@ struct ucl_emitter_context {
  * #UCL_EMIT_CONFIG then emit config like object
  * @return dump of an object (must be freed after using) or NULL in case of error
  */
-UCL_EXTERN unsigned char *ucl_object_emit (const ucl_object_t *obj,
-               enum ucl_emitter emit_type);
+UCL_EXTERN unsigned char *ucl_object_emit(const ucl_object_t *obj,
+                                                                                 enum ucl_emitter emit_type);
 
 /**
  * Emit object to a string that can contain `\0` inside
@@ -1493,8 +1493,8 @@ UCL_EXTERN unsigned char *ucl_object_emit (const ucl_object_t *obj,
  * @param len the resulting length
  * @return dump of an object (must be freed after using) or NULL in case of error
  */
-UCL_EXTERN unsigned char *ucl_object_emit_len (const ucl_object_t *obj,
-               enum ucl_emitter emit_type, size_t *len);
+UCL_EXTERN unsigned char *ucl_object_emit_len(const ucl_object_t *obj,
+                                                                                         enum ucl_emitter emit_type, size_t *len);
 
 /**
  * Emit object to a string
@@ -1505,10 +1505,10 @@ UCL_EXTERN unsigned char *ucl_object_emit_len (const ucl_object_t *obj,
  * @param comments optional comments for the parser
  * @return dump of an object (must be freed after using) or NULL in case of error
  */
-UCL_EXTERN bool ucl_object_emit_full (const ucl_object_t *obj,
-               enum ucl_emitter emit_type,
-               struct ucl_emitter_functions *emitter,
-               const ucl_object_t *comments);
+UCL_EXTERN bool ucl_object_emit_full(const ucl_object_t *obj,
+                                                                        enum ucl_emitter emit_type,
+                                                                        struct ucl_emitter_functions *emitter,
+                                                                        const ucl_object_t *comments);
 
 /**
  * Start streamlined UCL object emitter
@@ -1518,65 +1518,66 @@ UCL_EXTERN bool ucl_object_emit_full (const ucl_object_t *obj,
  * @return new streamlined context that should be freed by
  * `ucl_object_emit_streamline_finish`
  */
-UCL_EXTERN struct ucl_emitter_context* ucl_object_emit_streamline_new (
-               const ucl_object_t *obj, enum ucl_emitter emit_type,
-               struct ucl_emitter_functions *emitter);
+UCL_EXTERN struct ucl_emitter_context *ucl_object_emit_streamline_new(
+       const ucl_object_t *obj, enum ucl_emitter emit_type,
+       struct ucl_emitter_functions *emitter);
 
 /**
  * Start object or array container for the streamlined output
  * @param ctx streamlined context
  * @param obj container object
+ * @return true if the container was started, false if obj is not a container
  */
-UCL_EXTERN void ucl_object_emit_streamline_start_container (
-               struct ucl_emitter_context *ctx, const ucl_object_t *obj);
+UCL_EXTERN bool ucl_object_emit_streamline_start_container(
+       struct ucl_emitter_context *ctx, const ucl_object_t *obj);
 /**
  * Add a complete UCL object to streamlined output
  * @param ctx streamlined context
  * @param obj object to output
  */
-UCL_EXTERN void ucl_object_emit_streamline_add_object (
-               struct ucl_emitter_context *ctx, const ucl_object_t *obj);
+UCL_EXTERN void ucl_object_emit_streamline_add_object(
+       struct ucl_emitter_context *ctx, const ucl_object_t *obj);
 /**
  * End previously added container
  * @param ctx streamlined context
  */
-UCL_EXTERN void ucl_object_emit_streamline_end_container (
-               struct ucl_emitter_context *ctx);
+UCL_EXTERN void ucl_object_emit_streamline_end_container(
+       struct ucl_emitter_context *ctx);
 /**
  * Terminate streamlined container finishing all containers in it
  * @param ctx streamlined context
  */
-UCL_EXTERN void ucl_object_emit_streamline_finish (
-               struct ucl_emitter_context *ctx);
+UCL_EXTERN void ucl_object_emit_streamline_finish(
+       struct ucl_emitter_context *ctx);
 
 /**
  * Returns functions to emit object to memory
  * @param pmem target pointer (should be freed by caller)
  * @return emitter functions structure
  */
-UCL_EXTERN struct ucl_emitter_functions* ucl_object_emit_memory_funcs (
-               void **pmem);
+UCL_EXTERN struct ucl_emitter_functions *ucl_object_emit_memory_funcs(
+       void **pmem);
 
 /**
  * Returns functions to emit object to FILE *
  * @param fp FILE * object
  * @return emitter functions structure
  */
-UCL_EXTERN struct ucl_emitter_functions* ucl_object_emit_file_funcs (
-               FILE *fp);
+UCL_EXTERN struct ucl_emitter_functions *ucl_object_emit_file_funcs(
+       FILE *fp);
 /**
  * Returns functions to emit object to a file descriptor
  * @param fd file descriptor
  * @return emitter functions structure
  */
-UCL_EXTERN struct ucl_emitter_functions* ucl_object_emit_fd_funcs (
-               int fd);
+UCL_EXTERN struct ucl_emitter_functions *ucl_object_emit_fd_funcs(
+       int fd);
 
 /**
  * Free emitter functions
  * @param f pointer to functions
  */
-UCL_EXTERN void ucl_object_emit_funcs_free (struct ucl_emitter_functions *f);
+UCL_EXTERN void ucl_object_emit_funcs_free(struct ucl_emitter_functions *f);
 
 /** @} */
 
@@ -1591,25 +1592,25 @@ UCL_EXTERN void ucl_object_emit_funcs_free (struct ucl_emitter_functions *f);
  * Used to define UCL schema error
  */
 enum ucl_schema_error_code {
-       UCL_SCHEMA_OK = 0,          /**< no error */
-       UCL_SCHEMA_TYPE_MISMATCH,   /**< type of object is incorrect */
-       UCL_SCHEMA_INVALID_SCHEMA,  /**< schema is invalid */
-       UCL_SCHEMA_MISSING_PROPERTY,/**< one or more missing properties */
-       UCL_SCHEMA_CONSTRAINT,      /**< constraint found */
-       UCL_SCHEMA_MISSING_DEPENDENCY, /**< missing dependency */
+       UCL_SCHEMA_OK = 0,               /**< no error */
+       UCL_SCHEMA_TYPE_MISMATCH,        /**< type of object is incorrect */
+       UCL_SCHEMA_INVALID_SCHEMA,       /**< schema is invalid */
+       UCL_SCHEMA_MISSING_PROPERTY,     /**< one or more missing properties */
+       UCL_SCHEMA_CONSTRAINT,           /**< constraint found */
+       UCL_SCHEMA_MISSING_DEPENDENCY,   /**< missing dependency */
        UCL_SCHEMA_EXTERNAL_REF_MISSING, /**< cannot fetch external ref */
        UCL_SCHEMA_EXTERNAL_REF_INVALID, /**< invalid external ref */
-       UCL_SCHEMA_INTERNAL_ERROR, /**< something bad happened */
-       UCL_SCHEMA_UNKNOWN          /**< generic error */
+       UCL_SCHEMA_INTERNAL_ERROR,       /**< something bad happened */
+       UCL_SCHEMA_UNKNOWN               /**< generic error */
 };
 
 /**
  * Generic ucl schema error
  */
 struct ucl_schema_error {
-       enum ucl_schema_error_code code;        /**< error code */
-       char msg[128];                                          /**< error message */
-       const ucl_object_t *obj;                        /**< object where error occurred */
+       enum ucl_schema_error_code code; /**< error code */
+       char msg[128];                   /**< error message */
+       const ucl_object_t *obj;         /**< object where error occurred */
 };
 
 /**
@@ -1620,8 +1621,8 @@ struct ucl_schema_error {
  * occurred, then `err` is filled with the exact error definition.
  * @return true if `obj` is valid using `schema`
  */
-UCL_EXTERN bool ucl_object_validate (const ucl_object_t *schema,
-               const ucl_object_t *obj, struct ucl_schema_error *err);
+UCL_EXTERN bool ucl_object_validate(const ucl_object_t *schema,
+                                                                       const ucl_object_t *obj, struct ucl_schema_error *err);
 
 /**
  * Validate object `obj` using schema object `schema` and root schema at `root`.
@@ -1632,10 +1633,10 @@ UCL_EXTERN bool ucl_object_validate (const ucl_object_t *schema,
  * occurred, then `err` is filled with the exact error definition.
  * @return true if `obj` is valid using `schema`
  */
-UCL_EXTERN bool ucl_object_validate_root (const ucl_object_t *schema,
-               const ucl_object_t *obj,
-               const ucl_object_t *root,
-               struct ucl_schema_error *err);
+UCL_EXTERN bool ucl_object_validate_root(const ucl_object_t *schema,
+                                                                                const ucl_object_t *obj,
+                                                                                const ucl_object_t *root,
+                                                                                struct ucl_schema_error *err);
 
 /**
  * Validate object `obj` using schema object `schema` and root schema at `root`
@@ -1648,15 +1649,15 @@ UCL_EXTERN bool ucl_object_validate_root (const ucl_object_t *schema,
  * occurred, then `err` is filled with the exact error definition.
  * @return true if `obj` is valid using `schema`
  */
-UCL_EXTERN bool ucl_object_validate_root_ext (const ucl_object_t *schema,
-               const ucl_object_t *obj,
-               const ucl_object_t *root,
-               ucl_object_t *ext_refs,
-               struct ucl_schema_error *err);
+UCL_EXTERN bool ucl_object_validate_root_ext(const ucl_object_t *schema,
+                                                                                        const ucl_object_t *obj,
+                                                                                        const ucl_object_t *root,
+                                                                                        ucl_object_t *ext_refs,
+                                                                                        struct ucl_schema_error *err);
 
 /** @} */
 
-#ifdef  __cplusplus
+#ifdef __cplusplus
 }
 #endif
 /*
index 777093aca77777a50ba101bf00409feb177d8e00..2c179694d5b88e129b774c229a4c451a75983260 100644 (file)
  * Serialise UCL object to various of output formats
  */
 
-static void ucl_emitter_common_elt (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj, bool first, bool print_key, bool compact);
-
-#define UCL_EMIT_TYPE_OPS(type)                \
-       static void ucl_emit_ ## type ## _elt (struct ucl_emitter_context *ctx, \
-               const ucl_object_t *obj, bool first, bool print_key);   \
-       static void ucl_emit_ ## type ## _start_obj (struct ucl_emitter_context *ctx,   \
-               const ucl_object_t *obj, bool print_key);       \
-       static void ucl_emit_ ## type## _start_array (struct ucl_emitter_context *ctx,  \
-               const ucl_object_t *obj, bool print_key);       \
-       static void ucl_emit_ ##type## _end_object (struct ucl_emitter_context *ctx,    \
-               const ucl_object_t *obj);       \
-       static void ucl_emit_ ##type## _end_array (struct ucl_emitter_context *ctx,     \
-               const ucl_object_t *obj)
+static void ucl_emitter_common_elt(struct ucl_emitter_context *ctx,
+                                                                  const ucl_object_t *obj, bool first, bool print_key, bool compact);
+
+#define UCL_EMIT_TYPE_OPS(type)                                                             \
+       static void ucl_emit_##type##_elt(struct ucl_emitter_context *ctx,                      \
+                                                                         const ucl_object_t *obj, bool first, bool print_key); \
+       static void ucl_emit_##type##_start_obj(struct ucl_emitter_context *ctx,                \
+                                                                                       const ucl_object_t *obj, bool print_key);       \
+       static void ucl_emit_##type##_start_array(struct ucl_emitter_context *ctx,              \
+                                                                                         const ucl_object_t *obj, bool print_key);     \
+       static void ucl_emit_##type##_end_object(struct ucl_emitter_context *ctx,               \
+                                                                                        const ucl_object_t *obj);                      \
+       static void ucl_emit_##type##_end_array(struct ucl_emitter_context *ctx,                \
+                                                                                       const ucl_object_t *obj)
 
 /*
  * JSON format operations
@@ -64,27 +64,25 @@ UCL_EMIT_TYPE_OPS(config);
 UCL_EMIT_TYPE_OPS(yaml);
 UCL_EMIT_TYPE_OPS(msgpack);
 
-#define UCL_EMIT_TYPE_CONTENT(type) {  \
-       .ucl_emitter_write_elt = ucl_emit_ ## type ## _elt,     \
-       .ucl_emitter_start_object = ucl_emit_ ## type ##_start_obj,     \
-       .ucl_emitter_start_array = ucl_emit_ ## type ##_start_array,    \
-       .ucl_emitter_end_object = ucl_emit_ ## type ##_end_object,      \
-       .ucl_emitter_end_array = ucl_emit_ ## type ##_end_array \
-}
+#define UCL_EMIT_TYPE_CONTENT(type) {                         \
+       .ucl_emitter_write_elt = ucl_emit_##type##_elt,           \
+       .ucl_emitter_start_object = ucl_emit_##type##_start_obj,  \
+       .ucl_emitter_start_array = ucl_emit_##type##_start_array, \
+       .ucl_emitter_end_object = ucl_emit_##type##_end_object,   \
+       .ucl_emitter_end_array = ucl_emit_##type##_end_array}
 
 static const struct ucl_emitter_operations ucl_standart_emitter_ops[] = {
        [UCL_EMIT_JSON] = UCL_EMIT_TYPE_CONTENT(json),
        [UCL_EMIT_JSON_COMPACT] = UCL_EMIT_TYPE_CONTENT(json_compact),
        [UCL_EMIT_CONFIG] = UCL_EMIT_TYPE_CONTENT(config),
        [UCL_EMIT_YAML] = UCL_EMIT_TYPE_CONTENT(yaml),
-       [UCL_EMIT_MSGPACK] = UCL_EMIT_TYPE_CONTENT(msgpack)
-};
+       [UCL_EMIT_MSGPACK] = UCL_EMIT_TYPE_CONTENT(msgpack)};
 
 /*
  * Utility to check whether we need a top object
  */
 #define UCL_EMIT_IDENT_TOP_OBJ(ctx, obj) ((ctx)->top != (obj) || \
-               ((ctx)->id == UCL_EMIT_JSON_COMPACT || (ctx)->id == UCL_EMIT_JSON))
+                                                                                 ((ctx)->id == UCL_EMIT_JSON_COMPACT || (ctx)->id == UCL_EMIT_JSON))
 
 
 /**
@@ -93,11 +91,11 @@ static const struct ucl_emitter_operations ucl_standart_emitter_ops[] = {
  * @param tabs number of tabs to add
  */
 static inline void
-ucl_add_tabs (const struct ucl_emitter_functions *func, unsigned int tabs,
-               bool compact)
+ucl_add_tabs(const struct ucl_emitter_functions *func, unsigned int tabs,
+                        bool compact)
 {
        if (!compact && tabs > 0) {
-               func->ucl_emitter_append_character (' ', tabs * 4, func->ud);
+               func->ucl_emitter_append_character(' ', tabs * 4, func->ud);
        }
 }
 
@@ -107,8 +105,8 @@ ucl_add_tabs (const struct ucl_emitter_functions *func, unsigned int tabs,
  * @param obj
  */
 static void
-ucl_emitter_print_key (bool print_key, struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj, bool compact)
+ucl_emitter_print_key(bool print_key, struct ucl_emitter_context *ctx,
+                                         const ucl_object_t *obj, bool compact)
 {
        const struct ucl_emitter_functions *func = ctx->func;
 
@@ -118,52 +116,52 @@ ucl_emitter_print_key (bool print_key, struct ucl_emitter_context *ctx,
 
        if (ctx->id == UCL_EMIT_CONFIG) {
                if (obj->flags & UCL_OBJECT_NEED_KEY_ESCAPE) {
-                       ucl_elt_string_write_json (obj->key, obj->keylen, ctx);
+                       ucl_elt_string_write_json(obj->key, obj->keylen, ctx);
                }
                else {
-                       func->ucl_emitter_append_len (obj->key, obj->keylen, func->ud);
+                       func->ucl_emitter_append_len(obj->key, obj->keylen, func->ud);
                }
 
                if (obj->type != UCL_OBJECT && obj->type != UCL_ARRAY) {
-                       func->ucl_emitter_append_len (" = ", 3, func->ud);
+                       func->ucl_emitter_append_len(" = ", 3, func->ud);
                }
                else {
-                       func->ucl_emitter_append_character (' ', 1, func->ud);
+                       func->ucl_emitter_append_character(' ', 1, func->ud);
                }
        }
        else if (ctx->id == UCL_EMIT_YAML) {
                if (obj->keylen > 0 && (obj->flags & UCL_OBJECT_NEED_KEY_ESCAPE)) {
-                       ucl_elt_string_write_json (obj->key, obj->keylen, ctx);
+                       ucl_elt_string_write_json(obj->key, obj->keylen, ctx);
                }
                else if (obj->keylen > 0) {
-                       func->ucl_emitter_append_len (obj->key, obj->keylen, func->ud);
+                       func->ucl_emitter_append_len(obj->key, obj->keylen, func->ud);
                }
                else {
-                       func->ucl_emitter_append_len ("null", 4, func->ud);
+                       func->ucl_emitter_append_len("null", 4, func->ud);
                }
 
-               func->ucl_emitter_append_len (": ", 2, func->ud);
+               func->ucl_emitter_append_len(": ", 2, func->ud);
        }
        else {
                if (obj->keylen > 0) {
-                       ucl_elt_string_write_json (obj->key, obj->keylen, ctx);
+                       ucl_elt_string_write_json(obj->key, obj->keylen, ctx);
                }
                else {
-                       func->ucl_emitter_append_len ("null", 4, func->ud);
+                       func->ucl_emitter_append_len("null", 4, func->ud);
                }
 
                if (compact) {
-                       func->ucl_emitter_append_character (':', 1, func->ud);
+                       func->ucl_emitter_append_character(':', 1, func->ud);
                }
                else {
-                       func->ucl_emitter_append_len (": ", 2, func->ud);
+                       func->ucl_emitter_append_len(": ", 2, func->ud);
                }
        }
 }
 
 static void
-ucl_emitter_finish_object (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj, bool compact, bool is_array)
+ucl_emitter_finish_object(struct ucl_emitter_context *ctx,
+                                                 const ucl_object_t *obj, bool compact, bool is_array)
 {
        const struct ucl_emitter_functions *func = ctx->func;
 
@@ -171,15 +169,15 @@ ucl_emitter_finish_object (struct ucl_emitter_context *ctx,
                if (obj->type != UCL_OBJECT && obj->type != UCL_ARRAY) {
                        if (!is_array) {
                                /* Objects are split by ';' */
-                               func->ucl_emitter_append_len (";\n", 2, func->ud);
+                               func->ucl_emitter_append_len(";\n", 2, func->ud);
                        }
                        else {
                                /* Use commas for arrays */
-                               func->ucl_emitter_append_len (",\n", 2, func->ud);
+                               func->ucl_emitter_append_len(",\n", 2, func->ud);
                        }
                }
                else {
-                       func->ucl_emitter_append_character ('\n', 1, func->ud);
+                       func->ucl_emitter_append_character('\n', 1, func->ud);
                }
        }
 }
@@ -190,27 +188,27 @@ ucl_emitter_finish_object (struct ucl_emitter_context *ctx,
  * @param compact compact flag
  */
 static void
-ucl_emitter_common_end_object (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj, bool compact)
+ucl_emitter_common_end_object(struct ucl_emitter_context *ctx,
+                                                         const ucl_object_t *obj, bool compact)
 {
        const struct ucl_emitter_functions *func = ctx->func;
 
        if (UCL_EMIT_IDENT_TOP_OBJ(ctx, obj)) {
-               ctx->indent --;
+               ctx->indent--;
                if (compact || obj->len == 0) {
-                       func->ucl_emitter_append_character ('}', 1, func->ud);
+                       func->ucl_emitter_append_character('}', 1, func->ud);
                }
                else {
                        if (ctx->id != UCL_EMIT_CONFIG) {
                                /* newline is already added for this format */
-                               func->ucl_emitter_append_character ('\n', 1, func->ud);
+                               func->ucl_emitter_append_character('\n', 1, func->ud);
                        }
-                       ucl_add_tabs (func, ctx->indent, compact);
-                       func->ucl_emitter_append_character ('}', 1, func->ud);
+                       ucl_add_tabs(func, ctx->indent, compact);
+                       func->ucl_emitter_append_character('}', 1, func->ud);
                }
        }
 
-       ucl_emitter_finish_object (ctx, obj, compact, false);
+       ucl_emitter_finish_object(ctx, obj, compact, false);
 }
 
 /**
@@ -219,25 +217,25 @@ ucl_emitter_common_end_object (struct ucl_emitter_context *ctx,
  * @param compact compact flag
  */
 static void
-ucl_emitter_common_end_array (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj, bool compact)
+ucl_emitter_common_end_array(struct ucl_emitter_context *ctx,
+                                                        const ucl_object_t *obj, bool compact)
 {
        const struct ucl_emitter_functions *func = ctx->func;
 
-       ctx->indent --;
+       ctx->indent--;
        if (compact || obj->len == 0) {
-               func->ucl_emitter_append_character (']', 1, func->ud);
+               func->ucl_emitter_append_character(']', 1, func->ud);
        }
        else {
                if (ctx->id != UCL_EMIT_CONFIG) {
                        /* newline is already added for this format */
-                       func->ucl_emitter_append_character ('\n', 1, func->ud);
+                       func->ucl_emitter_append_character('\n', 1, func->ud);
                }
-               ucl_add_tabs (func, ctx->indent, compact);
-               func->ucl_emitter_append_character (']', 1, func->ud);
+               ucl_add_tabs(func, ctx->indent, compact);
+               func->ucl_emitter_append_character(']', 1, func->ud);
        }
 
-       ucl_emitter_finish_object (ctx, obj, compact, true);
+       ucl_emitter_finish_object(ctx, obj, compact, true);
 }
 
 /**
@@ -247,29 +245,29 @@ ucl_emitter_common_end_array (struct ucl_emitter_context *ctx,
  * @param compact compact flag
  */
 static void
-ucl_emitter_common_start_array (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj, bool print_key, bool compact)
+ucl_emitter_common_start_array(struct ucl_emitter_context *ctx,
+                                                          const ucl_object_t *obj, bool print_key, bool compact)
 {
        const ucl_object_t *cur;
        ucl_object_iter_t iter = NULL;
        const struct ucl_emitter_functions *func = ctx->func;
        bool first = true;
 
-       ucl_emitter_print_key (print_key, ctx, obj, compact);
+       ucl_emitter_print_key(print_key, ctx, obj, compact);
 
        if (compact || obj->len == 0) {
-               func->ucl_emitter_append_character ('[', 1, func->ud);
+               func->ucl_emitter_append_character('[', 1, func->ud);
        }
        else {
-               func->ucl_emitter_append_len ("[\n", 2, func->ud);
+               func->ucl_emitter_append_len("[\n", 2, func->ud);
        }
 
-       ctx->indent ++;
+       ctx->indent++;
 
        if (obj->type == UCL_ARRAY) {
                /* explicit array */
-               while ((cur = ucl_object_iterate (obj, &iter, true)) != NULL) {
-                       ucl_emitter_common_elt (ctx, cur, first, false, compact);
+               while ((cur = ucl_object_iterate(obj, &iter, true)) != NULL) {
+                       ucl_emitter_common_elt(ctx, cur, first, false, compact);
                        first = false;
                }
        }
@@ -277,7 +275,7 @@ ucl_emitter_common_start_array (struct ucl_emitter_context *ctx,
                /* implicit array */
                cur = obj;
                while (cur) {
-                       ucl_emitter_common_elt (ctx, cur, first, false, compact);
+                       ucl_emitter_common_elt(ctx, cur, first, false, compact);
                        first = false;
                        cur = cur->next;
                }
@@ -291,53 +289,48 @@ ucl_emitter_common_start_array (struct ucl_emitter_context *ctx,
  * @param compact compact flag
  */
 static void
-ucl_emitter_common_start_object (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj, bool print_key, bool compact)
+ucl_emitter_common_start_object(struct ucl_emitter_context *ctx,
+                                                               const ucl_object_t *obj, bool print_key, bool compact)
 {
        ucl_hash_iter_t it = NULL;
        const ucl_object_t *cur, *elt;
        const struct ucl_emitter_functions *func = ctx->func;
        bool first = true;
 
-       ucl_emitter_print_key (print_key, ctx, obj, compact);
+       ucl_emitter_print_key(print_key, ctx, obj, compact);
        /*
         * Print <ident_level>{
         * <ident_level + 1><object content>
         */
        if (UCL_EMIT_IDENT_TOP_OBJ(ctx, obj)) {
                if (compact || obj->len == 0) {
-                       func->ucl_emitter_append_character ('{', 1, func->ud);
+                       func->ucl_emitter_append_character('{', 1, func->ud);
                }
                else {
-                       func->ucl_emitter_append_len ("{\n", 2, func->ud);
+                       func->ucl_emitter_append_len("{\n", 2, func->ud);
                }
-               ctx->indent ++;
+               ctx->indent++;
        }
 
-       while ((cur = ucl_hash_iterate (obj->value.ov, &it))) {
+       while ((cur = ucl_hash_iterate(obj->value.ov, &it))) {
 
                if (ctx->id == UCL_EMIT_CONFIG) {
-                       LL_FOREACH (cur, elt) {
-                               ucl_emitter_common_elt (ctx, elt, first, true, compact);
+                       LL_FOREACH(cur, elt)
+                       {
+                               ucl_emitter_common_elt(ctx, elt, first, true, compact);
                        }
                }
                else {
                        /* Expand implicit arrays */
                        if (cur->next != NULL) {
-                               if (!first) {
-                                       if (compact) {
-                                               func->ucl_emitter_append_character (',', 1, func->ud);
-                                       }
-                                       else {
-                                               func->ucl_emitter_append_len (",\n", 2, func->ud);
-                                       }
+                               if (first) {
+                                       ucl_add_tabs(func, ctx->indent, compact);
                                }
-                               ucl_add_tabs (func, ctx->indent, compact);
-                               ucl_emitter_common_start_array (ctx, cur, true, compact);
-                               ucl_emitter_common_end_array (ctx, cur, compact);
+                               ucl_emitter_common_start_array(ctx, cur, first, compact);
+                               ucl_emitter_common_end_array(ctx, cur, compact);
                        }
                        else {
-                               ucl_emitter_common_elt (ctx, cur, first, true, compact);
+                               ucl_emitter_common_elt(ctx, cur, first, true, compact);
                        }
                }
 
@@ -354,8 +347,8 @@ ucl_emitter_common_start_object (struct ucl_emitter_context *ctx,
  * @param compact compact output
  */
 static void
-ucl_emitter_common_elt (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj, bool first, bool print_key, bool compact)
+ucl_emitter_common_elt(struct ucl_emitter_context *ctx,
+                                          const ucl_object_t *obj, bool first, bool print_key, bool compact)
 {
        const struct ucl_emitter_functions *func = ctx->func;
        bool flag;
@@ -365,31 +358,33 @@ ucl_emitter_common_elt (struct ucl_emitter_context *ctx,
 
        if (ctx->id != UCL_EMIT_CONFIG && !first) {
                if (compact) {
-                       func->ucl_emitter_append_character (',', 1, func->ud);
+                       func->ucl_emitter_append_character(',', 1, func->ud);
                }
                else {
                        if (ctx->id == UCL_EMIT_YAML && ctx->indent == 0) {
-                               func->ucl_emitter_append_len ("\n", 1, func->ud);
-                       } else {
-                               func->ucl_emitter_append_len (",\n", 2, func->ud);
+                               func->ucl_emitter_append_len("\n", 1, func->ud);
+                       }
+                       else {
+                               func->ucl_emitter_append_len(",\n", 2, func->ud);
                        }
                }
        }
 
-       ucl_add_tabs (func, ctx->indent, compact);
+       ucl_add_tabs(func, ctx->indent, compact);
 
        if (ctx->comments && ctx->id == UCL_EMIT_CONFIG) {
-               comment = ucl_object_lookup_len (ctx->comments, (const char *)&obj,
-                               sizeof (void *));
+               comment = ucl_object_lookup_len(ctx->comments, (const char *) &obj,
+                                                                               sizeof(void *));
 
                if (comment) {
                        if (!(comment->flags & UCL_OBJECT_INHERITED)) {
-                               DL_FOREACH (comment, cur_comment) {
-                                       func->ucl_emitter_append_len (cur_comment->value.sv,
-                                                       cur_comment->len,
-                                                       func->ud);
-                                       func->ucl_emitter_append_character ('\n', 1, func->ud);
-                                       ucl_add_tabs (func, ctx->indent, compact);
+                               DL_FOREACH(comment, cur_comment)
+                               {
+                                       func->ucl_emitter_append_len(cur_comment->value.sv,
+                                                                                                cur_comment->len,
+                                                                                                func->ud);
+                                       func->ucl_emitter_append_character('\n', 1, func->ud);
+                                       ucl_add_tabs(func, ctx->indent, compact);
                                }
 
                                comment = NULL;
@@ -399,81 +394,84 @@ ucl_emitter_common_elt (struct ucl_emitter_context *ctx,
 
        switch (obj->type) {
        case UCL_INT:
-               ucl_emitter_print_key (print_key, ctx, obj, compact);
-               func->ucl_emitter_append_int (ucl_object_toint (obj), func->ud);
-               ucl_emitter_finish_object (ctx, obj, compact, !print_key);
+               ucl_emitter_print_key(print_key, ctx, obj, compact);
+               func->ucl_emitter_append_int(ucl_object_toint(obj), func->ud);
+               ucl_emitter_finish_object(ctx, obj, compact, !print_key);
                break;
        case UCL_FLOAT:
        case UCL_TIME:
-               ucl_emitter_print_key (print_key, ctx, obj, compact);
-               func->ucl_emitter_append_double (ucl_object_todouble (obj), func->ud);
-               ucl_emitter_finish_object (ctx, obj, compact, !print_key);
+               ucl_emitter_print_key(print_key, ctx, obj, compact);
+               func->ucl_emitter_append_double(ucl_object_todouble(obj), func->ud);
+               ucl_emitter_finish_object(ctx, obj, compact, !print_key);
                break;
        case UCL_BOOLEAN:
-               ucl_emitter_print_key (print_key, ctx, obj, compact);
-               flag = ucl_object_toboolean (obj);
+               ucl_emitter_print_key(print_key, ctx, obj, compact);
+               flag = ucl_object_toboolean(obj);
                if (flag) {
-                       func->ucl_emitter_append_len ("true", 4, func->ud);
+                       func->ucl_emitter_append_len("true", 4, func->ud);
                }
                else {
-                       func->ucl_emitter_append_len ("false", 5, func->ud);
+                       func->ucl_emitter_append_len("false", 5, func->ud);
                }
-               ucl_emitter_finish_object (ctx, obj, compact, !print_key);
+               ucl_emitter_finish_object(ctx, obj, compact, !print_key);
                break;
        case UCL_STRING:
-               ucl_emitter_print_key (print_key, ctx, obj, compact);
+               ucl_emitter_print_key(print_key, ctx, obj, compact);
                if (ctx->id == UCL_EMIT_CONFIG) {
-                       if (ucl_maybe_long_string (obj)) {
-                               ucl_elt_string_write_multiline (obj->value.sv, obj->len, ctx);
-                       } else {
+                       if (ucl_maybe_long_string(obj)) {
+                               ucl_elt_string_write_multiline(obj->value.sv, obj->len, ctx);
+                       }
+                       else {
                                if (obj->flags & UCL_OBJECT_SQUOTED) {
-                                       ucl_elt_string_write_squoted (obj->value.sv, obj->len, ctx);
-                               } else {
-                                       ucl_elt_string_write_json (obj->value.sv, obj->len, ctx);
+                                       ucl_elt_string_write_squoted(obj->value.sv, obj->len, ctx);
+                               }
+                               else {
+                                       ucl_elt_string_write_json(obj->value.sv, obj->len, ctx);
                                }
                        }
                }
                else {
-                       ucl_elt_string_write_json (obj->value.sv, obj->len, ctx);
+                       ucl_elt_string_write_json(obj->value.sv, obj->len, ctx);
                }
-               ucl_emitter_finish_object (ctx, obj, compact, !print_key);
+               ucl_emitter_finish_object(ctx, obj, compact, !print_key);
                break;
        case UCL_NULL:
-               ucl_emitter_print_key (print_key, ctx, obj, compact);
-               func->ucl_emitter_append_len ("null", 4, func->ud);
-               ucl_emitter_finish_object (ctx, obj, compact, !print_key);
+               ucl_emitter_print_key(print_key, ctx, obj, compact);
+               func->ucl_emitter_append_len("null", 4, func->ud);
+               ucl_emitter_finish_object(ctx, obj, compact, !print_key);
                break;
        case UCL_OBJECT:
-               ucl_emitter_common_start_object (ctx, obj, print_key, compact);
-               ucl_emitter_common_end_object (ctx, obj, compact);
+               ucl_emitter_common_start_object(ctx, obj, print_key, compact);
+               ucl_emitter_common_end_object(ctx, obj, compact);
                break;
        case UCL_ARRAY:
-               ucl_emitter_common_start_array (ctx, obj, print_key, compact);
-               ucl_emitter_common_end_array (ctx, obj, compact);
+               ucl_emitter_common_start_array(ctx, obj, print_key, compact);
+               ucl_emitter_common_end_array(ctx, obj, compact);
                break;
        case UCL_USERDATA:
-               ud = (struct ucl_object_userdata *)obj;
-               ucl_emitter_print_key (print_key, ctx, obj, compact);
+               ud = (struct ucl_object_userdata *) obj;
+               ucl_emitter_print_key(print_key, ctx, obj, compact);
                if (ud->emitter) {
-                       ud_out = ud->emitter (obj->value.ud);
+                       ud_out = ud->emitter(obj->value.ud);
                        if (ud_out == NULL) {
                                ud_out = "null";
                        }
                }
-               ucl_elt_string_write_json (ud_out, strlen (ud_out), ctx);
-               ucl_emitter_finish_object (ctx, obj, compact, !print_key);
+               ucl_elt_string_write_json(ud_out, strlen(ud_out), ctx);
+               ucl_emitter_finish_object(ctx, obj, compact, !print_key);
                break;
        }
 
        if (comment) {
-               DL_FOREACH (comment, cur_comment) {
-                       func->ucl_emitter_append_len (cur_comment->value.sv,
-                                       cur_comment->len,
-                                       func->ud);
-                       func->ucl_emitter_append_character ('\n', 1, func->ud);
+               DL_FOREACH(comment, cur_comment)
+               {
+                       func->ucl_emitter_append_len(cur_comment->value.sv,
+                                                                                cur_comment->len,
+                                                                                func->ud);
+                       func->ucl_emitter_append_character('\n', 1, func->ud);
 
                        if (cur_comment->next) {
-                               ucl_add_tabs (func, ctx->indent, compact);
+                               ucl_add_tabs(func, ctx->indent, compact);
                        }
                }
        }
@@ -482,26 +480,31 @@ ucl_emitter_common_elt (struct ucl_emitter_context *ctx,
 /*
  * Specific standard implementations of the emitter functions
  */
-#define UCL_EMIT_TYPE_IMPL(type, compact)              \
-       static void ucl_emit_ ## type ## _elt (struct ucl_emitter_context *ctx, \
-               const ucl_object_t *obj, bool first, bool print_key) {  \
-               ucl_emitter_common_elt (ctx, obj, first, print_key, (compact)); \
-       }       \
-       static void ucl_emit_ ## type ## _start_obj (struct ucl_emitter_context *ctx,   \
-               const ucl_object_t *obj, bool print_key) {      \
-               ucl_emitter_common_start_object (ctx, obj, print_key, (compact));       \
-       }       \
-       static void ucl_emit_ ## type## _start_array (struct ucl_emitter_context *ctx,  \
-               const ucl_object_t *obj, bool print_key) {      \
-               ucl_emitter_common_start_array (ctx, obj, print_key, (compact));        \
-       }       \
-       static void ucl_emit_ ##type## _end_object (struct ucl_emitter_context *ctx,    \
-               const ucl_object_t *obj) {      \
-               ucl_emitter_common_end_object (ctx, obj, (compact));    \
-       }       \
-       static void ucl_emit_ ##type## _end_array (struct ucl_emitter_context *ctx,     \
-               const ucl_object_t *obj) {      \
-               ucl_emitter_common_end_array (ctx, obj, (compact));     \
+#define UCL_EMIT_TYPE_IMPL(type, compact)                                                  \
+       static void ucl_emit_##type##_elt(struct ucl_emitter_context *ctx,                     \
+                                                                         const ucl_object_t *obj, bool first, bool print_key) \
+       {                                                                                      \
+               ucl_emitter_common_elt(ctx, obj, first, print_key, (compact));                     \
+       }                                                                                      \
+       static void ucl_emit_##type##_start_obj(struct ucl_emitter_context *ctx,               \
+                                                                                       const ucl_object_t *obj, bool print_key)       \
+       {                                                                                      \
+               ucl_emitter_common_start_object(ctx, obj, print_key, (compact));                   \
+       }                                                                                      \
+       static void ucl_emit_##type##_start_array(struct ucl_emitter_context *ctx,             \
+                                                                                         const ucl_object_t *obj, bool print_key)     \
+       {                                                                                      \
+               ucl_emitter_common_start_array(ctx, obj, print_key, (compact));                    \
+       }                                                                                      \
+       static void ucl_emit_##type##_end_object(struct ucl_emitter_context *ctx,              \
+                                                                                        const ucl_object_t *obj)                      \
+       {                                                                                      \
+               ucl_emitter_common_end_object(ctx, obj, (compact));                                \
+       }                                                                                      \
+       static void ucl_emit_##type##_end_array(struct ucl_emitter_context *ctx,               \
+                                                                                       const ucl_object_t *obj)                       \
+       {                                                                                      \
+               ucl_emitter_common_end_array(ctx, obj, (compact));                                 \
        }
 
 UCL_EMIT_TYPE_IMPL(json, false)
@@ -510,8 +513,8 @@ UCL_EMIT_TYPE_IMPL(config, false)
 UCL_EMIT_TYPE_IMPL(yaml, false)
 
 static void
-ucl_emit_msgpack_elt (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj, bool first, bool print_key)
+ucl_emit_msgpack_elt(struct ucl_emitter_context *ctx,
+                                        const ucl_object_t *obj, bool first, bool print_key)
 {
        ucl_object_iter_t it;
        struct ucl_object_userdata *ud;
@@ -520,46 +523,47 @@ ucl_emit_msgpack_elt (struct ucl_emitter_context *ctx,
 
        switch (obj->type) {
        case UCL_INT:
-               ucl_emitter_print_key_msgpack (print_key, ctx, obj);
-               ucl_emitter_print_int_msgpack (ctx, ucl_object_toint (obj));
+               ucl_emitter_print_key_msgpack(print_key, ctx, obj);
+               ucl_emitter_print_int_msgpack(ctx, ucl_object_toint(obj));
                break;
 
        case UCL_FLOAT:
        case UCL_TIME:
-               ucl_emitter_print_key_msgpack (print_key, ctx, obj);
-               ucl_emitter_print_double_msgpack (ctx, ucl_object_todouble (obj));
+               ucl_emitter_print_key_msgpack(print_key, ctx, obj);
+               ucl_emitter_print_double_msgpack(ctx, ucl_object_todouble(obj));
                break;
 
        case UCL_BOOLEAN:
-               ucl_emitter_print_key_msgpack (print_key, ctx, obj);
-               ucl_emitter_print_bool_msgpack (ctx, ucl_object_toboolean (obj));
+               ucl_emitter_print_key_msgpack(print_key, ctx, obj);
+               ucl_emitter_print_bool_msgpack(ctx, ucl_object_toboolean(obj));
                break;
 
        case UCL_STRING:
-               ucl_emitter_print_key_msgpack (print_key, ctx, obj);
+               ucl_emitter_print_key_msgpack(print_key, ctx, obj);
 
                if (obj->flags & UCL_OBJECT_BINARY) {
-                       ucl_emitter_print_binary_string_msgpack (ctx, obj->value.sv,
-                                       obj->len);
+                       ucl_emitter_print_binary_string_msgpack(ctx, obj->value.sv,
+                                                                                                       obj->len);
                }
                else {
-                       ucl_emitter_print_string_msgpack (ctx, obj->value.sv, obj->len);
+                       ucl_emitter_print_string_msgpack(ctx, obj->value.sv, obj->len);
                }
                break;
 
        case UCL_NULL:
-               ucl_emitter_print_key_msgpack (print_key, ctx, obj);
-               ucl_emitter_print_null_msgpack (ctx);
+               ucl_emitter_print_key_msgpack(print_key, ctx, obj);
+               ucl_emitter_print_null_msgpack(ctx);
                break;
 
        case UCL_OBJECT:
-               ucl_emitter_print_key_msgpack (print_key, ctx, obj);
-               ucl_emit_msgpack_start_obj (ctx, obj, print_key);
+               ucl_emitter_print_key_msgpack(print_key, ctx, obj);
+               ucl_emit_msgpack_start_obj(ctx, obj, print_key);
                it = NULL;
 
-               while ((cur = ucl_object_iterate (obj, &it, true)) != NULL) {
-                       LL_FOREACH (cur, celt) {
-                               ucl_emit_msgpack_elt (ctx, celt, false, true);
+               while ((cur = ucl_object_iterate(obj, &it, true)) != NULL) {
+                       LL_FOREACH(cur, celt)
+                       {
+                               ucl_emit_msgpack_elt(ctx, celt, false, true);
                                /* XXX:
                                 * in msgpack the length of objects is encoded within a single elt
                                 * so in case of multi-value keys we are using merely the first
@@ -572,68 +576,66 @@ ucl_emit_msgpack_elt (struct ucl_emitter_context *ctx,
                break;
 
        case UCL_ARRAY:
-               ucl_emitter_print_key_msgpack (print_key, ctx, obj);
-               ucl_emit_msgpack_start_array (ctx, obj, print_key);
+               ucl_emitter_print_key_msgpack(print_key, ctx, obj);
+               ucl_emit_msgpack_start_array(ctx, obj, print_key);
                it = NULL;
 
-               while ((cur = ucl_object_iterate (obj, &it, true)) != NULL) {
-                       ucl_emit_msgpack_elt (ctx, cur, false, false);
+               while ((cur = ucl_object_iterate(obj, &it, true)) != NULL) {
+                       ucl_emit_msgpack_elt(ctx, cur, false, false);
                }
 
                break;
 
        case UCL_USERDATA:
-               ud = (struct ucl_object_userdata *)obj;
-               ucl_emitter_print_key_msgpack (print_key, ctx, obj);
+               ud = (struct ucl_object_userdata *) obj;
+               ucl_emitter_print_key_msgpack(print_key, ctx, obj);
 
                if (ud->emitter) {
-                       ud_out = ud->emitter (obj->value.ud);
+                       ud_out = ud->emitter(obj->value.ud);
                        if (ud_out == NULL) {
                                ud_out = "null";
                        }
                }
-               ucl_emitter_print_string_msgpack (ctx, obj->value.sv, obj->len);
+               ucl_emitter_print_string_msgpack(ctx, obj->value.sv, obj->len);
                break;
        }
 }
 
 static void
-ucl_emit_msgpack_start_obj (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj, bool print_key)
+ucl_emit_msgpack_start_obj(struct ucl_emitter_context *ctx,
+                                                  const ucl_object_t *obj, bool print_key)
 {
-       ucl_emitter_print_object_msgpack (ctx, obj->len);
+       ucl_emitter_print_object_msgpack(ctx, obj->len);
 }
 
 static void
-ucl_emit_msgpack_start_array (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj, bool print_key)
+ucl_emit_msgpack_start_array(struct ucl_emitter_context *ctx,
+                                                        const ucl_object_t *obj, bool print_key)
 {
-       ucl_emitter_print_array_msgpack (ctx, obj->len);
+       ucl_emitter_print_array_msgpack(ctx, obj->len);
 }
 
 static void
-ucl_emit_msgpack_end_object (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj)
+ucl_emit_msgpack_end_object(struct ucl_emitter_context *ctx,
+                                                       const ucl_object_t *obj)
 {
-
 }
 
 static void
-ucl_emit_msgpack_end_array (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj)
+ucl_emit_msgpack_end_array(struct ucl_emitter_context *ctx,
+                                                  const ucl_object_t *obj)
 {
-
 }
 
 unsigned char *
-ucl_object_emit (const ucl_object_t *obj, enum ucl_emitter emit_type)
+ucl_object_emit(const ucl_object_t *obj, enum ucl_emitter emit_type)
 {
-       return ucl_object_emit_len (obj, emit_type, NULL);
+       return ucl_object_emit_len(obj, emit_type, NULL);
 }
 
 unsigned char *
-ucl_object_emit_len (const ucl_object_t *obj, enum ucl_emitter emit_type,
-               size_t *outlen)
+ucl_object_emit_len(const ucl_object_t *obj, enum ucl_emitter emit_type,
+                                       size_t *outlen)
 {
        unsigned char *res = NULL;
        struct ucl_emitter_functions *func;
@@ -643,40 +645,39 @@ ucl_object_emit_len (const ucl_object_t *obj, enum ucl_emitter emit_type,
                return NULL;
        }
 
-       func = ucl_object_emit_memory_funcs ((void **)&res);
+       func = ucl_object_emit_memory_funcs((void **) &res);
 
        if (func != NULL) {
                s = func->ud;
-               ucl_object_emit_full (obj, emit_type, func, NULL);
+               ucl_object_emit_full(obj, emit_type, func, NULL);
 
                if (outlen != NULL) {
                        *outlen = s->i;
                }
 
-               ucl_object_emit_funcs_free (func);
+               ucl_object_emit_funcs_free(func);
        }
 
        return res;
 }
 
-bool
-ucl_object_emit_full (const ucl_object_t *obj, enum ucl_emitter emit_type,
-               struct ucl_emitter_functions *emitter,
-               const ucl_object_t *comments)
+bool ucl_object_emit_full(const ucl_object_t *obj, enum ucl_emitter emit_type,
+                                                 struct ucl_emitter_functions *emitter,
+                                                 const ucl_object_t *comments)
 {
        const struct ucl_emitter_context *ctx;
        struct ucl_emitter_context my_ctx;
        bool res = false;
 
-       ctx = ucl_emit_get_standard_context (emit_type);
+       ctx = ucl_emit_get_standard_context(emit_type);
        if (ctx != NULL) {
-               memcpy (&my_ctx, ctx, sizeof (my_ctx));
+               memcpy(&my_ctx, ctx, sizeof(my_ctx));
                my_ctx.func = emitter;
                my_ctx.indent = 0;
                my_ctx.top = obj;
                my_ctx.comments = comments;
 
-               my_ctx.ops->ucl_emitter_write_elt (&my_ctx, obj, true, false);
+               my_ctx.ops->ucl_emitter_write_elt(&my_ctx, obj, true, false);
                res = true;
        }
 
@@ -684,37 +685,15 @@ ucl_object_emit_full (const ucl_object_t *obj, enum ucl_emitter emit_type,
 }
 
 static const struct ucl_emitter_context ucl_standard_emitters[] = {
-               [UCL_EMIT_JSON] = {
-                               .name = "json",
-                               .id = UCL_EMIT_JSON,
-                               .func = NULL,
-                               .ops = &ucl_standart_emitter_ops[UCL_EMIT_JSON]
-               },
-               [UCL_EMIT_JSON_COMPACT] = {
-                               .name = "json_compact",
-                               .id = UCL_EMIT_JSON_COMPACT,
-                               .func = NULL,
-                               .ops = &ucl_standart_emitter_ops[UCL_EMIT_JSON_COMPACT]
-               },
-               [UCL_EMIT_CONFIG] = {
-                               .name = "config",
-                               .id = UCL_EMIT_CONFIG,
-                               .func = NULL,
-                               .ops = &ucl_standart_emitter_ops[UCL_EMIT_CONFIG]
-               },
-               [UCL_EMIT_YAML] = {
-                               .name = "yaml",
-                               .id = UCL_EMIT_YAML,
-                               .func = NULL,
-                               .ops = &ucl_standart_emitter_ops[UCL_EMIT_YAML]
-               },
-               [UCL_EMIT_MSGPACK] = {
-                               .name = "msgpack",
-                               .id = UCL_EMIT_MSGPACK,
-                               .func = NULL,
-                               .ops = &ucl_standart_emitter_ops[UCL_EMIT_MSGPACK]
-               }
-};
+       [UCL_EMIT_JSON] = {
+               .name = "json",
+               .id = UCL_EMIT_JSON,
+               .func = NULL,
+               .ops = &ucl_standart_emitter_ops[UCL_EMIT_JSON]},
+       [UCL_EMIT_JSON_COMPACT] = {.name = "json_compact", .id = UCL_EMIT_JSON_COMPACT, .func = NULL, .ops = &ucl_standart_emitter_ops[UCL_EMIT_JSON_COMPACT]},
+       [UCL_EMIT_CONFIG] = {.name = "config", .id = UCL_EMIT_CONFIG, .func = NULL, .ops = &ucl_standart_emitter_ops[UCL_EMIT_CONFIG]},
+       [UCL_EMIT_YAML] = {.name = "yaml", .id = UCL_EMIT_YAML, .func = NULL, .ops = &ucl_standart_emitter_ops[UCL_EMIT_YAML]},
+       [UCL_EMIT_MSGPACK] = {.name = "msgpack", .id = UCL_EMIT_MSGPACK, .func = NULL, .ops = &ucl_standart_emitter_ops[UCL_EMIT_MSGPACK]}};
 
 /**
  * Get standard emitter context for a specified emit_type
@@ -722,7 +701,7 @@ static const struct ucl_emitter_context ucl_standard_emitters[] = {
  * @return context or NULL if input is invalid
  */
 const struct ucl_emitter_context *
-ucl_emit_get_standard_context (enum ucl_emitter emit_type)
+ucl_emit_get_standard_context(enum ucl_emitter emit_type)
 {
        if (emit_type >= UCL_EMIT_JSON && emit_type < UCL_EMIT_MAX) {
                return &ucl_standard_emitters[emit_type];
@@ -736,135 +715,132 @@ ucl_emit_get_standard_context (enum ucl_emitter emit_type)
  * @param str string to emit
  * @param buf target buffer
  */
-void
-ucl_elt_string_write_json (const char *str, size_t size,
-                                                  struct ucl_emitter_context *ctx)
+void ucl_elt_string_write_json(const char *str, size_t size,
+                                                          struct ucl_emitter_context *ctx)
 {
        const char *p = str, *c = str;
        size_t len = 0;
        const struct ucl_emitter_functions *func = ctx->func;
 
-       func->ucl_emitter_append_character ('"', 1, func->ud);
+       func->ucl_emitter_append_character('"', 1, func->ud);
 
        while (size) {
-               if (ucl_test_character (*p, (UCL_CHARACTER_JSON_UNSAFE|
-                                                                        UCL_CHARACTER_DENIED|
-                                                                        UCL_CHARACTER_WHITESPACE_UNSAFE))) {
+               if (ucl_test_character(*p, (UCL_CHARACTER_JSON_UNSAFE |
+                                                                       UCL_CHARACTER_DENIED |
+                                                                       UCL_CHARACTER_WHITESPACE_UNSAFE))) {
                        if (len > 0) {
-                               func->ucl_emitter_append_len (c, len, func->ud);
+                               func->ucl_emitter_append_len(c, len, func->ud);
                        }
                        switch (*p) {
                        case '\0':
-                               func->ucl_emitter_append_len ("\\u0000", 6, func->ud);
+                               func->ucl_emitter_append_len("\\u0000", 6, func->ud);
                                break;
                        case '\n':
-                               func->ucl_emitter_append_len ("\\n", 2, func->ud);
+                               func->ucl_emitter_append_len("\\n", 2, func->ud);
                                break;
                        case '\r':
-                               func->ucl_emitter_append_len ("\\r", 2, func->ud);
+                               func->ucl_emitter_append_len("\\r", 2, func->ud);
                                break;
                        case '\b':
-                               func->ucl_emitter_append_len ("\\b", 2, func->ud);
+                               func->ucl_emitter_append_len("\\b", 2, func->ud);
                                break;
                        case '\t':
-                               func->ucl_emitter_append_len ("\\t", 2, func->ud);
+                               func->ucl_emitter_append_len("\\t", 2, func->ud);
                                break;
                        case '\f':
-                               func->ucl_emitter_append_len ("\\f", 2, func->ud);
+                               func->ucl_emitter_append_len("\\f", 2, func->ud);
                                break;
                        case '\v':
-                               func->ucl_emitter_append_len ("\\u000B", 6, func->ud);
+                               func->ucl_emitter_append_len("\\u000B", 6, func->ud);
                                break;
                        case '\\':
-                               func->ucl_emitter_append_len ("\\\\", 2, func->ud);
+                               func->ucl_emitter_append_len("\\\\", 2, func->ud);
                                break;
                        case ' ':
-                               func->ucl_emitter_append_character (' ', 1, func->ud);
+                               func->ucl_emitter_append_character(' ', 1, func->ud);
                                break;
                        case '"':
-                               func->ucl_emitter_append_len ("\\\"", 2, func->ud);
+                               func->ucl_emitter_append_len("\\\"", 2, func->ud);
                                break;
                        default:
                                /* Emit unicode unknown character */
-                               func->ucl_emitter_append_len ("\\uFFFD", 6, func->ud);
+                               func->ucl_emitter_append_len("\\uFFFD", 6, func->ud);
                                break;
                        }
                        len = 0;
                        c = ++p;
                }
                else {
-                       p ++;
-                       len ++;
+                       p++;
+                       len++;
                }
-               size --;
+               size--;
        }
 
        if (len > 0) {
-               func->ucl_emitter_append_len (c, len, func->ud);
+               func->ucl_emitter_append_len(c, len, func->ud);
        }
 
-       func->ucl_emitter_append_character ('"', 1, func->ud);
+       func->ucl_emitter_append_character('"', 1, func->ud);
 }
 
-void
-ucl_elt_string_write_squoted (const char *str, size_t size,
-                                                         struct ucl_emitter_context *ctx)
+void ucl_elt_string_write_squoted(const char *str, size_t size,
+                                                                 struct ucl_emitter_context *ctx)
 {
        const char *p = str, *c = str;
        size_t len = 0;
        const struct ucl_emitter_functions *func = ctx->func;
 
-       func->ucl_emitter_append_character ('\'', 1, func->ud);
+       func->ucl_emitter_append_character('\'', 1, func->ud);
 
        while (size) {
                if (*p == '\'') {
                        if (len > 0) {
-                               func->ucl_emitter_append_len (c, len, func->ud);
+                               func->ucl_emitter_append_len(c, len, func->ud);
                        }
 
                        len = 0;
                        c = ++p;
-                       func->ucl_emitter_append_len ("\\\'", 2, func->ud);
+                       func->ucl_emitter_append_len("\\\'", 2, func->ud);
                }
                else {
-                       p ++;
-                       len ++;
+                       p++;
+                       len++;
                }
-               size --;
+               size--;
        }
 
        if (len > 0) {
-               func->ucl_emitter_append_len (c, len, func->ud);
+               func->ucl_emitter_append_len(c, len, func->ud);
        }
 
-       func->ucl_emitter_append_character ('\'', 1, func->ud);
+       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)
+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);
+       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
  */
 static int
-ucl_utstring_append_character (unsigned char c, size_t len, void *ud)
+ucl_utstring_append_character(unsigned char c, size_t len, void *ud)
 {
        UT_string *buf = ud;
 
        if (len == 1) {
-               utstring_append_c (buf, c);
+               utstring_append_c(buf, c);
        }
        else {
-               utstring_reserve (buf, len + 1);
-               memset (&buf->d[buf->i], c, len);
+               utstring_reserve(buf, len + 1);
+               memset(&buf->d[buf->i], c, len);
                buf->i += len;
                buf->d[buf->i] = '\0';
        }
@@ -873,39 +849,39 @@ ucl_utstring_append_character (unsigned char c, size_t len, void *ud)
 }
 
 static int
-ucl_utstring_append_len (const unsigned char *str, size_t len, void *ud)
+ucl_utstring_append_len(const unsigned char *str, size_t len, void *ud)
 {
        UT_string *buf = ud;
 
-       utstring_append_len (buf, str, len);
+       utstring_append_len(buf, str, len);
 
        return 0;
 }
 
 static int
-ucl_utstring_append_int (int64_t val, void *ud)
+ucl_utstring_append_int(int64_t val, void *ud)
 {
        UT_string *buf = ud;
 
-       utstring_printf (buf, "%jd", (intmax_t)val);
+       utstring_printf(buf, "%jd", (intmax_t) val);
        return 0;
 }
 
 static int
-ucl_utstring_append_double (double val, void *ud)
+ucl_utstring_append_double(double val, void *ud)
 {
        UT_string *buf = ud;
        const double delta = 0.0000001;
 
-       if (val == (double)(int)val) {
-               utstring_printf (buf, "%.1lf", val);
+       if (val == (double) (int) val) {
+               utstring_printf(buf, "%.1lf", val);
        }
-       else if (fabs (val - (double)(int)val) < delta) {
+       else if (fabs(val - (double) (int) val) < delta) {
                /* Write at maximum precision */
-               utstring_printf (buf, "%.*lg", DBL_DIG, val);
+               utstring_printf(buf, "%.*lg", DBL_DIG, val);
        }
        else {
-               utstring_printf (buf, "%lf", val);
+               utstring_printf(buf, "%lf", val);
        }
 
        return 0;
@@ -915,52 +891,52 @@ ucl_utstring_append_double (double val, void *ud)
  * Generic file output
  */
 static int
-ucl_file_append_character (unsigned char c, size_t len, void *ud)
+ucl_file_append_character(unsigned char c, size_t len, void *ud)
 {
        FILE *fp = ud;
 
-       while (len --) {
-               fputc (c, fp);
+       while (len--) {
+               fputc(c, fp);
        }
 
        return 0;
 }
 
 static int
-ucl_file_append_len (const unsigned char *str, size_t len, void *ud)
+ucl_file_append_len(const unsigned char *str, size_t len, void *ud)
 {
        FILE *fp = ud;
 
-       fwrite (str, len, 1, fp);
+       fwrite(str, len, 1, fp);
 
        return 0;
 }
 
 static int
-ucl_file_append_int (int64_t val, void *ud)
+ucl_file_append_int(int64_t val, void *ud)
 {
        FILE *fp = ud;
 
-       fprintf (fp, "%jd", (intmax_t)val);
+       fprintf(fp, "%jd", (intmax_t) val);
 
        return 0;
 }
 
 static int
-ucl_file_append_double (double val, void *ud)
+ucl_file_append_double(double val, void *ud)
 {
        FILE *fp = ud;
        const double delta = 0.0000001;
 
-       if (val == (double)(int)val) {
-               fprintf (fp, "%.1lf", val);
+       if (val == (double) (int) val) {
+               fprintf(fp, "%.1lf", val);
        }
-       else if (fabs (val - (double)(int)val) < delta) {
+       else if (fabs(val - (double) (int) val) < delta) {
                /* Write at maximum precision */
-               fprintf (fp, "%.*lg", DBL_DIG, val);
+               fprintf(fp, "%.*lg", DBL_DIG, val);
        }
        else {
-               fprintf (fp, "%lf", val);
+               fprintf(fp, "%lf", val);
        }
 
        return 0;
@@ -970,31 +946,31 @@ ucl_file_append_double (double val, void *ud)
  * Generic file descriptor writing functions
  */
 static int
-ucl_fd_append_character (unsigned char c, size_t len, void *ud)
+ucl_fd_append_character(unsigned char c, size_t len, void *ud)
 {
-       int fd = *(int *)ud;
+       int fd = *(int *) ud;
        unsigned char *buf;
 
        if (len == 1) {
-               return write (fd, &c, 1);
+               return write(fd, &c, 1);
        }
        else {
-               buf = malloc (len);
+               buf = malloc(len);
                if (buf == NULL) {
                        /* Fallback */
-                       while (len --) {
-                               if (write (fd, &c, 1) == -1) {
+                       while (len--) {
+                               if (write(fd, &c, 1) == -1) {
                                        return -1;
                                }
                        }
                }
                else {
-                       memset (buf, c, len);
-                       if (write (fd, buf, len) == -1) {
+                       memset(buf, c, len);
+                       if (write(fd, buf, len) == -1) {
                                free(buf);
                                return -1;
                        }
-                       free (buf);
+                       free(buf);
                }
        }
 
@@ -1002,51 +978,51 @@ ucl_fd_append_character (unsigned char c, size_t len, void *ud)
 }
 
 static int
-ucl_fd_append_len (const unsigned char *str, size_t len, void *ud)
+ucl_fd_append_len(const unsigned char *str, size_t len, void *ud)
 {
-       int fd = *(int *)ud;
+       int fd = *(int *) ud;
 
-       return write (fd, str, len);
+       return write(fd, str, len);
 }
 
 static int
-ucl_fd_append_int (int64_t val, void *ud)
+ucl_fd_append_int(int64_t val, void *ud)
 {
-       int fd = *(int *)ud;
+       int fd = *(int *) ud;
        char intbuf[64];
 
-       snprintf (intbuf, sizeof (intbuf), "%jd", (intmax_t)val);
-       return write (fd, intbuf, strlen (intbuf));
+       snprintf(intbuf, sizeof(intbuf), "%jd", (intmax_t) val);
+       return write(fd, intbuf, strlen(intbuf));
 }
 
 static int
-ucl_fd_append_double (double val, void *ud)
+ucl_fd_append_double(double val, void *ud)
 {
-       int fd = *(int *)ud;
+       int fd = *(int *) ud;
        const double delta = 0.0000001;
        char nbuf[64];
 
-       if (val == (double)(int)val) {
-               snprintf (nbuf, sizeof (nbuf), "%.1lf", val);
+       if (val == (double) (int) val) {
+               snprintf(nbuf, sizeof(nbuf), "%.1lf", val);
        }
-       else if (fabs (val - (double)(int)val) < delta) {
+       else if (fabs(val - (double) (int) val) < delta) {
                /* Write at maximum precision */
-               snprintf (nbuf, sizeof (nbuf), "%.*lg", DBL_DIG, val);
+               snprintf(nbuf, sizeof(nbuf), "%.*lg", DBL_DIG, val);
        }
        else {
-               snprintf (nbuf, sizeof (nbuf), "%lf", val);
+               snprintf(nbuf, sizeof(nbuf), "%lf", val);
        }
 
-       return write (fd, nbuf, strlen (nbuf));
+       return write(fd, nbuf, strlen(nbuf));
 }
 
-struct ucl_emitter_functions*
-ucl_object_emit_memory_funcs (void **pmem)
+struct ucl_emitter_functions *
+ucl_object_emit_memory_funcs(void **pmem)
 {
        struct ucl_emitter_functions *f;
        UT_string *s;
 
-       f = calloc (1, sizeof (*f));
+       f = calloc(1, sizeof(*f));
 
        if (f != NULL) {
                f->ucl_emitter_append_character = ucl_utstring_append_character;
@@ -1054,7 +1030,7 @@ ucl_object_emit_memory_funcs (void **pmem)
                f->ucl_emitter_append_int = ucl_utstring_append_int;
                f->ucl_emitter_append_len = ucl_utstring_append_len;
                f->ucl_emitter_free_func = free;
-               utstring_new (s);
+               utstring_new(s);
                f->ud = s;
                *pmem = s->d;
                s->pd = pmem;
@@ -1063,12 +1039,12 @@ ucl_object_emit_memory_funcs (void **pmem)
        return f;
 }
 
-struct ucl_emitter_functions*
-ucl_object_emit_file_funcs (FILE *fp)
+struct ucl_emitter_functions *
+ucl_object_emit_file_funcs(FILE *fp)
 {
        struct ucl_emitter_functions *f;
 
-       f = calloc (1, sizeof (*f));
+       f = calloc(1, sizeof(*f));
 
        if (f != NULL) {
                f->ucl_emitter_append_character = ucl_file_append_character;
@@ -1082,22 +1058,22 @@ ucl_object_emit_file_funcs (FILE *fp)
        return f;
 }
 
-struct ucl_emitter_functions*
-ucl_object_emit_fd_funcs (int fd)
+struct ucl_emitter_functions *
+ucl_object_emit_fd_funcs(int fd)
 {
        struct ucl_emitter_functions *f;
        int *ip;
 
-       f = calloc (1, sizeof (*f));
+       f = calloc(1, sizeof(*f));
 
        if (f != NULL) {
-               ip = malloc (sizeof (fd));
+               ip = malloc(sizeof(fd));
                if (ip == NULL) {
-                       free (f);
+                       free(f);
                        return NULL;
                }
 
-               memcpy (ip, &fd, sizeof (fd));
+               memcpy(ip, &fd, sizeof(fd));
                f->ucl_emitter_append_character = ucl_fd_append_character;
                f->ucl_emitter_append_double = ucl_fd_append_double;
                f->ucl_emitter_append_int = ucl_fd_append_int;
@@ -1109,20 +1085,19 @@ ucl_object_emit_fd_funcs (int fd)
        return f;
 }
 
-void
-ucl_object_emit_funcs_free (struct ucl_emitter_functions *f)
+void ucl_object_emit_funcs_free(struct ucl_emitter_functions *f)
 {
        if (f != NULL) {
                if (f->ucl_emitter_free_func != NULL) {
-                       f->ucl_emitter_free_func (f->ud);
+                       f->ucl_emitter_free_func(f->ud);
                }
-               free (f);
+               free(f);
        }
 }
 
 
 unsigned char *
-ucl_object_emit_single_json (const ucl_object_t *obj)
+ucl_object_emit_single_json(const ucl_object_t *obj)
 {
        UT_string *buf = NULL;
        unsigned char *res = NULL;
@@ -1131,43 +1106,43 @@ ucl_object_emit_single_json (const ucl_object_t *obj)
                return NULL;
        }
 
-       utstring_new (buf);
+       utstring_new(buf);
 
        if (buf != NULL) {
                switch (obj->type) {
                case UCL_OBJECT:
-                       ucl_utstring_append_len ("object", 6, buf);
+                       ucl_utstring_append_len("object", 6, buf);
                        break;
                case UCL_ARRAY:
-                       ucl_utstring_append_len ("array", 5, buf);
+                       ucl_utstring_append_len("array", 5, buf);
                        break;
                case UCL_INT:
-                       ucl_utstring_append_int (obj->value.iv, buf);
+                       ucl_utstring_append_int(obj->value.iv, buf);
                        break;
                case UCL_FLOAT:
                case UCL_TIME:
-                       ucl_utstring_append_double (obj->value.dv, buf);
+                       ucl_utstring_append_double(obj->value.dv, buf);
                        break;
                case UCL_NULL:
-                       ucl_utstring_append_len ("null", 4, buf);
+                       ucl_utstring_append_len("null", 4, buf);
                        break;
                case UCL_BOOLEAN:
                        if (obj->value.iv) {
-                               ucl_utstring_append_len ("true", 4, buf);
+                               ucl_utstring_append_len("true", 4, buf);
                        }
                        else {
-                               ucl_utstring_append_len ("false", 5, buf);
+                               ucl_utstring_append_len("false", 5, buf);
                        }
                        break;
                case UCL_STRING:
-                       ucl_utstring_append_len (obj->value.sv, obj->len, buf);
+                       ucl_utstring_append_len(obj->value.sv, obj->len, buf);
                        break;
                case UCL_USERDATA:
-                       ucl_utstring_append_len ("userdata", 8, buf);
+                       ucl_utstring_append_len("userdata", 8, buf);
                        break;
                }
-               res = utstring_body (buf);
-               free (buf);
+               res = utstring_body(buf);
+               free(buf);
        }
 
        return res;
@@ -1175,12 +1150,11 @@ ucl_object_emit_single_json (const ucl_object_t *obj)
 
 #define LONG_STRING_LIMIT 80
 
-bool
-ucl_maybe_long_string (const ucl_object_t *obj)
+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) {
+               if (memchr(obj->value.sv, '\n', obj->len) != NULL) {
                        return true;
                }
        }
index a7178c5d74b03218b8e7be259afdd79d80f37f6c..41a73453174aa1316084ca8d453d9f6ce5df48b6 100644 (file)
@@ -57,39 +57,38 @@ struct ucl_emitter_context_streamline {
        struct ucl_emitter_streamline_stack *containers;
 };
 
-#define TO_STREAMLINE(ctx) (struct ucl_emitter_context_streamline *)(ctx)
+#define TO_STREAMLINE(ctx) (struct ucl_emitter_context_streamline *) (ctx)
 
-struct ucl_emitter_context*
-ucl_object_emit_streamline_new (const ucl_object_t *obj,
-               enum ucl_emitter emit_type,
-               struct ucl_emitter_functions *emitter)
+struct ucl_emitter_context *
+ucl_object_emit_streamline_new(const ucl_object_t *obj,
+                                                          enum ucl_emitter emit_type,
+                                                          struct ucl_emitter_functions *emitter)
 {
        const struct ucl_emitter_context *ctx;
        struct ucl_emitter_context_streamline *sctx;
 
-       ctx = ucl_emit_get_standard_context (emit_type);
+       ctx = ucl_emit_get_standard_context(emit_type);
        if (ctx == NULL) {
                return NULL;
        }
 
-       sctx = calloc (1, sizeof (*sctx));
+       sctx = calloc(1, sizeof(*sctx));
        if (sctx == NULL) {
                return NULL;
        }
 
-       memcpy (sctx, ctx, sizeof (*ctx));
+       memcpy(sctx, ctx, sizeof(*ctx));
        sctx->func = emitter;
        sctx->top = obj;
 
-       ucl_object_emit_streamline_start_container ((struct ucl_emitter_context *)sctx,
-                       obj);
+       ucl_object_emit_streamline_start_container((struct ucl_emitter_context *) sctx,
+                                                                                          obj);
 
-       return (struct ucl_emitter_context *)sctx;
+       return (struct ucl_emitter_context *) sctx;
 }
 
-void
-ucl_object_emit_streamline_start_container (struct ucl_emitter_context *ctx,
-               const ucl_object_t *obj)
+bool ucl_object_emit_streamline_start_container(struct ucl_emitter_context *ctx,
+                                                                                               const ucl_object_t *obj)
 {
        struct ucl_emitter_context_streamline *sctx = TO_STREAMLINE(ctx);
        struct ucl_emitter_streamline_stack *st, *top;
@@ -101,28 +100,35 @@ ucl_object_emit_streamline_start_container (struct ucl_emitter_context *ctx,
        }
 
        top = sctx->containers;
-       st = malloc (sizeof (*st));
+       st = malloc(sizeof(*st));
        if (st != NULL) {
-               if (top != NULL && !top->is_array) {
+               st->empty = true;
+               if (top && !top->is_array) {
                        print_key = true;
                }
-               st->empty = true;
                st->obj = obj;
                if (obj != NULL && obj->type == UCL_ARRAY) {
                        st->is_array = true;
-                       sctx->ops->ucl_emitter_start_array (ctx, obj, print_key);
+                       sctx->ops->ucl_emitter_start_array(ctx, obj, print_key);
                }
-               else {
+               else if (obj != NULL && obj->type == UCL_OBJECT) {
                        st->is_array = false;
-                       sctx->ops->ucl_emitter_start_object (ctx, obj, print_key);
+                       sctx->ops->ucl_emitter_start_object(ctx, obj, print_key);
                }
-               LL_PREPEND (sctx->containers, st);
+               else {
+                       /* API MISUSE */
+                       free(st);
+
+                       return false;
+               }
+               LL_PREPEND(sctx->containers, st);
        }
+
+       return true;
 }
 
-void
-ucl_object_emit_streamline_add_object (
-               struct ucl_emitter_context *ctx, const ucl_object_t *obj)
+void ucl_object_emit_streamline_add_object(
+       struct ucl_emitter_context *ctx, const ucl_object_t *obj)
 {
        struct ucl_emitter_context_streamline *sctx = TO_STREAMLINE(ctx);
        bool is_array = false, is_first = false;
@@ -137,11 +143,10 @@ ucl_object_emit_streamline_add_object (
                }
        }
 
-       sctx->ops->ucl_emitter_write_elt (ctx, obj, is_first, !is_array);
+       sctx->ops->ucl_emitter_write_elt(ctx, obj, is_first, !is_array);
 }
 
-void
-ucl_object_emit_streamline_end_container (struct ucl_emitter_context *ctx)
+void ucl_object_emit_streamline_end_container(struct ucl_emitter_context *ctx)
 {
        struct ucl_emitter_context_streamline *sctx = TO_STREAMLINE(ctx);
        struct ucl_emitter_streamline_stack *st;
@@ -150,24 +155,23 @@ ucl_object_emit_streamline_end_container (struct ucl_emitter_context *ctx)
                st = sctx->containers;
 
                if (st->is_array) {
-                       sctx->ops->ucl_emitter_end_array (ctx, st->obj);
+                       sctx->ops->ucl_emitter_end_array(ctx, st->obj);
                }
                else {
-                       sctx->ops->ucl_emitter_end_object (ctx, st->obj);
+                       sctx->ops->ucl_emitter_end_object(ctx, st->obj);
                }
                sctx->containers = st->next;
-               free (st);
+               free(st);
        }
 }
 
-void
-ucl_object_emit_streamline_finish (struct ucl_emitter_context *ctx)
+void ucl_object_emit_streamline_finish(struct ucl_emitter_context *ctx)
 {
        struct ucl_emitter_context_streamline *sctx = TO_STREAMLINE(ctx);
 
        while (sctx->containers != NULL) {
-               ucl_object_emit_streamline_end_container (ctx);
+               ucl_object_emit_streamline_end_container(ctx);
        }
 
-       free (sctx);
+       free(sctx);
 }
index 107706b457f478b76ebfc073d5ddd89d263b1f48..9bb786831d0fcddd4266e59d9b8465682315209d 100644 (file)
@@ -165,51 +165,50 @@ start:
                        }
                }
        }
-       else if (chunk->remain >= 2 && *p == '/') {
-               if (p[1] == '*') {
-                       beg = p;
-                       ucl_chunk_skipc(chunk, p);
-                       comments_nested++;
-                       ucl_chunk_skipc(chunk, p);
-
-                       while (p < chunk->end) {
-                               if (*p == '"' && *(p - 1) != '\\') {
-                                       quoted = !quoted;
-                               }
-
-                               if (!quoted) {
-                                       if (*p == '*') {
-                                               ucl_chunk_skipc(chunk, p);
-                                               if (chunk->remain > 0 && *p == '/') {
-                                                       comments_nested--;
-                                                       if (comments_nested == 0) {
-                                                               if (parser->flags & UCL_PARSER_SAVE_COMMENTS) {
-                                                                       ucl_save_comment(parser, beg, p - beg + 1);
-                                                                       beg = NULL;
-                                                               }
-
-                                                               ucl_chunk_skipc(chunk, p);
-                                                               goto start;
-                                                       }
-                                               }
-                                               ucl_chunk_skipc(chunk, p);
-                                       }
-                                       else if (p[0] == '/' && chunk->remain >= 2 && p[1] == '*') {
-                                               comments_nested++;
-                                               ucl_chunk_skipc(chunk, p);
-                                               ucl_chunk_skipc(chunk, p);
-                                               continue;
+       else if (chunk->remain >= 2 && *p == '/' && p[1] == '*') {
+               beg = p;
+               comments_nested++;
+               ucl_chunk_skipc(chunk, p);
+               ucl_chunk_skipc(chunk, p);
+               while (p < chunk->end) {
+                       if (*p == '"' && *(p - 1) != '\\') {
+                               /* begin or end double-quoted string */
+                               quoted = !quoted;
+                               ucl_chunk_skipc(chunk, p);
+                       }
+                       else if (quoted) {
+                               /* quoted character */
+                               ucl_chunk_skipc(chunk, p);
+                       }
+                       else if (chunk->remain >= 2 && *p == '*' && p[1] == '/') {
+                               /* end of comment */
+                               ucl_chunk_skipc(chunk, p);
+                               ucl_chunk_skipc(chunk, p);
+                               comments_nested--;
+                               if (comments_nested == 0) {
+                                       if (parser->flags & UCL_PARSER_SAVE_COMMENTS) {
+                                               ucl_save_comment(parser, beg, p - beg + 1);
+                                               beg = NULL;
                                        }
+                                       goto start;
                                }
-
+                       }
+                       else if (chunk->remain >= 2 && *p == '/' && p[1] == '*') {
+                               /* start of nested comment */
+                               comments_nested++;
+                               ucl_chunk_skipc(chunk, p);
                                ucl_chunk_skipc(chunk, p);
                        }
-                       if (comments_nested != 0) {
-                               ucl_set_err(parser, UCL_ENESTED,
-                                                       "unfinished multiline comment", &parser->err);
-                               return false;
+                       else {
+                               /* anything else */
+                               ucl_chunk_skipc(chunk, p);
                        }
                }
+               if (comments_nested != 0) {
+                       ucl_set_err(parser, UCL_ENESTED,
+                                               "unfinished multiline comment", &parser->err);
+                       return false;
+               }
        }
 
        if (beg && p > beg && (parser->flags & UCL_PARSER_SAVE_COMMENTS)) {
@@ -1011,7 +1010,7 @@ int ucl_maybe_parse_number(ucl_object_t *obj,
                        while (p < end && ucl_test_character(*p, UCL_CHARACTER_WHITESPACE)) {
                                p++;
                        }
-                       if (ucl_lex_is_atom_end(*p))
+                       if (p == end || ucl_lex_is_atom_end(*p))
                                goto set_obj;
                        break;
                }
@@ -1254,6 +1253,15 @@ bool ucl_parser_process_object_element(struct ucl_parser *parser, ucl_object_t *
                        tobj = __DECONST(ucl_object_t *, ucl_hash_search_obj(cur->value.ov, nobj));
 
                        if (tobj != NULL) {
+                               /*
+                                * Check if we have found an object in the same container.
+                                * If not, we should probably ignore it as we cannot replace it
+                                * effectively and we definitely should not unref it.
+                                */
+                               if (cur->value.ov != container) {
+                                       tobj = NULL;
+                                       continue;
+                               }
                                break;
                        }
                }
@@ -1676,7 +1684,7 @@ ucl_parse_multiline_string(struct ucl_parser *parser,
                        }
                        else if (memcmp(p, term, term_len) == 0) {
                                tend = p + term_len;
-                               if (*tend != '\n' && *tend != ';' && *tend != ',') {
+                               if (tend < chunk->end && *tend != '\n' && *tend != ';' && *tend != ',') {
                                        /* Incomplete terminator */
                                        ucl_chunk_skipc(chunk, p);
                                        continue;