Skip to content

Commit

Permalink
Error handling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Sep 7, 2024
1 parent c920325 commit b839c8b
Show file tree
Hide file tree
Showing 5 changed files with 543 additions and 175 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ prior to invoking `make`. The following build variables can be configured:
- `LDFLAGS`: Linker flags (default is `-lm`).

- `BUILD_MODE`: You can set it to `debug` to enable debugging features: it will initialize the global `xDebug`
variable to `TRUE`) and add `-g` to `CFLAGS`.
variable to `TRUE` and add `-g` to `CFLAGS`.

- `CHECKEXTRA`: Extra options to pass to `cppcheck` for the `make check` target

Expand Down
50 changes: 49 additions & 1 deletion include/xchange.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ extern boolean xDebug; ///< Switch to enable debugging (very verbose) o
// In xutil.c ------------------------------------------------>
boolean xIsVerbose();
void xSetVerbose(boolean value);
int xError(const char *func, int errorCode); // TODO...
void xSetDebug(boolean value);
int xError(int code, const char *fn);
const char *xErrorDescription(int code);

// Structure access methods ----------------------------------->
Expand Down Expand Up @@ -258,4 +259,51 @@ void xZero(void *buf, XType type, int count);
char *xStringCopyOf(const char *str);


// <================= xchange internals ======================>

/// \cond PRIVATE
#ifdef __XCHANGE_INTERNAL_API__

# include <stdio.h>
# include <math.h>

// On some older platform NAN may not be defined, so define it here if need be
#ifndef NAN
# define NAN (0.0/0.0)
#endif

# ifndef THREAD_LOCAL
# if __STDC_VERSION__ >= 201112L
# define THREAD_LOCAL _Thread_local ///< C11 standard for thread-local variables
# elif __GNUC__ >= 3 && __GNUC_MINOR__ >= 3
# define THREAD_LOCAL __thread ///< pre C11 gcc >= 3.3 standard for thread-local variables
# else
# define THREAD_LOCAL ///< no thread-local variables
# endif
# endif


int x_trace(const char *loc, const char *op, int n);
void *x_trace_null(const char *loc, const char *op);
void x_set_errno(int en, const char *from, const char *desc, ...);
int x_error(int ret, int en, const char *from, const char *desc, ...);
int x_warn(const char *from, const char *desc, ...);

/**
* Propagates an error (if any) with an offset. If the error is non-zero, it returns with the offset
* error value. Otherwise it keeps going as if it weren't even there...
*
* @param n {int} error code or the call that produces the error code
*
* @sa error_return
*/
# define prop_error(loc, n) { \
int __ret = x_trace(loc, NULL, n); \
if (__ret != 0) \
return __ret; \
}

#endif /* __XCHANGE_INTERNAL_API__ */
/// \endcond

#endif /* XCHANGE_H_ */
Loading

0 comments on commit b839c8b

Please sign in to comment.