Skip to content

Commit

Permalink
Implemented timed assert definition
Browse files Browse the repository at this point in the history
  • Loading branch information
kala13x committed Aug 8, 2024
1 parent e3d45ce commit 614ba35
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# https://github.com/kala13x/smake #
####################################

CFLAGS = -D_XUTILS_USE_SSL -g -O2 -Wall -D_XUTILS_DEBUG -D_XUTILS_USE_GNU
CFLAGS = -D_XUTILS_USE_SSL -g -O2 -Wall -D_XUTILS_DEBUG -D_XUTILS_USE_GNU -D_ASSERT_TIMED
CFLAGS += -I./src/crypt -I./src/data -I./src/net -I./src/sys -I./src
LIBS = -lssl -lcrypto -lpthread
NAME = libxutils.a
Expand Down
2 changes: 1 addition & 1 deletion misc/Makefile.tmp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# https://github.com/kala13x/smake #
####################################

CFLAGS = _SSL_FLAGS_ -g -O2 -Wall -D_XUTILS_DEBUG -D_XUTILS_USE_GNU
CFLAGS = _SSL_FLAGS_ -g -O2 -Wall -D_XUTILS_DEBUG -D_XUTILS_USE_GNU -D_ASSERT_TIMED
CFLAGS += -I./src/crypt -I./src/data -I./src/net -I./src/sys -I./src
LIBS = _SSL_LIBS_ -lpthread
NAME = libxutils.a
Expand Down
2 changes: 1 addition & 1 deletion misc/smake.tmp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"build": {
"name": "libxutils.a",
"outputDir": "./build",
"flags": "-g -O2 -Wall -D_XUTILS_DEBUG -D_XUTILS_USE_GNU",
"flags": "-g -O2 -Wall -D_XUTILS_DEBUG -D_XUTILS_USE_GNU -D_ASSERT_TIMED",
"libs": "-lpthread",
"overwrite": true,
"verbose": 2,
Expand Down
2 changes: 1 addition & 1 deletion smake.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"build": {
"name": "libxutils.a",
"outputDir": "./build",
"flags": "-g -O2 -Wall -D_XUTILS_DEBUG -D_XUTILS_USE_GNU",
"flags": "-g -O2 -Wall -D_XUTILS_DEBUG -D_XUTILS_USE_GNU -D_ASSERT_TIMED",
"libs": "-lpthread",
"overwrite": true,
"verbose": 2,
Expand Down
20 changes: 20 additions & 0 deletions src/xdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,25 @@ typedef uint8_t xbool_t;
#define XLOCATION_LVL2(line) XLOCATION_LVL1(line)
#define __XLOCATION__ XLOCATION_LVL2(__LINE__)

#ifdef _ASSERT_TIMED
#include <time.h>
#define XTROW_LOCATION \
{ \
char timeStr[20]; \
time_t now = time(NULL); \
struct tm *tmInfo = localtime(&now); \
strftime(timeStr, sizeof(timeStr), \
"%H:%M:%S.%03d", tmInfo ); \
printf("%s %s<error>%s " \
"Assert failed: " \
"%s:%s():%s\n", \
XCLR_RED, XCLR_RES, \
timeStr, \
__FILE__, \
__FUNCTION__, \
__XLOCATION__); \
}
#else
#define XTROW_LOCATION \
printf("%s<error>%s " \
"Assert failed: " \
Expand All @@ -118,6 +137,7 @@ typedef uint8_t xbool_t;
__FILE__, \
__FUNCTION__, \
__XLOCATION__)
#endif

#define XASSERT_RET(condition, value) \
if (!condition) return value
Expand Down

0 comments on commit 614ba35

Please sign in to comment.