aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorMarkus Teich <teichm@fs.tum.de>2016-10-09 11:51:12 +0000
committerMarkus Teich <teichm@fs.tum.de>2016-10-09 11:51:12 +0000
commiteb876a69e4d34771a7c614fa1355f4e902bd1abe (patch)
treecba68e08d575ed01b5d7441b4323c617d2e7c45a /src/util
parentc9f2b5e884cac0605dd9f2931c7154fb94baeb84 (diff)
downloadgnunet-eb876a69e4d34771a7c614fa1355f4e902bd1abe.tar.gz
gnunet-eb876a69e4d34771a7c614fa1355f4e902bd1abe.zip
libgnunetutil: add file, line debug info to multidimensional array allocators
Diffstat (limited to 'src/util')
-rw-r--r--src/util/common_allocation.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index f5b683569..71a2221ee 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -95,14 +95,18 @@ GNUNET_xmalloc_ (size_t size,
95 * @param n size of the first dimension 95 * @param n size of the first dimension
96 * @param m size of the second dimension 96 * @param m size of the second dimension
97 * @param elementSize size of a single element in bytes 97 * @param elementSize size of a single element in bytes
98 * @param filename where is this call being made (for debugging)
99 * @param linenumber line where this call is being made (for debugging)
98 * @return allocated memory, never NULL 100 * @return allocated memory, never NULL
99 */ 101 */
100void ** 102void **
101GNUNET_xnew_array_2d_ (size_t n, size_t m, size_t elementSize) 103GNUNET_xnew_array_2d_ (size_t n, size_t m, size_t elementSize,
104 const char *filename, int linenumber)
102{ 105{
103 /* use char pointer internally to avoid void pointer arithmetic warnings */ 106 /* use char pointer internally to avoid void pointer arithmetic warnings */
104 char **ret = GNUNET_malloc (n * sizeof (void *) + /* 1. dim header */ 107 char **ret = GNUNET_xmalloc_ (n * sizeof (void *) + /* 1. dim header */
105 n * m * elementSize); /* element data */ 108 n * m * elementSize, /* element data */
109 filename, linenumber);
106 110
107 for (size_t i = 0; i < n; i++) 111 for (size_t i = 0; i < n; i++)
108 ret[i] = (char *)ret + /* base address */ 112 ret[i] = (char *)ret + /* base address */
@@ -123,15 +127,19 @@ GNUNET_xnew_array_2d_ (size_t n, size_t m, size_t elementSize)
123 * @param m size of the second dimension 127 * @param m size of the second dimension
124 * @param o size of the third dimension 128 * @param o size of the third dimension
125 * @param elementSize size of a single element in bytes 129 * @param elementSize size of a single element in bytes
130 * @param filename where is this call being made (for debugging)
131 * @param linenumber line where this call is being made (for debugging)
126 * @return allocated memory, never NULL 132 * @return allocated memory, never NULL
127 */ 133 */
128void *** 134void ***
129GNUNET_xnew_array_3d_ (size_t n, size_t m, size_t o, size_t elementSize) 135GNUNET_xnew_array_3d_ (size_t n, size_t m, size_t o, size_t elementSize,
136 const char *filename, int linenumber)
130{ 137{
131 /* use char pointer internally to avoid void pointer arithmetic warnings */ 138 /* use char pointer internally to avoid void pointer arithmetic warnings */
132 char ***ret = GNUNET_malloc (n * sizeof (void **) + /* 1. dim header */ 139 char ***ret = GNUNET_xmalloc_ (n * sizeof (void **) + /* 1. dim header */
133 n * m * sizeof (void *) + /* 2. dim header */ 140 n * m * sizeof (void *) + /* 2. dim header */
134 n * m * o * elementSize); /* element data */ 141 n * m * o * elementSize, /* element data */
142 filename, linenumber);
135 143
136 for (size_t i = 0; i < n; i++) 144 for (size_t i = 0; i < n; i++)
137 { 145 {