cmark

My personal build of CMark ✏️

Commit
fdbdbf7ecc8597d2b6ae329ecbdabebaf0793fba
Parent
71ef02503ebbd82497920ecc7d580c480865c47a
Author
John MacFarlane <jgm@berkeley.edu>
Date

Add cmark_get_default_mem_allocator().

API change: This adds a new exported function in cmark.h.

Closes #330.

Diffstat

4 files changed, 19 insertions, 2 deletions

Status File Name N° Changes Insertions Deletions
Modified api_test/main.c 4 3 1
Modified man/man3/cmark.3 8 7 1
Modified src/cmark.c 5 5 0
Modified src/cmark.h 4 4 0
diff --git a/api_test/main.c b/api_test/main.c
@@ -320,7 +320,9 @@ static void iterator_delete(test_batch_runner *runner) {
                                  "<p>a  c</p>\n";
   STR_EQ(runner, html, expected, "iterate and delete nodes");
 
-  free(html);
+  cmark_mem *allocator = cmark_get_default_mem_allocator();
+
+  allocator->free(html);
   cmark_iter_free(iter);
   cmark_node_free(doc);
 }
diff --git a/man/man3/cmark.3 b/man/man3/cmark.3
@@ -1,4 +1,4 @@
-.TH cmark 3 "March 19, 2019" "LOCAL" "Library Functions Manual"
+.TH cmark 3 "February 09, 2020" "LOCAL" "Library Functions Manual"
 .SH
 NAME
 .PP
@@ -115,6 +115,12 @@ typedef struct cmark_mem {
 Defines the memory allocation functions to be used by CMark when parsing
 and allocating a document tree
 
+.PP
+\fIcmark_mem *\f[] \fBcmark_get_default_mem_allocator\f[](\fI\f[])
+
+.PP
+Returns a pointer to the default memory allocator.
+
 .SS
 Creating and Destroying Nodes
 
diff --git a/src/cmark.c b/src/cmark.c
@@ -30,6 +30,11 @@ static void *xrealloc(void *ptr, size_t size) {
 
 cmark_mem DEFAULT_MEM_ALLOCATOR = {xcalloc, xrealloc, free};
 
+cmark_mem *cmark_get_default_mem_allocator() {
+  return &DEFAULT_MEM_ALLOCATOR;
+}
+
+
 char *cmark_markdown_to_html(const char *text, size_t len, int options) {
   cmark_node *doc;
   char *result;
diff --git a/src/cmark.h b/src/cmark.h
@@ -100,6 +100,10 @@ typedef struct cmark_mem {
   void (*free)(void *);
 } cmark_mem;
 
+/** Returns a pointer to the default memory allocator.
+ */
+CMARK_EXPORT cmark_mem *cmark_get_default_mem_allocator();
+
 /**
  * ## Creating and Destroying Nodes
  */