Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(35)

Unified Diff: Python/bltinmodule.c

Issue 8256: input() doesn't catch _PyUnicode_AsString() exception; io.StringIO().encoding is None
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Python/bltinmodule.c Tue Oct 06 18:52:52 2015 +0300
+++ b/Python/bltinmodule.c Tue Oct 06 22:05:15 2015 +0300
@@ -1878,10 +1878,12 @@ builtin_input_impl(PyModuleDef *module,
stdin_encoding = _PyObject_GetAttrId(fin, &PyId_encoding);
stdin_errors = _PyObject_GetAttrId(fin, &PyId_errors);
- if (!stdin_encoding || !stdin_errors)
+ if (!stdin_encoding || !stdin_errors ||
+ !PyUnicode_Check(stdin_encoding) ||
+ !PyUnicode_Check(stdin_errors))
/* stdin is a text stream, so it must have an
encoding. */
- goto _readline_errors;
+ goto fallback;
stdin_encoding_str = _PyUnicode_AsString(stdin_encoding);
stdin_errors_str = _PyUnicode_AsString(stdin_errors);
if (!stdin_encoding_str || !stdin_errors_str)
@@ -1897,8 +1899,10 @@ builtin_input_impl(PyModuleDef *module,
PyObject *stringpo;
stdout_encoding = _PyObject_GetAttrId(fout, &PyId_encoding);
stdout_errors = _PyObject_GetAttrId(fout, &PyId_errors);
- if (!stdout_encoding || !stdout_errors)
- goto _readline_errors;
+ if (!stdout_encoding || !stdout_errors ||
+ !PyUnicode_Check(stdout_encoding) ||
+ !PyUnicode_Check(stdout_errors))
+ goto fallback;
stdout_encoding_str = _PyUnicode_AsString(stdout_encoding);
stdout_errors_str = _PyUnicode_AsString(stdout_errors);
if (!stdout_encoding_str || !stdout_errors_str)
@@ -1962,7 +1966,9 @@ builtin_input_impl(PyModuleDef *module,
return NULL;
}
+fallback:
/* Fallback if we're not interactive */
+ PyErr_Clear();
if (prompt != NULL) {
if (PyFile_WriteObject(prompt, fout, Py_PRINT_RAW) != 0)
return NULL;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+