This is the mail archive of the
mailing list for the Archer project.
Re: [python][patch] Add options length parameter tovalue.string(...)
El jue, 09-04-2009 a las 17:28 +0100, Phil Muldoon escribiÃ:
> Thiago Jung Bauermann wrote:
> > 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?
> Aha I see what you mean now. I wrote the patch to follow this logic:
> 1) If a length of -1 is specified, read until first null character. This
> is what read_string does, and seems sane in the C string sense. The
> default parameter passed to LA_GET_STRING in value.string() is -1, and
> so the current behaviour just fetches a string up to the first null for
> c strings.
> 2) If a length is specified, ignore any embedded nulls - just fetch
> until length is satisfied, or fetchlimit is reached.
> char foo ="george";
> char bar = "george\0mildred";
> char *foobar = "bungle";
> With the patch (I just sent Tom's requested changes back to him) the
> behaviour is:
> so just string() in the foo variable would return "george", length 6.
> string() in the bar variable would return "george", length 6
> string(length = 15) in the bar variable would override the null
> termination and return "george\0mildred"
> string() in the foobar variable would return "bungle", but string(length
> = 500), would return "bungle" + trash.
foobar is an interesting example. It is both a well-behaved
null-terminated string, and (AFAIK) an array with known size (7 bytes).
But your code will work correctly for it, no matter what default we
choose for the array-wit-known-size case, so it's not really important.
> With Tom's patch to the python string pretty printer (in C++) we can
> determine length.
> > 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'm not adverse to this if this is what is the most sensible thing to
> do. I guess what is the sanest default?
I don't think it's clear what the default should be. In your examples
above, do we want string() to return "george", or "george\0mildred" + 35
bytes of garbage? Tough.
Thiago Jung Bauermann
IBM Linux Technology Center