![]() |
GNUnet
0.16.x
|
wrapper around malloc/free More...
Go to the source code of this file.
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "util-common-allocation", __VA_ARGS__) |
#define | LOG_STRERROR(kind, syscall) GNUNET_log_from_strerror (kind, "util-common-allocation", syscall) |
#define | INT_MAX 0x7FFFFFFF |
#define | BAADFOOD_STR "\x0D\xF0\xAD\xBA" |
#define | BAADFOOD_STR "\xBA\xAD\xF0\x0D" |
Functions | |
void * | GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber) |
Allocate memory. More... | |
void ** | GNUNET_xnew_array_2d_ (size_t n, size_t m, size_t elementSize, const char *filename, int linenumber) |
Allocate memory for a two dimensional array in one block and set up pointers. More... | |
void *** | GNUNET_xnew_array_3d_ (size_t n, size_t m, size_t o, size_t elementSize, const char *filename, int linenumber) |
Allocate memory for a three dimensional array in one block and set up pointers. More... | |
void * | GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, int linenumber) |
Allocate and initialize memory. More... | |
void * | GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber) |
Wrapper around malloc(). More... | |
void * | GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber) |
Reallocate memory. More... | |
void | GNUNET_xfree_ (void *ptr, const char *filename, int linenumber) |
Free memory. More... | |
char * | GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber) |
Dup a string (same semantics as strdup). More... | |
static size_t | strnlen (const char *s, size_t n) |
char * | GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, int linenumber) |
Dup partially a string (same semantics as strndup). More... | |
void | GNUNET_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount, unsigned int newCount, const char *filename, int linenumber) |
Grow an array. More... | |
int | GNUNET_asprintf (char **buf, const char *format,...) |
Like asprintf(), just portable. More... | |
int | GNUNET_snprintf (char *buf, size_t size, const char *format,...) |
Like snprintf(), just aborts if the buffer is of insufficient size. More... | |
struct GNUNET_MessageHeader * | GNUNET_copy_message (const struct GNUNET_MessageHeader *msg) |
Create a copy of the given message. More... | |
enum GNUNET_GenericReturnValue | GNUNET_is_zero_ (const void *a, size_t n) |
Check that memory in a is all zeros. More... | |
wrapper around malloc/free
Definition in file common_allocation.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "util-common-allocation", __VA_ARGS__) |
Definition at line 35 of file common_allocation.c.
#define LOG_STRERROR | ( | kind, | |
syscall | |||
) | GNUNET_log_from_strerror (kind, "util-common-allocation", syscall) |
Definition at line 38 of file common_allocation.c.
#define INT_MAX 0x7FFFFFFF |
Definition at line 42 of file common_allocation.c.
#define BAADFOOD_STR "\x0D\xF0\xAD\xBA" |
Definition at line 273 of file common_allocation.c.
#define BAADFOOD_STR "\xBA\xAD\xF0\x0D" |
Definition at line 273 of file common_allocation.c.
void* GNUNET_xmalloc_ | ( | size_t | size, |
const char * | filename, | ||
int | linenumber | ||
) |
Allocate memory.
Checks the return value, aborts if no more memory is available.
size | how many bytes of memory to allocate, do NOT use this function (or GNUNET_malloc()) to allocate more than several MB of memory, if you are possibly needing a very large chunk use GNUNET_xmalloc_unchecked_() instead. |
filename | where in the code was the call to GNUNET_malloc() |
linenumber | where in the code was the call to GNUNET_malloc() |
Definition at line 59 of file common_allocation.c.
References filename, GNUNET_assert, GNUNET_assert_at, GNUNET_ERROR_TYPE_ERROR, GNUNET_MAX_MALLOC_CHECKED, GNUNET_xmalloc_unchecked_(), LOG_STRERROR, ret, and size.
Referenced by GNUNET_xgrow_(), GNUNET_xnew_array_2d_(), GNUNET_xnew_array_3d_(), GNUNET_xstrdup_(), and GNUNET_xstrndup_().
void** GNUNET_xnew_array_2d_ | ( | size_t | n, |
size_t | m, | ||
size_t | elementSize, | ||
const char * | filename, | ||
int | linenumber | ||
) |
Allocate memory for a two dimensional array in one block and set up pointers.
Aborts if no more memory is available. Don't use GNUNET_xnew_array_2d_ directly. Use the GNUNET_new_array_2d macro. The memory of the elements will be zero'ed out.
n | size of the first dimension |
m | size of the second dimension |
elementSize | size of a single element in bytes |
filename | where is this call being made (for debugging) |
linenumber | line where this call is being made (for debugging) |
Definition at line 91 of file common_allocation.c.
References filename, GNUNET_xmalloc_(), m, and ret.
void*** GNUNET_xnew_array_3d_ | ( | size_t | n, |
size_t | m, | ||
size_t | o, | ||
size_t | elementSize, | ||
const char * | filename, | ||
int | linenumber | ||
) |
Allocate memory for a three dimensional array in one block and set up pointers.
Aborts if no more memory is available. Don't use GNUNET_xnew_array_3d_ directly. Use the GNUNET_new_array_3d macro. The memory of the elements will be zero'ed out.
n | size of the first dimension |
m | size of the second dimension |
o | size of the third dimension |
elementSize | size of a single element in bytes |
filename | where is this call being made (for debugging) |
linenumber | line where this call is being made (for debugging) |
Definition at line 127 of file common_allocation.c.
References filename, GNUNET_xmalloc_(), m, and ret.
void* GNUNET_xmemdup_ | ( | const void * | buf, |
size_t | size, | ||
const char * | filename, | ||
int | linenumber | ||
) |
Allocate and initialize memory.
Checks the return value, aborts if no more memory is available. Don't use GNUNET_xmemdup_() directly. Use the GNUNET_memdup() macro.
buf | buffer to initialize from (must contain size bytes) |
size | number of bytes to allocate |
filename | where is this call being made (for debugging) |
linenumber | line where this call is being made (for debugging) |
Definition at line 170 of file common_allocation.c.
References buf, filename, GNUNET_assert, GNUNET_assert_at, GNUNET_ERROR_TYPE_ERROR, GNUNET_MAX_MALLOC_CHECKED, GNUNET_memcpy, INT_MAX, LOG_STRERROR, ret, and size.
void* GNUNET_xmalloc_unchecked_ | ( | size_t | size, |
const char * | filename, | ||
int | linenumber | ||
) |
Wrapper around malloc().
Allocate memory.
Allocates size bytes of memory. The memory will be zero'ed out.
size | the number of bytes to allocate |
filename | where in the code was the call to GNUNET_malloc_unchecked() |
linenumber | where in the code was the call to GNUNET_malloc_unchecked() |
Definition at line 202 of file common_allocation.c.
References filename, result, and size.
Referenced by GNUNET_xmalloc_().
void* GNUNET_xrealloc_ | ( | void * | ptr, |
size_t | n, | ||
const char * | filename, | ||
int | linenumber | ||
) |
Reallocate memory.
Checks the return value, aborts if no more memory is available. The content of the intersection of the new and old size will be unchanged.
ptr | the pointer to reallocate |
n | how many bytes of memory to allocate |
filename | where in the code was the call to GNUNET_realloc() |
linenumber | where in the code was the call to GNUNET_realloc() |
Definition at line 230 of file common_allocation.c.
References filename, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_memcpy, GNUNET_MIN, GNUNET_ntohll(), and LOG_STRERROR.
void GNUNET_xfree_ | ( | void * | ptr, |
const char * | filename, | ||
int | linenumber | ||
) |
Free memory.
Merely a wrapper for the case that we want to keep track of allocations.
ptr | the pointer to free |
filename | where in the code was the call to GNUNET_free() |
linenumber | where in the code was the call to GNUNET_free() |
Definition at line 294 of file common_allocation.c.
References GNUNET_memcpy, and GNUNET_ntohll().
Referenced by GNUNET_xgrow_().
char* GNUNET_xstrdup_ | ( | const char * | str, |
const char * | filename, | ||
int | linenumber | ||
) |
Dup a string (same semantics as strdup).
Dup a string.
str | the string to dup |
filename | where in the code was the call to GNUNET_strdup() |
linenumber | where in the code was the call to GNUNET_strdup() |
strdup(@a str)
Definition at line 326 of file common_allocation.c.
References filename, GNUNET_assert_at, GNUNET_memcpy, GNUNET_xmalloc_(), and res.
|
static |
Definition at line 341 of file common_allocation.c.
References e.
Referenced by convert_with_table(), and GNUNET_xstrndup_().
char* GNUNET_xstrndup_ | ( | const char * | str, |
size_t | len, | ||
const char * | filename, | ||
int | linenumber | ||
) |
Dup partially a string (same semantics as strndup).
Dup partially a string.
str | the string to dup |
len | the length of the string to dup |
filename | where in the code was the call to GNUNET_strndup() |
linenumber | where in the code was the call to GNUNET_strndup() |
strndup(@a str,@a len)
Definition at line 365 of file common_allocation.c.
References filename, GNUNET_assert_at, GNUNET_memcpy, GNUNET_strdup, GNUNET_xmalloc_(), len, res, and strnlen().
void GNUNET_xgrow_ | ( | void ** | old, |
size_t | elementSize, | ||
unsigned int * | oldCount, | ||
unsigned int | newCount, | ||
const char * | filename, | ||
int | linenumber | ||
) |
Grow an array.
Grow an array, the new elements are zeroed out.
Grows old by (*oldCount-newCount)*elementSize bytes and sets *oldCount to newCount.
old | address of the pointer to the array *old may be NULL |
elementSize | the size of the elements of the array |
oldCount | address of the number of elements in the *old array |
newCount | number of elements in the new array, may be 0 |
filename | where in the code was the call to GNUNET_array_grow() |
linenumber | where in the code was the call to GNUNET_array_grow() |
Definition at line 396 of file common_allocation.c.
References filename, GNUNET_assert_at, GNUNET_memcpy, GNUNET_MIN, GNUNET_xfree_(), GNUNET_xmalloc_(), INT_MAX, and size.
int GNUNET_asprintf | ( | char ** | buf, |
const char * | format, | ||
... | |||
) |
Like asprintf(), just portable.
buf | set to a buffer of sufficient size (allocated, caller must free) |
format | format string (see printf(), fprintf(), etc.) |
... | data for format string |
*@a buf
, excluding 0-termination Definition at line 439 of file common_allocation.c.
References consensus-simulation::args, buf, GNUNET_assert, GNUNET_malloc, and ret.
int GNUNET_snprintf | ( | char * | buf, |
size_t | size, | ||
const char * | format, | ||
... | |||
) |
Like snprintf(), just aborts if the buffer is of insufficient size.
buf | pointer to buffer that is written to |
size | number of bytes in buf |
format | format strings |
... | data for format string |
Definition at line 466 of file common_allocation.c.
References consensus-simulation::args, buf, GNUNET_assert, ret, and size.
enum GNUNET_GenericReturnValue GNUNET_is_zero_ | ( | const void * | a, |
size_t | n | ||
) |
Check that memory in a is all zeros.
a must be a pointer.
a | pointer to n bytes which should be tested for the entire memory being zero'ed out. |
n | number of bytes in to be tested |
Definition at line 486 of file common_allocation.c.