You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kg...@apache.org on 2020/06/10 14:30:30 UTC

[qpid-dispatch] branch master updated: DISPATCH-1685: add heap allocation API that aborts on failure

This is an automated email from the ASF dual-hosted git repository.

kgiusti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git


The following commit(s) were added to refs/heads/master by this push:
     new 14a6e0d  DISPATCH-1685: add heap allocation API that aborts on failure
14a6e0d is described below

commit 14a6e0debc60408e259c2f3772d6a1fe92508f37
Author: Kenneth Giusti <kg...@apache.org>
AuthorDate: Tue Jun 9 10:02:27 2020 -0400

    DISPATCH-1685: add heap allocation API that aborts on failure
    
    This closes #757
---
 include/qpid/dispatch/ctools.h | 51 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/include/qpid/dispatch/ctools.h b/include/qpid/dispatch/ctools.h
index e883c03..08fb471 100644
--- a/include/qpid/dispatch/ctools.h
+++ b/include/qpid/dispatch/ctools.h
@@ -26,6 +26,8 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <memory.h>
+#include <string.h>
+#include <stdio.h>
 
 #define CT_ASSERT(exp) { assert(exp); }
 
@@ -217,4 +219,53 @@ do {                                    \
 #define MIN(a,b) (((a)<(b))?(a):(b))
 #define MAX(a,b) (((a)>(b))?(a):(b))
 
+//
+// Heap allocation with abort() on failure
+//
+
+static inline void *qd_malloc(size_t size)
+{
+    assert(size);
+    void *ptr = malloc(size);
+    if (!ptr) {
+        perror("qd_malloc");
+        abort();
+    }
+    return ptr;
+}
+
+static inline void *qd_calloc(size_t nmemb, size_t size)
+{
+    assert(nmemb && size);
+    void *ptr = calloc(nmemb, size);
+    if (!ptr) {
+        perror("qd_calloc");
+        abort();
+    }
+    return ptr;
+}
+
+static inline void *qd_realloc(void *buf, size_t size)
+{
+    assert(buf && size);
+    void *ptr = realloc(buf, size);
+    if (!ptr) {
+        perror("qd_realloc");
+        abort();
+    }
+    return ptr;
+}
+
+static inline char *qd_strdup(const char *s)
+{
+    assert(s);
+    char *ptr = strdup(s);
+    if (!ptr) {
+        perror("qd_strdup");
+        abort();
+    }
+    return ptr;
+}
+
+
 #endif


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org