diff options
author | Markus Teich <teichm@fs.tum.de> | 2016-10-09 11:51:12 +0000 |
---|---|---|
committer | Markus Teich <teichm@fs.tum.de> | 2016-10-09 11:51:12 +0000 |
commit | eb876a69e4d34771a7c614fa1355f4e902bd1abe (patch) | |
tree | cba68e08d575ed01b5d7441b4323c617d2e7c45a | |
parent | c9f2b5e884cac0605dd9f2931c7154fb94baeb84 (diff) |
libgnunetutil: add file, line debug info to multidimensional array allocators
-rw-r--r-- | src/include/gnunet_common.h | 14 | ||||
-rw-r--r-- | src/util/common_allocation.c | 22 |
2 files changed, 25 insertions, 11 deletions
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index dfe8effcd5..dcd0c60568 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h @@ -807,7 +807,7 @@ GNUNET_ntoh_double (double d); * @param m size of the second dimension * @param type name of the struct or union, i.e. pass 'struct Foo'. */ -#define GNUNET_new_array_2d(n, m, type) (type **) GNUNET_xnew_array_2d_ (n, m, sizeof (type)) +#define GNUNET_new_array_2d(n, m, type) (type **) GNUNET_xnew_array_2d_ (n, m, sizeof (type), __FILE__, __LINE__) /** * @ingroup memory @@ -819,7 +819,7 @@ GNUNET_ntoh_double (double d); * @param o size of the third dimension * @param type name of the struct or union, i.e. pass 'struct Foo'. */ -#define GNUNET_new_array_3d(n, m, o, type) (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof (type)) +#define GNUNET_new_array_3d(n, m, o, type) (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof (type), __FILE__, __LINE__) /** * @ingroup memory @@ -1001,10 +1001,13 @@ GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber); * @param n size of the first dimension * @param m size of the second dimension * @param elementSize size of a single element in bytes + * @param filename where is this call being made (for debugging) + * @param linenumber line where this call is being made (for debugging) * @return allocated memory, never NULL */ void ** -GNUNET_xnew_array_2d_ (size_t n, size_t m, size_t elementSize); +GNUNET_xnew_array_2d_ (size_t n, size_t m, size_t elementSize, + const char *filename, int linenumber); /** @@ -1018,10 +1021,13 @@ GNUNET_xnew_array_2d_ (size_t n, size_t m, size_t elementSize); * @param m size of the second dimension * @param o size of the third dimension * @param elementSize size of a single element in bytes + * @param filename where is this call being made (for debugging) + * @param linenumber line where this call is being made (for debugging) * @return allocated memory, never NULL */ void *** -GNUNET_xnew_array_3d_ (size_t n, size_t m, size_t o, size_t elementSize); +GNUNET_xnew_array_3d_ (size_t n, size_t m, size_t o, size_t elementSize, + const char *filename, int linenumber); /** diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c index f5b6835691..71a2221eec 100644 --- a/src/util/common_allocation.c +++ b/src/util/common_allocation.c @@ -95,14 +95,18 @@ GNUNET_xmalloc_ (size_t size, * @param n size of the first dimension * @param m size of the second dimension * @param elementSize size of a single element in bytes + * @param filename where is this call being made (for debugging) + * @param linenumber line where this call is being made (for debugging) * @return allocated memory, never NULL */ void ** -GNUNET_xnew_array_2d_ (size_t n, size_t m, size_t elementSize) +GNUNET_xnew_array_2d_ (size_t n, size_t m, size_t elementSize, + const char *filename, int linenumber) { /* use char pointer internally to avoid void pointer arithmetic warnings */ - char **ret = GNUNET_malloc (n * sizeof (void *) + /* 1. dim header */ - n * m * elementSize); /* element data */ + char **ret = GNUNET_xmalloc_ (n * sizeof (void *) + /* 1. dim header */ + n * m * elementSize, /* element data */ + filename, linenumber); for (size_t i = 0; i < n; i++) ret[i] = (char *)ret + /* base address */ @@ -123,15 +127,19 @@ GNUNET_xnew_array_2d_ (size_t n, size_t m, size_t elementSize) * @param m size of the second dimension * @param o size of the third dimension * @param elementSize size of a single element in bytes + * @param filename where is this call being made (for debugging) + * @param linenumber line where this call is being made (for debugging) * @return allocated memory, never NULL */ void *** -GNUNET_xnew_array_3d_ (size_t n, size_t m, size_t o, size_t elementSize) +GNUNET_xnew_array_3d_ (size_t n, size_t m, size_t o, size_t elementSize, + const char *filename, int linenumber) { /* use char pointer internally to avoid void pointer arithmetic warnings */ - char ***ret = GNUNET_malloc (n * sizeof (void **) + /* 1. dim header */ - n * m * sizeof (void *) + /* 2. dim header */ - n * m * o * elementSize); /* element data */ + char ***ret = GNUNET_xmalloc_ (n * sizeof (void **) + /* 1. dim header */ + n * m * sizeof (void *) + /* 2. dim header */ + n * m * o * elementSize, /* element data */ + filename, linenumber); for (size_t i = 0; i < n; i++) { |