This is the mail archive of the
mailing list for the Archer project.
Re: [python] StdStringPrinter misleading?
- From: Tom Tromey <tromey at redhat dot com>
- To: Phil Muldoon <pmuldoon at redhat dot com>
- Cc: Thiago Jung Bauermann <bauerman at br dot ibm dot com>, Paul Pluzhnikov <ppluzhnikov at google dot com>, archer at sourceware dot org
- Date: Fri, 03 Apr 2009 13:06:45 -0600
- Subject: Re: [python] StdStringPrinter misleading?
- References: <20090328002208.083A33A6BE4@localhost><firstname.lastname@example.org><email@example.com><firstname.lastname@example.org><email@example.com><firstname.lastname@example.org> <49D65557.email@example.com>
- Reply-to: Tom Tromey <tromey at redhat dot com>
Phil> And an additional len parameter to string:
Phil> return self.val['_M_dataplus']['_M_p'].string(encoding, len)
I guess you added the new argument between 'encoding' and 'errors'?
Normally I would say great -- as a general rule I think we should
order positional arguments according to expected frequency of use.
However in this particular case, there's already Python APIs using the
"encoding, errors" sorting; so I would tend to put length last, and
then access it via a keyword argument.
Phil> So I coded in the relevant optional argument logic into the Python
Phil> sections of the code, and I then passed this length argument to
Phil> LA_GET_STRING. This does the usual language lookups and (in my example
Phil> case) resolves to c_get_string. I found to my dismay that with this
Phil> particular language's get_string implementation I cannot pass a length
Phil> parameter that it will use.
Yeah, you have to implement this as well.
The idea is to change the length argument from an out-only argument to
an in-out argument. You will have to fix all implementations of this
language method, and also fix all callers to initialize the argument.
The implementations should check the argument; if it is -1 they should
compute the length. If it is not -1, they should respect the
Phil> So we'd have to rewrite c_get_string to
Phil> pay attention to length if it has a value, and ignore nulls if
Phil> length_read < length_specified. This makes me a little nervous.
It will be ok. Just write a test case or two.
This is really just what you wrote, restated :)