summaryrefslogtreecommitdiffstats
path: root/Objects/fileobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/fileobject.c')
-rw-r--r--Objects/fileobject.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 313f1d0..babaa05 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -359,6 +359,9 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
Py_ssize_t n;
int err;
+ /* The function can clear the current exception */
+ assert(!PyErr_Occurred());
+
if (self->fd < 0) {
/* fd might be invalid on Windows
* I can't raise an exception here. It may lead to an
@@ -367,10 +370,11 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
Py_RETURN_NONE;
}
- if (!PyArg_ParseTuple(args, "U", &unicode))
+ if (!PyArg_ParseTuple(args, "U", &unicode)) {
return NULL;
+ }
- /* encode Unicode to UTF-8 */
+ /* Encode Unicode to UTF-8/surrogateescape */
str = PyUnicode_AsUTF8AndSize(unicode, &n);
if (str == NULL) {
PyErr_Clear();