Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ Not supported:
* ``PyInitConfig_SetStrList()``
* ``PyType_GetBaseByToken()``
* ``PyUnicodeWriter_DecodeUTF8Stateful()``
* ``PyUnicodeWriter_WriteUCS4()``
* ``Py_InitializeFromInitConfig()``


Expand Down
5 changes: 5 additions & 0 deletions pythoncapi_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,11 @@ PyUnicodeWriter_WriteStr(PyUnicodeWriter *writer, PyObject *obj)
static inline int
PyUnicodeWriter_WriteRepr(PyUnicodeWriter *writer, PyObject *obj)
{
if (obj == NULL) {
return _PyUnicodeWriter_WriteASCIIString((_PyUnicodeWriter*)writer,
"<NULL>", 6);
}

PyObject *str = PyObject_Repr(obj);
if (str == NULL) {
return -1;
Expand Down
6 changes: 5 additions & 1 deletion tests/test_pythoncapi_compat_cext.c
Original file line number Diff line number Diff line change
Expand Up @@ -1908,13 +1908,17 @@ test_unicodewriter(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args))
goto error;
}
Py_CLEAR(str);
if (PyUnicodeWriter_WriteRepr(writer, NULL) < 0) {
goto error;
}

{
PyObject *result = PyUnicodeWriter_Finish(writer);
if (result == NULL) {
return NULL;
}
assert(PyUnicode_EqualToUTF8(result, "var=long non-ASCII valu\xC3\xA9 'repr'"));
const char *expected = "var=long non-ASCII valu\xC3\xA9 'repr'<NULL>";
assert(PyUnicode_EqualToUTF8(result, expected));
Py_DECREF(result);
}

Expand Down
Loading