[Mesa-dev] [PATCH 05/11] i965: Initialize all member variables of bblock_t on construction.

Kenneth Graunke kenneth at whitecape.org
Tue Sep 24 11:10:57 PDT 2013


On 09/20/2013 09:51 PM, Francisco Jerez wrote:
> The bblock_t object relies on the memory allocator zeroing out its
> contents before it's initialized, which is quite an unusual practice
> in the C++ world because it ties objects to some specific allocation
> scheme, and gives unpredictable results when an object is created with
> a different allocator -- Stack allocation, array allocation, or
> aggregation inside a different object are some of the useful
> possibilities that come to my mind.  Initialize all fields from the
> constructor and stop using the zeroing allocator.
> ---
>  src/mesa/drivers/dri/i965/brw_cfg.cpp | 3 ++-
>  src/mesa/drivers/dri/i965/brw_cfg.h   | 2 +-
>  2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/src/mesa/drivers/dri/i965/brw_cfg.cpp b/src/mesa/drivers/dri/i965/brw_cfg.cpp
> index f4cfcd5..6a886ce 100644
> --- a/src/mesa/drivers/dri/i965/brw_cfg.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_cfg.cpp
> @@ -44,7 +44,8 @@ pop_stack(exec_list *list)
>     return block;
>  }
>  
> -bblock_t::bblock_t()
> +bblock_t::bblock_t() :
> +   start_ip(), end_ip(), block_num()
>  {
>     start = NULL;
>     end = NULL;

I would prefer to see either:

bblock_t::bblock_t() :
   start_ip(0), end_ip(0), block_num(0)
{
   ...
}

or

bblock_t::bblock_t()
{
   start_ip = 0;
   end_ip = 0;
   block_num = 0;
}

I don't really care which, but I dislike using a no-argument constructor
on integers.  Explicitly specifying zero is very little extra typing and
just a lot clearer, IMHO.

Otherwise, I'm definitely in favor of this change.

> diff --git a/src/mesa/drivers/dri/i965/brw_cfg.h b/src/mesa/drivers/dri/i965/brw_cfg.h
> index 27bc8b6..505a5cf 100644
> --- a/src/mesa/drivers/dri/i965/brw_cfg.h
> +++ b/src/mesa/drivers/dri/i965/brw_cfg.h
> @@ -39,7 +39,7 @@ public:
>  
>  class bblock_t {
>  public:
> -   DECLARE_RZALLOC_CXX_OPERATORS(bblock_t)
> +   DECLARE_RALLOC_CXX_OPERATORS(bblock_t)
>  
>     bblock_link *make_list(void *mem_ctx);
>  
> 



More information about the mesa-dev mailing list