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 to value.string(...)

Thiago Jung Bauermann wrote:
El jue, 09-04-2009 a las 10:58 +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[50]  ="george";
char bar[50] = "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.

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?



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