This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Better checking in alloc-pool.c


On Wed, May 07, 2003 at 04:09:43PM +0200, Josef Zlomek wrote:
> 	* alloc-pool.h (ALLOC_POOL_ID_TYPE): New type.
> 	(struct alloc_pool_def): New element 'id'.
> 	* alloc-pool.c (fancy_abort): Extern function prototype.
> 	(abort): Macro which uses fancy_abort.
> 	(last_id): New variable.
> 	(ID_SIZE): New macro.
> 	(create_alloc_pool): Add ID_SIZE to size of element, increase
> 	and use last_id.
> 	(free_alloc_pool): Do the checking only when ENABLE_CHECKING.
> 	(pool_alloc): Likewise. Set ID for elements.
> 	(pool_free): Check whether the PTR was allocated from POOL.

I wish you would find a cleaner way to do this:

> ! 	*((ALLOC_POOL_ID_TYPE *) block) = 0;

and all the other related ID manipulation.
Perhaps have an allocation object struct like

	struct asdf {
	#ifdef ENABLE_CHECKING
	  ALLOC_POOL_ID_TYPE id;
	#endif
	  union {
	    char data[1];
	    double align_d;
	    HOST_WIDE_INT align_i;
	#ifdef HAVE_LONG_DOUBLE
	    long double align_ld;
	#endif
	  } u;
	};

Use offsetof to get back to the struct from the user pointer.

This assures correct object alignment, instead of the fixed
eight bytes of your ID_SIZE.


r~


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]