| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1fc41ae commit a2d8c4b
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,6 +47,7 @@ Objects/clinic/*.h linguist-generated=true | |||
| 47 | 47 | PC/clinic/*.h linguist-generated=true | |
| 48 | 48 | Python/clinic/*.h linguist-generated=true | |
| 49 | 49 | Python/frozen_modules/*.h linguist-generated=true | |
| 50 | + Python/frozen_modules/MANIFEST linguist-generated=true | ||
| 50 | 51 | Include/internal/pycore_ast.h linguist-generated=true | |
| 51 | 52 | Python/Python-ast.c linguist-generated=true | |
| 52 | 53 | Include/opcode.h linguist-generated=true | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -121,6 +121,13 @@ Tools/msi/obj | |||
| 121 | 121 | Tools/ssl/amd64 | |
| 122 | 122 | Tools/ssl/win32 | |
| 123 | 123 | ||
| 124 | + # TODO: Once we auto-regen frozem modules for Windows builds | ||
| 125 | + # we can drop the .h files from the repo and ignore them here. | ||
| 126 | + # At that point we will rely the frozen manifest file to identify | ||
| 127 | + # changed generated files. We'll drop the entry for it then. | ||
| 128 | + # See: Tools/scripts/freeze_modules.py. | ||
| 129 | + #Python/frozen_modules/*.h | ||
| 130 | + | ||
| 124 | 131 | # Two-trick pony for OSX and other case insensitive file systems: | |
| 125 | 132 | # Ignore ./python binary on Unix but still look into ./Python/ directory. | |
| 126 | 133 | /python | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,9 +2,12 @@ | |||
| 2 | 2 | A testcase which accesses *values* in a dll. | |
| 3 | 3 | """ | |
| 4 | 4 | ||
| 5 | + import imp | ||
| 6 | + import importlib.util | ||
| 5 | 7 | import unittest | |
| 6 | 8 | import sys | |
| 7 | 9 | from ctypes import * | |
| 10 | + from test.support import import_helper, captured_stdout | ||
| 8 | 11 | ||
| 9 | 12 | import _ctypes_test | |
| 10 | 13 | ||
@@ -55,41 +58,32 @@ class struct_frozen(Structure): | |||
| 55 | 58 | ||
| 56 | 59 | ft = FrozenTable.in_dll(pythonapi, "PyImport_FrozenModules") | |
| 57 | 60 | # ft is a pointer to the struct_frozen entries: | |
| 58 | - items = [] | ||
| 59 | - # _frozen_importlib changes size whenever importlib._bootstrap | ||
| 60 | - # changes, so it gets a special case. We should make sure it's | ||
| 61 | - # found, but don't worry about its size too much. The same | ||
| 62 | - # applies to _frozen_importlib_external. | ||
| 63 | - bootstrap_seen = [] | ||
| 64 | - bootstrap_expected = [ | ||
| 65 | - b'_frozen_importlib', | ||
| 66 | - b'_frozen_importlib_external', | ||
| 67 | - b'zipimport', | ||
| 68 | - ] | ||
| 61 | + modules = [] | ||
| 69 | 62 | for entry in ft: | |
| 70 | 63 | # This is dangerous. We *can* iterate over a pointer, but | |
| 71 | 64 | # the loop will not terminate (maybe with an access | |
| 72 | 65 | # violation;-) because the pointer instance has no size. | |
| 73 | 66 | if entry.name is None: | |
| 74 | 67 | break | |
| 75 | - | ||
| 76 | - if entry.name in bootstrap_expected: | ||
| 77 | - bootstrap_seen.append(entry.name) | ||
| 78 | - self.assertTrue(entry.size, | ||
| 79 | - "{!r} was reported as having no size".format(entry.name)) | ||
| 80 | - continue | ||
| 81 | - items.append((entry.name.decode("ascii"), entry.size)) | ||
| 82 | - | ||
| 83 | - expected = [("__hello__", 164), | ||
| 84 | - ("__phello__", -164), | ||
| 85 | - ("__phello__.spam", 164), | ||
| 86 | - ] | ||
| 87 | - self.assertEqual(items, expected, "PyImport_FrozenModules example " | ||
| 68 | + modname = entry.name.decode("ascii") | ||
| 69 | + modules.append(modname) | ||
| 70 | + with self.subTest(modname): | ||
| 71 | + # Do a sanity check on entry.size and entry.code. | ||
| 72 | + self.assertGreater(abs(entry.size), 10) | ||
| 73 | + self.assertTrue([entry.code[i] for i in range(abs(entry.size))]) | ||
| 74 | + # Check the module's package-ness. | ||
| 75 | + spec = importlib.util.find_spec(modname) | ||
| 76 | + if entry.size < 0: | ||
| 77 | + # It's a package. | ||
| 78 | + self.assertIsNotNone(spec.submodule_search_locations) | ||
| 79 | + else: | ||
| 80 | + self.assertIsNone(spec.submodule_search_locations) | ||
| 81 | + | ||
| 82 | + expected = imp._frozen_module_names() | ||
| 83 | + self.maxDiff = None | ||
| 84 | + self.assertEqual(modules, expected, "PyImport_FrozenModules example " | ||
| 88 | 85 | "in Doc/library/ctypes.rst may be out of date") | |
| 89 | 86 | ||
| 90 | - self.assertEqual(sorted(bootstrap_seen), bootstrap_expected, | ||
| 91 | - "frozen bootstrap modules did not match PyImport_FrozenModules") | ||
| 92 | - | ||
| 93 | 87 | from ctypes import _pointer_type_cache | |
| 94 | 88 | del _pointer_type_cache[struct_frozen] | |
| 95 | 89 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ | |||
| 9 | 9 | from _imp import (lock_held, acquire_lock, release_lock, | |
| 10 | 10 | get_frozen_object, is_frozen_package, | |
| 11 | 11 | init_frozen, is_builtin, is_frozen, | |
| 12 | - _fix_co_filename) | ||
| 12 | + _fix_co_filename, _frozen_module_names) | ||
| 13 | 13 | try: | |
| 14 | 14 | from _imp import create_dynamic | |
| 15 | 15 | except ImportError: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -750,22 +750,22 @@ regen-frozen: Tools/scripts/freeze_modules.py $(FROZEN_FILES) | |||
| 750 | 750 | ||
| 751 | 751 | # BEGIN: freezing modules | |
| 752 | 752 | ||
| 753 | - Python/frozen_modules/importlib__bootstrap.h: $(srcdir)/Programs/_freeze_module $(srcdir)/Lib/importlib/_bootstrap.py | ||
| 753 | + Python/frozen_modules/importlib__bootstrap.h: Programs/_freeze_module Lib/importlib/_bootstrap.py | ||
| 754 | 754 | $(srcdir)/Programs/_freeze_module importlib._bootstrap \ | |
| 755 | 755 | $(srcdir)/Lib/importlib/_bootstrap.py \ | |
| 756 | 756 | $(srcdir)/Python/frozen_modules/importlib__bootstrap.h | |
| 757 | 757 | ||
| 758 | - Python/frozen_modules/importlib__bootstrap_external.h: $(srcdir)/Programs/_freeze_module $(srcdir)/Lib/importlib/_bootstrap_external.py | ||
| 758 | + Python/frozen_modules/importlib__bootstrap_external.h: Programs/_freeze_module Lib/importlib/_bootstrap_external.py | ||
| 759 | 759 | $(srcdir)/Programs/_freeze_module importlib._bootstrap_external \ | |
| 760 | 760 | $(srcdir)/Lib/importlib/_bootstrap_external.py \ | |
| 761 | 761 | $(srcdir)/Python/frozen_modules/importlib__bootstrap_external.h | |
| 762 | 762 | ||
| 763 | - Python/frozen_modules/zipimport.h: $(srcdir)/Programs/_freeze_module $(srcdir)/Lib/zipimport.py | ||
| 763 | + Python/frozen_modules/zipimport.h: Programs/_freeze_module Lib/zipimport.py | ||
| 764 | 764 | $(srcdir)/Programs/_freeze_module zipimport \ | |
| 765 | 765 | $(srcdir)/Lib/zipimport.py \ | |
| 766 | 766 | $(srcdir)/Python/frozen_modules/zipimport.h | |
| 767 | 767 | ||
| 768 | - Python/frozen_modules/hello.h: $(srcdir)/Programs/_freeze_module $(srcdir)/Tools/freeze/flag.py | ||
| 768 | + Python/frozen_modules/hello.h: Programs/_freeze_module Tools/freeze/flag.py | ||
| 769 | 769 | $(srcdir)/Programs/_freeze_module hello \ | |
| 770 | 770 | $(srcdir)/Tools/freeze/flag.py \ | |
| 771 | 771 | $(srcdir)/Python/frozen_modules/hello.h | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,7 +47,7 @@ | |||
| 47 | 47 | /* Note that a negative size indicates a package. */ | |
| 48 | 48 | ||
| 49 | 49 | static const struct _frozen _PyImport_FrozenModules[] = { | |
| 50 | - /* importlib */ | ||
| 50 | + /* import system */ | ||
| 51 | 51 | {"_frozen_importlib", _Py_M__importlib__bootstrap, | |
| 52 | 52 | (int)sizeof(_Py_M__importlib__bootstrap)}, | |
| 53 | 53 | {"_frozen_importlib_external", _Py_M__importlib__bootstrap_external, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,7 @@ | |||
| 1 | + This directory contains the generated .h files for all the frozen | ||
| 2 | + modules. Python/frozen.c depends on these files. | ||
| 3 | + | ||
| 4 | + Note that, other than the required frozen modules, none of these files | ||
| 5 | + are committed into the repo. | ||
| 6 | + | ||
| 7 | + See Tools/scripts/freeze_modules.py for more info. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,7 @@ | |||
| 16 | 16 | #include "code.h" | |
| 17 | 17 | #include "importdl.h" | |
| 18 | 18 | #include "pydtrace.h" | |
| 19 | + #include <stdbool.h> | ||
| 19 | 20 | ||
| 20 | 21 | #ifdef HAVE_FCNTL_H | |
| 21 | 22 | #include <fcntl.h> | |
@@ -1049,6 +1050,32 @@ _imp_create_builtin(PyObject *module, PyObject *spec) | |||
| 1049 | 1050 | ||
| 1050 | 1051 | /* Frozen modules */ | |
| 1051 | 1052 | ||
| 1053 | + static PyObject * | ||
| 1054 | + list_frozen_module_names(bool force) | ||
| 1055 | + { | ||
| 1056 | + PyObject *names = PyList_New(0); | ||
| 1057 | + if (names == NULL) { | ||
| 1058 | + return NULL; | ||
| 1059 | + } | ||
| 1060 | + for (const struct _frozen *p = PyImport_FrozenModules; ; p++) { | ||
| 1061 | + if (p->name == NULL) { | ||
| 1062 | + break; | ||
| 1063 | + } | ||
| 1064 | + PyObject *name = PyUnicode_FromString(p->name); | ||
| 1065 | + if (name == NULL) { | ||
| 1066 | + Py_DECREF(names); | ||
| 1067 | + return NULL; | ||
| 1068 | + } | ||
| 1069 | + int res = PyList_Append(names, name); | ||
| 1070 | + Py_DECREF(name); | ||
| 1071 | + if (res != 0) { | ||
| 1072 | + Py_DECREF(names); | ||
| 1073 | + return NULL; | ||
| 1074 | + } | ||
| 1075 | + } | ||
| 1076 | + return names; | ||
| 1077 | + } | ||
| 1078 | + | ||
| 1052 | 1079 | static const struct _frozen * | |
| 1053 | 1080 | find_frozen(PyObject *name) | |
| 1054 | 1081 | { | |
@@ -1954,6 +1981,19 @@ _imp_is_frozen_impl(PyObject *module, PyObject *name) | |||
| 1954 | 1981 | return PyBool_FromLong((long) (p == NULL ? 0 : p->size)); | |
| 1955 | 1982 | } | |
| 1956 | 1983 | ||
| 1984 | + /*[clinic input] | ||
| 1985 | + _imp._frozen_module_names | ||
| 1986 | + | ||
| 1987 | + Returns the list of available frozen modules. | ||
| 1988 | + [clinic start generated code]*/ | ||
| 1989 | + | ||
| 1990 | + static PyObject * | ||
| 1991 | + _imp__frozen_module_names_impl(PyObject *module) | ||
| 1992 | + /*[clinic end generated code: output=80609ef6256310a8 input=76237fbfa94460d2]*/ | ||
| 1993 | + { | ||
| 1994 | + return list_frozen_module_names(true); | ||
| 1995 | + } | ||
| 1996 | + | ||
| 1957 | 1997 | /* Common implementation for _imp.exec_dynamic and _imp.exec_builtin */ | |
| 1958 | 1998 | static int | |
| 1959 | 1999 | exec_builtin_or_dynamic(PyObject *mod) { | |
@@ -2114,6 +2154,7 @@ static PyMethodDef imp_methods[] = { | |||
| 2114 | 2154 | _IMP_INIT_FROZEN_METHODDEF | |
| 2115 | 2155 | _IMP_IS_BUILTIN_METHODDEF | |
| 2116 | 2156 | _IMP_IS_FROZEN_METHODDEF | |
| 2157 | + _IMP__FROZEN_MODULE_NAMES_METHODDEF | ||
| 2117 | 2158 | _IMP_CREATE_DYNAMIC_METHODDEF | |
| 2118 | 2159 | _IMP_EXEC_DYNAMIC_METHODDEF | |
| 2119 | 2160 | _IMP_EXEC_BUILTIN_METHODDEF | |
| Back | FazBrowse Home | New Git URL |
0 commit comments