1
0

Cleaned up some macros

This commit is contained in:
Patrick Gaskin
2020-05-25 07:06:04 -04:00
parent c4ab0154bc
commit 1093239ba7
2 changed files with 9 additions and 9 deletions

View File

@@ -98,7 +98,7 @@ nm_config_t *nm_config_parse(char **err_out) {
fclose(cfgfile); \
free(line); \
closedir(cfgdir); \
NM_RETURN_ERR(fmt, ##__VA_ARGS__); \
NM_RETURN_ERR(fmt, ##__VA_ARGS__); \
} while (0)
// parse each line

View File

@@ -38,20 +38,20 @@ inline char *strtrim(char *s){
// writes the formatted error message to *err_out as a malloc'd string. The
// arguments may or may not be evaluated more than once.
#define NM_RETURN(ret, fmt, ...) _NM_RETURN(0, ret, fmt, ##__VA_ARGS__)
#define _NM_RETURN(noerr, ret, fmt, ...) ({ \
__typeof__(ret) _ret = (ret); \
if (err_out) { \
if (!noerr && _ret == NM_ERR_RET) asprintf(err_out, fmt " (%s:%d)", ##__VA_ARGS__, __FILE__, __LINE__); \
else *err_out = NULL; \
} \
return _ret; \
#define _NM_RETURN(noerr, ret, fmt, ...) ({ \
__typeof__(ret) _ret = (ret); \
if (err_out) { \
if (!noerr && _ret == NM_ERR_RET) asprintf(err_out, fmt " (%s:%d)", ##__VA_ARGS__, __FILE__, __LINE__); \
else *err_out = NULL; \
} \
return _ret; \
})
// NM_ASSERT is like assert, but it writes the formatted error message to
// err_out as a malloc'd string, and returns NM_ERR_RET. Cond will always be
// evaluated exactly once. The other arguments may or may not be evaluated one
// or more times.
#define NM_ASSERT(cond, fmt, ...) ({ \
#define NM_ASSERT(cond, fmt, ...) ({ \
if (!(cond)) _NM_RETURN(0, NM_ERR_RET, fmt " (assertion failed: %s)", ##__VA_ARGS__, #cond); \
})