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

Side by Side 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
Left:
Right:
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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Built-in functions */ 1 /* Built-in functions */
2 2
3 #include "Python.h" 3 #include "Python.h"
4 #include "Python-ast.h" 4 #include "Python-ast.h"
5 5
6 #include "node.h" 6 #include "node.h"
7 #include "code.h" 7 #include "code.h"
8 8
9 #include "asdl.h" 9 #include "asdl.h"
10 #include "ast.h" 10 #include "ast.h"
(...skipping 1860 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 char *promptstr; 1871 char *promptstr;
1872 char *s = NULL; 1872 char *s = NULL;
1873 PyObject *stdin_encoding = NULL, *stdin_errors = NULL; 1873 PyObject *stdin_encoding = NULL, *stdin_errors = NULL;
1874 PyObject *stdout_encoding = NULL, *stdout_errors = NULL; 1874 PyObject *stdout_encoding = NULL, *stdout_errors = NULL;
1875 char *stdin_encoding_str, *stdin_errors_str; 1875 char *stdin_encoding_str, *stdin_errors_str;
1876 PyObject *result; 1876 PyObject *result;
1877 size_t len; 1877 size_t len;
1878 1878
1879 stdin_encoding = _PyObject_GetAttrId(fin, &PyId_encoding); 1879 stdin_encoding = _PyObject_GetAttrId(fin, &PyId_encoding);
1880 stdin_errors = _PyObject_GetAttrId(fin, &PyId_errors); 1880 stdin_errors = _PyObject_GetAttrId(fin, &PyId_errors);
1881 if (!stdin_encoding || !stdin_errors) 1881 if (!stdin_encoding || !stdin_errors ||
1882 !PyUnicode_Check(stdin_encoding) ||
1883 !PyUnicode_Check(stdin_errors))
1882 /* stdin is a text stream, so it must have an 1884 /* stdin is a text stream, so it must have an
1883 encoding. */ 1885 encoding. */
1884 goto _readline_errors; 1886 goto fallback;
1885 stdin_encoding_str = _PyUnicode_AsString(stdin_encoding); 1887 stdin_encoding_str = _PyUnicode_AsString(stdin_encoding);
1886 stdin_errors_str = _PyUnicode_AsString(stdin_errors); 1888 stdin_errors_str = _PyUnicode_AsString(stdin_errors);
1887 if (!stdin_encoding_str || !stdin_errors_str) 1889 if (!stdin_encoding_str || !stdin_errors_str)
1888 goto _readline_errors; 1890 goto _readline_errors;
1889 tmp = _PyObject_CallMethodId(fout, &PyId_flush, ""); 1891 tmp = _PyObject_CallMethodId(fout, &PyId_flush, "");
1890 if (tmp == NULL) 1892 if (tmp == NULL)
1891 PyErr_Clear(); 1893 PyErr_Clear();
1892 else 1894 else
1893 Py_DECREF(tmp); 1895 Py_DECREF(tmp);
1894 if (prompt != NULL) { 1896 if (prompt != NULL) {
1895 /* We have a prompt, encode it as stdout would */ 1897 /* We have a prompt, encode it as stdout would */
1896 char *stdout_encoding_str, *stdout_errors_str; 1898 char *stdout_encoding_str, *stdout_errors_str;
1897 PyObject *stringpo; 1899 PyObject *stringpo;
1898 stdout_encoding = _PyObject_GetAttrId(fout, &PyId_encoding); 1900 stdout_encoding = _PyObject_GetAttrId(fout, &PyId_encoding);
1899 stdout_errors = _PyObject_GetAttrId(fout, &PyId_errors); 1901 stdout_errors = _PyObject_GetAttrId(fout, &PyId_errors);
1900 if (!stdout_encoding || !stdout_errors) 1902 if (!stdout_encoding || !stdout_errors ||
1901 goto _readline_errors; 1903 !PyUnicode_Check(stdout_encoding) ||
1904 !PyUnicode_Check(stdout_errors))
1905 goto fallback;
1902 stdout_encoding_str = _PyUnicode_AsString(stdout_encoding); 1906 stdout_encoding_str = _PyUnicode_AsString(stdout_encoding);
1903 stdout_errors_str = _PyUnicode_AsString(stdout_errors); 1907 stdout_errors_str = _PyUnicode_AsString(stdout_errors);
1904 if (!stdout_encoding_str || !stdout_errors_str) 1908 if (!stdout_encoding_str || !stdout_errors_str)
1905 goto _readline_errors; 1909 goto _readline_errors;
1906 stringpo = PyObject_Str(prompt); 1910 stringpo = PyObject_Str(prompt);
1907 if (stringpo == NULL) 1911 if (stringpo == NULL)
1908 goto _readline_errors; 1912 goto _readline_errors;
1909 po = PyUnicode_AsEncodedString(stringpo, 1913 po = PyUnicode_AsEncodedString(stringpo,
1910 stdout_encoding_str, stdout_errors_str); 1914 stdout_encoding_str, stdout_errors_str);
1911 Py_CLEAR(stdout_encoding); 1915 Py_CLEAR(stdout_encoding);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1955 return result; 1959 return result;
1956 _readline_errors: 1960 _readline_errors:
1957 Py_XDECREF(stdin_encoding); 1961 Py_XDECREF(stdin_encoding);
1958 Py_XDECREF(stdout_encoding); 1962 Py_XDECREF(stdout_encoding);
1959 Py_XDECREF(stdin_errors); 1963 Py_XDECREF(stdin_errors);
1960 Py_XDECREF(stdout_errors); 1964 Py_XDECREF(stdout_errors);
1961 Py_XDECREF(po); 1965 Py_XDECREF(po);
1962 return NULL; 1966 return NULL;
1963 } 1967 }
1964 1968
1969 fallback:
1965 /* Fallback if we're not interactive */ 1970 /* Fallback if we're not interactive */
1971 PyErr_Clear();
1966 if (prompt != NULL) { 1972 if (prompt != NULL) {
1967 if (PyFile_WriteObject(prompt, fout, Py_PRINT_RAW) != 0) 1973 if (PyFile_WriteObject(prompt, fout, Py_PRINT_RAW) != 0)
1968 return NULL; 1974 return NULL;
1969 } 1975 }
1970 tmp = _PyObject_CallMethodId(fout, &PyId_flush, ""); 1976 tmp = _PyObject_CallMethodId(fout, &PyId_flush, "");
1971 if (tmp == NULL) 1977 if (tmp == NULL)
1972 PyErr_Clear(); 1978 PyErr_Clear();
1973 else 1979 else
1974 Py_DECREF(tmp); 1980 Py_DECREF(tmp);
1975 return PyFile_GetLine(fin, -1); 1981 return PyFile_GetLine(fin, -1);
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
2696 if (PyDict_SetItemString(dict, "__debug__", debug) < 0) { 2702 if (PyDict_SetItemString(dict, "__debug__", debug) < 0) {
2697 Py_XDECREF(debug); 2703 Py_XDECREF(debug);
2698 return NULL; 2704 return NULL;
2699 } 2705 }
2700 Py_XDECREF(debug); 2706 Py_XDECREF(debug);
2701 2707
2702 return mod; 2708 return mod;
2703 #undef ADD_TO_ALL 2709 #undef ADD_TO_ALL
2704 #undef SETBUILTIN 2710 #undef SETBUILTIN
2705 } 2711 }
OLDNEW
« 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+