[x265] [PATCH] common: add CHECKED_MALLOC macro that logs malloc failures and jumps to fail label

Steve Borho steve at borho.org
Fri Sep 20 18:10:49 CEST 2013


On Fri, Sep 20, 2013 at 1:46 AM, Gopu Govindaswamy <
gopu at multicorewareinc.com> wrote:

> # HG changeset patch
> # User Gopu Govindaswamy <gopu at multicorewareinc.com>
> # Date 1379659509 -19800
> # Node ID 03195b8c3267dee542fe12886617902b7333a202
> # Parent  20d8fa0541d8cf77d52106c08022ae97f3ff5de8
> common: add CHECKED_MALLOC macro that logs malloc failures and jumps to
> fail label
>

queued for default


> diff -r 20d8fa0541d8 -r 03195b8c3267 source/common/common.cpp
> --- a/source/common/common.cpp  Thu Sep 19 22:26:46 2013 -0500
> +++ b/source/common/common.cpp  Fri Sep 20 12:15:09 2013 +0530
> @@ -86,7 +86,7 @@
>
>  void x265_log(x265_param_t *param, int level, const char *fmt, ...)
>  {
> -    if (level > param->logLevel)
> +    if (param && level > param->logLevel)
>          return;
>      const char *log_level;
>      switch (level)
> diff -r 20d8fa0541d8 -r 03195b8c3267 source/common/common.h
> --- a/source/common/common.h    Thu Sep 19 22:26:46 2013 -0500
> +++ b/source/common/common.h    Fri Sep 20 12:15:09 2013 +0530
> @@ -96,6 +96,16 @@
>  #define X265_MAX4(a, b, c, d) X265_MAX((a), X265_MAX3((b), (c), (d)))
>  #define QP_BD_OFFSET (6*(X265_DEPTH-8))
>
> +#define CHECKED_MALLOC(var, type, count )\
> +{\
> +    var = (type *)X265_MALLOC(type, sizeof(type) * (count));\
> +    if (!var)\
> +    {\
> +        x265_log(NULL, X265_LOG_ERROR, "malloc of size %d failed\n",
> sizeof(type) * (count));\
> +        goto fail;\
> +    }\
> +}
> +
>  #define ENABLE_CYCLE_COUNTERS 0
>  #if ENABLE_CYCLE_COUNTERS
>  #include <intrin.h>
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>



-- 
Steve Borho
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20130920/b4677ed0/attachment.html>


More information about the x265-devel mailing list