[Patches] slightly expanded Unicode supported Py_BuildValue
Sat, 29 Apr 2000 15:01:01 +0200
Brian Hooper wrote:
> Hi again,
> > > Here's a patch which changes modsupport to add 'U' and 'U#',
> > > to support building Unicode objects from a null-terminated
> > > Py_UNICODE *, and a Py_UNICODE * with length, respectively.
> >If you would change the 'U' (capital U) to 'u' (lowercase u)
> >the patch would be perfect :-)
> After using the API with the lower-case 'u' a little bit, I feel
> I should mention that it's actually a little confusing to have
> the argument to PyArgs_ParseTuple be 'U' but the argument to
> Py_BuildValue be 'u' - this in comparison with 's', which is
> the same for both PyArgs_ParseTuple and Py_BuildValue, even though
> one signifies a Python string object and the other signifies
> regular char * data which gets turned into a Python string.
> Doesn't this case seem like it ought to be parallel? I think after actually
> trying it out it seems a little unwieldy and confusing. If 'u' is
> preferable to 'U', why not change the PyArgs_ParseTuple argument to 'u'
> also? I think making PyArgs_ParseTuple and Py_BuildValue as complimentary
> as possible makes them easiest to use and understand.
With the case switch, your patch gets in sync with what
"s" does for PyArgs_ParseTuple() and Py_BuildValue(): the
first reads string objects as char* while the second creates
string objects from char*.
The "U" in PyArgs_ParseTuple() does two things: it first
checks the object for being a Unicode object and then
returns a PyObject*. There also is a "S" marker which
does the same for string objects.
One could argue to also have a set of "u" markers for
PyArgs_ParseTuple(): these should then return Py_UNICODE*
instead of char*. Perhaps this is what you are thinking
about ? It would make a nice complement to your recent patches.
Python Pages: http://www.lemburg.com/python/