aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Python/importdl.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-02-12 07:53:52 +0300
committershadchin <shadchin@yandex-team.com>2024-02-12 08:07:36 +0300
commitce1b7ca3171f9158180640c6a02a74b4afffedea (patch)
treee47c1e8391b1b0128262c1e9b1e6ed4c8fff2348 /contrib/tools/python3/src/Python/importdl.c
parent57350d96f030db90f220ce50ee591d5c5d403df7 (diff)
downloadydb-ce1b7ca3171f9158180640c6a02a74b4afffedea.tar.gz
Update Python from 3.11.8 to 3.12.2
Diffstat (limited to 'contrib/tools/python3/src/Python/importdl.c')
-rw-r--r--contrib/tools/python3/src/Python/importdl.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/contrib/tools/python3/src/Python/importdl.c b/contrib/tools/python3/src/Python/importdl.c
index 870ae27300..3a3a30ddbd 100644
--- a/contrib/tools/python3/src/Python/importdl.c
+++ b/contrib/tools/python3/src/Python/importdl.c
@@ -3,6 +3,7 @@
#include "Python.h"
#include "pycore_call.h"
+#include "pycore_import.h"
#include "pycore_pystate.h"
#include "pycore_runtime.h"
@@ -99,7 +100,7 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
#endif
PyObject *name_unicode = NULL, *name = NULL, *path = NULL, *m = NULL;
const char *name_buf, *hook_prefix;
- const char *oldcontext;
+ const char *oldcontext, *newcontext;
dl_funcptr exportfunc;
PyModuleDef *def;
PyModInitFunction p0;
@@ -113,6 +114,10 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
"spec.name must be a string");
goto error;
}
+ newcontext = PyUnicode_AsUTF8(name_unicode);
+ if (newcontext == NULL) {
+ goto error;
+ }
name = get_encoded_name(name_unicode, &hook_prefix);
if (name == NULL) {
@@ -160,14 +165,9 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
p0 = (PyModInitFunction)exportfunc;
/* Package context is needed for single-phase init */
- oldcontext = _Py_PackageContext;
- _Py_PackageContext = PyUnicode_AsUTF8(name_unicode);
- if (_Py_PackageContext == NULL) {
- _Py_PackageContext = oldcontext;
- goto error;
- }
+ oldcontext = _PyImport_SwapPackageContext(newcontext);
m = _PyImport_InitFunc_TrampolineCall(p0);
- _Py_PackageContext = oldcontext;
+ _PyImport_SwapPackageContext(oldcontext);
if (m == NULL) {
if (!PyErr_Occurred()) {
@@ -178,8 +178,7 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
}
goto error;
} else if (PyErr_Occurred()) {
- PyErr_Clear();
- PyErr_Format(
+ _PyErr_FormatFromCause(
PyExc_SystemError,
"initialization of %s raised unreported exception",
name_buf);
@@ -205,6 +204,10 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
/* Fall back to single-phase init mechanism */
+ if (_PyImport_CheckSubinterpIncompatibleExtensionAllowed(name_buf) < 0) {
+ goto error;
+ }
+
if (hook_prefix == nonascii_prefix) {
/* don't allow legacy init for non-ASCII module names */
PyErr_Format(