CMR  1.3.0
Loading...
Searching...
No Matches
env_internal.h
Go to the documentation of this file.
1#ifndef CMR_ENV_INTERNAL_H
2#define CMR_ENV_INTERNAL_H
3
4#include <stdio.h>
5#include <stdbool.h>
6#include <stdarg.h>
7
8#include <cmr/env.h>
9
10#if defined(CMR_DEBUG)
11
12static inline
13void CMRdbgMsg(int indent, const char* format, ...)
14{
15 va_list args;
16
17 for (int i = 0; i < indent; ++i)
18 putchar(' ');
19 va_start(args, format);
20 vprintf(format, args);
21 va_end(args);
22 fflush(stdout);
23}
24
25#else /* !CMR_DEBUG */
26
27static inline
28void CMRdbgMsg(int indent, const char* format, ...)
29{
30 CMR_UNUSED(indent);
31 CMR_UNUSED(format);
32}
33/*#define CMRdbgMsg(...) */
34
35#endif /* CMR_DEBUG */
36
37
38typedef struct
39{
40 char* memory;
41 size_t top;
42} CMR_STACK;
43
58
59#include <cmr/env.h>
60
68#define CMRallocStack(cmr, ptr) \
69 _CMRallocStack(cmr, (void**) ptr, sizeof(**ptr))
70
77CMR_EXPORT
79 CMR* cmr,
80 void** ptr,
81 size_t size
82);
83
88#define CMRfreeStack(cmr, ptr) \
89 _CMRfreeStack(cmr, (void**) ptr, sizeof(**ptr))
90
97CMR_EXPORT
99 CMR* cmr,
100 void** ptr
101);
102
107#define CMRallocStackArray(cmr, ptr, length) \
108 _CMRallocStack(cmr, (void**) ptr, sizeof(**ptr) * (length))
109
114#define CMRfreeStackArray(cmr, ptr) \
115 _CMRfreeStack(cmr, (void**) ptr)
116
117#if !defined(NDEBUG)
118
126 CMR* cmr
127);
128
129#else
130
131static inline
133 CMR* cmr
134)
135{
136 CMR_UNUSED(cmr);
137 assert(cmr);
138}
139
140#endif /* !NDEBUG */
141
143 CMR* cmr,
144 const char* format,
145 ...
146);
147
148size_t CMRgetStackUsage(
149 CMR* cmr
150);
151
152char* CMRconsistencyMessage(const char* format, ...);
153
154#if defined(CMR_DEBUG)
155
166#define CMRdbgConsistencyAssert( call ) \
167 do \
168 { \
169 char* __message = call; \
170 if (__message) \
171 { \
172 fflush(stdout); \
173 fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, __message); \
174 fflush(stderr); \
175 free(__message); \
176 assert(!"Consistency assertion raised!"); \
177 } \
178 } \
179 while (false);
180
181#else
182
183#define CMRdbgConsistencyAssert( call )
184
185#endif
186
187#endif /* CMR_ENV_INTERNAL_H */
Basic functionality of the software library.
#define CMR_UNUSED(x)
Definition env.h:24
CMR_ERROR
Type for return codes of library functions.
Definition env.h:32
size_t CMRgetStackUsage(CMR *cmr)
Definition env.c:366
void CMRassertStackConsistency(CMR *cmr)
Checks stack protection fields for corruption.
Definition env.c:339
CMR_EXPORT CMR_ERROR _CMRfreeStack(CMR *cmr, void **ptr)
Carries out the deallocation for CMRfreeStack.
Definition env.c:284
char * CMRconsistencyMessage(const char *format,...)
Definition env.c:411
CMR_EXPORT CMR_ERROR _CMRallocStack(CMR *cmr, void **ptr, size_t size)
Carries out the allocation for CMRallocStack.
Definition env.c:209
static void CMRdbgMsg(int indent, const char *format,...)
Definition env_internal.h:28
void CMRraiseErrorMessage(CMR *cmr, const char *format,...)
Definition env.c:378
Definition env_internal.h:45
size_t numStacks
Number of allocated stacks in stack array.
Definition env_internal.h:53
size_t memStacks
Memory for stack array.
Definition env_internal.h:54
CMR_STACK * stacks
Array of stacks.
Definition env_internal.h:56
int numThreads
Number of threads to use.
Definition env_internal.h:51
char * errorMessage
Error message.
Definition env_internal.h:46
int verbosity
Verbosity level.
Definition env_internal.h:50
bool closeOutput
Whether to close the output stream at the end.
Definition env_internal.h:49
size_t currentStack
Index of last used stack.
Definition env_internal.h:55
FILE * output
Output stream or NULL if silent.
Definition env_internal.h:48
Definition env_internal.h:39
size_t top
First used byte.
Definition env_internal.h:41
char * memory
Raw memory.
Definition env_internal.h:40