diff options
| author | shadchin <[email protected]> | 2022-04-18 12:39:32 +0300 |
|---|---|---|
| committer | shadchin <[email protected]> | 2022-04-18 12:39:32 +0300 |
| commit | d4be68e361f4258cf0848fc70018dfe37a2acc24 (patch) | |
| tree | 153e294cd97ac8b5d7a989612704a0c1f58e8ad4 /contrib/tools/python3/src/Python/errors.c | |
| parent | 260c02f5ccf242d9d9b8a873afaf6588c00237d6 (diff) | |
IGNIETFERRO-1816 Update Python 3 from 3.9.12 to 3.10.4
ref:9f96be6d02ee8044fdd6f124b799b270c20ce641
Diffstat (limited to 'contrib/tools/python3/src/Python/errors.c')
| -rw-r--r-- | contrib/tools/python3/src/Python/errors.c | 118 |
1 files changed, 92 insertions, 26 deletions
diff --git a/contrib/tools/python3/src/Python/errors.c b/contrib/tools/python3/src/Python/errors.c index 79278764cc5..bc1b55e440e 100644 --- a/contrib/tools/python3/src/Python/errors.c +++ b/contrib/tools/python3/src/Python/errors.c @@ -317,14 +317,14 @@ _PyErr_NormalizeException(PyThreadState *tstate, PyObject **exc, PyObject **val, PyObject **tb) { int recursion_depth = 0; - tstate->overflowed++; + tstate->recursion_headroom++; PyObject *type, *value, *initial_tb; restart: type = *exc; if (type == NULL) { /* There was no exception, so nothing to do. */ - tstate->overflowed--; + tstate->recursion_headroom--; return; } @@ -376,7 +376,7 @@ _PyErr_NormalizeException(PyThreadState *tstate, PyObject **exc, } *exc = type; *val = value; - tstate->overflowed--; + tstate->recursion_headroom--; return; error: @@ -1109,7 +1109,6 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict) { PyThreadState *tstate = _PyThreadState_GET(); PyObject *modulename = NULL; - PyObject *classname = NULL; PyObject *mydict = NULL; PyObject *bases = NULL; PyObject *result = NULL; @@ -1129,10 +1128,11 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict) goto failure; } - if (_PyDict_GetItemIdWithError(dict, &PyId___module__) == NULL) { - if (_PyErr_Occurred(tstate)) { - goto failure; - } + int r = _PyDict_ContainsId(dict, &PyId___module__); + if (r < 0) { + goto failure; + } + if (r == 0) { modulename = PyUnicode_FromStringAndSize(name, (Py_ssize_t)(dot-name)); if (modulename == NULL) @@ -1155,7 +1155,6 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict) failure: Py_XDECREF(bases); Py_XDECREF(mydict); - Py_XDECREF(classname); Py_XDECREF(modulename); return result; } @@ -1220,7 +1219,7 @@ static PyStructSequence_Desc UnraisableHookArgs_desc = { PyStatus -_PyErr_Init(void) +_PyErr_InitTypes(void) { if (UnraisableHookArgsType.tp_name == NULL) { if (PyStructSequence_InitType2(&UnraisableHookArgsType, @@ -1561,9 +1560,6 @@ PyErr_WriteUnraisable(PyObject *obj) } -extern PyObject *PyModule_GetWarningsModule(void); - - void PyErr_SyntaxLocation(const char *filename, int lineno) { @@ -1575,14 +1571,17 @@ PyErr_SyntaxLocation(const char *filename, int lineno) If the exception is not a SyntaxError, also sets additional attributes to make printing of exceptions believe it is a syntax error. */ -void -PyErr_SyntaxLocationObject(PyObject *filename, int lineno, int col_offset) +static void +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(); @@ -1612,6 +1611,32 @@ PyErr_SyntaxLocationObject(PyObject *filename, int lineno, int col_offset) _PyErr_Clear(tstate); } Py_XDECREF(tmp); + + tmp = NULL; + if (end_lineno >= 0) { + tmp = PyLong_FromLong(end_lineno); + if (tmp == NULL) { + _PyErr_Clear(tstate); + } + } + if (_PyObject_SetAttrId(v, &PyId_end_lineno, tmp ? tmp : Py_None)) { + _PyErr_Clear(tstate); + } + Py_XDECREF(tmp); + + tmp = NULL; + if (end_col_offset >= 0) { + tmp = PyLong_FromLong(end_col_offset); + if (tmp == NULL) { + _PyErr_Clear(tstate); + } + } + if (_PyObject_SetAttrId(v, &PyId_end_offset, tmp ? tmp : Py_None)) { + _PyErr_Clear(tstate); + } + Py_XDECREF(tmp); + + tmp = NULL; if (filename != NULL) { if (_PyObject_SetAttrId(v, &PyId_filename, filename)) { _PyErr_Clear(tstate); @@ -1624,9 +1649,18 @@ PyErr_SyntaxLocationObject(PyObject *filename, int lineno, int col_offset) } Py_DECREF(tmp); } + else { + _PyErr_Clear(tstate); + } } if (exc != PyExc_SyntaxError) { - if (!_PyObject_HasAttrId(v, &PyId_msg)) { + if (_PyObject_LookupAttrId(v, &PyId_msg, &tmp) < 0) { + _PyErr_Clear(tstate); + } + else if (tmp) { + Py_DECREF(tmp); + } + else { tmp = PyObject_Str(v); if (tmp) { if (_PyObject_SetAttrId(v, &PyId_msg, tmp)) { @@ -1638,7 +1672,13 @@ PyErr_SyntaxLocationObject(PyObject *filename, int lineno, int col_offset) _PyErr_Clear(tstate); } } - if (!_PyObject_HasAttrId(v, &PyId_print_file_and_line)) { + if (_PyObject_LookupAttrId(v, &PyId_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)) { _PyErr_Clear(tstate); @@ -1649,6 +1689,17 @@ PyErr_SyntaxLocationObject(PyObject *filename, int lineno, int col_offset) } void +PyErr_SyntaxLocationObject(PyObject *filename, int lineno, int col_offset) { + PyErr_SyntaxLocationObjectEx(filename, lineno, col_offset, lineno, -1); +} + +void +PyErr_RangedSyntaxLocationObject(PyObject *filename, int lineno, int col_offset, + int end_lineno, int end_col_offset) { + PyErr_SyntaxLocationObjectEx(filename, lineno, col_offset, end_lineno, end_col_offset); +} + +void PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset) { PyThreadState *tstate = _PyThreadState_GET(); @@ -1673,7 +1724,7 @@ PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset) functionality in tb_displayline() in traceback.c. */ static PyObject * -err_programtext(PyThreadState *tstate, FILE *fp, int lineno) +err_programtext(PyThreadState *tstate, FILE *fp, int lineno, const char* encoding) { int i; char linebuf[1000]; @@ -1701,7 +1752,11 @@ after_loop: fclose(fp); if (i == lineno) { PyObject *res; - res = PyUnicode_FromString(linebuf); + if (encoding != NULL) { + res = PyUnicode_Decode(linebuf, strlen(linebuf), encoding, "replace"); + } else { + res = PyUnicode_FromString(linebuf); + } if (res == NULL) _PyErr_Clear(tstate); return res; @@ -1712,17 +1767,22 @@ after_loop: PyObject * PyErr_ProgramText(const char *filename, int lineno) { - FILE *fp; - if (filename == NULL || *filename == '\0' || lineno <= 0) { + if (filename == NULL) { return NULL; } - PyThreadState *tstate = _PyThreadState_GET(); - fp = _Py_fopen(filename, "r" PY_STDIOTEXTMODE); - return err_programtext(tstate, fp, lineno); + + PyObject *filename_obj = PyUnicode_DecodeFSDefault(filename); + if (filename_obj == NULL) { + PyErr_Clear(); + return NULL; + } + PyObject *res = PyErr_ProgramTextObject(filename_obj, lineno); + Py_DECREF(filename_obj); + return res; } PyObject * -PyErr_ProgramTextObject(PyObject *filename, int lineno) +_PyErr_ProgramDecodedTextObject(PyObject *filename, int lineno, const char* encoding) { if (filename == NULL || lineno <= 0) { return NULL; @@ -1734,7 +1794,13 @@ PyErr_ProgramTextObject(PyObject *filename, int lineno) _PyErr_Clear(tstate); return NULL; } - return err_programtext(tstate, fp, lineno); + return err_programtext(tstate, fp, lineno, encoding); +} + +PyObject * +PyErr_ProgramTextObject(PyObject *filename, int lineno) +{ + return _PyErr_ProgramDecodedTextObject(filename, lineno, NULL); } #ifdef __cplusplus |
