]> git.sesse.net Git - ffmpeg/commitdiff
avutil/internal: remove FF_ALLOCx{_ARRAY}_OR_GOTO macros
authorLimin Wang <lance.lmwang@gmail.com>
Tue, 2 Jun 2020 11:18:32 +0000 (19:18 +0800)
committerLimin Wang <lance.lmwang@gmail.com>
Fri, 12 Jun 2020 22:59:19 +0000 (06:59 +0800)
These functions have a terrible design, let us fix them before extending
them.
First design mistake: no error code. A helper function for testing
memory allocation failure where AVERROR(ENOMEM) does not appear is
absurd.

Second design mistake: printing a message. Return the error code, let
the caller print the error message.

Third design mistake: hard-coded use of goto.

http://ffmpeg.org/pipermail/ffmpeg-devel/2020-May/262544.html

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
libavutil/internal.h

index 00f1a578c03c935d3af4edff5b060b1b93f134af..b87cc6d6975ae0a15f3e80cc153116176f349965 100644 (file)
 #define FF_ALLOC_TYPED_ARRAY(p, nelem)  (p = av_malloc_array(nelem, sizeof(*p)))
 #define FF_ALLOCZ_TYPED_ARRAY(p, nelem) (p = av_mallocz_array(nelem, sizeof(*p)))
 
-#define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
-{\
-    p = av_malloc(size);\
-    if (!(p) && (size) != 0) {\
-        av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
-        goto label;\
-    }\
-}
-
-#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
-{\
-    p = av_mallocz(size);\
-    if (!(p) && (size) != 0) {\
-        av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
-        goto label;\
-    }\
-}
-
-#define FF_ALLOC_ARRAY_OR_GOTO(ctx, p, nelem, elsize, label)\
-{\
-    p = av_malloc_array(nelem, elsize);\
-    if (!p) {\
-        av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
-        goto label;\
-    }\
-}
-
-#define FF_ALLOCZ_ARRAY_OR_GOTO(ctx, p, nelem, elsize, label)\
-{\
-    p = av_mallocz_array(nelem, elsize);\
-    if (!p) {\
-        av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
-        goto label;\
-    }\
-}
-
 #include "libm.h"
 
 /**