X-Git-Url: http://andersk.mit.edu/gitweb/libyaml.git/blobdiff_plain/0174ed6e0abc4b9316a91d32163f2507a31d29fb..c45550e5cf265bf6877cad127faa9854851e291e:/src/api.c diff --git a/src/api.c b/src/api.c index f5d5cd2..ee170d8 100644 --- a/src/api.c +++ b/src/api.c @@ -74,7 +74,7 @@ YAML_DECLARE(int) yaml_string_extend(yaml_char_t **start, yaml_char_t **pointer, yaml_char_t **end) { - yaml_char_t *new_start = yaml_realloc(*start, (*end - *start)*2); + yaml_char_t *new_start = (yaml_char_t *)yaml_realloc((void*)*start, (*end - *start)*2); if (!new_start) return 0; @@ -94,8 +94,9 @@ yaml_string_extend(yaml_char_t **start, YAML_DECLARE(int) yaml_string_join( yaml_char_t **a_start, yaml_char_t **a_pointer, yaml_char_t **a_end, - yaml_char_t **b_start, yaml_char_t **b_pointer, yaml_char_t **b_end) + yaml_char_t **b_start, yaml_char_t **b_pointer, SHIM(yaml_char_t **b_end)) { + UNUSED_PARAM(b_end) if (*b_start == *b_pointer) return 1; @@ -177,17 +178,17 @@ yaml_parser_initialize(yaml_parser_t *parser) goto error; if (!BUFFER_INIT(parser, parser->buffer, INPUT_BUFFER_SIZE)) goto error; - if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_SIZE)) + if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_SIZE, yaml_token_t*)) goto error; - if (!STACK_INIT(parser, parser->indents, INITIAL_STACK_SIZE)) + if (!STACK_INIT(parser, parser->indents, int*)) goto error; - if (!STACK_INIT(parser, parser->simple_keys, INITIAL_STACK_SIZE)) + if (!STACK_INIT(parser, parser->simple_keys, yaml_simple_key_t*)) goto error; - if (!STACK_INIT(parser, parser->states, INITIAL_STACK_SIZE)) + if (!STACK_INIT(parser, parser->states, yaml_parser_state_t*)) goto error; - if (!STACK_INIT(parser, parser->marks, INITIAL_STACK_SIZE)) + if (!STACK_INIT(parser, parser->marks, yaml_mark_t*)) goto error; - if (!STACK_INIT(parser, parser->tag_directives, INITIAL_STACK_SIZE)) + if (!STACK_INIT(parser, parser->tag_directives, yaml_tag_directive_t*)) goto error; return 1; @@ -243,7 +244,7 @@ static int yaml_string_read_handler(void *data, unsigned char *buffer, size_t size, size_t *size_read) { - yaml_parser_t *parser = data; + yaml_parser_t *parser = (yaml_parser_t *)data; if (parser->input.string.current == parser->input.string.end) { *size_read = 0; @@ -269,7 +270,7 @@ static int yaml_file_read_handler(void *data, unsigned char *buffer, size_t size, size_t *size_read) { - yaml_parser_t *parser = data; + yaml_parser_t *parser = (yaml_parser_t *)data; *size_read = fread(buffer, 1, size, parser->input.file); return !ferror(parser->input.file); @@ -355,13 +356,13 @@ yaml_emitter_initialize(yaml_emitter_t *emitter) goto error; if (!BUFFER_INIT(emitter, emitter->raw_buffer, OUTPUT_RAW_BUFFER_SIZE)) goto error; - if (!STACK_INIT(emitter, emitter->states, INITIAL_STACK_SIZE)) + if (!STACK_INIT(emitter, emitter->states, yaml_emitter_state_t*)) goto error; - if (!QUEUE_INIT(emitter, emitter->events, INITIAL_QUEUE_SIZE)) + if (!QUEUE_INIT(emitter, emitter->events, INITIAL_QUEUE_SIZE, yaml_event_t*)) goto error; - if (!STACK_INIT(emitter, emitter->indents, INITIAL_STACK_SIZE)) + if (!STACK_INIT(emitter, emitter->indents, int*)) goto error; - if (!STACK_INIT(emitter, emitter->tag_directives, INITIAL_STACK_SIZE)) + if (!STACK_INIT(emitter, emitter->tag_directives, yaml_tag_directive_t*)) goto error; return 1; @@ -413,9 +414,9 @@ yaml_emitter_delete(yaml_emitter_t *emitter) static int yaml_string_write_handler(void *data, unsigned char *buffer, size_t size) { - yaml_emitter_t *emitter = data; + yaml_emitter_t *emitter = (yaml_emitter_t *)data; - if (emitter->output.string.size + *emitter->output.string.size_written + if (emitter->output.string.size - *emitter->output.string.size_written < size) { memcpy(emitter->output.string.buffer + *emitter->output.string.size_written, @@ -439,7 +440,7 @@ yaml_string_write_handler(void *data, unsigned char *buffer, size_t size) static int yaml_file_write_handler(void *data, unsigned char *buffer, size_t size) { - yaml_emitter_t *emitter = data; + yaml_emitter_t *emitter = (yaml_emitter_t *)data; return (fwrite(buffer, 1, size, emitter->output.file) == size); } @@ -717,7 +718,7 @@ yaml_document_start_event_initialize(yaml_event_t *event, /* Valid tag directives are expected. */ if (version_directive) { - version_directive_copy = yaml_malloc(sizeof(yaml_version_directive_t)); + version_directive_copy = YAML_MALLOC_STATIC(yaml_version_directive_t); if (!version_directive_copy) goto error; version_directive_copy->major = version_directive->major; version_directive_copy->minor = version_directive->minor; @@ -725,7 +726,7 @@ yaml_document_start_event_initialize(yaml_event_t *event, if (tag_directives_start != tag_directives_end) { yaml_tag_directive_t *tag_directive; - if (!STACK_INIT(&context, tag_directives_copy, INITIAL_STACK_SIZE)) + if (!STACK_INIT(&context, tag_directives_copy, yaml_tag_directive_t*)) goto error; for (tag_directive = tag_directives_start; tag_directive != tag_directives_end; tag_directive ++) { @@ -843,7 +844,7 @@ yaml_scalar_event_initialize(yaml_event_t *event, } if (!yaml_check_utf8(value, length)) goto error; - value_copy = yaml_malloc(length+1); + value_copy = YAML_MALLOC(length+1); if (!value_copy) goto error; memcpy(value_copy, value, length); value_copy[length] = '\0'; @@ -1055,10 +1056,10 @@ yaml_document_initialize(yaml_document_t *document, (tag_directives_start == tag_directives_end)); /* Valid tag directives are expected. */ - if (!STACK_INIT(&context, nodes, INITIAL_STACK_SIZE)) goto error; + if (!STACK_INIT(&context, nodes, yaml_node_t*)) goto error; if (version_directive) { - version_directive_copy = yaml_malloc(sizeof(yaml_version_directive_t)); + version_directive_copy = YAML_MALLOC_STATIC(yaml_version_directive_t); if (!version_directive_copy) goto error; version_directive_copy->major = version_directive->major; version_directive_copy->minor = version_directive->minor; @@ -1066,7 +1067,7 @@ yaml_document_initialize(yaml_document_t *document, if (tag_directives_start != tag_directives_end) { yaml_tag_directive_t *tag_directive; - if (!STACK_INIT(&context, tag_directives_copy, INITIAL_STACK_SIZE)) + if (!STACK_INIT(&context, tag_directives_copy, yaml_tag_directive_t*)) goto error; for (tag_directive = tag_directives_start; tag_directive != tag_directives_end; tag_directive ++) { @@ -1118,9 +1119,11 @@ yaml_document_delete(yaml_document_t *document) { struct { yaml_error_type_t error; - } context = { YAML_NO_ERROR }; + } context; yaml_tag_directive_t *tag_directive; + context.error = YAML_NO_ERROR; /* Eliminate a compliler warning. */ + assert(document); /* Non-NULL document object is expected. */ while (!STACK_EMPTY(&context, document->nodes)) { @@ -1159,12 +1162,12 @@ yaml_document_delete(yaml_document_t *document) */ YAML_DECLARE(yaml_node_t *) -yaml_document_get_node(yaml_document_t *document, int node) +yaml_document_get_node(yaml_document_t *document, int index) { assert(document); /* Non-NULL document object is expected. */ - if (node > 0 && document->nodes.start + node <= document->nodes.top) { - return document->nodes.start + node - 1; + if (index > 0 && document->nodes.start + index <= document->nodes.top) { + return document->nodes.start + index - 1; } return NULL; } @@ -1205,7 +1208,7 @@ yaml_document_add_scalar(yaml_document_t *document, assert(value); /* Non-NULL value is expected. */ if (!tag) { - tag = YAML_DEFAULT_SCALAR_TAG; + tag = (yaml_char_t *)YAML_DEFAULT_SCALAR_TAG; } if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; @@ -1217,7 +1220,7 @@ yaml_document_add_scalar(yaml_document_t *document, } if (!yaml_check_utf8(value, length)) goto error; - value_copy = yaml_malloc(length+1); + value_copy = YAML_MALLOC(length+1); if (!value_copy) goto error; memcpy(value_copy, value, length); value_copy[length] = '\0'; @@ -1257,14 +1260,14 @@ yaml_document_add_sequence(yaml_document_t *document, assert(document); /* Non-NULL document object is expected. */ if (!tag) { - tag = YAML_DEFAULT_SEQUENCE_TAG; + tag = (yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG; } if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; tag_copy = yaml_strdup(tag); if (!tag_copy) goto error; - if (!STACK_INIT(&context, items, INITIAL_STACK_SIZE)) goto error; + if (!STACK_INIT(&context, items, yaml_node_item_t*)) goto error; SEQUENCE_NODE_INIT(node, tag_copy, items.start, items.end, style, mark, mark); @@ -1302,14 +1305,14 @@ yaml_document_add_mapping(yaml_document_t *document, assert(document); /* Non-NULL document object is expected. */ if (!tag) { - tag = YAML_DEFAULT_MAPPING_TAG; + tag = (yaml_char_t *)YAML_DEFAULT_MAPPING_TAG; } if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error; tag_copy = yaml_strdup(tag); if (!tag_copy) goto error; - if (!STACK_INIT(&context, pairs, INITIAL_STACK_SIZE)) goto error; + if (!STACK_INIT(&context, pairs, yaml_node_pair_t*)) goto error; MAPPING_NODE_INIT(node, tag_copy, pairs.start, pairs.end, style, mark, mark); @@ -1363,7 +1366,8 @@ yaml_document_append_mapping_pair(yaml_document_t *document, struct { yaml_error_type_t error; } context; - yaml_node_pair_t pair = { key, value }; + + yaml_node_pair_t pair; assert(document); /* Non-NULL document is required. */ assert(mapping > 0 @@ -1376,6 +1380,9 @@ yaml_document_append_mapping_pair(yaml_document_t *document, assert(value > 0 && document->nodes.start + value <= document->nodes.top); /* Valid value id is required. */ + pair.key = key; + pair.value = value; + if (!PUSH(&context, document->nodes.start[mapping-1].data.mapping.pairs, pair)) return 0;