summaryrefslogtreecommitdiff
path: root/Python/errors.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/errors.c')
-rw-r--r--Python/errors.c53
1 files changed, 19 insertions, 34 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 023234974c..10a06a5ae3 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -28,12 +28,6 @@ extern char *strerror(int);
extern "C" {
#endif
-_Py_IDENTIFIER(__main__);
-_Py_IDENTIFIER(__module__);
-_Py_IDENTIFIER(builtins);
-_Py_IDENTIFIER(stderr);
-_Py_IDENTIFIER(flush);
-
/* Forward declarations */
static PyObject *
_PyErr_FormatV(PyThreadState *tstate, PyObject *exception,
@@ -1135,7 +1129,7 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
goto failure;
}
- int r = _PyDict_ContainsId(dict, &PyId___module__);
+ int r = PyDict_Contains(dict, &_Py_ID(__module__));
if (r < 0) {
goto failure;
}
@@ -1144,7 +1138,7 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
(Py_ssize_t)(dot-name));
if (modulename == NULL)
goto failure;
- if (_PyDict_SetItemId(dict, &PyId___module__, modulename) != 0)
+ if (PyDict_SetItem(dict, &_Py_ID(__module__), modulename) != 0)
goto failure;
}
if (PyTuple_Check(base)) {
@@ -1347,7 +1341,7 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type,
assert(PyExceptionClass_Check(exc_type));
- PyObject *modulename = _PyObject_GetAttrId(exc_type, &PyId___module__);
+ PyObject *modulename = PyObject_GetAttr(exc_type, &_Py_ID(__module__));
if (modulename == NULL || !PyUnicode_Check(modulename)) {
Py_XDECREF(modulename);
_PyErr_Clear(tstate);
@@ -1356,8 +1350,8 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type,
}
}
else {
- if (!_PyUnicode_EqualToASCIIId(modulename, &PyId_builtins) &&
- !_PyUnicode_EqualToASCIIId(modulename, &PyId___main__)) {
+ if (!_PyUnicode_Equal(modulename, &_Py_ID(builtins)) &&
+ !_PyUnicode_Equal(modulename, &_Py_ID(__main__))) {
if (PyFile_WriteObject(modulename, file, Py_PRINT_RAW) < 0) {
Py_DECREF(modulename);
return -1;
@@ -1405,7 +1399,7 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type,
}
/* Explicitly call file.flush() */
- PyObject *res = _PyObject_CallMethodIdNoArgs(file, &PyId_flush);
+ PyObject *res = _PyObject_CallMethodNoArgs(file, &_Py_ID(flush));
if (!res) {
return -1;
}
@@ -1420,7 +1414,7 @@ write_unraisable_exc(PyThreadState *tstate, PyObject *exc_type,
PyObject *exc_value, PyObject *exc_tb, PyObject *err_msg,
PyObject *obj)
{
- PyObject *file = _PySys_GetObjectId(&PyId_stderr);
+ PyObject *file = _PySys_GetAttr(tstate, &_Py_ID(stderr));
if (file == NULL || file == Py_None) {
return 0;
}
@@ -1524,8 +1518,7 @@ _PyErr_WriteUnraisableMsg(const char *err_msg_str, PyObject *obj)
goto error;
}
- _Py_IDENTIFIER(unraisablehook);
- PyObject *hook = _PySys_GetObjectId(&PyId_unraisablehook);
+ PyObject *hook = _PySys_GetAttr(tstate, &_Py_ID(unraisablehook));
if (hook == NULL) {
Py_DECREF(hook_args);
goto default_hook;
@@ -1600,14 +1593,6 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
int end_lineno, int end_col_offset)
{
PyObject *exc, *v, *tb, *tmp;
- _Py_IDENTIFIER(filename);
- _Py_IDENTIFIER(lineno);
- _Py_IDENTIFIER(end_lineno);
- _Py_IDENTIFIER(msg);
- _Py_IDENTIFIER(offset);
- _Py_IDENTIFIER(end_offset);
- _Py_IDENTIFIER(print_file_and_line);
- _Py_IDENTIFIER(text);
PyThreadState *tstate = _PyThreadState_GET();
/* add attributes for the line number and filename for the error */
@@ -1619,7 +1604,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
if (tmp == NULL)
_PyErr_Clear(tstate);
else {
- if (_PyObject_SetAttrId(v, &PyId_lineno, tmp)) {
+ if (PyObject_SetAttr(v, &_Py_ID(lineno), tmp)) {
_PyErr_Clear(tstate);
}
Py_DECREF(tmp);
@@ -1631,7 +1616,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
_PyErr_Clear(tstate);
}
}
- if (_PyObject_SetAttrId(v, &PyId_offset, tmp ? tmp : Py_None)) {
+ if (PyObject_SetAttr(v, &_Py_ID(offset), tmp ? tmp : Py_None)) {
_PyErr_Clear(tstate);
}
Py_XDECREF(tmp);
@@ -1643,7 +1628,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
_PyErr_Clear(tstate);
}
}
- if (_PyObject_SetAttrId(v, &PyId_end_lineno, tmp ? tmp : Py_None)) {
+ if (PyObject_SetAttr(v, &_Py_ID(end_lineno), tmp ? tmp : Py_None)) {
_PyErr_Clear(tstate);
}
Py_XDECREF(tmp);
@@ -1655,20 +1640,20 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
_PyErr_Clear(tstate);
}
}
- if (_PyObject_SetAttrId(v, &PyId_end_offset, tmp ? tmp : Py_None)) {
+ if (PyObject_SetAttr(v, &_Py_ID(end_offset), tmp ? tmp : Py_None)) {
_PyErr_Clear(tstate);
}
Py_XDECREF(tmp);
tmp = NULL;
if (filename != NULL) {
- if (_PyObject_SetAttrId(v, &PyId_filename, filename)) {
+ if (PyObject_SetAttr(v, &_Py_ID(filename), filename)) {
_PyErr_Clear(tstate);
}
tmp = PyErr_ProgramTextObject(filename, lineno);
if (tmp) {
- if (_PyObject_SetAttrId(v, &PyId_text, tmp)) {
+ if (PyObject_SetAttr(v, &_Py_ID(text), tmp)) {
_PyErr_Clear(tstate);
}
Py_DECREF(tmp);
@@ -1678,7 +1663,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
}
}
if (exc != PyExc_SyntaxError) {
- if (_PyObject_LookupAttrId(v, &PyId_msg, &tmp) < 0) {
+ if (_PyObject_LookupAttr(v, &_Py_ID(msg), &tmp) < 0) {
_PyErr_Clear(tstate);
}
else if (tmp) {
@@ -1687,7 +1672,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
else {
tmp = PyObject_Str(v);
if (tmp) {
- if (_PyObject_SetAttrId(v, &PyId_msg, tmp)) {
+ if (PyObject_SetAttr(v, &_Py_ID(msg), tmp)) {
_PyErr_Clear(tstate);
}
Py_DECREF(tmp);
@@ -1696,15 +1681,15 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
_PyErr_Clear(tstate);
}
}
- if (_PyObject_LookupAttrId(v, &PyId_print_file_and_line, &tmp) < 0) {
+
+ if (_PyObject_LookupAttr(v, &_Py_ID(print_file_and_line), &tmp) < 0) {
_PyErr_Clear(tstate);
}
else if (tmp) {
Py_DECREF(tmp);
}
else {
- if (_PyObject_SetAttrId(v, &PyId_print_file_and_line,
- Py_None)) {
+ if (PyObject_SetAttr(v, &_Py_ID(print_file_and_line), Py_None)) {
_PyErr_Clear(tstate);
}
}