[RFA] Constify find_condition_and_thread

Pedro Alves palves@redhat.com
Fri Mar 1 18:56:00 GMT 2013


On 03/01/2013 06:40 PM, Eli Zaretskii wrote:
>> Date: Fri, 01 Mar 2013 10:18:37 -0800
>> From: Keith Seitz <keiths@redhat.com>
>>
>> -	  expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
>> +	  orig = copy = xstrdup (tok);
>> +	  cleanup = make_cleanup (xfree, orig);
>> +	  expr = parse_exp_1 (&copy, pc, block_for_pc (pc), 0);
>>  	  xfree (expr);
>> +	  tok += copy - orig;
>> +	  do_cleanups (cleanup);
> 
> If we really need this kind of dance, just to avoid explicit casts to
> 'char *', there should be a comment explaining why we do this.

Yeah.  I think casting the const out would be okay, and
better than forcing a xstrdup. (run time cost, and extra
complication for not that much gain over cast).

An alternative would be to perhaps make the interface of
parse_exp_1 similar to strtol -- split input and output
pointers, with the explicit guarantee that the output pointer
points somewhere within the input string.  Is it really that
messy?  There doesn't seem to be many parse_exp_1 callers.

-- 
Pedro Alves



More information about the Gdb-patches mailing list