[Python-3000] Pleaswe help with the countdown to zero failing tests in the struni branch!

Thomas Heller theller at ctypes.org
Tue Aug 7 17:50:27 CEST 2007


Guido van Rossum schrieb:
> On 8/7/07, Thomas Heller <theller at ctypes.org> wrote:
>> Guido van Rossum schrieb:
>> > test_ctypes
>> > Recently one test started failing again, after Martin changed
>> > PyUnicode_FromStringAndSize() to use UTF8 instead of Latin1.
>>
>> I wanted to look into this and noticed that 'import time' on Windows
>> doesn't work anymore on my machine.  The reason is that PyUnicode_FromStringAndSize()
>> is called for the string 'Westeuropäische Normalzeit', and then fails with
>>
>> UnicodeDecodeError: 'utf8' codec can't decode bytes in position 9-11: invalid data
> 
> I'm assuming that's a literal somewhere? In what encoding is it? That
> function was recently changed to require the input to be UTF-8. If the
> input isn't UTF-8, you'll have to use another API with an explicit
> encoding, PyUnicode_Decode().

It's in Modules/timemodule.c, line 691:
	PyModule_AddObject(m, "tzname",
			   Py_BuildValue("(zz)", tzname[0], tzname[1]));

According to MSDN, tzname is a global variable; the contents is somehow
derived from the TZ environment variable (which is not set in my case).

Is there another Py_BuildValue code that should be used?  BTW: There are
other occurrences of Py_BuildValue("(zz)", ...) in this file; someone should
probably check if the UTF8 can be assumed as input.

> I'm pretty sure this change is also responsible for the one failure
> (as it started around the time that change was made) but I don't
> understand the failure well enough to track it down. (It looked like
> uninitialized memory was being accessed though.)

I'm not sure what failure you are talking about here.

> In case you wonder why it was changed, it's for symmetry with
> _PyUnicode_AsDefaultEncodedString(), which is the most common way to
> turn Unicode back into a char* without specifying an encoding. (And
> yes, that name needs to be changed.)
> 
> See recent posts here.
> 



More information about the Python-3000 mailing list