[Python-3000] C API cleanup str

"Martin v. Löwis" martin at v.loewis.de
Mon Aug 6 10:07:20 CEST 2007


>> I now tried, and it turned out that bytes.__reduce__ would break
>> (again); I fixed it and changed it in r56755.
>>
>> It turned out that PyUnicode_FromString was even documented to
>> accept latin-1.
> 
> Yes, that seemed to me to be the most obvious interpretion.

Unfortunately, this made creating and retrieving asymmetric:
when you do PyUnicode_AsString, you'll get an UTF-8 string; when
you do PyUnicode_FromString, you did have to pass Latin-1. Making
AsString also return Latin-1 would, of course, restrict the number of
cases where it works.

>> While I was looking at it, I wondered why PyUnicode_FromStringAndSize
>> allows a NULL first argument, creating a null-initialized Unicode
>> object.
> 
> Because that's what PyString_FromStringAndSize() does.

I guessed that was the historic reason; I just wondered whether the
rationale for having it in PyString_FromStringAndSize still applies
to Unicode.

> So should NULL support be dropped from PyUnicode_FromStringAndSize()?

That's my proposal, yes.

Regards,
Martin


More information about the Python-3000 mailing list