aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Python/pylifecycle.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2025-06-13 00:05:26 +0300
committershadchin <shadchin@yandex-team.com>2025-06-13 00:35:30 +0300
commit796b9088366b10b4cd42885101fc20c0b5709b07 (patch)
treef287eacb0b95ffd7cabf95b16cafb4788645dc38 /contrib/tools/python3/Python/pylifecycle.c
parentc72bca862651e507d2ff4980ef7f4ff7267a7227 (diff)
downloadydb-796b9088366b10b4cd42885101fc20c0b5709b07.tar.gz
Update Python 3 to 3.12.10
commit_hash:dd2398e159fe1d72ea6b12da52fccc933a41a785
Diffstat (limited to 'contrib/tools/python3/Python/pylifecycle.c')
-rw-r--r--contrib/tools/python3/Python/pylifecycle.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/contrib/tools/python3/Python/pylifecycle.c b/contrib/tools/python3/Python/pylifecycle.c
index ef4e6076570..f5bea14b16b 100644
--- a/contrib/tools/python3/Python/pylifecycle.c
+++ b/contrib/tools/python3/Python/pylifecycle.c
@@ -1189,8 +1189,12 @@ init_interp_main(PyThreadState *tstate)
if (is_main_interp) {
/* Initialize warnings. */
- PyObject *warnoptions = PySys_GetObject("warnoptions");
- if (warnoptions != NULL && PyList_Size(warnoptions) > 0)
+ PyObject *warnoptions;
+ if (_PySys_GetOptionalAttrString("warnoptions", &warnoptions) < 0) {
+ return _PyStatus_ERR("can't initialize warnings");
+ }
+ if (warnoptions != NULL && PyList_Check(warnoptions) &&
+ PyList_Size(warnoptions) > 0)
{
PyObject *warnings_module = PyImport_ImportModule("warnings");
if (warnings_module == NULL) {
@@ -1199,6 +1203,7 @@ init_interp_main(PyThreadState *tstate)
}
Py_XDECREF(warnings_module);
}
+ Py_XDECREF(warnoptions);
interp->runtime->initialized = 1;
}
@@ -1667,24 +1672,32 @@ file_is_closed(PyObject *fobj)
static int
flush_std_files(void)
{
- PyThreadState *tstate = _PyThreadState_GET();
- PyObject *fout = _PySys_GetAttr(tstate, &_Py_ID(stdout));
- PyObject *ferr = _PySys_GetAttr(tstate, &_Py_ID(stderr));
+ PyObject *file;
PyObject *tmp;
int status = 0;
- if (fout != NULL && fout != Py_None && !file_is_closed(fout)) {
- tmp = PyObject_CallMethodNoArgs(fout, &_Py_ID(flush));
+ if (_PySys_GetOptionalAttr(&_Py_ID(stdout), &file) < 0) {
+ status = -1;
+ }
+ else if (file != NULL && file != Py_None && !file_is_closed(file)) {
+ tmp = PyObject_CallMethodNoArgs(file, &_Py_ID(flush));
if (tmp == NULL) {
- PyErr_WriteUnraisable(fout);
status = -1;
}
else
Py_DECREF(tmp);
}
+ if (status < 0) {
+ PyErr_WriteUnraisable(file);
+ }
+ Py_XDECREF(file);
- if (ferr != NULL && ferr != Py_None && !file_is_closed(ferr)) {
- tmp = PyObject_CallMethodNoArgs(ferr, &_Py_ID(flush));
+ if (_PySys_GetOptionalAttr(&_Py_ID(stderr), &file) < 0) {
+ PyErr_Clear();
+ status = -1;
+ }
+ else if (file != NULL && file != Py_None && !file_is_closed(file)) {
+ tmp = PyObject_CallMethodNoArgs(file, &_Py_ID(flush));
if (tmp == NULL) {
PyErr_Clear();
status = -1;
@@ -1692,6 +1705,7 @@ flush_std_files(void)
else
Py_DECREF(tmp);
}
+ Py_XDECREF(file);
return status;
}
@@ -2655,10 +2669,14 @@ _Py_FatalError_PrintExc(PyThreadState *tstate)
return 0;
}
- PyObject *ferr = _PySys_GetAttr(tstate, &_Py_ID(stderr));
+ PyObject *ferr;
+ if (_PySys_GetOptionalAttr(&_Py_ID(stderr), &ferr) < 0) {
+ _PyErr_Clear(tstate);
+ }
if (ferr == NULL || ferr == Py_None) {
/* sys.stderr is not set yet or set to None,
no need to try to display the exception */
+ Py_XDECREF(ferr);
Py_DECREF(exc);
return 0;
}
@@ -2678,6 +2696,7 @@ _Py_FatalError_PrintExc(PyThreadState *tstate)
else {
Py_DECREF(res);
}
+ Py_DECREF(ferr);
return has_tb;
}