cmark

My personal build of CMark ✏️

Commit
0b746507aad92a8f7ec942e06889df62ec441f54
Parent
feb119992a6fbea3cedead04b1941b1fe114990b
Author
John MacFarlane <jgm@berkeley.edu>
Date

Removed cmark_free_nodes from public API.

Replace it with static S_free_nodes.

Diffstat

5 files changed, 42 insertions, 45 deletions

Status File Name N° Changes Insertions Deletions
Modified src/cmark.c 8 4 4
Modified src/cmark.h 3 0 3
Modified src/inlines.c 3 1 2
Modified src/main.c 2 1 1
Modified src/node.c 71 36 35
diff --git a/src/cmark.c b/src/cmark.c
@@ -8,13 +8,13 @@
 
 char *cmark_markdown_to_html(const char *text, int len)
 {
-	cmark_node *blocks;
+	cmark_node *doc;
 	char *result;
 
-	blocks = cmark_parse_document(text, len);
+	doc = cmark_parse_document(text, len);
 
-	result = cmark_render_html(blocks);
-	cmark_free_nodes(blocks);
+	result = cmark_render_html(doc);
+	cmark_node_free(doc);
 
 	return result;
 }
diff --git a/src/cmark.h b/src/cmark.h
@@ -63,9 +63,6 @@ cmark_node_new(cmark_node_type type);
 CMARK_EXPORT void
 cmark_node_free(cmark_node *node);
 
-CMARK_EXPORT void
-cmark_free_nodes(cmark_node *e);
-
 // Tree traversal
 
 CMARK_EXPORT cmark_node*
diff --git a/src/inlines.c b/src/inlines.c
@@ -450,8 +450,7 @@ static void process_emphasis(subject *subj, delimiter_stack *stack_bottom)
 					if (tmp->next) {
 						tmp->next->prev = emph;
 					}
-					cmark_node_unlink(tmp);
-					cmark_free_nodes(tmp);
+					cmark_node_free(tmp);
 					// remove closer from stack
 					tempstack = closer->next;
 					remove_delimiter(subj, closer);
diff --git a/src/main.c b/src/main.c
@@ -101,7 +101,7 @@ int main(int argc, char *argv[])
 	end_timer("print_document");
 
 	start_timer();
-	cmark_free_nodes(document);
+	cmark_node_free(document);
 	end_timer("free_blocks");
 
 	free(files);
diff --git a/src/node.c b/src/node.c
@@ -32,11 +32,46 @@ cmark_node_new(cmark_node_type type) {
 	return node;
 }
 
+// Free a cmark_node list and any children.
+static
+void S_free_nodes(cmark_node *e)
+{
+	cmark_node *next;
+	while (e != NULL) {
+		strbuf_free(&e->string_content);
+		switch (e->type){
+		case NODE_CODE_BLOCK:
+			strbuf_free(&e->as.code.info);
+			break;
+		case NODE_TEXT:
+		case NODE_INLINE_HTML:
+		case NODE_INLINE_CODE:
+			cmark_chunk_free(&e->as.literal);
+			break;
+		case NODE_LINK:
+		case NODE_IMAGE:
+			free(e->as.link.url);
+			free(e->as.link.title);
+			break;
+		default:
+			break;
+		}
+		if (e->last_child) {
+			// Splice children into list
+			e->last_child->next = e->next;
+			e->next = e->first_child;
+		}
+		next = e->next;
+		free(e);
+		e = next;
+	}
+}
+
 void
 cmark_node_free(cmark_node *node) {
 	S_node_unlink(node);
 	node->next = NULL;
-	cmark_free_nodes(node);
+	S_free_nodes(node);
 }
 
 cmark_node_type
@@ -612,38 +647,4 @@ cmark_node_check(cmark_node *node, FILE *out)
 	return errors;
 }
 
-// Free a cmark_node list and any children.
-void cmark_free_nodes(cmark_node *e)
-{
-	cmark_node *next;
-	while (e != NULL) {
-		strbuf_free(&e->string_content);
-		switch (e->type){
-		case NODE_CODE_BLOCK:
-			strbuf_free(&e->as.code.info);
-			break;
-		case NODE_TEXT:
-		case NODE_INLINE_HTML:
-		case NODE_INLINE_CODE:
-			cmark_chunk_free(&e->as.literal);
-			break;
-		case NODE_LINK:
-		case NODE_IMAGE:
-			free(e->as.link.url);
-			free(e->as.link.title);
-			break;
-		default:
-			break;
-		}
-		if (e->last_child) {
-			// Splice children into list
-			e->last_child->next = e->next;
-			e->next = e->first_child;
-		}
-		next = e->next;
-		free(e);
-		e = next;
-	}
-}
-