[FFmpeg-devel] [PATCH] avutil/common: add FFRET/FFGOTO macro
Michael Niedermayer
michael at niedermayer.cc
Tue Dec 20 17:53:12 EET 2016
On Tue, Dec 20, 2016 at 09:05:56PM +0700, Muhammad Faiz wrote:
> On 12/20/16, Michael Niedermayer <michael at niedermayer.cc> wrote:
> > On Tue, Dec 20, 2016 at 04:38:34PM +0700, Muhammad Faiz wrote:
> >> FFRET_ERR and FFGOTO_ERR for common error handling
> >> FFRET_OOM and FFGOTO_OOM for oom handling
> >>
> >> Signed-off-by: Muhammad Faiz <mfcc64 at 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__)
> >
> > complex macros makes code less accessable to new developers.
> > it also makes code grep-ing harder
> > i dont think this is a good idea
>
> if vaargs is removed, is this still considered complex?
I think so, yes
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Complexity theory is the science of finding the exact solution to an
approximation. Benchmarking OTOH is finding an approximation of the exact
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20161220/6e209c95/attachment.sig>
More information about the ffmpeg-devel
mailing list