Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.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 | 954167ce92a3 |
| children | f39fac22ca9a |
comparison
equal
deleted
inserted
replaced
| 86998:23f0529a8b2f | 86999:01c4a0af73cf |
|---|---|
| 39 #ifdef HAVE_LANGINFO_H | 39 #ifdef HAVE_LANGINFO_H |
| 40 #include <locale.h> | 40 #include <locale.h> |
| 41 #include <langinfo.h> | 41 #include <langinfo.h> |
| 42 #endif | 42 #endif |
| 43 | 43 |
| 44 _Py_IDENTIFIER(_); | |
| 45 _Py_IDENTIFIER(__sizeof__); | |
| 46 _Py_IDENTIFIER(buffer); | |
| 47 _Py_IDENTIFIER(builtins); | |
| 48 _Py_IDENTIFIER(encoding); | |
| 49 _Py_IDENTIFIER(path); | |
| 50 _Py_IDENTIFIER(stdout); | |
| 51 _Py_IDENTIFIER(stderr); | |
| 52 _Py_IDENTIFIER(write); | |
| 53 | |
| 44 PyObject * | 54 PyObject * |
| 45 _PySys_GetObjectId(_Py_Identifier *key) | 55 _PySys_GetObjectId(_Py_Identifier *key) |
| 46 { | 56 { |
| 47 PyThreadState *tstate = PyThreadState_GET(); | 57 PyThreadState *tstate = PyThreadState_GET(); |
| 48 PyObject *sd = tstate->interp->sysdict; | 58 PyObject *sd = tstate->interp->sysdict; |
| 102 { | 112 { |
| 103 PyObject *stdout_encoding = NULL; | 113 PyObject *stdout_encoding = NULL; |
| 104 PyObject *encoded, *escaped_str, *repr_str, *buffer, *result; | 114 PyObject *encoded, *escaped_str, *repr_str, *buffer, *result; |
| 105 char *stdout_encoding_str; | 115 char *stdout_encoding_str; |
| 106 int ret; | 116 int ret; |
| 107 _Py_IDENTIFIER(encoding); | |
| 108 _Py_IDENTIFIER(buffer); | |
| 109 | 117 |
| 110 stdout_encoding = _PyObject_GetAttrId(outf, &PyId_encoding); | 118 stdout_encoding = _PyObject_GetAttrId(outf, &PyId_encoding); |
| 111 if (stdout_encoding == NULL) | 119 if (stdout_encoding == NULL) |
| 112 goto error; | 120 goto error; |
| 113 stdout_encoding_str = _PyUnicode_AsString(stdout_encoding); | 121 stdout_encoding_str = _PyUnicode_AsString(stdout_encoding); |
| 124 if (encoded == NULL) | 132 if (encoded == NULL) |
| 125 goto error; | 133 goto error; |
| 126 | 134 |
| 127 buffer = _PyObject_GetAttrId(outf, &PyId_buffer); | 135 buffer = _PyObject_GetAttrId(outf, &PyId_buffer); |
| 128 if (buffer) { | 136 if (buffer) { |
| 129 _Py_IDENTIFIER(write); | |
| 130 result = _PyObject_CallMethodId(buffer, &PyId_write, "(O)", encoded); | 137 result = _PyObject_CallMethodId(buffer, &PyId_write, "(O)", encoded); |
| 131 Py_DECREF(buffer); | 138 Py_DECREF(buffer); |
| 132 Py_DECREF(encoded); | 139 Py_DECREF(encoded); |
| 133 if (result == NULL) | 140 if (result == NULL) |
| 134 goto error; | 141 goto error; |
| 163 PyInterpreterState *interp = PyThreadState_GET()->interp; | 170 PyInterpreterState *interp = PyThreadState_GET()->interp; |
| 164 PyObject *modules = interp->modules; | 171 PyObject *modules = interp->modules; |
| 165 PyObject *builtins; | 172 PyObject *builtins; |
| 166 static PyObject *newline = NULL; | 173 static PyObject *newline = NULL; |
| 167 int err; | 174 int err; |
| 168 _Py_IDENTIFIER(_); | |
| 169 _Py_IDENTIFIER(builtins); | |
| 170 | 175 |
| 171 builtins = _PyDict_GetItemId(modules, &PyId_builtins); | 176 builtins = _PyDict_GetItemId(modules, &PyId_builtins); |
| 172 if (builtins == NULL) { | 177 if (builtins == NULL) { |
| 173 PyErr_SetString(PyExc_RuntimeError, "lost builtins module"); | 178 PyErr_SetString(PyExc_RuntimeError, "lost builtins module"); |
| 174 return NULL; | 179 return NULL; |
| 181 Py_INCREF(Py_None); | 186 Py_INCREF(Py_None); |
| 182 return Py_None; | 187 return Py_None; |
| 183 } | 188 } |
| 184 if (_PyObject_SetAttrId(builtins, &PyId__, Py_None) != 0) | 189 if (_PyObject_SetAttrId(builtins, &PyId__, Py_None) != 0) |
| 185 return NULL; | 190 return NULL; |
| 186 outf = _PySys_GetObjectId(&_PyId_stdout); | 191 outf = _PySys_GetObjectId(&PyId_stdout); |
| 187 if (outf == NULL || outf == Py_None) { | 192 if (outf == NULL || outf == Py_None) { |
| 188 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); | 193 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); |
| 189 return NULL; | 194 return NULL; |
| 190 } | 195 } |
| 191 if (PyFile_WriteObject(o, outf, 0) != 0) { | 196 if (PyFile_WriteObject(o, outf, 0) != 0) { |
| 852 PyObject *res = NULL; | 857 PyObject *res = NULL; |
| 853 static PyObject *gc_head_size = NULL; | 858 static PyObject *gc_head_size = NULL; |
| 854 static char *kwlist[] = {"object", "default", 0}; | 859 static char *kwlist[] = {"object", "default", 0}; |
| 855 PyObject *o, *dflt = NULL; | 860 PyObject *o, *dflt = NULL; |
| 856 PyObject *method; | 861 PyObject *method; |
| 857 _Py_IDENTIFIER(__sizeof__); | |
| 858 | 862 |
| 859 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:getsizeof", | 863 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:getsizeof", |
| 860 kwlist, &o, &dflt)) | 864 kwlist, &o, &dflt)) |
| 861 return NULL; | 865 return NULL; |
| 862 | 866 |
| 1823 PySys_SetPath(const wchar_t *path) | 1827 PySys_SetPath(const wchar_t *path) |
| 1824 { | 1828 { |
| 1825 PyObject *v; | 1829 PyObject *v; |
| 1826 if ((v = makepathobject(path, DELIM)) == NULL) | 1830 if ((v = makepathobject(path, DELIM)) == NULL) |
| 1827 Py_FatalError("can't create sys.path"); | 1831 Py_FatalError("can't create sys.path"); |
| 1828 if (_PySys_SetObjectId(&_PyId_path, v) != 0) | 1832 if (_PySys_SetObjectId(&PyId_path, v) != 0) |
| 1829 Py_FatalError("can't assign sys.path"); | 1833 Py_FatalError("can't assign sys.path"); |
| 1830 Py_DECREF(v); | 1834 Py_DECREF(v); |
| 1831 } | 1835 } |
| 1832 | 1836 |
| 1833 static PyObject * | 1837 static PyObject * |
| 1892 wchar_t fullpath[MAXPATHLEN]; | 1896 wchar_t fullpath[MAXPATHLEN]; |
| 1893 #elif defined(MS_WINDOWS) && !defined(MS_WINCE) | 1897 #elif defined(MS_WINDOWS) && !defined(MS_WINCE) |
| 1894 wchar_t fullpath[MAX_PATH]; | 1898 wchar_t fullpath[MAX_PATH]; |
| 1895 #endif | 1899 #endif |
| 1896 | 1900 |
| 1897 path = _PySys_GetObjectId(&_PyId_path); | 1901 path = _PySys_GetObjectId(&PyId_path); |
| 1898 if (path == NULL) | 1902 if (path == NULL) |
| 1899 return; | 1903 return; |
| 1900 | 1904 |
| 1901 argv0 = argv[0]; | 1905 argv0 = argv[0]; |
| 1902 | 1906 |
| 2002 static int | 2006 static int |
| 2003 sys_pyfile_write_unicode(PyObject *unicode, PyObject *file) | 2007 sys_pyfile_write_unicode(PyObject *unicode, PyObject *file) |
| 2004 { | 2008 { |
| 2005 PyObject *writer = NULL, *args = NULL, *result = NULL; | 2009 PyObject *writer = NULL, *args = NULL, *result = NULL; |
| 2006 int err; | 2010 int err; |
| 2007 _Py_IDENTIFIER(write); | |
| 2008 | 2011 |
| 2009 if (file == NULL) | 2012 if (file == NULL) |
| 2010 return -1; | 2013 return -1; |
| 2011 | 2014 |
| 2012 writer = _PyObject_GetAttrId(file, &PyId_write); | 2015 writer = _PyObject_GetAttrId(file, &PyId_write); |
| 2107 PySys_WriteStdout(const char *format, ...) | 2110 PySys_WriteStdout(const char *format, ...) |
| 2108 { | 2111 { |
| 2109 va_list va; | 2112 va_list va; |
| 2110 | 2113 |
| 2111 va_start(va, format); | 2114 va_start(va, format); |
| 2112 sys_write(&_PyId_stdout, stdout, format, va); | 2115 sys_write(&PyId_stdout, stdout, format, va); |
| 2113 va_end(va); | 2116 va_end(va); |
| 2114 } | 2117 } |
| 2115 | 2118 |
| 2116 void | 2119 void |
| 2117 PySys_WriteStderr(const char *format, ...) | 2120 PySys_WriteStderr(const char *format, ...) |
| 2118 { | 2121 { |
| 2119 va_list va; | 2122 va_list va; |
| 2120 | 2123 |
| 2121 va_start(va, format); | 2124 va_start(va, format); |
| 2122 sys_write(&_PyId_stderr, stderr, format, va); | 2125 sys_write(&PyId_stderr, stderr, format, va); |
| 2123 va_end(va); | 2126 va_end(va); |
| 2124 } | 2127 } |
| 2125 | 2128 |
| 2126 static void | 2129 static void |
| 2127 sys_format(_Py_Identifier *key, FILE *fp, const char *format, va_list va) | 2130 sys_format(_Py_Identifier *key, FILE *fp, const char *format, va_list va) |
| 2149 PySys_FormatStdout(const char *format, ...) | 2152 PySys_FormatStdout(const char *format, ...) |
| 2150 { | 2153 { |
| 2151 va_list va; | 2154 va_list va; |
| 2152 | 2155 |
| 2153 va_start(va, format); | 2156 va_start(va, format); |
| 2154 sys_format(&_PyId_stdout, stdout, format, va); | 2157 sys_format(&PyId_stdout, stdout, format, va); |
| 2155 va_end(va); | 2158 va_end(va); |
| 2156 } | 2159 } |
| 2157 | 2160 |
| 2158 void | 2161 void |
| 2159 PySys_FormatStderr(const char *format, ...) | 2162 PySys_FormatStderr(const char *format, ...) |
| 2160 { | 2163 { |
| 2161 va_list va; | 2164 va_list va; |
| 2162 | 2165 |
| 2163 va_start(va, format); | 2166 va_start(va, format); |
| 2164 sys_format(&_PyId_stderr, stderr, format, va); | 2167 sys_format(&PyId_stderr, stderr, format, va); |
| 2165 va_end(va); | 2168 va_end(va); |
| 2166 } | 2169 } |
