#include <stdio.h>
#include <stdbool.h>
#include <stdarg.h>
#include <cmr/env.h>
Go to the source code of this file.
|
#define | CMRallocStack(cmr, ptr) _CMRallocStack(cmr, (void**) ptr, sizeof(**ptr)) |
| Allocates statck memory for *ptr . More...
|
|
#define | CMRfreeStack(cmr, ptr) _CMRfreeStack(cmr, (void**) ptr, sizeof(**ptr)) |
| Frees a stack memory chunk allocated with CMRallocStack. More...
|
|
#define | CMRallocStackArray(cmr, ptr, length) _CMRallocStack(cmr, (void**) ptr, sizeof(**ptr) * (length)) |
| Allocates memory for an array of blocks on the stack. More...
|
|
#define | CMRfreeStackArray(cmr, ptr) _CMRfreeStack(cmr, (void**) ptr) |
| Frees memory of an array of blocks on the stack. More...
|
|
#define | CMRconsistencyAssert(call) |
| Asserts that call reports consistency. Otherwise, the inconsistency explanation is printed and the program terminates. More...
|
|
◆ CMRallocStack
#define CMRallocStack |
( |
|
cmr, |
|
|
|
ptr |
|
) |
| _CMRallocStack(cmr, (void**) ptr, sizeof(**ptr)) |
Allocates statck memory for *ptr
.
Stack memory shall be freed with CMRfreeStack in the reverse order of allocation. The size is determined automatically.
◆ CMRallocStackArray
#define CMRallocStackArray |
( |
|
cmr, |
|
|
|
ptr, |
|
|
|
length |
|
) |
| _CMRallocStack(cmr, (void**) ptr, sizeof(**ptr) * (length)) |
Allocates memory for an array of blocks on the stack.
◆ CMRconsistencyAssert
#define CMRconsistencyAssert |
( |
|
call | ) |
|
Value: do \
{ \
char* __message = call; \
if (__message) \
{ \
fflush(stdout); \
fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, __message); \
fflush(stderr); \
free(__message); \
assert(!"Consistency assertion raised!"); \
} \
} \
while (false);
Asserts that call
reports consistency. Otherwise, the inconsistency explanation is printed and the program terminates.
The following example code checks matrix
(of type CMR_CHRMAT*) for consistency using CMRchrmatConsistency.
CMRconsistencyAssert( CMRchrmatConsistency(matrix) );
◆ CMRfreeStack
#define CMRfreeStack |
( |
|
cmr, |
|
|
|
ptr |
|
) |
| _CMRfreeStack(cmr, (void**) ptr, sizeof(**ptr)) |
◆ CMRfreeStackArray
#define CMRfreeStackArray |
( |
|
cmr, |
|
|
|
ptr |
|
) |
| _CMRfreeStack(cmr, (void**) ptr) |
Frees memory of an array of blocks on the stack.
◆ _CMRallocStack()
CMR_EXPORT CMR_ERROR _CMRallocStack |
( |
CMR * |
cmr, |
|
|
void ** |
ptr, |
|
|
size_t |
size |
|
) |
| |
Carries out the allocation for CMRallocStack.
- Note
- Use CMRallocStack to allocate stack memory.
- Parameters
-
cmr | CMR environment. |
ptr | Pointer where the space shall be allocated. |
size | Space to allocate. |
◆ _CMRfreeStack()
CMR_EXPORT CMR_ERROR _CMRfreeStack |
( |
CMR * |
cmr, |
|
|
void ** |
ptr |
|
) |
| |
Carries out the deallocation for CMRfreeStack.
- Note
- Use CMRfreeStack to free stack memory.
- Parameters
-
cmr | CMR environment. |
ptr | Pointer of space to be freed. |
◆ CMRassertStackConsistency()
void CMRassertStackConsistency |
( |
CMR * |
cmr | ) |
|
Checks stack protection fields for corruption.
Useful for debugging memory errors.
- Parameters
-
◆ CMRconsistencyMessage()
char* CMRconsistencyMessage |
( |
const char * |
format, |
|
|
|
... |
|
) |
| |
◆ CMRdbgMsg()
static void CMRdbgMsg |
( |
int |
indent, |
|
|
const char * |
format, |
|
|
|
... |
|
) |
| |
|
inlinestatic |
◆ CMRgetStackUsage()
size_t CMRgetStackUsage |
( |
CMR * |
cmr | ) |
|
◆ CMRraiseErrorMessage()
void CMRraiseErrorMessage |
( |
CMR * |
cmr, |
|
|
const char * |
format, |
|
|
|
... |
|
) |
| |
- Parameters
-
cmr | CMR environment. |
... | Variadic arguments in printf-style. |