~alextee/zrythm-cyaml

024b3400c0a17f7950f5d1a08daf7503bec3faa7 — Alexandros Theodotou 1 year, 11 months ago 8f1bbd1
update from upstream
4 files changed, 118 insertions(+), 15 deletions(-)

M include/cyaml/cyaml.h
M src/load.c
M src/save.c
M src/util.h
M include/cyaml/cyaml.h => include/cyaml/cyaml.h +82 -9
@@ 106,7 106,13 @@ typedef enum cyaml_type {
	 * - Values of this type do not need to be direct children of a mapping.
	 * - The minimum and maximum entry count must be the same.  If not
	 *   \ref CYAML_ERR_SEQUENCE_FIXED_COUNT will be returned.
	 * - Thee offset and size of the count structure member is unused.
	 * - Unlike with \ref CYAML_SEQUENCE, where the min and max are limits,
	 *   here they are the actual entry count.
	 * - Since values of this type represent a constant size array, the
	 *   given entry count must not be \ref CYAML_UNLIMITED, because that
	 *   would cause it to attempt a massive allocation, which on most
	 *   systems would fail.
	 * - The offset and size of the count structure member is unused.
	 *   Because the count is a schema-defined constant, it does not need
	 *   to be recorded.
	 */


@@ 259,6 265,63 @@ typedef enum cyaml_flag {
	 *       \ref cyaml_strval strings.
	 */
	CYAML_FLAG_CASE_INSENSITIVE = (1 << 8),
	/**
	 * When saving, emit scalar value with plain style (no quotes).
	 *
	 * \note This is ignored if the value is non-scaler.
	 *
	 * \note In cases where conflicting scalar style flags are set, the
	 *       the one with the highest precedence is used.  From lowest to
	 *       highest precedence:
	 *       \ref CYAML_FLAG_SCALAR_PLAIN,
	 *       \ref CYAML_FLAG_SCALAR_FOLDED,
	 *       \ref CYAML_FLAG_SCALAR_LITERAL,
	 *       \ref CYAML_FLAG_SCALAR_QUOTE_SINGLE,
	 *       \ref CYAML_FLAG_SCALAR_QUOTE_DOUBLE,
	 *
	 * If none of these are set, libyaml's default behaviour is used.
	 */
	CYAML_FLAG_SCALAR_PLAIN        = (1 <<  9),
	/**
	 * When saving, emit scalar value with folded style:
	 *
	 * ```yaml
	 * string: >
	 *   This string
	 *   really has no line breaks!
	 * ```
	 *
	 * See the notes for \ref CYAML_FLAG_SCALAR_PLAIN for applicability
	 * and precedence.
	 */
	CYAML_FLAG_SCALAR_FOLDED       = (1 << 10),
	/**
	 * When saving, emit scalar value with literal style:
	 *
	 * ```yaml
	 * string: |
	 *   This is a
	 *   multi-line string!
	 * ```
	 *
	 * See the notes for \ref CYAML_FLAG_SCALAR_PLAIN for applicability
	 * and precedence.
	 */
	CYAML_FLAG_SCALAR_LITERAL      = (1 << 11),
	/**
	 * When saving, emit scalar value with single quotes (`'`).
	 *
	 * See the notes for \ref CYAML_FLAG_SCALAR_PLAIN for applicability
	 * and precedence.
	 */
	CYAML_FLAG_SCALAR_QUOTE_SINGLE = (1 << 12),
	/**
	 * When saving, emit scalar value with double quotes (`"`).
	 *
	 * See the notes for \ref CYAML_FLAG_SCALAR_PLAIN for applicability
	 * and precedence.
	 */
	CYAML_FLAG_SCALAR_QUOTE_DOUBLE = (1 << 13),
} cyaml_flag_e;

/**


@@ 579,11 642,11 @@ typedef enum cyaml_err {
		_key, _flags, _structure, _member) \
{ \
	.key = _key, \
	.data_offset = offsetof(_structure, _member), \
	.value = { \
		CYAML_VALUE_INT(((_flags) & (~CYAML_FLAG_POINTER)), \
				(((_structure *)NULL)->_member)), \
	}, \
	.data_offset = offsetof(_structure, _member) \
}

/**


@@ 1099,11 1162,11 @@ typedef enum cyaml_err {
		_key, _flags, _structure, _member, _fields) \
{ \
	.key = _key, \
	.data_offset = offsetof(_structure, _member), \
	.value = { \
		CYAML_VALUE_MAPPING(((_flags) | CYAML_FLAG_POINTER), \
				(*(((_structure *)NULL)->_member)), _fields), \
	}, \
	.data_offset = offsetof(_structure, _member) \
}

/**


@@ 1163,14 1226,14 @@ typedef enum cyaml_err {
		_key, _flags, _structure, _member, _entry, _min, _max) \
{ \
	.key = _key, \
	.data_offset = offsetof(_structure, _member), \
	.count_offset = offsetof(_structure, _member ## _count), \
	.count_size = sizeof(((_structure *)NULL)->_member ## _count), \
	.value = { \
		CYAML_VALUE_SEQUENCE((_flags), \
				(*(((_structure *)NULL)->_member)), \
				_entry, _min, _max), \
	}, \
	.data_offset = offsetof(_structure, _member), \
	.count_size = sizeof(((_structure *)NULL)->_member ## _count), \
	.count_offset = offsetof(_structure, _member ## _count), \
}

/**


@@ 1211,19 1274,24 @@ typedef enum cyaml_err {
		_key, _flags, _structure, _member, _count, _entry, _min, _max) \
{ \
	.key = _key, \
	.data_offset = offsetof(_structure, _member), \
	.count_offset = offsetof(_structure, _count), \
	.count_size = sizeof(((_structure *)NULL)->_count), \
	.value = { \
		CYAML_VALUE_SEQUENCE((_flags), \
				(*(((_structure *)NULL)->_member)), \
				_entry, _min, _max), \
	}, \
	.data_offset = offsetof(_structure, _member), \
	.count_size = sizeof(((_structure *)NULL)->_count), \
	.count_offset = offsetof(_structure, _count), \
}

/**
 * Value schema helper macro for values with \ref CYAML_SEQUENCE_FIXED type.
 *
 * Note that since this is a fixed size sequence, it must not be used with an
 * excessive entry count. For example, passing \ref CYAML_UNLIMITED as the count
 * to a \ref CYAML_SEQUENCE_FIXED with the \ref CYAML_FLAG_POINTER flag would
 * cause an enormous allocation, which would fail on many systems.
 *
 * \param[in]  _flags      Any behavioural flags relevant to this value.
 * \param[in]  _type       The C type of sequence **entries**.
 * \param[in]  _entry      Pointer to schema for the **entries** in sequence.


@@ 1243,6 1311,11 @@ typedef enum cyaml_err {
/**
 * Mapping schema helper macro for keys with \ref CYAML_SEQUENCE_FIXED type.
 *
 * Note that since this is a fixed size sequence, it must not be used with an
 * excessive entry count. For example, passing \ref CYAML_UNLIMITED as the count
 * to a \ref CYAML_SEQUENCE_FIXED with the \ref CYAML_FLAG_POINTER flag would
 * cause an enormous allocation, which would fail on many systems.
 *
 * \param[in]  _key        String defining the YAML mapping key for this value.
 * \param[in]  _flags      Any behavioural flags relevant to this value.
 * \param[in]  _structure  The structure corresponding to the mapping.

M src/load.c => src/load.c +1 -1
@@ 1328,7 1328,7 @@ static cyaml_err_t cyaml__read_int(
		return CYAML_ERR_INVALID_DATA_SIZE;
	}

	max = (INT64_MAX >> ((8 - schema->data_size) * 8)) / 2;
	max = (int64_t)((UINT64_MAX >> ((8 - schema->data_size) * 8)) / 2);
	min = (-max) - 1;

	errno = 0;

M src/save.c => src/save.c +33 -3
@@ 217,6 217,35 @@ static inline yaml_mapping_style_t cyaml__get_emit_style_map(
}

/**
 * Get the style to use for scalar values from value flags.
 *
 * \param[in]  schema  The CYAML schema for the scaler value to be emitted.
 * \return The libyaml scalar style to emit the value with.
 */
static inline yaml_scalar_style_t cyaml__get_emit_style_scalar(
		const cyaml_schema_value_t *schema)
{
	/* Consult flags in order of decreasing priority. */
	if (schema->flags & CYAML_FLAG_SCALAR_QUOTE_DOUBLE) {
		return YAML_DOUBLE_QUOTED_SCALAR_STYLE;

	} else if (schema->flags & CYAML_FLAG_SCALAR_QUOTE_SINGLE) {
		return YAML_SINGLE_QUOTED_SCALAR_STYLE;

	} else if (schema->flags & CYAML_FLAG_SCALAR_LITERAL) {
		return YAML_LITERAL_SCALAR_STYLE;

	} else if (schema->flags & CYAML_FLAG_SCALAR_FOLDED) {
		return YAML_FOLDED_SCALAR_STYLE;

	} else if (schema->flags & CYAML_FLAG_SCALAR_PLAIN) {
		return YAML_PLAIN_SCALAR_STYLE;
	}

	return YAML_ANY_SCALAR_STYLE;
}

/**
 * Helper to discern whether to emit document delimiting marks.
 *
 * These are "---" for document start, and "..." for document end.


@@ 488,7 517,7 @@ static cyaml_err_t cyaml__emit_scalar(
	int ret;
	yaml_event_t event;

	if (schema == NULL) {
	if (schema->type == CYAML_MAPPING) {
		cyaml__log(ctx->config, CYAML_LOG_INFO, "Save: [%s]\n", value);
	} else {
		cyaml__log(ctx->config, CYAML_LOG_INFO,


@@ 499,7 528,7 @@ static cyaml_err_t cyaml__emit_scalar(
			(yaml_char_t *)tag,
			(yaml_char_t *)value,
			(int)strlen(value),
			1, 0, YAML_PLAIN_SCALAR_STYLE);
			1, 1, cyaml__get_emit_style_scalar(schema));

	return cyaml__emit_event_helper(ctx, ret, &event);
}


@@ 1136,7 1165,8 @@ static cyaml_err_t cyaml__write_mapping(
			}
		}

		err = cyaml__emit_scalar(ctx, NULL, field->key, YAML_STR_TAG);
		err = cyaml__emit_scalar(ctx, ctx->state->schema,
				field->key, YAML_STR_TAG);
		if (err != CYAML_OK) {
			return err;
		}

M src/util.h => src/util.h +2 -2
@@ 27,9 27,9 @@
 */
static inline bool cyaml__host_is_little_endian(void)
{
	static const uint16_t test = 1;
	const uint16_t test = 1;

	return ((const uint8_t *) &test)[0] == 1;
	return ((const uint8_t *) &test)[0];
}

/**