| 1140 | */ |
| 1141 | |
| 1142 | YAML_DECLARE(void) |
| 1143 | yaml_document_delete(yaml_document_t *document) |
| 1144 | { |
| 1145 | struct { |
| 1146 | yaml_error_type_t error; |
| 1147 | } context; |
| 1148 | yaml_tag_directive_t *tag_directive; |
| 1149 | |
| 1150 | context.error = YAML_NO_ERROR; /* Eliminate a compliler warning. */ |
| 1151 | |
| 1152 | assert(document); /* Non-NULL document object is expected. */ |
| 1153 | |
| 1154 | while (!STACK_EMPTY(&context, document->nodes)) { |
| 1155 | yaml_node_t node = POP(&context, document->nodes); |
| 1156 | yaml_free(node.tag); |
| 1157 | switch (node.type) { |
| 1158 | case YAML_SCALAR_NODE: |
| 1159 | yaml_free(node.data.scalar.value); |
| 1160 | break; |
| 1161 | case YAML_SEQUENCE_NODE: |
| 1162 | STACK_DEL(&context, node.data.sequence.items); |
| 1163 | break; |
| 1164 | case YAML_MAPPING_NODE: |
| 1165 | STACK_DEL(&context, node.data.mapping.pairs); |
| 1166 | break; |
| 1167 | default: |
| 1168 | assert(0); /* Should not happen. */ |
| 1169 | } |
| 1170 | } |
| 1171 | STACK_DEL(&context, document->nodes); |
| 1172 | |
| 1173 | yaml_free(document->version_directive); |
| 1174 | for (tag_directive = document->tag_directives.start; |
| 1175 | tag_directive != document->tag_directives.end; |
| 1176 | tag_directive++) { |
| 1177 | yaml_free(tag_directive->handle); |
| 1178 | yaml_free(tag_directive->prefix); |
| 1179 | } |
| 1180 | yaml_free(document->tag_directives.start); |
| 1181 | |
| 1182 | memset(document, 0, sizeof(yaml_document_t)); |
| 1183 | } |
| 1184 | |
| 1185 | /** |
| 1186 | * Get a document node. |