summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2021-09-13 22:18:37 (GMT)
committerGitHub <noreply@github.com>2021-09-13 22:18:37 (GMT)
commita2d8c4b81b8e68e2ffe10945f7ca69174c14e52a (patch)
treec46c7aead37c0a393f13ef0fb8bb97ea9a9836c6 /Python
parent1fc41ae8709e20d741bd86c2345173688a5e84b0 (diff)
downloadcpython-a2d8c4b81b8e68e2ffe10945f7ca69174c14e52a.zip
cpython-a2d8c4b81b8e68e2ffe10945f7ca69174c14e52a.tar.gz
cpython-a2d8c4b81b8e68e2ffe10945f7ca69174c14e52a.tar.bz2
bpo-45019: Do some cleanup related to frozen modules. (gh-28319)
There are a few things I missed in gh-27980. This is a follow-up that will make subsequent PRs cleaner. It includes fixes to tests and tools that reference the frozen modules. https://bugs.python.org/issue45019
Diffstat (limited to 'Python')
-rw-r--r--Python/clinic/import.c.h20
-rw-r--r--Python/frozen.c2
-rw-r--r--Python/frozen_modules/MANIFEST12
-rw-r--r--Python/frozen_modules/README.txt7
-rw-r--r--Python/import.c41
5 files changed, 80 insertions, 2 deletions
diff --git a/Python/clinic/import.c.h b/Python/clinic/import.c.h
index 4e013cc..ec4ebca 100644
--- a/Python/clinic/import.c.h
+++ b/Python/clinic/import.c.h
@@ -297,6 +297,24 @@ exit:
return return_value;
}
+PyDoc_STRVAR(_imp__frozen_module_names__doc__,
+"_frozen_module_names($module, /)\n"
+"--\n"
+"\n"
+"Returns the list of available frozen modules.");
+
+#define _IMP__FROZEN_MODULE_NAMES_METHODDEF \
+ {"_frozen_module_names", (PyCFunction)_imp__frozen_module_names, METH_NOARGS, _imp__frozen_module_names__doc__},
+
+static PyObject *
+_imp__frozen_module_names_impl(PyObject *module);
+
+static PyObject *
+_imp__frozen_module_names(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return _imp__frozen_module_names_impl(module);
+}
+
#if defined(HAVE_DYNAMIC_LOADING)
PyDoc_STRVAR(_imp_create_dynamic__doc__,
@@ -449,4 +467,4 @@ exit:
#ifndef _IMP_EXEC_DYNAMIC_METHODDEF
#define _IMP_EXEC_DYNAMIC_METHODDEF
#endif /* !defined(_IMP_EXEC_DYNAMIC_METHODDEF) */
-/*[clinic end generated code: output=7c31c433af88af6b input=a9049054013a1b77]*/
+/*[clinic end generated code: output=0ab3fa7c5808bba4 input=a9049054013a1b77]*/
diff --git a/Python/frozen.c b/Python/frozen.c
index 67aff2e..2975b1f 100644
--- a/Python/frozen.c
+++ b/Python/frozen.c
@@ -47,7 +47,7 @@
/* Note that a negative size indicates a package. */
static const struct _frozen _PyImport_FrozenModules[] = {
- /* importlib */
+ /* import system */
{"_frozen_importlib", _Py_M__importlib__bootstrap,
(int)sizeof(_Py_M__importlib__bootstrap)},
{"_frozen_importlib_external", _Py_M__importlib__bootstrap_external,
diff --git a/Python/frozen_modules/MANIFEST b/Python/frozen_modules/MANIFEST
new file mode 100644
index 0000000..42c72b9
--- /dev/null
+++ b/Python/frozen_modules/MANIFEST
@@ -0,0 +1,12 @@
+# The list of frozen modules with key information.
+# Note that the "check_generated_files" CI job will identify
+# when source files were changed but regen-frozen wasn't run.
+# This file is auto-generated by Tools/scripts/freeze_modules.py.
+ module ispkg source frozen checksum
+-------------------------- ----- ------------------------------- ------------------------------- ------------
+_frozen_importlib no <importlib._bootstrap> importlib__bootstrap.h 749d553f858d
+_frozen_importlib_external no <importlib._bootstrap_external> importlib__bootstrap_external.h e4539e6347d7
+zipimport no <zipimport> zipimport.h 374879e5d43d
+__hello__ no Tools/freeze/flag.py hello.h af6fb665713f
+__phello__ YES Tools/freeze/flag.py hello.h af6fb665713f
+__phello__.spam no Tools/freeze/flag.py hello.h af6fb665713f
diff --git a/Python/frozen_modules/README.txt b/Python/frozen_modules/README.txt
new file mode 100644
index 0000000..444167c
--- /dev/null
+++ b/Python/frozen_modules/README.txt
@@ -0,0 +1,7 @@
+This directory contains the generated .h files for all the frozen
+modules. Python/frozen.c depends on these files.
+
+Note that, other than the required frozen modules, none of these files
+are committed into the repo.
+
+See Tools/scripts/freeze_modules.py for more info.
diff --git a/Python/import.c b/Python/import.c
index 7301fcc..d896ff4 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -16,6 +16,7 @@
#include "code.h"
#include "importdl.h"
#include "pydtrace.h"
+#include <stdbool.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
@@ -1049,6 +1050,32 @@ _imp_create_builtin(PyObject *module, PyObject *spec)
/* Frozen modules */
+static PyObject *
+list_frozen_module_names(bool force)
+{
+ PyObject *names = PyList_New(0);
+ if (names == NULL) {
+ return NULL;
+ }
+ for (const struct _frozen *p = PyImport_FrozenModules; ; p++) {
+ if (p->name == NULL) {
+ break;
+ }
+ PyObject *name = PyUnicode_FromString(p->name);
+ if (name == NULL) {
+ Py_DECREF(names);
+ return NULL;
+ }
+ int res = PyList_Append(names, name);
+ Py_DECREF(name);
+ if (res != 0) {
+ Py_DECREF(names);
+ return NULL;
+ }
+ }
+ return names;
+}
+
static const struct _frozen *
find_frozen(PyObject *name)
{
@@ -1954,6 +1981,19 @@ _imp_is_frozen_impl(PyObject *module, PyObject *name)
return PyBool_FromLong((long) (p == NULL ? 0 : p->size));
}
+/*[clinic input]
+_imp._frozen_module_names
+
+Returns the list of available frozen modules.
+[clinic start generated code]*/
+
+static PyObject *
+_imp__frozen_module_names_impl(PyObject *module)
+/*[clinic end generated code: output=80609ef6256310a8 input=76237fbfa94460d2]*/
+{
+ return list_frozen_module_names(true);
+}
+
/* Common implementation for _imp.exec_dynamic and _imp.exec_builtin */
static int
exec_builtin_or_dynamic(PyObject *mod) {
@@ -2114,6 +2154,7 @@ static PyMethodDef imp_methods[] = {
_IMP_INIT_FROZEN_METHODDEF
_IMP_IS_BUILTIN_METHODDEF
_IMP_IS_FROZEN_METHODDEF
+ _IMP__FROZEN_MODULE_NAMES_METHODDEF
_IMP_CREATE_DYNAMIC_METHODDEF
_IMP_EXEC_DYNAMIC_METHODDEF
_IMP_EXEC_BUILTIN_METHODDEF