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]

Re: [RFA:] libiberty/hashtab: Introduce "failing" memory allocation API



> The BFD library in binutils is by convention not allowed to use the
> xmalloc and xcalloc functions; memory allocation failure should be handled
> more gracefully.  While this does not seem to be slavishly followed,
> introducing new offenders would just worsen the situation.  When
> introducing use of hashtab, there has to be non-xcalloc allocation
> machinery.  I thought for a minute about how to best augment the API to
> introduce non-failing allocation, and this seemed to be the simplest way,
> while having no constraining future consequences on maintenance.
> There might be a better name for the creator, but to me htab_try_create
> seemed to be the most appropriate while still usefully short.
> 
> Assuming the bootstrap in progress on i686-pc-linux-gnulibc1 shows no test
> regressions, Ok to commit?  (To gcc *and* src of course.)
>

  It is ok for me.  I did know that the hash tables are already used
in bfd.  Good solution of the problem.  It makes hash tables more
universal and permit to use them in other programs.

Thanks,

Vladimir Makarov
 
> libiberty:
> 	* hashtab.c (htab_expand): Change to return int.  Use calloc or
>  	xcalloc depending on htab->return_allocation_failure.  Return zero
>  	if calloc fails.
> 	(htab_create): Update comment to cover memory allocation.
> 	(htab_try_create): New.
> 	(htab_find_slot_with_hash): Return NULL if htab_expand fails.
>   	Update comment to cover this.
> 	Change all "void *" to PTR.
> 
> include:
> 	* hashtab.h (struct htab): Add member return_allocation_failure.
> 	(htab_try_create): New prototype.  Mention which functions may
> 	return NULL when this is used.
> 

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