aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiovanni Conte <gconte@cisco.com>2019-01-17 17:47:20 +0100
committerGiovanni Conte <gconte@cisco.com>2019-01-17 17:47:20 +0100
commit907a3e03d31d23d4981aa00e12f0416e4d69752a (patch)
tree44c0ed9af6bf0621fd7cbe009b6c8cd3a266b7d7
parent33b53c7f5cef4cf19770a38baa4b627f234322cf (diff)
parc assertions update
Change-Id: I39c8f9d1fa7a595e9833b838c476a0062c773521 Signed-off-by: Giovanni Conte <gconte@cisco.com>
-rw-r--r--libparc/parc/assert/parc_Assert.h212
1 files changed, 160 insertions, 52 deletions
diff --git a/libparc/parc/assert/parc_Assert.h b/libparc/parc/assert/parc_Assert.h
index 5718493..46e3e2f 100644
--- a/libparc/parc/assert/parc_Assert.h
+++ b/libparc/parc/assert/parc_Assert.h
@@ -13,71 +13,179 @@
* limitations under the License.
*/
+#include <assert.h>
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
-#include <errno.h>
#include <string.h>
-#include <assert.h>
-
#ifdef NDEBUG
#define parcClean_errno() (errno == 0 ? "None" : strerror(errno))
-#define parcLog_PrintError(M, ...) fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " M "\nExit (Failure)\n", __FILE__, __LINE__, parcClean_errno(), ##__VA_ARGS__);
+#define parcLog_PrintError(M, ...) \
+ fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " M "\nExit (Failure)\n", \
+ __FILE__, __LINE__, parcClean_errno(), ##__VA_ARGS__);
-#define parcAssertTrue(A, M, ...) if(!(A)) {assert(A); }
-#define parcAssertFalse(A, M, ...) if((A)) {assert(!(A)); }
-#define parcAssertNotNull(A, M, ...) if(A == NULL) {assert(A != NULL); }
-#define parcAssertNull(A, M, ...) if(A != NULL) {assert(A == NULL); }
+#define parcAssertTrue(A, M, ...) \
+ if (!(A)) { \
+ assert(A); \
+ }
+#define parcAssertFalse(A, M, ...) \
+ if ((A)) { \
+ assert(!(A)); \
+ }
+#define parcAssertNotNull(A, M, ...) \
+ if (A == NULL) { \
+ assert(A != NULL); \
+ }
+#define parcAssertNull(A, M, ...) \
+ if (A != NULL) { \
+ assert(A == NULL); \
+ }
-#define parcTrapIllegalValueIf(A, M, ...) if((A)) {assert(!(A)); }
-#define parcTrapIllegalValue(A, M, ...) {parcLog_PrintError("Illegal value: " M, ##__VA_ARGS__); assert(0); exit(1);}
-#define parcTrapNotImplemented(M, ...) {parcLog_PrintError("Feature not implemented: " M, ##__VA_ARGS__); assert(0); }
-#define parcTrapOutOfBounds(A, M, ...) {parcLog_PrintError("Element out of bounds, %zu :" M, A, ##__VA_ARGS__); assert(0); exit(1);}
-#define parcTrapOutOfBoundsIf(A, M, ...) {assert(!(A)); }
-#define parcTrapOutOfMemory(M, ...) {parcLog_PrintError("Out of memory. " M, ##__VA_ARGS__); assert(0); exit(1);}
-#define parcTrapOutOfMemoryIf(A, M, ...) {assert(!(A)); }
-#define parcTrapUnexpectedState(M, ...) {parcLog_PrintError("Unexpected state. " M, ##__VA_ARGS__); assert(0); exit(1);}
-#define parcTrapUnexpectedStateIf(A, M, ...) {assert(!(A)); }
-#define parcTrapUnrecoverableState(M, ...) {parcLog_PrintError("Unrecoverable State: " M, ##__VA_ARGS__); assert(0); exit(1);}
-#define parcTrapInvalidValueIf(A, M, ...) {assert(!(A)); }
-#define parcTrapCannotObtainLock(M, ...) {parcLog_PrintError("Cannot obtain lock: " M, ##__VA_ARGS__); assert(0); exit(1);}
-#define parcTrapCannotObtainLockIf(A, M, ...) { assert(!(A)); }
-#define parcAssertAligned(address, alignment, ...) {assert( ((alignment & (~alignment + 1)) == alignment) ? (((uintptr_t) address) % alignment) == 0 ? 1 : 0 : 0);}
+#define parcTrapIllegalValueIf(A, M, ...) \
+ if ((A)) { \
+ assert(!(A)); \
+ }
+#define parcTrapIllegalValue(A, M, ...) \
+ { \
+ parcLog_PrintError("Illegal value: " M, ##__VA_ARGS__); \
+ assert(0); \
+ exit(1); \
+ }
+#define parcTrapNotImplemented(M, ...) \
+ { \
+ parcLog_PrintError("Feature not implemented: " M, ##__VA_ARGS__); \
+ assert(0); \
+ }
+#define parcTrapOutOfBounds(A, M, ...) \
+ { \
+ parcLog_PrintError("Element out of bounds, %zu :" M, A, ##__VA_ARGS__); \
+ assert(0); \
+ exit(1); \
+ }
+#define parcTrapOutOfBoundsIf(A, M, ...) \
+ { assert(!(A)); }
+#define parcTrapOutOfMemory(M, ...) \
+ { \
+ parcLog_PrintError("Out of memory. " M, ##__VA_ARGS__); \
+ assert(0); \
+ exit(1); \
+ }
+#define parcTrapOutOfMemoryIf(A, M, ...) \
+ { assert(!(A)); }
+#define parcTrapUnexpectedState(M, ...) \
+ { \
+ parcLog_PrintError("Unexpected state. " M, ##__VA_ARGS__); \
+ assert(0); \
+ exit(1); \
+ }
+#define parcTrapUnexpectedStateIf(A, M, ...) \
+ { assert(!(A)); }
+#define parcTrapUnrecoverableState(M, ...) \
+ { \
+ parcLog_PrintError("Unrecoverable State: " M, ##__VA_ARGS__); \
+ assert(0); \
+ exit(1); \
+ }
+#define parcTrapInvalidValueIf(A, M, ...) \
+ { assert(!(A)); }
+#define parcTrapCannotObtainLock(M, ...) \
+ { \
+ parcLog_PrintError("Cannot obtain lock: " M, ##__VA_ARGS__); \
+ assert(0); \
+ exit(1); \
+ }
+#define parcTrapCannotObtainLockIf(A, M, ...) \
+ { assert(!(A)); }
+#define parcAssertAligned(address, alignment, ...) \
+ { \
+ assert(((alignment & (~alignment + 1)) == alignment) \
+ ? (((uintptr_t)address) % alignment) == 0 ? 1 : 0 \
+ : 0); \
+ }
#else
-#define parcLog_PrintError(M, ...) fprintf(stderr, "[ERROR] " M "\n", ##__VA_ARGS__);
+#define parcLog_PrintError(M, ...) \
+ fprintf(stderr, "[ERROR] " M "\n", ##__VA_ARGS__);
-#define parcAssertTrue(A, M, ...) if(!(A)) { parcLog_PrintError(M, ##__VA_ARGS__); assert(A); }
-#define parcAssertFalse(A, M, ...) if((A)) { parcLog_PrintError(M, ##__VA_ARGS__); assert(!(A)); }
-#define parcAssertNotNull(A, M, ...) if(A == NULL) {parcLog_PrintError(M, ##__VA_ARGS__); assert(A != NULL); }
-#define parcAssertNull(A, M, ...) if(A != NULL) {parcLog_PrintError(M, ##__VA_ARGS__); assert(A == NULL); }
+#define parcAssertTrue(A, M, ...) \
+ if (!(A)) { \
+ parcLog_PrintError(M, ##__VA_ARGS__); \
+ assert(A); \
+ }
+#define parcAssertFalse(A, M, ...) \
+ if ((A)) { \
+ parcLog_PrintError(M, ##__VA_ARGS__); \
+ assert(!(A)); \
+ }
+#define parcAssertNotNull(A, M, ...) \
+ if (A == NULL) { \
+ parcLog_PrintError(M, ##__VA_ARGS__); \
+ assert(A != NULL); \
+ }
+#define parcAssertNull(A, M, ...) \
+ if (A != NULL) { \
+ parcLog_PrintError(M, ##__VA_ARGS__); \
+ assert(A == NULL); \
+ }
-#define parcTrapIllegalValueIf(A, M, ...) if((A)) {parcLog_PrintError("Illegal value: " M, ##__VA_ARGS__); }
-#define parcTrapIllegalValue(A, M, ...) parcLog_PrintError("Illegal value: " M, ##__VA_ARGS__); assert(0);
-#define parcTrapNotImplemented(M, ...) parcLog_PrintError("Feature not implemented: " M, ##__VA_ARGS__); assert(0);
-#define parcTrapOutOfBounds(A, M, ...) parcLog_PrintError("Element out of bounds, %zu :" M, A, ##__VA_ARGS__); assert(0);
-#define parcTrapOutOfBoundsIf(A, M, ...) if((A)) {parcLog_PrintError("Out of bounds: " M, ##__VA_ARGS__); }
-#define parcTrapOutOfMemory(M, ...) parcLog_PrintError("Out of memory. " M, ##__VA_ARGS__); assert(0);
-#define parcTrapOutOfMemoryIf(A, M, ...) if((A)) {parcLog_PrintError("Out of memory. " M, ##__VA_ARGS__); }
-#define parcTrapUnexpectedState(M, ...) parcLog_PrintError("Unexpected state. " M, ##__VA_ARGS__); assert(0);
-#define parcTrapUnexpectedStateIf(A, M, ...) if((A)) {parcLog_PrintError("Unexpected state: " M, ##__VA_ARGS__); } if((A))
-#define parcTrapUnrecoverableState(M, ...) parcLog_PrintError("Unrecoverable State: " M, ##__VA_ARGS__); assert(0);
-#define parcTrapInvalidValueIf(A, M, ...) if((A)) {parcLog_PrintError("Invalid value: " M, ##__VA_ARGS__); }
-#define parcTrapCannotObtainLock(M, ...) parcLog_PrintError("Cannot obtain lock: " M, ##__VA_ARGS__); assert(0);
-#define parcTrapCannotObtainLockIf(A, M, ...) if((A)) {parcLog_PrintError("Cannot obtain lock: " M, ##__VA_ARGS__); }
-#define parcAssertAligned(address, alignment, ...) if ((alignment & (~alignment + 1)) == alignment) { if ((((uintptr_t) address) % alignment) != 0)parcLog_PrintError(__VA_ARGS__);} assert((alignment & (~alignment + 1)) == alignment ? (((uintptr_t) address) % alignment) == 0 ? 1 : 0 : 0);
-/*
-
- ((alignment & (~alignment + 1)) == alignment) ? (((uintptr_t) address) % alignment) == 0 ? 1 : 0 : 0);
+#define parcTrapIllegalValueIf(A, M, ...) \
+ if ((A)) { \
+ parcLog_PrintError("Illegal value: " M, ##__VA_ARGS__); \
+ assert(!(A)); \
+ }
+#define parcTrapIllegalValue(A, M, ...) \
+ parcLog_PrintError("Illegal value: " M, ##__VA_ARGS__); \
+ assert(0);
+#define parcTrapNotImplemented(M, ...) \
+ parcLog_PrintError("Feature not implemented: " M, ##__VA_ARGS__); \
+ assert(0);
+#define parcTrapOutOfBounds(A, M, ...) \
+ parcLog_PrintError("Element out of bounds, %zu :" M, A, ##__VA_ARGS__); \
+ assert(0);
+#define parcTrapOutOfBoundsIf(A, M, ...) \
+ if ((A)) { \
+ parcLog_PrintError("Out of bounds: " M, ##__VA_ARGS__); \
+ assert(!(A)); \
+ }
+#define parcTrapOutOfMemory(M, ...) \
+ parcLog_PrintError("Out of memory. " M, ##__VA_ARGS__); \
+ assert(0);
+#define parcTrapOutOfMemoryIf(A, M, ...) \
+ if ((A)) { \
+ parcLog_PrintError("Out of memory. " M, ##__VA_ARGS__); \
+ assert(!(A)); \
+ }
+#define parcTrapUnexpectedState(M, ...) \
+ parcLog_PrintError("Unexpected state. " M, ##__VA_ARGS__); \
+ assert(0);
+#define parcTrapUnexpectedStateIf(A, M, ...) \
+ if ((A)) { \
+ parcLog_PrintError("Unexpected state: " M, ##__VA_ARGS__); \
+ assert(!(A)); \
+ }
+#define parcTrapUnrecoverableState(M, ...) \
+ parcLog_PrintError("Unrecoverable State: " M, ##__VA_ARGS__); \
+ assert(0);
+#define parcTrapInvalidValueIf(A, M, ...) \
+ if ((A)) { \
+ parcLog_PrintError("Invalid value: " M, ##__VA_ARGS__); \
+ assert(!(A)); \
+ }
+#define parcTrapCannotObtainLock(M, ...) \
+ parcLog_PrintError("Cannot obtain lock: " M, ##__VA_ARGS__); \
+ assert(0);
+#define parcTrapCannotObtainLockIf(A, M, ...) \
+ if ((A)) { \
+ parcLog_PrintError("Cannot obtain lock: " M, ##__VA_ARGS__); \
+ assert(!(A)); \
+ }
+#define parcAssertAligned(address, alignment, ...) \
+ parcLog_PrintError(__VA_ARGS__); \
+ assert(((alignment & (~alignment + 1)) == alignment) \
+ ? (((uintptr_t)address) % alignment) == 0 ? 1 : 0 \
+ : 0);
-bool
-longBowRuntime_TestAddressIsAligned(const void *address, size_t alignment)
-{
- if ((alignment & (~alignment + 1)) == alignment) {
- return (((uintptr_t) address) % alignment) == 0 ? true : false;
- }
- return false;
-}*/
#endif