This is the mail archive of the archer@sourceware.org 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] StdStringPrinter misleading?


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
passed-in value.

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 :)

Tom


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