improve asserts

This commit is contained in:
Wim Taymans 2016-10-12 17:38:02 +02:00
parent 82414810e8
commit 672e5d8fa6
2 changed files with 10 additions and 23 deletions

View file

@ -127,30 +127,24 @@ typedef void (*SpaNotify) (void *data);
#endif #endif
#define spa_return_if_fail (log, expr) \ #define spa_return_if_fail(expr) \
do { \ do { \
if (SPA_UNLIKELY (!(expr))) { \ if (SPA_UNLIKELY (!(expr))) \
spa_log_debug(log, "Assertion '%s' failed\n", #expr); \
return; \ return; \
} \
} while(false) } while(false)
#define spa_return_val_if_fail (log, expr, val) \ #define spa_return_val_if_fail(expr, val) \
do { \ do { \
if (SPA_UNLIKELY(!(expr))) { \ if (SPA_UNLIKELY(!(expr))) \
spa_log_debug (log, "Assertion '%s' failed\n", #expr); \
return (val); \ return (val); \
} \
} while(false) } while(false)
/* spa_assert_se() is an assert which guarantees side effects of x, /* spa_assert_se() is an assert which guarantees side effects of x,
* i.e. is never optimized away, regardless of NDEBUG or FASTPATH. */ * i.e. is never optimized away, regardless of NDEBUG or FASTPATH. */
#define spa_assert_se (expr) \ #define spa_assert_se(expr) \
do { \ do { \
if (SPA_UNLIKELY(!(expr))) { \ if (SPA_UNLIKELY(!(expr))) \
spa_log_error("Assertion '%s' failed, Aborting\n.", #expr); \
abort(); \ abort(); \
} \
} while (false) } while (false)
/* Does exactly nothing */ /* Does exactly nothing */

View file

@ -699,21 +699,14 @@ spa_v4l2_source_node_port_reuse_buffer (SpaNode *node,
SpaV4l2State *state; SpaV4l2State *state;
SpaResult res; SpaResult res;
if (node == NULL) spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
return SPA_RESULT_INVALID_ARGUMENTS; spa_return_val_if_fail (port_id == 0, SPA_RESULT_INVALID_PORT);
this = SPA_CONTAINER_OF (node, SpaV4l2Source, node); this = SPA_CONTAINER_OF (node, SpaV4l2Source, node);
if (port_id != 0)
return SPA_RESULT_INVALID_PORT;
state = &this->state[port_id]; state = &this->state[port_id];
if (state->n_buffers == 0) spa_return_val_if_fail (state->n_buffers > 0, SPA_RESULT_NO_BUFFERS);
return SPA_RESULT_NO_BUFFERS; spa_return_val_if_fail (buffer_id < state->n_buffers, SPA_RESULT_INVALID_BUFFER_ID);
if (buffer_id >= state->n_buffers)
return SPA_RESULT_INVALID_BUFFER_ID;
res = spa_v4l2_buffer_recycle (this, buffer_id); res = spa_v4l2_buffer_recycle (this, buffer_id);