diff options
author | Vicent Marti <tanoku@gmail.com> | 2016-05-27 16:55:16 +0200 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2016-06-06 15:39:05 -0700 |
commit | 25429c96f6554ffac415f9d865934b1183f3398e (patch) | |
tree | 84d4eef404e99ff9e88d96a86d348a863d7c466f /src/cmark.h | |
parent | ab6c81b960e86b26c7fda366f51ff29d1683a555 (diff) |
cmark: Implement support for custom allocators
Diffstat (limited to 'src/cmark.h')
-rw-r--r-- | src/cmark.h | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/cmark.h b/src/cmark.h index a43011b..293919d 100644 --- a/src/cmark.h +++ b/src/cmark.h @@ -4,6 +4,7 @@ #include <stdio.h> #include <cmark_export.h> #include <cmark_version.h> +#include "memory.h" #ifdef __cplusplus extern "C" { @@ -88,6 +89,19 @@ typedef struct cmark_parser cmark_parser; typedef struct cmark_iter cmark_iter; /** + * ## Custom memory allocator support + */ + +/** Defines the memory allocation functions to be used by CMark + * when parsing and allocating a document tree + */ +typedef struct cmark_mem { + void *(*calloc)(size_t, size_t); + void (*free)(void *); +} cmark_mem; + + +/** * ## Creating and Destroying Nodes */ @@ -97,6 +111,11 @@ typedef struct cmark_iter cmark_iter; */ CMARK_EXPORT cmark_node *cmark_node_new(cmark_node_type type); +/** Same as `cmark_node_new`, but explicitly listing the memory + * allocator used to allocate the node + */ +CMARK_EXPORT cmark_node *cmark_node_new2(cmark_node_type type, cmark_mem *mem); + /** Frees the memory allocated for a node and any children. */ CMARK_EXPORT void cmark_node_free(cmark_node *node); @@ -437,6 +456,11 @@ CMARK_EXPORT void cmark_consolidate_text_nodes(cmark_node *root); CMARK_EXPORT cmark_parser *cmark_parser_new(int options); +/** Creates a new parser object with the given memory allocator + */ +CMARK_EXPORT +cmark_parser *cmark_parser_new2(int options, cmark_mem *mem); + /** Frees memory allocated for a parser object. */ CMARK_EXPORT @@ -573,20 +597,6 @@ int cmark_version(); CMARK_EXPORT const char *cmark_version_string(); -/** Set the callback function that will be issued whenever the - * library hits an out of memory situation. - * - * This can happen when the heap memory allocator fails to allocate - * a block of memory, or when the index of an in-memory buffer overflows - * - * If no OOM handler is set, the library will call `abort` and - * terminate itself and the running process. If the custom OOM handler - * you set does return (i.e. it does not gracefully terminate the - * application), the behavior of the library will be unspecified. - */ -CMARK_EXPORT -void cmark_set_oom_handler(void (*handler)(void)); - /** # AUTHORS * * John MacFarlane, Vicent Marti, Kārlis Gaņģis, Nick Wellnhofer. |