CMR  1.3.0
Classes | Macros | Functions
env_internal.h File Reference
#include <stdio.h>
#include <stdbool.h>
#include <stdarg.h>
#include <cmr/env.h>

Go to the source code of this file.

Classes

struct  CMR_STACK
 
struct  CMR_ENVIRONMENT
 

Macros

#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...
 

Functions

static void CMRdbgMsg (int indent, const char *format,...)
 
CMR_EXPORT CMR_ERROR _CMRallocStack (CMR *cmr, void **ptr, size_t size)
 Carries out the allocation for CMRallocStack. More...
 
CMR_EXPORT CMR_ERROR _CMRfreeStack (CMR *cmr, void **ptr)
 Carries out the deallocation for CMRfreeStack. More...
 
void CMRassertStackConsistency (CMR *cmr)
 Checks stack protection fields for corruption. More...
 
void CMRraiseErrorMessage (CMR *cmr, const char *format,...)
 
size_t CMRgetStackUsage (CMR *cmr)
 
char * CMRconsistencyMessage (const char *format,...)
 

Macro Definition Documentation

◆ 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))

Frees a stack memory chunk allocated with CMRallocStack.

◆ CMRfreeStackArray

#define CMRfreeStackArray (   cmr,
  ptr 
)     _CMRfreeStack(cmr, (void**) ptr)

Frees memory of an array of blocks on the stack.

Function Documentation

◆ _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
cmrCMR environment.
ptrPointer where the space shall be allocated.
sizeSpace 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
cmrCMR environment.
ptrPointer of space to be freed.

◆ CMRassertStackConsistency()

void CMRassertStackConsistency ( CMR cmr)

Checks stack protection fields for corruption.

Useful for debugging memory errors.

Parameters
cmrCMR environment.

◆ CMRconsistencyMessage()

char* CMRconsistencyMessage ( const char *  format,
  ... 
)

◆ CMRdbgMsg()

static void CMRdbgMsg ( int  indent,
const char *  format,
  ... 
)
inlinestatic

◆ CMRgetStackUsage()

size_t CMRgetStackUsage ( CMR cmr)
Parameters
cmrCMR environment.

◆ CMRraiseErrorMessage()

void CMRraiseErrorMessage ( CMR cmr,
const char *  format,
  ... 
)
Parameters
cmrCMR environment.
...Variadic arguments in printf-style.