This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lemburg
Recipients Arfrever, amaury.forgeotdarc, lemburg, loewis, vstinner
Date 2009-08-19.12:49:56
SpamBayes Score 9.277135e-12
Marked as misclassified No
Message-id <>
In-reply-to <>
Amaury Forgeot d'Arc wrote:
> Amaury Forgeot d'Arc <> added the comment:
> The problem is actually wider::
>     >>> getattr(None, "\udc80")
>     Segmentation fault
> An idea would be to change _PyUnicode_AsDefaultEncodedString and allow
> unpaired surrogates (utf8+surrogateescape, as explained in PEP383), but
> I fear the consequences...
> The code that fails seems pretty common:
> 	PyErr_Format(PyExc_AttributeError,
> 		     "'%.50s' object has no attribute '%.400s'",
> 		     tp->tp_name, _PyUnicode_AsString(name));
> It would be unfortunate to replace all usages of _PyUnicode_AsString to
> check the return value.

The use of _PyUnicode_AsString() is wrong here. There are several
cases where it can fail, e.g. MemoryErrors, embedded NULs, encoding

The same is true for _PyUnicode_AsStringAndSize(), which is why
I turned them into Python interpreter private APIs before 3.0

If you want a fail-safe stringified version of a Unicode object,
your only choice is to create a new API that does error checking,
properly clears the error and then returns a reference to a constant
string, e.g. "<repr-error>".
Date User Action Args
2009-08-19 12:50:08lemburgsetrecipients: + lemburg, loewis, amaury.forgeotdarc, vstinner, Arfrever
2009-08-19 12:49:56lemburglinkissue6697 messages
2009-08-19 12:49:56lemburgcreate