On Tue, Dec 20, 2016 at 10:38 AM, Muhammad Faiz <mfc...@gmail.com> wrote: > FFRET_ERR and FFGOTO_ERR for common error handling > FFRET_OOM and FFGOTO_OOM for oom handling > > Signed-off-by: Muhammad Faiz <mfc...@gmail.com> > --- > libavutil/common.h | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/libavutil/common.h b/libavutil/common.h > index 8142b31..b868d60 100644 > --- a/libavutil/common.h > +++ b/libavutil/common.h > @@ -99,6 +99,29 @@ > #define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) > #define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0])) > > +/* Common error handling */ > +#define FFRET_ERR(val, ...) \ > + do { \ > + int ffret_err_ret__ = (val); \ > + if (ffret_err_ret__ < 0) { \ > + __VA_ARGS__; \ > + return ffret_err_ret__; \ > + } \ > + } while (0) > + > +#define FFGOTO_ERR(val, ret, dst, ...) \ > + do { \ > + int ffgoto_err_ret__ = (val); \ > + if (ffgoto_err_ret__ < 0) { \ > + ret = ffgoto_err_ret__; \ > + __VA_ARGS__; \ > + goto dst; \ > + } \ > + } while (0) > + > +#define FFRET_OOM(val, ...) FFRET_ERR((val) ? 0 : AVERROR(ENOMEM), > __VA_ARGS__) > +#define FFGOTO_OOM(val, ret, dst, ...) FFGOTO_ERR((val) ? 0 : > AVERROR(ENOMEM), ret, dst, __VA_ARGS__) > +
I don't really like these. Passing code to a macro as vaargs is iffy at best and make it rather hard to read, and ultimately doesn't make the code any simpler imho, which the goal should be. - Hendrik _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel