gas/hash.c: add interface for looking up non-NUL-terminated strings

Zack Weinberg zack@codesourcery.com
Mon Apr 4 05:33:00 GMT 2005


Alan Modra <amodra@bigpond.net.au> writes:

> On Tue, Mar 29, 2005 at 12:00:37PM -0800, Zack Weinberg wrote:
>> 
>> The appended patch adds a new interface to gas/hash.c, hash_find_n,
>> with exactly the same semantics as hash_find except that the length of
>> the key is passed in as an argument, and the key is not assumed to be
>> NUL-terminated.  This is more convenient when parsing an assembly
>> instruction: one does not need to write a NUL into the line buffer so
>> that hash_find knows where to stop.
>
> Hmm, seems to me that writing a NUL into the line buffer isn't that
> onerous. 

I suppose to some extent it's a matter of taste, but having this
interface available allows me to make dramatic simplifications in
tc-arm.c.  I should have something to show y'all sometime this week on
that score.

> I'd like to see more justification for this patch, particularly
> since we have too many hash table implementations already in
> binutils.  At some stage I'd like to move bfd and gas over to use
> libiberty's hashtab.c, and another interface difference will make
> that task harder.

For what GAS uses hash tables for, I don't think that's a good idea.
libiberty's hashtab.c is extremely generic; you'd have to write
nontrivial amounts of wrapper code, and you'd take a nasty performance
hit.  (multiple indirect function calls on every lookup).

cpplib's symtab.c might be a better fit (it can be used independently
from the rest of cpplib) -- and it already has this interface. :)

>> -	  if (strcmp (p->string, key) == 0)
>> +	  if (p->string[len] == '\0' && strncmp (p->string, key, len) == 0)
>
> Potential access past the end of p->string.  The strncmp must come
> first.

Good point, will correct in my copy.

zw



More information about the Binutils mailing list