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

Helpful assert errors #240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
162 changes: 82 additions & 80 deletions src/api.c

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions src/dumper.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ yaml_emitter_open(yaml_emitter_t *emitter)
yaml_event_t event;
yaml_mark_t mark = { 0, 0, 0 };

assert(emitter); /* Non-NULL emitter object is required. */
assert(!emitter->opened); /* Emitter should not be opened yet. */
assert(emitter && "Non-NULL emitter object is required.");
assert(!emitter->opened && "Emitter should not be opened yet.");

STREAM_START_EVENT_INIT(event, YAML_ANY_ENCODING, mark, mark);

Expand All @@ -88,8 +88,8 @@ yaml_emitter_close(yaml_emitter_t *emitter)
yaml_event_t event;
yaml_mark_t mark = { 0, 0, 0 };

assert(emitter); /* Non-NULL emitter object is required. */
assert(emitter->opened); /* Emitter should be opened. */
assert(emitter && "Non-NULL emitter object is required.");
assert(emitter->opened && "Emitter should be opened.");

if (emitter->closed) return 1;

Expand All @@ -114,8 +114,8 @@ yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document)
yaml_event_t event;
yaml_mark_t mark = { 0, 0, 0 };

assert(emitter); /* Non-NULL emitter object is required. */
assert(document); /* Non-NULL emitter object is expected. */
assert(emitter && "Non-NULL emitter object is required.");
assert(document && "Non-NULL emitter object is expected.");

emitter->document = document;

Expand All @@ -129,7 +129,7 @@ yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document)
return 1;
}

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

emitter->anchors = (yaml_anchors_t*)yaml_malloc(sizeof(*(emitter->anchors))
* (document->nodes.top - document->nodes.start));
Expand Down Expand Up @@ -286,7 +286,7 @@ yaml_emitter_dump_node(yaml_emitter_t *emitter, int index)
case YAML_MAPPING_NODE:
return yaml_emitter_dump_mapping(emitter, node, anchor);
default:
assert(0); /* Could not happen. */
assert(0 && "Could not happen.");
break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/emitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ yaml_emitter_state_machine(yaml_emitter_t *emitter, yaml_event_t *event)
"expected nothing after STREAM-END");

default:
assert(1); /* Invalid state. */
assert(0 && "Invalid state.");
}

return 0;
Expand Down Expand Up @@ -1338,7 +1338,7 @@ yaml_emitter_process_scalar(yaml_emitter_t *emitter)
emitter->scalar_data.value, emitter->scalar_data.length);

default:
assert(1); /* Impossible. */
assert(0 && "Impossible.");
}

return 0;
Expand Down
18 changes: 9 additions & 9 deletions src/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document)
{
yaml_event_t event;

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

memset(document, 0, sizeof(yaml_document_t));
if (!STACK_INIT(parser, document->nodes, yaml_node_t*))
goto error;

if (!parser->stream_start_produced) {
if (!yaml_parser_parse(parser, &event)) goto error;
assert(event.type == YAML_STREAM_START_EVENT);
/* STREAM-START is expected. */
assert(event.type == YAML_STREAM_START_EVENT
&& "STREAM-START is expected.");
}

if (parser->stream_end_produced) {
Expand Down Expand Up @@ -186,8 +186,8 @@ yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *event)
{
struct loader_ctx ctx = { NULL, NULL, NULL };

assert(event->type == YAML_DOCUMENT_START_EVENT);
/* DOCUMENT-START is expected. */
assert(event->type == YAML_DOCUMENT_START_EVENT
&& "DOCUMENT-START is expected.");

parser->document->version_directive
= event->data.document_start.version_directive;
Expand Down Expand Up @@ -243,7 +243,7 @@ yaml_parser_load_nodes(yaml_parser_t *parser, struct loader_ctx *ctx)
return 0;
break;
default:
assert(0); /* Could not happen. */
assert(0 && "yaml_parse Case Failure"); /* Could not happen. */
return 0;
case YAML_DOCUMENT_END_EVENT:
break;
Expand Down Expand Up @@ -337,7 +337,7 @@ yaml_parser_load_node_add(yaml_parser_t *parser, struct loader_ctx *ctx,
break;
}
default:
assert(0); /* Could not happen. */
assert(0 && "YAML SEQ/MAP case failure."); /* Could not happen. */
return 0;
}
return 1;
Expand Down Expand Up @@ -541,4 +541,4 @@ yaml_parser_load_mapping_end(yaml_parser_t *parser, yaml_event_t *event,
(void)POP(parser, *ctx);

return 1;
}
}
6 changes: 3 additions & 3 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ yaml_parser_append_tag_directive(yaml_parser_t *parser,
YAML_DECLARE(int)
yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event)
{
assert(parser); /* Non-NULL parser object is expected. */
assert(event); /* Non-NULL event object is expected. */
assert(parser && "Non-NULL parser object is expected.");
assert(event && "Non-NULL event object is expected.");

/* Erase the event object. */

Expand Down Expand Up @@ -297,7 +297,7 @@ yaml_parser_state_machine(yaml_parser_t *parser, yaml_event_t *event)
return yaml_parser_parse_flow_mapping_value(parser, event, 1);

default:
assert(1); /* Invalid state. */
assert(0 && "Invalid state.");
}

return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ yaml_parser_update_buffer(yaml_parser_t *parser, size_t length)
{
int first = 1;

assert(parser->read_handler); /* Read handler must be set. */
assert(parser->read_handler && "Read handler must be set.");

/* If the EOF flag is set and the raw buffer is empty, do nothing. */

Expand Down Expand Up @@ -394,7 +394,7 @@ yaml_parser_update_buffer(yaml_parser_t *parser, size_t length)
break;

default:
assert(1); /* Impossible. */
assert(0 && "Impossible.");
}

/* Check if the raw buffer contains enough bytes to form a character. */
Expand Down
4 changes: 2 additions & 2 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,8 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token);
YAML_DECLARE(int)
yaml_parser_scan(yaml_parser_t *parser, yaml_token_t *token)
{
assert(parser); /* Non-NULL parser object is expected. */
assert(token); /* Non-NULL token object is expected. */
assert(parser && "Non-NULL parser object is expected.");
assert(token && "Non-NULL token object is expected.");

/* Erase the token object. */

Expand Down
6 changes: 3 additions & 3 deletions src/writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ yaml_emitter_flush(yaml_emitter_t *emitter)
{
int low, high;

assert(emitter); /* Non-NULL emitter object is expected. */
assert(emitter->write_handler); /* Write handler must be set. */
assert(emitter->encoding); /* Output encoding must be set. */
assert(emitter && "Non-NULL emitter object is expected.");
assert(emitter->write_handler && "Write handler must be set.");
assert(emitter->encoding && "Output encoding must be set.");

emitter->buffer.last = emitter->buffer.pointer;
emitter->buffer.pointer = emitter->buffer.start;
Expand Down