| 128 | | if (STACK_EMPTY(emitter, document->nodes)) { |
| | 126 | if (document->type == YAML_DOCUMENT) |
| | 127 | { |
| | 128 | assert(emitter->is_opened); /* Emitter should be opened. */ |
| | 129 | |
| | 130 | if (STACK_EMPTY(emitter, emitter->nodes)) { |
| | 131 | SERIALIZER_ERROR_INIT(emitter, "root node is not specified"); |
| | 132 | goto error; |
| | 133 | } |
| | 134 | |
| | 135 | emitter->anchors = yaml_malloc(sizeof(*(emitter->anchors)) |
| | 136 | * (document->nodes.length)); |
| | 137 | if (!emitter->anchors) goto error; |
| | 138 | memset(emitter->anchors, 0, sizeof(*(emitter->anchors)) |
| | 139 | * (document->nodes.length)); |
| | 140 | |
| | 141 | DOCUMENT_START_EVENT_INIT(event, document->version_directive, |
| | 142 | document->tag_directives.list, document->tag_directives.length, |
| | 143 | document->tag_directives.capacity, |
| | 144 | document->start_implicit, mark, mark); |
| | 145 | if (!yaml_emitter_emit(emitter, &event)) goto error; |
| | 146 | |
| | 147 | yaml_emitter_anchor_node(emitter, 0); |
| | 148 | if (!yaml_emitter_dump_node(emitter, 0)) goto error; |
| | 149 | |
| | 150 | DOCUMENT_END_EVENT_INIT(event, document->end_implicit, mark, mark); |
| | 151 | if (!yaml_emitter_emit(emitter, &event)) goto error; |
| | 152 | } |
| | 153 | |
| | 154 | if (!document->type) { |
| 130 | | yaml_emitter_delete_document_and_anchors(emitter); |
| 131 | | return 1; |
| 132 | | } |
| 133 | | |
| 134 | | assert(emitter->opened); /* Emitter should be opened. */ |
| 135 | | |
| 136 | | emitter->anchors = yaml_malloc(sizeof(*(emitter->anchors)) |
| 137 | | * (document->nodes.top - document->nodes.start)); |
| 138 | | if (!emitter->anchors) goto error; |
| 139 | | memset(emitter->anchors, 0, sizeof(*(emitter->anchors)) |
| 140 | | * (document->nodes.top - document->nodes.start)); |
| 141 | | |
| 142 | | DOCUMENT_START_EVENT_INIT(event, document->version_directive, |
| 143 | | document->tag_directives.start, document->tag_directives.end, |
| 144 | | document->start_implicit, mark, mark); |
| 145 | | if (!yaml_emitter_emit(emitter, &event)) goto error; |
| 146 | | |
| 147 | | yaml_emitter_anchor_node(emitter, 1); |
| 148 | | if (!yaml_emitter_dump_node(emitter, 1)) goto error; |
| 149 | | |
| 150 | | DOCUMENT_END_EVENT_INIT(event, document->end_implicit, mark, mark); |
| 151 | | if (!yaml_emitter_emit(emitter, &event)) goto error; |
| | 156 | } |