From bd303c165bc914fc943026ece55f4ebd225614c9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 7 Nov 2013 23:07:29 +0100 Subject: 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. --- Include/object.h | 8 -------- Modules/_ctypes/callbacks.c | 2 +- Modules/_cursesmodule.c | 2 +- Modules/_lsprof.c | 2 +- Modules/_threadmodule.c | 4 +++- Modules/faulthandler.c | 10 ++++++---- Modules/main.c | 2 +- Modules/syslogmodule.c | 2 +- Objects/object.c | 13 +++++++------ Objects/typeobject.c | 7 ++++--- Python/_warnings.c | 6 ++++-- Python/bltinmodule.c | 28 +++++++++++++++------------- Python/errors.c | 7 +++++-- Python/import.c | 2 +- Python/pythonrun.c | 45 ++++++++++++++++++++------------------------- Python/sysmodule.c | 31 +++++++++++++++++-------------- Python/traceback.c | 11 ++++++----- 17 files changed, 93 insertions(+), 89 deletions(-) diff --git a/Include/object.h b/Include/object.h index 27f48a5..a6130fe 100644 --- a/Include/object.h +++ b/Include/object.h @@ -147,14 +147,6 @@ typedef struct _Py_Identifier { #define _Py_static_string(varname, value) static _Py_Identifier varname = _Py_static_string_init(value) #define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname) -/* Common identifiers (ex: _PyId_path is the string "path") */ -PyAPI_DATA(_Py_Identifier) _PyId_argv; -PyAPI_DATA(_Py_Identifier) _PyId_builtins; -PyAPI_DATA(_Py_Identifier) _PyId_path; -PyAPI_DATA(_Py_Identifier) _PyId_stdin; -PyAPI_DATA(_Py_Identifier) _PyId_stdout; -PyAPI_DATA(_Py_Identifier) _PyId_stderr; - /* Type objects contain a string containing the type name (to help somewhat in debugging), the allocation parameters (see PyObject_New() and diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c index 756f4ef..ec8fd12 100644 --- a/Modules/_ctypes/callbacks.c +++ b/Modules/_ctypes/callbacks.c @@ -80,7 +80,7 @@ static void PrintError(char *msg, ...) { char buf[512]; - PyObject *f = _PySys_GetObjectId(&_PyId_stderr); + PyObject *f = PySys_GetObject("stderr"); va_list marker; va_start(marker, msg); diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index 5cdd926..1f192dc 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -2578,7 +2578,7 @@ PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds) if (fd == -1) { PyObject* sys_stdout; - sys_stdout = _PySys_GetObjectId(&_PyId_stdout); + sys_stdout = PySys_GetObject("stdout"); if (sys_stdout == NULL || sys_stdout == Py_None) { PyErr_SetString( diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index 3ef7d65..8947889 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -185,7 +185,7 @@ normalizeUserObj(PyObject *obj) } } if (modname != NULL) { - if (_PyUnicode_CompareWithId(modname, &_PyId_builtins) != 0) { + if (PyUnicode_CompareWithASCIIString(modname, "builtins") != 0) { PyObject *result; result = PyUnicode_FromFormat("<%U.%s>", modname, fn->m_ml->ml_name); diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index a7123b7..ab0fea4 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -17,6 +17,8 @@ static PyObject *ThreadError; static long nb_threads = 0; static PyObject *str_dict; +_Py_IDENTIFIER(stderr); + /* Lock objects */ typedef struct { @@ -1005,7 +1007,7 @@ t_bootstrap(void *boot_raw) PySys_WriteStderr( "Unhandled exception in thread started by "); PyErr_Fetch(&exc, &value, &tb); - file = _PySys_GetObjectId(&_PyId_stderr); + file = _PySys_GetObjectId(&PyId_stderr); if (file != NULL && file != Py_None) PyFile_WriteObject(boot->func, file, 0); else diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index 315b32d..27b1d54 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -26,6 +26,11 @@ (anyway, the length is smaller than 30 characters) */ #define PUTS(fd, str) write(fd, str, (int)strlen(str)) +_Py_IDENTIFIER(enable); +_Py_IDENTIFIER(fileno); +_Py_IDENTIFIER(flush); +_Py_IDENTIFIER(stderr); + #ifdef HAVE_SIGACTION typedef struct sigaction _Py_sighandler_t; #else @@ -130,13 +135,11 @@ static PyObject* faulthandler_get_fileno(PyObject *file, int *p_fd) { PyObject *result; - _Py_IDENTIFIER(fileno); - _Py_IDENTIFIER(flush); long fd_long; int fd; if (file == NULL || file == Py_None) { - file = _PySys_GetObjectId(&_PyId_stderr); + file = _PySys_GetObjectId(&PyId_stderr); if (file == NULL) { PyErr_SetString(PyExc_RuntimeError, "unable to get sys.stderr"); return NULL; @@ -1047,7 +1050,6 @@ static int faulthandler_env_options(void) { PyObject *xoptions, *key, *module, *res; - _Py_IDENTIFIER(enable); char *p; if (!((p = Py_GETENV("PYTHONFAULTHANDLER")) && *p != '\0')) { diff --git a/Modules/main.c b/Modules/main.c index 4b1a968..9171070 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -261,7 +261,7 @@ RunMainFromImporter(wchar_t *filename) /* argv0 is usable as an import source, so put it in sys.path[0] and import __main__ */ - sys_path = _PySys_GetObjectId(&_PyId_path); + sys_path = PySys_GetObject("path"); if (sys_path == NULL) { PyErr_SetString(PyExc_RuntimeError, "unable to get sys.path"); goto error; diff --git a/Modules/syslogmodule.c b/Modules/syslogmodule.c index edd12ab..9d79eec 100644 --- a/Modules/syslogmodule.c +++ b/Modules/syslogmodule.c @@ -71,7 +71,7 @@ syslog_get_argv(void) Py_ssize_t argv_len, scriptlen; PyObject *scriptobj; Py_ssize_t slash; - PyObject *argv = _PySys_GetObjectId(&_PyId_argv); + PyObject *argv = PySys_GetObject("argv"); if (argv == NULL) { return(NULL); diff --git a/Objects/object.c b/Objects/object.c index 9d96e86..acc34af 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -8,6 +8,12 @@ extern "C" { #endif +_Py_IDENTIFIER(Py_Repr); +_Py_IDENTIFIER(__bytes__); +_Py_IDENTIFIER(__dir__); +_Py_IDENTIFIER(__isabstractmethod__); +_Py_IDENTIFIER(builtins); + #ifdef Py_REF_DEBUG Py_ssize_t _Py_RefTotal; @@ -560,7 +566,6 @@ PyObject * PyObject_Bytes(PyObject *v) { PyObject *result, *func; - _Py_IDENTIFIER(__bytes__); if (v == NULL) return PyBytes_FromString(""); @@ -949,7 +954,6 @@ _PyObject_IsAbstract(PyObject *obj) { int res; PyObject* isabstract; - _Py_IDENTIFIER(__isabstractmethod__); if (obj == NULL) return 0; @@ -1124,7 +1128,7 @@ _PyObject_GetBuiltin(const char *name) { PyObject *mod_name, *mod, *attr; - mod_name = _PyUnicode_FromId(&_PyId_builtins); /* borrowed */ + mod_name = _PyUnicode_FromId(&PyId_builtins); /* borrowed */ if (mod_name == NULL) return NULL; mod = PyImport_Import(mod_name); @@ -1440,7 +1444,6 @@ static PyObject * _dir_object(PyObject *obj) { PyObject *result, *sorted; - _Py_IDENTIFIER(__dir__); PyObject *dirfunc = _PyObject_LookupSpecial(obj, &PyId___dir__); assert(obj); @@ -1973,8 +1976,6 @@ _PyObject_DebugTypeStats(FILE *out) See dictobject.c and listobject.c for examples of use. */ -_Py_IDENTIFIER(Py_Repr); - int Py_ReprEnter(PyObject *obj) { diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 8bccb68..0708d67 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -53,6 +53,7 @@ _Py_IDENTIFIER(__module__); _Py_IDENTIFIER(__name__); _Py_IDENTIFIER(__new__); _Py_IDENTIFIER(__setitem__); +_Py_IDENTIFIER(builtins); static PyObject * slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds); @@ -366,7 +367,7 @@ type_module(PyTypeObject *type, void *context) if (s != NULL) return PyUnicode_FromStringAndSize( type->tp_name, (Py_ssize_t)(s - type->tp_name)); - name = _PyUnicode_FromId(&_PyId_builtins); + name = _PyUnicode_FromId(&PyId_builtins); Py_XINCREF(name); return name; } @@ -718,7 +719,7 @@ type_repr(PyTypeObject *type) return NULL; } - if (mod != NULL && _PyUnicode_CompareWithId(mod, &_PyId_builtins)) + if (mod != NULL && _PyUnicode_CompareWithId(mod, &PyId_builtins)) rtn = PyUnicode_FromFormat("", mod, name); else rtn = PyUnicode_FromFormat("", type->tp_name); @@ -3189,7 +3190,7 @@ object_repr(PyObject *self) Py_XDECREF(mod); return NULL; } - if (mod != NULL && _PyUnicode_CompareWithId(mod, &_PyId_builtins)) + if (mod != NULL && _PyUnicode_CompareWithId(mod, &PyId_builtins)) rtn = PyUnicode_FromFormat("<%U.%U object at %p>", mod, name, self); else rtn = PyUnicode_FromFormat("<%s object at %p>", diff --git a/Python/_warnings.c b/Python/_warnings.c index de60128..6013d7d 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -13,6 +13,8 @@ static PyObject *_filters; /* List */ static PyObject *_once_registry; /* Dict */ static PyObject *_default_action; /* String */ +_Py_IDENTIFIER(argv); +_Py_IDENTIFIER(stderr); static int check_matched(PyObject *obj, PyObject *arg) @@ -265,7 +267,7 @@ show_warning(PyObject *filename, int lineno, PyObject *text, PyObject if (name == NULL) /* XXX Can an object lack a '__name__' attribute? */ goto error; - f_stderr = _PySys_GetObjectId(&_PyId_stderr); + f_stderr = _PySys_GetObjectId(&PyId_stderr); if (f_stderr == NULL) { fprintf(stderr, "lost sys.stderr\n"); goto error; @@ -562,7 +564,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, else { *filename = NULL; if (*module != Py_None && PyUnicode_CompareWithASCIIString(*module, "__main__") == 0) { - PyObject *argv = _PySys_GetObjectId(&_PyId_argv); + PyObject *argv = _PySys_GetObjectId(&PyId_argv); /* PyList_Check() is needed because sys.argv is set to None during Python finalization */ if (argv != NULL && PyList_Check(argv) && PyList_Size(argv) > 0) { diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 7f3593c..96ccd64 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -32,9 +32,19 @@ const char *Py_FileSystemDefaultEncoding = NULL; /* set by initfsencoding() */ int Py_HasFileSystemDefaultEncoding = 0; #endif +_Py_IDENTIFIER(__builtins__); +_Py_IDENTIFIER(__dict__); +_Py_IDENTIFIER(__prepare__); +_Py_IDENTIFIER(__round__); +_Py_IDENTIFIER(encoding); +_Py_IDENTIFIER(errors); _Py_IDENTIFIER(fileno); _Py_IDENTIFIER(flush); -_Py_IDENTIFIER(__builtins__); +_Py_IDENTIFIER(metaclass); +_Py_IDENTIFIER(sort); +_Py_IDENTIFIER(stdin); +_Py_IDENTIFIER(stdout); +_Py_IDENTIFIER(stderr); static PyObject * builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds) @@ -43,8 +53,6 @@ builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds) PyObject *cls = NULL; Py_ssize_t nargs; int isclass; - _Py_IDENTIFIER(__prepare__); - _Py_IDENTIFIER(metaclass); assert(args != NULL); if (!PyTuple_Check(args)) { @@ -1547,7 +1555,6 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds) static PyObject *dummy_args; PyObject *sep = NULL, *end = NULL, *file = NULL, *flush = NULL; int i, err; - _Py_IDENTIFIER(flush); if (dummy_args == NULL && !(dummy_args = PyTuple_New(0))) return NULL; @@ -1555,7 +1562,7 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds) kwlist, &sep, &end, &file, &flush)) return NULL; if (file == NULL || file == Py_None) { - file = _PySys_GetObjectId(&_PyId_stdout); + file = _PySys_GetObjectId(&PyId_stdout); if (file == NULL) { PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); return NULL; @@ -1640,9 +1647,9 @@ static PyObject * builtin_input(PyObject *self, PyObject *args) { PyObject *promptarg = NULL; - PyObject *fin = _PySys_GetObjectId(&_PyId_stdin); - PyObject *fout = _PySys_GetObjectId(&_PyId_stdout); - PyObject *ferr = _PySys_GetObjectId(&_PyId_stderr); + PyObject *fin = _PySys_GetObjectId(&PyId_stdin); + PyObject *fout = _PySys_GetObjectId(&PyId_stdout); + PyObject *ferr = _PySys_GetObjectId(&PyId_stderr); PyObject *tmp; long fd; int tty; @@ -1713,8 +1720,6 @@ builtin_input(PyObject *self, PyObject *args) char *stdin_encoding_str, *stdin_errors_str; PyObject *result; size_t len; - _Py_IDENTIFIER(encoding); - _Py_IDENTIFIER(errors); stdin_encoding = _PyObject_GetAttrId(fin, &PyId_encoding); stdin_errors = _PyObject_GetAttrId(fin, &PyId_errors); @@ -1843,7 +1848,6 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds) PyObject *ndigits = NULL; static char *kwlist[] = {"number", "ndigits", 0}; PyObject *number, *round, *result; - _Py_IDENTIFIER(__round__); if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:round", kwlist, &number, &ndigits)) @@ -1886,7 +1890,6 @@ builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds) PyObject *callable; static char *kwlist[] = {"iterable", "key", "reverse", 0}; int reverse; - _Py_IDENTIFIER(sort); /* args 1-3 should match listsort in Objects/listobject.c */ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oi:sorted", @@ -1939,7 +1942,6 @@ builtin_vars(PyObject *self, PyObject *args) Py_INCREF(d); } else { - _Py_IDENTIFIER(__dict__); d = _PyObject_GetAttrId(v, &PyId___dict__); if (d == NULL) { PyErr_SetString(PyExc_TypeError, diff --git a/Python/errors.c b/Python/errors.c index 93e4724..90dc729 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -20,6 +20,9 @@ extern char *strerror(int); extern "C" { #endif +_Py_IDENTIFIER(builtins); +_Py_IDENTIFIER(stderr); + void PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback) @@ -844,7 +847,7 @@ PyErr_WriteUnraisable(PyObject *obj) PyErr_Fetch(&t, &v, &tb); - f = _PySys_GetObjectId(&_PyId_stderr); + f = _PySys_GetObjectId(&PyId_stderr); if (f == NULL || f == Py_None) goto done; @@ -878,7 +881,7 @@ PyErr_WriteUnraisable(PyObject *obj) goto done; } else { - if (_PyUnicode_CompareWithId(moduleName, &_PyId_builtins) != 0) { + if (_PyUnicode_CompareWithId(moduleName, &PyId_builtins) != 0) { if (PyFile_WriteObject(moduleName, f, Py_PRINT_RAW) < 0) goto done; if (PyFile_WriteString(".", f) < 0) diff --git a/Python/import.c b/Python/import.c index aea29e2..c96106f 100644 --- a/Python/import.c +++ b/Python/import.c @@ -310,7 +310,7 @@ PyImport_Cleanup(void) /* XXX Perhaps these precautions are obsolete. Who knows? */ - value = _PyDict_GetItemId(modules, &_PyId_builtins); + value = PyDict_GetItemString(modules, "builtins"); if (value != NULL && PyModule_Check(value)) { dict = PyModule_GetDict(value); if (Py_VerboseFlag) diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 5115c57..922446e 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -35,21 +35,16 @@ #define PATH_MAX MAXPATHLEN #endif -/* Common identifiers */ -_Py_Identifier _PyId_argv = _Py_static_string_init("argv"); -_Py_Identifier _PyId_builtins = _Py_static_string_init("builtins"); -_Py_Identifier _PyId_path = _Py_static_string_init("path"); -_Py_Identifier _PyId_stdin = _Py_static_string_init("stdin"); -_Py_Identifier _PyId_stdout = _Py_static_string_init("stdout"); -_Py_Identifier _PyId_stderr = _Py_static_string_init("stderr"); - -/* local identifiers */ +_Py_IDENTIFIER(builtins); _Py_IDENTIFIER(excepthook); -_Py_IDENTIFIER(ps1); -_Py_IDENTIFIER(ps2); +_Py_IDENTIFIER(last_traceback); _Py_IDENTIFIER(last_type); _Py_IDENTIFIER(last_value); -_Py_IDENTIFIER(last_traceback); +_Py_IDENTIFIER(ps1); +_Py_IDENTIFIER(ps2); +_Py_IDENTIFIER(stdin); +_Py_IDENTIFIER(stdout); +_Py_IDENTIFIER(stderr); _Py_static_string(PyId_string, ""); #ifdef Py_REF_DEBUG @@ -429,7 +424,7 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib) pstderr = PyFile_NewStdPrinter(fileno(stderr)); if (pstderr == NULL) Py_FatalError("Py_Initialize: can't set preliminary stderr"); - _PySys_SetObjectId(&_PyId_stderr, pstderr); + _PySys_SetObjectId(&PyId_stderr, pstderr); PySys_SetObject("__stderr__", pstderr); Py_DECREF(pstderr); @@ -514,8 +509,8 @@ file_is_closed(PyObject *fobj) static void flush_std_files(void) { - PyObject *fout = _PySys_GetObjectId(&_PyId_stdout); - PyObject *ferr = _PySys_GetObjectId(&_PyId_stderr); + PyObject *fout = _PySys_GetObjectId(&PyId_stdout); + PyObject *ferr = _PySys_GetObjectId(&PyId_stderr); PyObject *tmp; _Py_IDENTIFIER(flush); @@ -793,7 +788,7 @@ Py_NewInterpreter(void) pstderr = PyFile_NewStdPrinter(fileno(stderr)); if (pstderr == NULL) Py_FatalError("Py_Initialize: can't set preliminary stderr"); - _PySys_SetObjectId(&_PyId_stderr, pstderr); + _PySys_SetObjectId(&PyId_stderr, pstderr); PySys_SetObject("__stderr__", pstderr); Py_DECREF(pstderr); @@ -1187,7 +1182,7 @@ initstdio(void) goto error; } /* if (fd < 0) */ PySys_SetObject("__stdin__", std); - _PySys_SetObjectId(&_PyId_stdin, std); + _PySys_SetObjectId(&PyId_stdin, std); Py_DECREF(std); /* Set sys.stdout */ @@ -1202,7 +1197,7 @@ initstdio(void) goto error; } /* if (fd < 0) */ PySys_SetObject("__stdout__", std); - _PySys_SetObjectId(&_PyId_stdout, std); + _PySys_SetObjectId(&PyId_stdout, std); Py_DECREF(std); #if 1 /* Disable this if you have trouble debugging bootstrap stuff */ @@ -1236,7 +1231,7 @@ initstdio(void) Py_DECREF(std); goto error; } - if (_PySys_SetObjectId(&_PyId_stderr, std) < 0) { + if (_PySys_SetObjectId(&PyId_stderr, std) < 0) { Py_DECREF(std); goto error; } @@ -1368,7 +1363,7 @@ PyRun_InteractiveOneObject(FILE *fp, PyObject *filename, PyCompilerFlags *flags) if (fp == stdin) { /* Fetch encoding from sys.stdin if possible. */ - v = _PySys_GetObjectId(&_PyId_stdin); + v = _PySys_GetObjectId(&PyId_stdin); if (v && v != Py_None) { oenc = _PyObject_GetAttrId(v, &PyId_encoding); if (oenc) @@ -1774,7 +1769,7 @@ handle_system_exit(void) if (PyLong_Check(value)) exitcode = (int)PyLong_AsLong(value); else { - PyObject *sys_stderr = _PySys_GetObjectId(&_PyId_stderr); + PyObject *sys_stderr = _PySys_GetObjectId(&PyId_stderr); if (sys_stderr != NULL && sys_stderr != Py_None) { PyFile_WriteObject(value, sys_stderr, Py_PRINT_RAW); } else { @@ -1938,7 +1933,7 @@ print_exception(PyObject *f, PyObject *value) err = PyFile_WriteString("", f); } else { - if (_PyUnicode_CompareWithId(moduleName, &_PyId_builtins) != 0) + if (_PyUnicode_CompareWithId(moduleName, &PyId_builtins) != 0) { err = PyFile_WriteObject(moduleName, f, Py_PRINT_RAW); err += PyFile_WriteString(".", f); @@ -2033,7 +2028,7 @@ void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) { PyObject *seen; - PyObject *f = _PySys_GetObjectId(&_PyId_stderr); + PyObject *f = _PySys_GetObjectId(&PyId_stderr); if (PyExceptionInstance_Check(value) && tb != NULL && PyTraceBack_Check(tb)) { /* Put the traceback on the exception, otherwise it won't get @@ -2130,7 +2125,7 @@ flush_io(void) /* Save the current exception */ PyErr_Fetch(&type, &value, &traceback); - f = _PySys_GetObjectId(&_PyId_stderr); + f = _PySys_GetObjectId(&PyId_stderr); if (f != NULL) { r = _PyObject_CallMethodId(f, &PyId_flush, ""); if (r) @@ -2138,7 +2133,7 @@ flush_io(void) else PyErr_Clear(); } - f = _PySys_GetObjectId(&_PyId_stdout); + f = _PySys_GetObjectId(&PyId_stdout); if (f != NULL) { r = _PyObject_CallMethodId(f, &PyId_flush, ""); if (r) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index de33d55..3ebb6c9 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -41,6 +41,16 @@ extern const char *PyWin_DLLVersionString; #include #endif +_Py_IDENTIFIER(_); +_Py_IDENTIFIER(__sizeof__); +_Py_IDENTIFIER(buffer); +_Py_IDENTIFIER(builtins); +_Py_IDENTIFIER(encoding); +_Py_IDENTIFIER(path); +_Py_IDENTIFIER(stdout); +_Py_IDENTIFIER(stderr); +_Py_IDENTIFIER(write); + PyObject * _PySys_GetObjectId(_Py_Identifier *key) { @@ -104,8 +114,6 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o) PyObject *encoded, *escaped_str, *repr_str, *buffer, *result; char *stdout_encoding_str; int ret; - _Py_IDENTIFIER(encoding); - _Py_IDENTIFIER(buffer); stdout_encoding = _PyObject_GetAttrId(outf, &PyId_encoding); if (stdout_encoding == NULL) @@ -126,7 +134,6 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o) buffer = _PyObject_GetAttrId(outf, &PyId_buffer); if (buffer) { - _Py_IDENTIFIER(write); result = _PyObject_CallMethodId(buffer, &PyId_write, "(O)", encoded); Py_DECREF(buffer); Py_DECREF(encoded); @@ -165,8 +172,6 @@ sys_displayhook(PyObject *self, PyObject *o) PyObject *builtins; static PyObject *newline = NULL; int err; - _Py_IDENTIFIER(_); - _Py_IDENTIFIER(builtins); builtins = _PyDict_GetItemId(modules, &PyId_builtins); if (builtins == NULL) { @@ -183,7 +188,7 @@ sys_displayhook(PyObject *self, PyObject *o) } if (_PyObject_SetAttrId(builtins, &PyId__, Py_None) != 0) return NULL; - outf = _PySys_GetObjectId(&_PyId_stdout); + outf = _PySys_GetObjectId(&PyId_stdout); if (outf == NULL || outf == Py_None) { PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); return NULL; @@ -854,7 +859,6 @@ sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds) static char *kwlist[] = {"object", "default", 0}; PyObject *o, *dflt = NULL; PyObject *method; - _Py_IDENTIFIER(__sizeof__); if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:getsizeof", kwlist, &o, &dflt)) @@ -1825,7 +1829,7 @@ PySys_SetPath(const wchar_t *path) PyObject *v; if ((v = makepathobject(path, DELIM)) == NULL) Py_FatalError("can't create sys.path"); - if (_PySys_SetObjectId(&_PyId_path, v) != 0) + if (_PySys_SetObjectId(&PyId_path, v) != 0) Py_FatalError("can't assign sys.path"); Py_DECREF(v); } @@ -1894,7 +1898,7 @@ sys_update_path(int argc, wchar_t **argv) wchar_t fullpath[MAX_PATH]; #endif - path = _PySys_GetObjectId(&_PyId_path); + path = _PySys_GetObjectId(&PyId_path); if (path == NULL) return; @@ -2004,7 +2008,6 @@ sys_pyfile_write_unicode(PyObject *unicode, PyObject *file) { PyObject *writer = NULL, *args = NULL, *result = NULL; int err; - _Py_IDENTIFIER(write); if (file == NULL) return -1; @@ -2109,7 +2112,7 @@ PySys_WriteStdout(const char *format, ...) va_list va; va_start(va, format); - sys_write(&_PyId_stdout, stdout, format, va); + sys_write(&PyId_stdout, stdout, format, va); va_end(va); } @@ -2119,7 +2122,7 @@ PySys_WriteStderr(const char *format, ...) va_list va; va_start(va, format); - sys_write(&_PyId_stderr, stderr, format, va); + sys_write(&PyId_stderr, stderr, format, va); va_end(va); } @@ -2151,7 +2154,7 @@ PySys_FormatStdout(const char *format, ...) va_list va; va_start(va, format); - sys_format(&_PyId_stdout, stdout, format, va); + sys_format(&PyId_stdout, stdout, format, va); va_end(va); } @@ -2161,6 +2164,6 @@ PySys_FormatStderr(const char *format, ...) va_list va; va_start(va, format); - sys_format(&_PyId_stderr, stderr, format, va); + sys_format(&PyId_stderr, stderr, format, va); va_end(va); } diff --git a/Python/traceback.c b/Python/traceback.c index b0bed5f..e9169ce 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -21,6 +21,11 @@ /* Function from Parser/tokenizer.c */ extern char * PyTokenizer_FindEncodingFilename(int, PyObject *); +_Py_IDENTIFIER(TextIOWrapper); +_Py_IDENTIFIER(close); +_Py_IDENTIFIER(open); +_Py_IDENTIFIER(path); + static PyObject * tb_dir(PyTracebackObject *self) { @@ -152,7 +157,6 @@ _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject * const char* filepath; Py_ssize_t len; PyObject* result; - _Py_IDENTIFIER(open); filebytes = PyUnicode_EncodeFSDefault(filename); if (filebytes == NULL) { @@ -169,7 +173,7 @@ _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject * tail++; taillen = strlen(tail); - syspath = _PySys_GetObjectId(&_PyId_path); + syspath = _PySys_GetObjectId(&PyId_path); if (syspath == NULL || !PyList_Check(syspath)) goto error; npath = PyList_Size(syspath); @@ -232,9 +236,6 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent) char buf[MAXPATHLEN+1]; int kind; void *data; - _Py_IDENTIFIER(close); - _Py_IDENTIFIER(open); - _Py_IDENTIFIER(TextIOWrapper); /* open the file */ if (filename == NULL) -- cgit v0.12