Mescal
Loading...
Searching...
No Matches
alloc.h
Go to the documentation of this file.
1
#ifndef ALLOC_H_
2
#define ALLOC_H_
3
23
24
#include "
error.h
"
25
#include <stdarg.h>
26
#include <stdio.h>
27
#include <stdlib.h>
28
52
53
#define MALLOC(p, num_objects) \
54
do { \
55
DEBUG("Allocating %lu objects.", (unsigned long)(num_objects)); \
56
void *tmp = malloc(sizeof *(p) * (num_objects)); \
57
if (!tmp) \
58
FATAL("Malloc error."); \
59
(p) = tmp; \
60
} while (0)
61
85
#define CALLOC(p, num_objects) \
86
do { \
87
DEBUG("Callocating %lu objects.", (unsigned long)(num_objects)); \
88
void *tmp = calloc((num_objects), sizeof *(p)); \
89
if (!tmp) \
90
FATAL("Calloc error."); \
91
(p) = tmp; \
92
} while (0)
93
122
#define REALLOC(p, num_objects) \
123
do { \
124
DEBUG("Reallocating %lu objects.", (unsigned long)(num_objects)); \
125
void *tmp = realloc((p), sizeof *(p) * (num_objects)); \
126
if (!tmp) { \
127
FATAL("Realloc error."); \
128
} \
129
(p) = tmp; \
130
} while (0)
131
139
void
check_null
(
const
char
*function,
char
*file,
int
line,
int
n, ...);
140
164
165
#define CHECK_NULL(n, ...) \
166
check_null(__func__, __FILE__, __LINE__, n __VA_OPT__(, ) __VA_ARGS__)
167
190
191
void
multiple_free
(
void
*p, ...);
192
193
#endif
// ALLOC_H_
check_null
void check_null(const char *function, char *file, int line, int n,...)
Do not use this function directly; instead, use the macro CHECK_NULL(), which includes the error's lo...
Definition
alloc.c:18
multiple_free
void multiple_free(void *p,...)
Function to free memory using the free() function.
Definition
alloc.c:8
error.h
Macros for displaying error messages.
alloc.h
Generated by
1.13.2