MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / yaml_document_delete

Function yaml_document_delete

xs/tools/yaml/api.c:1142–1183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1140 */
1141
1142YAML_DECLARE(void)
1143yaml_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.

Callers 5

fxRunContextFunction · 0.85
yaml.hFile · 0.85
yaml_parser_loadFunction · 0.85

Calls 2

yaml_freeFunction · 0.85
assertFunction · 0.50

Tested by 1