Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 86999:01c4a0af73cf
Issue #19512, #19515: remove shared identifiers, move identifiers where they
are used.
Move also _Py_IDENTIFIER() defintions to the top in modified files to remove
identifiers duplicated in the same file.
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Thu, 07 Nov 2013 23:07:29 +0100 |
| parents | 7c71d2f97196 |
| children | c2a13acd5e2b |
comparison
equal
deleted
inserted
replaced
| 86998:23f0529a8b2f | 86999:01c4a0af73cf |
|---|---|
| 33 #undef BYTE | 33 #undef BYTE |
| 34 #include "windows.h" | 34 #include "windows.h" |
| 35 #define PATH_MAX MAXPATHLEN | 35 #define PATH_MAX MAXPATHLEN |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 /* Common identifiers */ | 38 _Py_IDENTIFIER(builtins); |
| 39 _Py_Identifier _PyId_argv = _Py_static_string_init("argv"); | |
| 40 _Py_Identifier _PyId_builtins = _Py_static_string_init("builtins"); | |
| 41 _Py_Identifier _PyId_path = _Py_static_string_init("path"); | |
| 42 _Py_Identifier _PyId_stdin = _Py_static_string_init("stdin"); | |
| 43 _Py_Identifier _PyId_stdout = _Py_static_string_init("stdout"); | |
| 44 _Py_Identifier _PyId_stderr = _Py_static_string_init("stderr"); | |
| 45 | |
| 46 /* local identifiers */ | |
| 47 _Py_IDENTIFIER(excepthook); | 39 _Py_IDENTIFIER(excepthook); |
| 40 _Py_IDENTIFIER(last_traceback); | |
| 41 _Py_IDENTIFIER(last_type); | |
| 42 _Py_IDENTIFIER(last_value); | |
| 48 _Py_IDENTIFIER(ps1); | 43 _Py_IDENTIFIER(ps1); |
| 49 _Py_IDENTIFIER(ps2); | 44 _Py_IDENTIFIER(ps2); |
| 50 _Py_IDENTIFIER(last_type); | 45 _Py_IDENTIFIER(stdin); |
| 51 _Py_IDENTIFIER(last_value); | 46 _Py_IDENTIFIER(stdout); |
| 52 _Py_IDENTIFIER(last_traceback); | 47 _Py_IDENTIFIER(stderr); |
| 53 _Py_static_string(PyId_string, "<string>"); | 48 _Py_static_string(PyId_string, "<string>"); |
| 54 | 49 |
| 55 #ifdef Py_REF_DEBUG | 50 #ifdef Py_REF_DEBUG |
| 56 static | 51 static |
| 57 void _print_total_refs(void) { | 52 void _print_total_refs(void) { |
| 427 /* Set up a preliminary stderr printer until we have enough | 422 /* Set up a preliminary stderr printer until we have enough |
| 428 infrastructure for the io module in place. */ | 423 infrastructure for the io module in place. */ |
| 429 pstderr = PyFile_NewStdPrinter(fileno(stderr)); | 424 pstderr = PyFile_NewStdPrinter(fileno(stderr)); |
| 430 if (pstderr == NULL) | 425 if (pstderr == NULL) |
| 431 Py_FatalError("Py_Initialize: can't set preliminary stderr"); | 426 Py_FatalError("Py_Initialize: can't set preliminary stderr"); |
| 432 _PySys_SetObjectId(&_PyId_stderr, pstderr); | 427 _PySys_SetObjectId(&PyId_stderr, pstderr); |
| 433 PySys_SetObject("__stderr__", pstderr); | 428 PySys_SetObject("__stderr__", pstderr); |
| 434 Py_DECREF(pstderr); | 429 Py_DECREF(pstderr); |
| 435 | 430 |
| 436 _PyImport_Init(); | 431 _PyImport_Init(); |
| 437 | 432 |
| 512 } | 507 } |
| 513 | 508 |
| 514 static void | 509 static void |
| 515 flush_std_files(void) | 510 flush_std_files(void) |
| 516 { | 511 { |
| 517 PyObject *fout = _PySys_GetObjectId(&_PyId_stdout); | 512 PyObject *fout = _PySys_GetObjectId(&PyId_stdout); |
| 518 PyObject *ferr = _PySys_GetObjectId(&_PyId_stderr); | 513 PyObject *ferr = _PySys_GetObjectId(&PyId_stderr); |
| 519 PyObject *tmp; | 514 PyObject *tmp; |
| 520 _Py_IDENTIFIER(flush); | 515 _Py_IDENTIFIER(flush); |
| 521 | 516 |
| 522 if (fout != NULL && fout != Py_None && !file_is_closed(fout)) { | 517 if (fout != NULL && fout != Py_None && !file_is_closed(fout)) { |
| 523 tmp = _PyObject_CallMethodId(fout, &PyId_flush, ""); | 518 tmp = _PyObject_CallMethodId(fout, &PyId_flush, ""); |
| 791 /* Set up a preliminary stderr printer until we have enough | 786 /* Set up a preliminary stderr printer until we have enough |
| 792 infrastructure for the io module in place. */ | 787 infrastructure for the io module in place. */ |
| 793 pstderr = PyFile_NewStdPrinter(fileno(stderr)); | 788 pstderr = PyFile_NewStdPrinter(fileno(stderr)); |
| 794 if (pstderr == NULL) | 789 if (pstderr == NULL) |
| 795 Py_FatalError("Py_Initialize: can't set preliminary stderr"); | 790 Py_FatalError("Py_Initialize: can't set preliminary stderr"); |
| 796 _PySys_SetObjectId(&_PyId_stderr, pstderr); | 791 _PySys_SetObjectId(&PyId_stderr, pstderr); |
| 797 PySys_SetObject("__stderr__", pstderr); | 792 PySys_SetObject("__stderr__", pstderr); |
| 798 Py_DECREF(pstderr); | 793 Py_DECREF(pstderr); |
| 799 | 794 |
| 800 _PyImportHooks_Init(); | 795 _PyImportHooks_Init(); |
| 801 | 796 |
| 1185 std = create_stdio(iomod, fd, 0, "<stdin>", encoding, errors); | 1180 std = create_stdio(iomod, fd, 0, "<stdin>", encoding, errors); |
| 1186 if (std == NULL) | 1181 if (std == NULL) |
| 1187 goto error; | 1182 goto error; |
| 1188 } /* if (fd < 0) */ | 1183 } /* if (fd < 0) */ |
| 1189 PySys_SetObject("__stdin__", std); | 1184 PySys_SetObject("__stdin__", std); |
| 1190 _PySys_SetObjectId(&_PyId_stdin, std); | 1185 _PySys_SetObjectId(&PyId_stdin, std); |
| 1191 Py_DECREF(std); | 1186 Py_DECREF(std); |
| 1192 | 1187 |
| 1193 /* Set sys.stdout */ | 1188 /* Set sys.stdout */ |
| 1194 fd = fileno(stdout); | 1189 fd = fileno(stdout); |
| 1195 if (!is_valid_fd(fd)) { | 1190 if (!is_valid_fd(fd)) { |
| 1200 std = create_stdio(iomod, fd, 1, "<stdout>", encoding, errors); | 1195 std = create_stdio(iomod, fd, 1, "<stdout>", encoding, errors); |
| 1201 if (std == NULL) | 1196 if (std == NULL) |
| 1202 goto error; | 1197 goto error; |
| 1203 } /* if (fd < 0) */ | 1198 } /* if (fd < 0) */ |
| 1204 PySys_SetObject("__stdout__", std); | 1199 PySys_SetObject("__stdout__", std); |
| 1205 _PySys_SetObjectId(&_PyId_stdout, std); | 1200 _PySys_SetObjectId(&PyId_stdout, std); |
| 1206 Py_DECREF(std); | 1201 Py_DECREF(std); |
| 1207 | 1202 |
| 1208 #if 1 /* Disable this if you have trouble debugging bootstrap stuff */ | 1203 #if 1 /* Disable this if you have trouble debugging bootstrap stuff */ |
| 1209 /* Set sys.stderr, replaces the preliminary stderr */ | 1204 /* Set sys.stderr, replaces the preliminary stderr */ |
| 1210 fd = fileno(stderr); | 1205 fd = fileno(stderr); |
| 1234 | 1229 |
| 1235 if (PySys_SetObject("__stderr__", std) < 0) { | 1230 if (PySys_SetObject("__stderr__", std) < 0) { |
| 1236 Py_DECREF(std); | 1231 Py_DECREF(std); |
| 1237 goto error; | 1232 goto error; |
| 1238 } | 1233 } |
| 1239 if (_PySys_SetObjectId(&_PyId_stderr, std) < 0) { | 1234 if (_PySys_SetObjectId(&PyId_stderr, std) < 0) { |
| 1240 Py_DECREF(std); | 1235 Py_DECREF(std); |
| 1241 goto error; | 1236 goto error; |
| 1242 } | 1237 } |
| 1243 Py_DECREF(std); | 1238 Py_DECREF(std); |
| 1244 #endif | 1239 #endif |
| 1366 return -1; | 1361 return -1; |
| 1367 } | 1362 } |
| 1368 | 1363 |
| 1369 if (fp == stdin) { | 1364 if (fp == stdin) { |
| 1370 /* Fetch encoding from sys.stdin if possible. */ | 1365 /* Fetch encoding from sys.stdin if possible. */ |
| 1371 v = _PySys_GetObjectId(&_PyId_stdin); | 1366 v = _PySys_GetObjectId(&PyId_stdin); |
| 1372 if (v && v != Py_None) { | 1367 if (v && v != Py_None) { |
| 1373 oenc = _PyObject_GetAttrId(v, &PyId_encoding); | 1368 oenc = _PyObject_GetAttrId(v, &PyId_encoding); |
| 1374 if (oenc) | 1369 if (oenc) |
| 1375 enc = _PyUnicode_AsString(oenc); | 1370 enc = _PyUnicode_AsString(oenc); |
| 1376 if (!enc) | 1371 if (!enc) |
| 1772 just let the else clause below print the error. */ | 1767 just let the else clause below print the error. */ |
| 1773 } | 1768 } |
| 1774 if (PyLong_Check(value)) | 1769 if (PyLong_Check(value)) |
| 1775 exitcode = (int)PyLong_AsLong(value); | 1770 exitcode = (int)PyLong_AsLong(value); |
| 1776 else { | 1771 else { |
| 1777 PyObject *sys_stderr = _PySys_GetObjectId(&_PyId_stderr); | 1772 PyObject *sys_stderr = _PySys_GetObjectId(&PyId_stderr); |
| 1778 if (sys_stderr != NULL && sys_stderr != Py_None) { | 1773 if (sys_stderr != NULL && sys_stderr != Py_None) { |
| 1779 PyFile_WriteObject(value, sys_stderr, Py_PRINT_RAW); | 1774 PyFile_WriteObject(value, sys_stderr, Py_PRINT_RAW); |
| 1780 } else { | 1775 } else { |
| 1781 PyObject_Print(value, stderr, Py_PRINT_RAW); | 1776 PyObject_Print(value, stderr, Py_PRINT_RAW); |
| 1782 fflush(stderr); | 1777 fflush(stderr); |
| 1936 { | 1931 { |
| 1937 Py_XDECREF(moduleName); | 1932 Py_XDECREF(moduleName); |
| 1938 err = PyFile_WriteString("<unknown>", f); | 1933 err = PyFile_WriteString("<unknown>", f); |
| 1939 } | 1934 } |
| 1940 else { | 1935 else { |
| 1941 if (_PyUnicode_CompareWithId(moduleName, &_PyId_builtins) != 0) | 1936 if (_PyUnicode_CompareWithId(moduleName, &PyId_builtins) != 0) |
| 1942 { | 1937 { |
| 1943 err = PyFile_WriteObject(moduleName, f, Py_PRINT_RAW); | 1938 err = PyFile_WriteObject(moduleName, f, Py_PRINT_RAW); |
| 1944 err += PyFile_WriteString(".", f); | 1939 err += PyFile_WriteString(".", f); |
| 1945 } | 1940 } |
| 1946 Py_DECREF(moduleName); | 1941 Py_DECREF(moduleName); |
| 2031 | 2026 |
| 2032 void | 2027 void |
| 2033 PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) | 2028 PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) |
| 2034 { | 2029 { |
| 2035 PyObject *seen; | 2030 PyObject *seen; |
| 2036 PyObject *f = _PySys_GetObjectId(&_PyId_stderr); | 2031 PyObject *f = _PySys_GetObjectId(&PyId_stderr); |
| 2037 if (PyExceptionInstance_Check(value) | 2032 if (PyExceptionInstance_Check(value) |
| 2038 && tb != NULL && PyTraceBack_Check(tb)) { | 2033 && tb != NULL && PyTraceBack_Check(tb)) { |
| 2039 /* Put the traceback on the exception, otherwise it won't get | 2034 /* Put the traceback on the exception, otherwise it won't get |
| 2040 displayed. See issue #18776. */ | 2035 displayed. See issue #18776. */ |
| 2041 PyObject *cur_tb = PyException_GetTraceback(value); | 2036 PyObject *cur_tb = PyException_GetTraceback(value); |
| 2128 _Py_IDENTIFIER(flush); | 2123 _Py_IDENTIFIER(flush); |
| 2129 | 2124 |
| 2130 /* Save the current exception */ | 2125 /* Save the current exception */ |
| 2131 PyErr_Fetch(&type, &value, &traceback); | 2126 PyErr_Fetch(&type, &value, &traceback); |
| 2132 | 2127 |
| 2133 f = _PySys_GetObjectId(&_PyId_stderr); | 2128 f = _PySys_GetObjectId(&PyId_stderr); |
| 2134 if (f != NULL) { | 2129 if (f != NULL) { |
| 2135 r = _PyObject_CallMethodId(f, &PyId_flush, ""); | 2130 r = _PyObject_CallMethodId(f, &PyId_flush, ""); |
| 2136 if (r) | 2131 if (r) |
| 2137 Py_DECREF(r); | 2132 Py_DECREF(r); |
| 2138 else | 2133 else |
| 2139 PyErr_Clear(); | 2134 PyErr_Clear(); |
| 2140 } | 2135 } |
| 2141 f = _PySys_GetObjectId(&_PyId_stdout); | 2136 f = _PySys_GetObjectId(&PyId_stdout); |
| 2142 if (f != NULL) { | 2137 if (f != NULL) { |
| 2143 r = _PyObject_CallMethodId(f, &PyId_flush, ""); | 2138 r = _PyObject_CallMethodId(f, &PyId_flush, ""); |
| 2144 if (r) | 2139 if (r) |
| 2145 Py_DECREF(r); | 2140 Py_DECREF(r); |
| 2146 else | 2141 else |
