This is the mail archive of the mailing list for the Archer 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: [python][patch] Add options length parameter tovalue.string(...)

El jue, 09-04-2009 a las 10:58 +0100, Phil Muldoon escribiÃ:
> Thiago Jung Bauermann wrote:
> > >From what we talked on IRC, in this block:
> >
> >       /* If we know the size of the array, we can use it as a limit on the
> >          number of characters to be fetched.  */
> >       if (TYPE_NFIELDS (type) == 1
> >           && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_RANGE)
> >
> > we want to set *length and not fetchlimit from the array size. But
> > probably only if *length is -1. If the caller specified a *length
> > already, we shouldn't override it and continue using the array size for
> > the fetchlimit.
> >   
> I'm not sure what benefit setting the length to arraysize in the case of 
> length  -1 would achieve? Fetchlimit will be set to either unint_max or 
> the actual bounds of the array, and -1 means return at first null or  
> fetchlimit length within the fetchlimit?  So sending length of -1, and a 
> fetchlimit as described in the current existing logic would "do the 
> right thing"? If I were to set length to the array bound in the -1 case, 
> it would fetch the whole array, and not stop on the first null (which we 
> want for -1)?

If you call read_string with length = -1, it will stop at the first null
character, or when fetchlimit is reached. So the current code doesn't
fetch all of an array, it stops at the first null character. I believe
this is what we're trying to avoid?

So, in the case of an array with known size, if we want to fetch the
whole of it without paying attention to null characters inside it, we
should set length to its size.

I say we should do this only if length is -1 assuming that the caller
knows what it's doing when it says exactly how many characters it wants,
and we shouldn't try to be smart without being asked to. But perhaps I'm
wrong here, and we should always set length to the array size? (This is
only a theoretical worry though, I'm not thinking of a specific case
where the array length is known but the caller is asking for a specific
number of characters).

Did I clarify my thoughts, or just added more confusion? :-)
Thiago Jung Bauermann
IBM Linux Technology Center

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