Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump libyaml version to 0.2.5 #456

Merged
merged 3 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions ext/psych/yaml/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ yaml_string_join(
YAML_DECLARE(int)
yaml_stack_extend(void **start, void **top, void **end)
{
void *new_start = yaml_realloc(*start, ((char *)*end - (char *)*start)*2);
void *new_start;

if ((char *)*end - (char *)*start >= INT_MAX / 2)
return 0;

new_start = yaml_realloc(*start, ((char *)*end - (char *)*start)*2);

if (!new_start) return 0;

Expand Down Expand Up @@ -618,10 +623,10 @@ yaml_token_delete(yaml_token_t *token)
*/

static int
yaml_check_utf8(yaml_char_t *start, size_t length)
yaml_check_utf8(const yaml_char_t *start, size_t length)
{
yaml_char_t *end = start+length;
yaml_char_t *pointer = start;
const yaml_char_t *end = start+length;
const yaml_char_t *pointer = start;

while (pointer < end) {
unsigned char octet;
Expand Down Expand Up @@ -789,7 +794,7 @@ yaml_document_end_event_initialize(yaml_event_t *event, int implicit)
*/

YAML_DECLARE(int)
yaml_alias_event_initialize(yaml_event_t *event, yaml_char_t *anchor)
yaml_alias_event_initialize(yaml_event_t *event, const yaml_char_t *anchor)
{
yaml_mark_t mark = { 0, 0, 0 };
yaml_char_t *anchor_copy = NULL;
Expand All @@ -814,8 +819,8 @@ yaml_alias_event_initialize(yaml_event_t *event, yaml_char_t *anchor)

YAML_DECLARE(int)
yaml_scalar_event_initialize(yaml_event_t *event,
yaml_char_t *anchor, yaml_char_t *tag,
yaml_char_t *value, int length,
const yaml_char_t *anchor, const yaml_char_t *tag,
const yaml_char_t *value, int length,
int plain_implicit, int quoted_implicit,
yaml_scalar_style_t style)
{
Expand Down Expand Up @@ -868,7 +873,7 @@ yaml_scalar_event_initialize(yaml_event_t *event,

YAML_DECLARE(int)
yaml_sequence_start_event_initialize(yaml_event_t *event,
yaml_char_t *anchor, yaml_char_t *tag, int implicit,
const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
yaml_sequence_style_t style)
{
yaml_mark_t mark = { 0, 0, 0 };
Expand Down Expand Up @@ -923,7 +928,7 @@ yaml_sequence_end_event_initialize(yaml_event_t *event)

YAML_DECLARE(int)
yaml_mapping_start_event_initialize(yaml_event_t *event,
yaml_char_t *anchor, yaml_char_t *tag, int implicit,
const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
yaml_mapping_style_t style)
{
yaml_mark_t mark = { 0, 0, 0 };
Expand Down Expand Up @@ -1117,15 +1122,8 @@ yaml_document_initialize(yaml_document_t *document,
YAML_DECLARE(void)
yaml_document_delete(yaml_document_t *document)
{
struct {
yaml_error_type_t error;
} context;
yaml_tag_directive_t *tag_directive;

/* Eliminate a compliler warning. */
context.error = YAML_NO_ERROR;
(void)context.error;

assert(document); /* Non-NULL document object is expected. */

while (!STACK_EMPTY(&context, document->nodes)) {
Expand Down Expand Up @@ -1195,7 +1193,7 @@ yaml_document_get_root_node(yaml_document_t *document)

YAML_DECLARE(int)
yaml_document_add_scalar(yaml_document_t *document,
yaml_char_t *tag, yaml_char_t *value, int length,
const yaml_char_t *tag, const yaml_char_t *value, int length,
yaml_scalar_style_t style)
{
struct {
Expand Down Expand Up @@ -1245,7 +1243,7 @@ yaml_document_add_scalar(yaml_document_t *document,

YAML_DECLARE(int)
yaml_document_add_sequence(yaml_document_t *document,
yaml_char_t *tag, yaml_sequence_style_t style)
const yaml_char_t *tag, yaml_sequence_style_t style)
{
struct {
yaml_error_type_t error;
Expand Down Expand Up @@ -1290,7 +1288,7 @@ yaml_document_add_sequence(yaml_document_t *document,

YAML_DECLARE(int)
yaml_document_add_mapping(yaml_document_t *document,
yaml_char_t *tag, yaml_mapping_style_t style)
const yaml_char_t *tag, yaml_mapping_style_t style)
{
struct {
yaml_error_type_t error;
Expand Down
82 changes: 76 additions & 6 deletions ext/psych/yaml/config.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,80 @@
/* include/config.h. Generated from config.h.in by configure. */
/* include/config.h.in. Generated from configure.ac by autoheader. */

/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1

/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1

/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1

/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1

/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1

/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1

/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1

/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1

/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1

/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1

/* Define to the sub-directory where libtool stores uninstalled libraries. */
#define LT_OBJDIR ".libs/"

/* Name of package */
#define PACKAGE "yaml"

/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "https://github.com/yaml/libyaml/issues/new"

/* Define to the full name of this package. */
#define PACKAGE_NAME "yaml"

/* Define to the full name and version of this package. */
#define PACKAGE_STRING "yaml 0.2.5"

/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "yaml"
#define PACKAGE_VERSION "0.2.1"
#define PACKAGE_STRING "yaml 0.2.1"
#define PACKAGE_BUGREPORT "https://github.com/yaml/libyaml/issues"
#define PACKAGE_URL "https://github.com/yaml/libyaml"

/* Define to the home page for this package. */
#define PACKAGE_URL ""

/* Define to the version of this package. */
#define PACKAGE_VERSION "0.2.5"

/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1

/* Version number of package */
#define VERSION "0.2.5"

/* Define the major version number. */
#define YAML_VERSION_MAJOR 0

/* Define the minor version number. */
#define YAML_VERSION_MINOR 2
#define YAML_VERSION_PATCH 1
#define YAML_VERSION_STRING "0.2.1"

/* Define the patch version number. */
#define YAML_VERSION_PATCH 5

/* Define the version string. */
#define YAML_VERSION_STRING "0.2.5"

/* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */

/* Define to `unsigned int' if <sys/types.h> does not define. */
/* #undef size_t */
2 changes: 1 addition & 1 deletion ext/psych/yaml/dumper.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document)

assert(emitter->opened); /* Emitter should be opened. */

emitter->anchors = yaml_malloc(sizeof(*(emitter->anchors))
emitter->anchors = (yaml_anchors_t*)yaml_malloc(sizeof(*(emitter->anchors))
* (document->nodes.top - document->nodes.start));
if (!emitter->anchors) goto error;
memset(emitter->anchors, 0, sizeof(*(emitter->anchors))
Expand Down
54 changes: 44 additions & 10 deletions ext/psych/yaml/emitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define PUT(emitter,value) \
(FLUSH(emitter) \
&& (*(emitter->buffer.pointer++) = (yaml_char_t)(value), \
emitter->column ++, \
emitter->column++, \
1))

/*
Expand Down Expand Up @@ -495,6 +495,7 @@ static int
yaml_emitter_emit_stream_start(yaml_emitter_t *emitter,
yaml_event_t *event)
{
emitter->open_ended = 0;
if (event->type == YAML_STREAM_START_EVENT)
{
if (!emitter->encoding) {
Expand Down Expand Up @@ -597,13 +598,20 @@ yaml_emitter_emit_document_start(yaml_emitter_t *emitter,
if (!yaml_emitter_write_indent(emitter))
return 0;
}
emitter->open_ended = 0;

if (event->data.document_start.version_directive) {
implicit = 0;
if (!yaml_emitter_write_indicator(emitter, "%YAML", 1, 0, 0))
return 0;
if (!yaml_emitter_write_indicator(emitter, "1.1", 1, 0, 0))
return 0;
if (event->data.document_start.version_directive->minor == 1) {
if (!yaml_emitter_write_indicator(emitter, "1.1", 1, 0, 0))
return 0;
}
else {
if (!yaml_emitter_write_indicator(emitter, "1.2", 1, 0, 0))
return 0;
}
if (!yaml_emitter_write_indent(emitter))
return 0;
}
Expand Down Expand Up @@ -644,19 +652,25 @@ yaml_emitter_emit_document_start(yaml_emitter_t *emitter,

emitter->state = YAML_EMIT_DOCUMENT_CONTENT_STATE;

emitter->open_ended = 0;
return 1;
}

else if (event->type == YAML_STREAM_END_EVENT)
{
if (emitter->open_ended)

/**
* This can happen if a block scalar with trailing empty lines
* is at the end of the stream
*/
if (emitter->open_ended == 2)
{
if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0))
return 0;
emitter->open_ended = 0;
if (!yaml_emitter_write_indent(emitter))
return 0;
}

if (!yaml_emitter_flush(emitter))
return 0;

Expand Down Expand Up @@ -698,9 +712,12 @@ yaml_emitter_emit_document_end(yaml_emitter_t *emitter,
if (!event->data.document_end.implicit) {
if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0))
return 0;
emitter->open_ended = 0;
if (!yaml_emitter_write_indent(emitter))
return 0;
}
else if (!emitter->open_ended)
emitter->open_ended = 1;
if (!yaml_emitter_flush(emitter))
return 0;

Expand Down Expand Up @@ -1006,6 +1023,8 @@ yaml_emitter_emit_alias(yaml_emitter_t *emitter, SHIM(yaml_event_t *event))
{
if (!yaml_emitter_process_anchor(emitter))
return 0;
if (emitter->simple_key_context)
if (!PUT(emitter, ' ')) return 0;
emitter->state = POP(emitter, emitter->states);

return 1;
Expand Down Expand Up @@ -1333,7 +1352,10 @@ static int
yaml_emitter_analyze_version_directive(yaml_emitter_t *emitter,
yaml_version_directive_t version_directive)
{
if (version_directive.major != 1 || version_directive.minor != 1) {
if (version_directive.major != 1 || (
version_directive.minor != 1
&& version_directive.minor != 2
)) {
return yaml_emitter_set_emitter_error(emitter,
"incompatible %YAML directive");
}
Expand Down Expand Up @@ -1803,7 +1825,6 @@ yaml_emitter_write_indicator(yaml_emitter_t *emitter,

emitter->whitespace = is_whitespace;
emitter->indention = (emitter->indention && is_indention);
emitter->open_ended = 0;

return 1;
}
Expand Down Expand Up @@ -1904,7 +1925,17 @@ yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter,

STRING_ASSIGN(string, value, length);

if (!emitter->whitespace) {
/**
* Avoid trailing spaces for empty values in block mode.
* In flow mode, we still want the space to prevent ambiguous things
* like {a:}.
* Currently, the emitter forbids any plain empty scalar in flow mode
* (e.g. it outputs {a: ''} instead), so emitter->flow_level will
* never be true here.
* But if the emitter is ever changed to allow emitting empty values,
* the check for flow_level is already here.
*/
if (!emitter->whitespace && (length || emitter->flow_level)) {
if (!PUT(emitter, ' ')) return 0;
}

Expand Down Expand Up @@ -2004,6 +2035,9 @@ yaml_emitter_write_single_quoted_scalar(yaml_emitter_t *emitter,
}
}

if (breaks)
if (!yaml_emitter_write_indent(emitter)) return 0;

if (!yaml_emitter_write_indicator(emitter, "'", 0, 0, 0))
return 0;

Expand Down Expand Up @@ -2203,7 +2237,7 @@ yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter,
else if (string.start == string.pointer)
{
chomp_hint = "+";
emitter->open_ended = 1;
emitter->open_ended = 2;
}
else
{
Expand All @@ -2213,7 +2247,7 @@ yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter,
if (IS_BREAK(string))
{
chomp_hint = "+";
emitter->open_ended = 1;
emitter->open_ended = 2;
}
}
}
Expand Down
Loading