aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Python/import.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/import.c
parentc72bca862651e507d2ff4980ef7f4ff7267a7227 (diff)
downloadydb-796b9088366b10b4cd42885101fc20c0b5709b07.tar.gz
Update Python 3 to 3.12.10
commit_hash:dd2398e159fe1d72ea6b12da52fccc933a41a785
Diffstat (limited to 'contrib/tools/python3/Python/import.c')
-rw-r--r--contrib/tools/python3/Python/import.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/contrib/tools/python3/Python/import.c b/contrib/tools/python3/Python/import.c
index 1b550d0451c..8f8d5c25cb5 100644
--- a/contrib/tools/python3/Python/import.c
+++ b/contrib/tools/python3/Python/import.c
@@ -2438,19 +2438,15 @@ PyObject *
PyImport_GetImporter(PyObject *path)
{
PyThreadState *tstate = _PyThreadState_GET();
- PyObject *path_importer_cache = PySys_GetObject("path_importer_cache");
+ PyObject *path_importer_cache = _PySys_GetRequiredAttrString("path_importer_cache");
if (path_importer_cache == NULL) {
- PyErr_SetString(PyExc_RuntimeError, "lost sys.path_importer_cache");
return NULL;
}
- Py_INCREF(path_importer_cache);
- PyObject *path_hooks = PySys_GetObject("path_hooks");
+ PyObject *path_hooks = _PySys_GetRequiredAttrString("path_hooks");
if (path_hooks == NULL) {
- PyErr_SetString(PyExc_RuntimeError, "lost sys.path_hooks");
Py_DECREF(path_importer_cache);
return NULL;
}
- Py_INCREF(path_hooks);
PyObject *importer = get_path_importer(tstate, path_importer_cache, path_hooks, path);
Py_DECREF(path_hooks);
Py_DECREF(path_importer_cache);
@@ -2754,15 +2750,31 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name)
_PyTime_t t1 = 0, accumulated_copy = accumulated;
- PyObject *sys_path = PySys_GetObject("path");
- PyObject *sys_meta_path = PySys_GetObject("meta_path");
- PyObject *sys_path_hooks = PySys_GetObject("path_hooks");
+ PyObject *sys_path, *sys_meta_path, *sys_path_hooks;
+ if (_PySys_GetOptionalAttrString("path", &sys_path) < 0) {
+ return NULL;
+ }
+ if (_PySys_GetOptionalAttrString("meta_path", &sys_meta_path) < 0) {
+ Py_XDECREF(sys_path);
+ return NULL;
+ }
+ if (_PySys_GetOptionalAttrString("path_hooks", &sys_path_hooks) < 0) {
+ Py_XDECREF(sys_meta_path);
+ Py_XDECREF(sys_path);
+ return NULL;
+ }
if (_PySys_Audit(tstate, "import", "OOOOO",
abs_name, Py_None, sys_path ? sys_path : Py_None,
sys_meta_path ? sys_meta_path : Py_None,
sys_path_hooks ? sys_path_hooks : Py_None) < 0) {
+ Py_XDECREF(sys_path_hooks);
+ Py_XDECREF(sys_meta_path);
+ Py_XDECREF(sys_path);
return NULL;
}
+ Py_XDECREF(sys_path_hooks);
+ Py_XDECREF(sys_meta_path);
+ Py_XDECREF(sys_path);
/* XOptions is initialized after first some imports.
@@ -3216,10 +3228,8 @@ _PyImport_FiniCore(PyInterpreterState *interp)
static int
init_zipimport(PyThreadState *tstate, int verbose)
{
- PyObject *path_hooks = PySys_GetObject("path_hooks");
+ PyObject *path_hooks = _PySys_GetRequiredAttrString("path_hooks");
if (path_hooks == NULL) {
- _PyErr_SetString(tstate, PyExc_RuntimeError,
- "unable to get sys.path_hooks");
return -1;
}
@@ -3239,12 +3249,14 @@ init_zipimport(PyThreadState *tstate, int verbose)
int err = PyList_Insert(path_hooks, 0, zipimporter);
Py_DECREF(zipimporter);
if (err < 0) {
+ Py_DECREF(path_hooks);
return -1;
}
if (verbose) {
PySys_WriteStderr("# installed zipimport hook\n");
}
}
+ Py_DECREF(path_hooks);
return 0;
}