Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 75a7967

Browse files
authored
PyUnicodeWriter_WriteRepr(NULL) now writes "<NULL>" (#170)
1 parent f6121eb commit 75a7967

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

docs/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ Not supported:
262262
* ``PyInitConfig_SetStrList()``
263263
* ``PyType_GetBaseByToken()``
264264
* ``PyUnicodeWriter_DecodeUTF8Stateful()``
265+
* ``PyUnicodeWriter_WriteUCS4()``
265266
* ``Py_InitializeFromInitConfig()``
266267

267268

pythoncapi_compat.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,11 @@ PyUnicodeWriter_WriteStr(PyUnicodeWriter *writer, PyObject *obj)
14251425
static inline int
14261426
PyUnicodeWriter_WriteRepr(PyUnicodeWriter *writer, PyObject *obj)
14271427
{
1428+
if (obj == NULL) {
1429+
return _PyUnicodeWriter_WriteASCIIString((_PyUnicodeWriter*)writer,
1430+
"<NULL>", 6);
1431+
}
1432+
14281433
PyObject *str = PyObject_Repr(obj);
14291434
if (str == NULL) {
14301435
return -1;

tests/test_pythoncapi_compat_cext.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1908,13 +1908,17 @@ test_unicodewriter(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args))
19081908
goto error;
19091909
}
19101910
Py_CLEAR(str);
1911+
if (PyUnicodeWriter_WriteRepr(writer, NULL) < 0) {
1912+
goto error;
1913+
}
19111914

19121915
{
19131916
PyObject *result = PyUnicodeWriter_Finish(writer);
19141917
if (result == NULL) {
19151918
return NULL;
19161919
}
1917-
assert(PyUnicode_EqualToUTF8(result, "var=long non-ASCII valu\xC3\xA9 'repr'"));
1920+
const char *expected = "var=long non-ASCII valu\xC3\xA9 'repr'<NULL>";
1921+
assert(PyUnicode_EqualToUTF8(result, expected));
19181922
Py_DECREF(result);
19191923
}
19201924

0 commit comments

Comments
 (0)