[Python-checkins] cpython: Issue #19512, #19515: remove shared identifiers, move identifiers where they

victor.stinner python-checkins at python.org
Thu Nov 7 23:08:09 CET 2013


http://hg.python.org/cpython/rev/01c4a0af73cf
changeset:   86999:01c4a0af73cf
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Thu Nov 07 23:07:29 2013 +0100
summary:
  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.

files:
  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
--- a/Include/object.h
+++ b/Include/object.h
@@ -147,14 +147,6 @@
 #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
--- a/Modules/_ctypes/callbacks.c
+++ b/Modules/_ctypes/callbacks.c
@@ -80,7 +80,7 @@
 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
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -2578,7 +2578,7 @@
     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
--- a/Modules/_lsprof.c
+++ b/Modules/_lsprof.c
@@ -185,7 +185,7 @@
             }
         }
         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
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -17,6 +17,8 @@
 static long nb_threads = 0;
 static PyObject *str_dict;
 
+_Py_IDENTIFIER(stderr);
+
 /* Lock objects */
 
 typedef struct {
@@ -1005,7 +1007,7 @@
             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
--- 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 @@
 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 @@
 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
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -261,7 +261,7 @@
 
     /* 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
--- a/Modules/syslogmodule.c
+++ b/Modules/syslogmodule.c
@@ -71,7 +71,7 @@
     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
--- 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_Bytes(PyObject *v)
 {
     PyObject *result, *func;
-    _Py_IDENTIFIER(__bytes__);
 
     if (v == NULL)
         return PyBytes_FromString("<NULL>");
@@ -949,7 +954,6 @@
 {
     int res;
     PyObject* isabstract;
-    _Py_IDENTIFIER(__isabstractmethod__);
 
     if (obj == NULL)
         return 0;
@@ -1124,7 +1128,7 @@
 {
     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 @@
 _dir_object(PyObject *obj)
 {
     PyObject *result, *sorted;
-    _Py_IDENTIFIER(__dir__);
     PyObject *dirfunc = _PyObject_LookupSpecial(obj, &PyId___dir__);
 
     assert(obj);
@@ -1973,8 +1976,6 @@
    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
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -53,6 +53,7 @@
 _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 @@
         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 @@
         return NULL;
     }
 
-    if (mod != NULL && _PyUnicode_CompareWithId(mod, &_PyId_builtins))
+    if (mod != NULL && _PyUnicode_CompareWithId(mod, &PyId_builtins))
         rtn = PyUnicode_FromFormat("<class '%U.%U'>", mod, name);
     else
         rtn = PyUnicode_FromFormat("<class '%s'>", type->tp_name);
@@ -3189,7 +3190,7 @@
         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
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -13,6 +13,8 @@
 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 @@
     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 @@
     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
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -32,9 +32,19 @@
 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 @@
     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 @@
     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 @@
                                      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 @@
 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 @@
         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 @@
     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 @@
     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 @@
         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
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -20,6 +20,9 @@
 extern "C" {
 #endif
 
+_Py_IDENTIFIER(builtins);
+_Py_IDENTIFIER(stderr);
+
 
 void
 PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback)
@@ -844,7 +847,7 @@
 
     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 @@
             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
--- a/Python/import.c
+++ b/Python/import.c
@@ -310,7 +310,7 @@
 
     /* 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
--- 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(last_traceback);
+_Py_IDENTIFIER(last_type);
+_Py_IDENTIFIER(last_value);
 _Py_IDENTIFIER(ps1);
 _Py_IDENTIFIER(ps2);
-_Py_IDENTIFIER(last_type);
-_Py_IDENTIFIER(last_value);
-_Py_IDENTIFIER(last_traceback);
+_Py_IDENTIFIER(stdin);
+_Py_IDENTIFIER(stdout);
+_Py_IDENTIFIER(stderr);
 _Py_static_string(PyId_string, "<string>");
 
 #ifdef Py_REF_DEBUG
@@ -429,7 +424,7 @@
     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 @@
 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 @@
         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 @@
             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 @@
             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 @@
         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 @@
 
     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 @@
     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 @@
             err = PyFile_WriteString("<unknown>", 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 @@
 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 @@
     /* 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 @@
         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
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -41,6 +41,16 @@
 #include <langinfo.h>
 #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 @@
     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 @@
 
     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 @@
     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 @@
     }
     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 @@
     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 @@
     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 @@
     wchar_t fullpath[MAX_PATH];
 #endif
 
-    path = _PySys_GetObjectId(&_PyId_path);
+    path = _PySys_GetObjectId(&PyId_path);
     if (path == NULL)
         return;
 
@@ -2004,7 +2008,6 @@
 {
     PyObject *writer = NULL, *args = NULL, *result = NULL;
     int err;
-    _Py_IDENTIFIER(write);
 
     if (file == NULL)
         return -1;
@@ -2109,7 +2112,7 @@
     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 @@
     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 @@
     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 @@
     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
--- 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 @@
     const char* filepath;
     Py_ssize_t len;
     PyObject* result;
-    _Py_IDENTIFIER(open);
 
     filebytes = PyUnicode_EncodeFSDefault(filename);
     if (filebytes == NULL) {
@@ -169,7 +173,7 @@
         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 @@
     char buf[MAXPATHLEN+1];
     int kind;
     void *data;
-    _Py_IDENTIFIER(close);
-    _Py_IDENTIFIER(open);
-    _Py_IDENTIFIER(TextIOWrapper);
 
     /* open the file */
     if (filename == NULL)

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list