diff options
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 0ef36bbb8c..a6e7c46568 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -141,12 +141,13 @@ get_codec_name(const char *encoding) { char *name_utf8, *name_str; PyObject *codec, *name = NULL; + _Py_IDENTIFIER(name); codec = _PyCodec_Lookup(encoding); if (!codec) goto error; - name = PyObject_GetAttrString(codec, "name"); + name = _PyObject_GetAttrId(codec, &PyId_name); Py_CLEAR(codec); if (!name) goto error; @@ -352,7 +353,7 @@ flush_std_files(void) PyObject *fout = PySys_GetObject("stdout"); PyObject *ferr = PySys_GetObject("stderr"); PyObject *tmp; - _Py_identifier(flush); + _Py_IDENTIFIER(flush); if (fout != NULL && fout != Py_None) { tmp = _PyObject_CallMethodId(fout, &PyId_flush, ""); @@ -806,9 +807,11 @@ create_stdio(PyObject* io, const char* newline; PyObject *line_buffering; int buffering, isatty; - _Py_identifier(open); - _Py_identifier(isatty); - _Py_identifier(TextIOWrapper); + _Py_IDENTIFIER(open); + _Py_IDENTIFIER(isatty); + _Py_IDENTIFIER(TextIOWrapper); + _Py_IDENTIFIER(name); + _Py_IDENTIFIER(mode); /* stdin is always opened in buffered mode, first because it shouldn't make a difference in common use cases, second because TextIOWrapper @@ -830,7 +833,8 @@ create_stdio(PyObject* io, goto error; if (buffering) { - raw = PyObject_GetAttrString(buf, "raw"); + _Py_IDENTIFIER(raw); + raw = _PyObject_GetAttrId(buf, &PyId_raw); if (raw == NULL) goto error; } @@ -840,7 +844,7 @@ create_stdio(PyObject* io, } text = PyUnicode_FromString(name); - if (text == NULL || PyObject_SetAttrString(raw, "name", text) < 0) + if (text == NULL || _PyObject_SetAttrId(raw, &PyId_name, text) < 0) goto error; res = _PyObject_CallMethodId(raw, &PyId_isatty, ""); if (res == NULL) @@ -877,7 +881,7 @@ create_stdio(PyObject* io, else mode = "r"; text = PyUnicode_FromString(mode); - if (!text || PyObject_SetAttrString(stream, "mode", text) < 0) + if (!text || _PyObject_SetAttrId(stream, &PyId_mode, text) < 0) goto error; Py_CLEAR(text); return stream; @@ -1115,13 +1119,14 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags PyArena *arena; char *ps1 = "", *ps2 = "", *enc = NULL; int errcode = 0; + _Py_IDENTIFIER(encoding); if (fp == stdin) { /* Fetch encoding from sys.stdin */ v = PySys_GetObject("stdin"); if (v == NULL || v == Py_None) return -1; - oenc = PyObject_GetAttrString(v, "encoding"); + oenc = _PyObject_GetAttrId(v, &PyId_encoding); if (!oenc) return -1; enc = _PyUnicode_AsString(oenc); @@ -1318,6 +1323,11 @@ parse_syntax_error(PyObject *err, PyObject **message, const char **filename, { long hold; PyObject *v; + _Py_IDENTIFIER(msg); + _Py_IDENTIFIER(filename); + _Py_IDENTIFIER(lineno); + _Py_IDENTIFIER(offset); + _Py_IDENTIFIER(text); /* old style errors */ if (PyTuple_Check(err)) @@ -1326,11 +1336,11 @@ parse_syntax_error(PyObject *err, PyObject **message, const char **filename, /* new style errors. `err' is an instance */ - if (! (v = PyObject_GetAttrString(err, "msg"))) + if (! (v = _PyObject_GetAttrId(err, &PyId_msg))) goto finally; *message = v; - if (!(v = PyObject_GetAttrString(err, "filename"))) + if (!(v = _PyObject_GetAttrId(err, &PyId_filename))) goto finally; if (v == Py_None) *filename = NULL; @@ -1338,7 +1348,7 @@ parse_syntax_error(PyObject *err, PyObject **message, const char **filename, goto finally; Py_DECREF(v); - if (!(v = PyObject_GetAttrString(err, "lineno"))) + if (!(v = _PyObject_GetAttrId(err, &PyId_lineno))) goto finally; hold = PyLong_AsLong(v); Py_DECREF(v); @@ -1347,7 +1357,7 @@ parse_syntax_error(PyObject *err, PyObject **message, const char **filename, goto finally; *lineno = (int)hold; - if (!(v = PyObject_GetAttrString(err, "offset"))) + if (!(v = _PyObject_GetAttrId(err, &PyId_offset))) goto finally; if (v == Py_None) { *offset = -1; @@ -1362,7 +1372,7 @@ parse_syntax_error(PyObject *err, PyObject **message, const char **filename, *offset = (int)hold; } - if (!(v = PyObject_GetAttrString(err, "text"))) + if (!(v = _PyObject_GetAttrId(err, &PyId_text))) goto finally; if (v == Py_None) *text = NULL; @@ -1431,7 +1441,8 @@ handle_system_exit(void) goto done; if (PyExceptionInstance_Check(value)) { /* The error code should be in the `code' attribute. */ - PyObject *code = PyObject_GetAttrString(value, "code"); + _Py_IDENTIFIER(code); + PyObject *code = _PyObject_GetAttrId(value, &PyId_code); if (code) { Py_DECREF(value); value = code; @@ -1538,6 +1549,7 @@ print_exception(PyObject *f, PyObject *value) { int err = 0; PyObject *type, *tb; + _Py_IDENTIFIER(print_file_and_line); if (!PyExceptionInstance_Check(value)) { PyFile_WriteString("TypeError: print_exception(): Exception expected for value, ", f); @@ -1553,7 +1565,7 @@ print_exception(PyObject *f, PyObject *value) if (tb && tb != Py_None) err = PyTraceBack_Print(tb, f); if (err == 0 && - PyObject_HasAttrString(value, "print_file_and_line")) + _PyObject_HasAttrId(value, &PyId_print_file_and_line)) { PyObject *message; const char *filename, *text; @@ -1588,6 +1600,7 @@ print_exception(PyObject *f, PyObject *value) else { PyObject* moduleName; char* className; + _Py_IDENTIFIER(__module__); assert(PyExceptionClass_Check(type)); className = PyExceptionClass_Name(type); if (className != NULL) { @@ -1596,7 +1609,7 @@ print_exception(PyObject *f, PyObject *value) className = dot+1; } - moduleName = PyObject_GetAttrString(type, "__module__"); + moduleName = _PyObject_GetAttrId(type, &PyId___module__); if (moduleName == NULL || !PyUnicode_Check(moduleName)) { Py_XDECREF(moduleName); @@ -1763,7 +1776,7 @@ flush_io(void) { PyObject *f, *r; PyObject *type, *value, *traceback; - _Py_identifier(flush); + _Py_IDENTIFIER(flush); /* Save the current exception */ PyErr_Fetch(&type, &value, &traceback); @@ -2210,7 +2223,7 @@ static void wait_for_thread_shutdown(void) { #ifdef WITH_THREAD - _Py_identifier(_shutdown); + _Py_IDENTIFIER(_shutdown); PyObject *result; PyThreadState *tstate = PyThreadState_GET(); PyObject *threading = PyMapping_GetItemString(tstate->interp->modules, |