diff options
author | Vicent Marti <tanoku@gmail.com> | 2016-05-24 15:50:44 +0200 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2016-06-06 15:39:05 -0700 |
commit | 42b07cc9c8d2e6251d190e5ea0d13fd66cb51e6d (patch) | |
tree | 493ffc6b16278c54da28645d96a9359717625576 /src/cmark.c | |
parent | 0eafc0af940646ab581e47e63090c1692a3525aa (diff) |
cmake: Global handler for OOM situations
Diffstat (limited to 'src/cmark.c')
-rw-r--r-- | src/cmark.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/cmark.c b/src/cmark.c index 3491199..3288308 100644 --- a/src/cmark.c +++ b/src/cmark.c @@ -10,6 +10,36 @@ int cmark_version() { return CMARK_VERSION; } const char *cmark_version_string() { return CMARK_VERSION_STRING; } +void (*_cmark_on_oom)(void) = NULL; + +void cmark_trigger_oom(void) +{ + if (_cmark_on_oom) + _cmark_on_oom(); + abort(); +} + +void cmark_set_oom_handler(void (*handler)(void)) +{ + _cmark_on_oom = handler; +} + +void *cmark_calloc(size_t nmem, size_t size) +{ + void *ptr = calloc(nmem, size); + if (!ptr) + cmark_trigger_oom(); + return ptr; +} + +void *cmark_realloc(void *ptr, size_t size) +{ + void *ptr_new = realloc(ptr, size); + if (!ptr_new) + cmark_trigger_oom(); + return ptr_new; +} + char *cmark_markdown_to_html(const char *text, size_t len, int options) { cmark_node *doc; char *result; |