Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jens Gustedt
P99 - macros and functions for C99
Commits
325b026e
Commit
325b026e
authored
Dec 04, 2012
by
Simon Peeters
Committed by
Jens Gustedt
Dec 04, 2012
Browse files
add a macro to capture negative returns that are negated to form an error code
Signed-off-by:
Jens Gustedt
<
Jens.Gustedt@loria.fr
>
parent
e217c956
Changes
1
Hide whitespace changes
Inline
Side-by-side
p99/p99_try.h
View file @
325b026e
...
...
@@ -366,6 +366,46 @@ p00_throw_call_neg(F(__VA_ARGS__), E, p00_unwind_top, P99_STRINGIFY(__LINE__), _
**/
#define P99_THROW_CALL_NEG(F, E, ...) P00_THROW_CALL_NEG(F, E, __VA_ARGS__)
p99_inline
int
p00_throw_call_negate
(
int
p00_neg
,
errno_t
p00_def
,
p00_jmp_buf0
*
p00_top
,
char
const
*
p00_file
,
char
const
*
p00_context
,
char
const
*
p00_info
)
{
if
(
P99_UNLIKELY
(
p00_neg
<
0
))
p00_jmp_throw
(
-
p00_neg
,
p00_top
,
p00_file
,
p00_context
,
p00_info
);
return
p00_neg
;
}
#define P00_THROW_CALL_NEGATE(F, E, ...) \
p00_throw_call_negate(F(__VA_ARGS__), E, p00_unwind_top, P99_STRINGIFY(__LINE__), __func__, #F ", neg return")
/**
** @brief Wrap a function call to @a F such that it throws an error
** on negative return.
**
** A common strategy of libraries and also the Linux kernel is to
** return an @c int and signal an error with a negative value. The
** error code is then the negation of that return value. This wrapper
** makes this transparent such that it ensures that the error code is
** always checked, and if an error occurs the negated value is
** thrown.
**
** @return the value of the call to the function if that was
** successful. Never returns if it wasn't.
**
** @see P99_THROW_CALL_NEG for a similar macro that also checks if
** the return value is negative but that returns the value of @c
** errno, instead.
**
** @see P99_THROW_CALL_ZERO for a similar macro that checks if the
** return value is @c 0
**
** @see P99_THROW_CALL_VOIDP for a similar macro that checks a
** pointer return value
**/
#define P99_THROW_CALL_NEGATE(F, E, ...) P00_THROW_CALL_NEGATE(F, E, __VA_ARGS__)
p99_inline
void
*
p00_throw_call_voidp
(
void
*
p00_p
,
errno_t
p00_def
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment