7#ifndef ELLIPSIS_MALLOC_H
8#define ELLIPSIS_MALLOC_H 1
20#define STRINGIFY(...) STRINGIFY_(__VA_ARGS__)
21#define STRINGIFY_(...) #__VA_ARGS__
23#define ELLIPSIS_CONTRACT_VIOLATION(COUNT, VERB, CTYPE, CSTR, ...) \
25 static char const contract_format_ ## COUNT[] = \
26 __FILE__ ":" STRINGIFY(__LINE__) ": violation of " CTYPE " `" CSTR "`" __VA_OPT__(", ") __VA_ARGS__ "\n";\
28 ? fputs(contract_format_ ## COUNT, stderr) \
32#define ELLIPSIS_CONTRACT_IMPL(COUNT, COND, ACTION, VERB, CSTR, CTYPE, ...) \
35 : (ELLIPSIS_CONTRACT_VIOLATION(COUNT, VERB, CTYPE, CSTR __VA_OPT__(,) __VA_ARGS__) \
40#define ELLIPSIS_TO_VOIDS(...) ((void*)((uintptr_t)((__VA_ARGS__)-(__VA_ARGS__))))
42#define ELLIPSIS_TEST_ICE(...) (false ? ELLIPSIS_TO_VOIDS(__VA_ARGS__) : (ellipsis‿contracts‿is_ice*)nullptr)
44#define ELLIPSIS_CONTRACT_ICE_OR_TRUE(...) \
46 ELLIPSIS_TEST_ICE(__VA_ARGS__), \
47 ellipsis‿contracts‿is_ice*: (__VA_ARGS__), \
50#define ELLIPSIS_CONTRACT_CHECK_STATIC(CTYPE, COND, CSTR, ...) \
52 static_assert(ELLIPSIS_CONTRACT_ICE_OR_TRUE(COND), \
53 "compile time violation of " CTYPE " " CSTR \
54 __VA_OPT__(", ") __VA_ARGS__ );\
57#define ELLIPSIS_CONTRACT(COUNT, COND, ACTION, VERB, CSTR, CTYPE, ...) \
61 ELLIPSIS_TEST_ICE(COND), \
62 ellipsis‿contracts‿is_ice*: ELLIPSIS_CONTRACT_CHECK_STATIC(CTYPE, COND, CSTR __VA_OPT__(,) __VA_ARGS__), \
63 default: ELLIPSIS_CONTRACT_IMPL(COUNT, COND, ACTION, VERB, CSTR, CTYPE __VA_OPT__(,) __VA_ARGS__));\
71 ELLIPSIS_CONTRACT(1, __LOC_ID_0_1, abort,
true,
"__LOC(0, 1)",
"assertion",
"request to allocate empty storage instance");
72 void* __LOC_ID_1_1 = malloc(__LOC_ID_0_1);
73 ELLIPSIS_CONTRACT(2, __LOC_ID_1_1, abort,
true,
"__LOC()",
"assertion",
"unable to allocate storage instance, malloc failed");
79 ELLIPSIS_CONTRACT(3, __LOC_ID_0_2, abort,
true,
"__LOC(0, 1)",
"assertion",
"request to duplicate non-existing string");
80 char* __LOC_ID_1_2 = strdup(__LOC_ID_0_2);
81 ELLIPSIS_CONTRACT(4, __LOC_ID_1_2, abort,
true,
"__LOC()",
"assertion",
"unable to allocate storage instance, strdup failed");
87 ELLIPSIS_CONTRACT(5, __LOC_ID_0_4, abort,
true,
"__LOC(0, 1)",
"assertion",
"request to re-allocate empty storage instance");
88 void* __LOC_ID_1_3 = realloc(__LOC_ID_0_3, __LOC_ID_0_4);
89 ELLIPSIS_CONTRACT(6, __LOC_ID_1_3, abort,
true,
"__LOC()",
"assertion",
"unable to re-allocate storage instance, realloc failed");
struct ellipsis‿contracts‿is_ice ellipsis‿contracts‿is_ice
Definition ellipsis-expression.c:24
ellipsis‿realloc ellipsis‿realloc
Definition ellipsis-malloc.c:12
ellipsis‿malloc ellipsis‿malloc
Definition ellipsis-malloc.c:10
ellipsis‿strdup ellipsis‿strdup
Definition ellipsis-malloc.c:11
thread_local bool volatile ellipsis‿contracts‿verbose‿dynamic
#define ELLIPSIS_CONTRACT(COUNT, COND, ACTION, VERB, CSTR, CTYPE,...)
Definition ellipsis-malloc.h:57
thread_local bool volatile ellipsis‿contracts‿proceed‿dynamic
thread_local bool volatile ellipsis‿contracts‿ignore‿dynamic