Skip to content

Commit d84ef06

Browse files
authored
Merge branch 'main' into fix-pythongh-144681
2 parents aa8ef2e + 099943b commit d84ef06

File tree

14 files changed

+157
-169
lines changed

14 files changed

+157
-169
lines changed

Doc/faq/programming.rst

Lines changed: 68 additions & 62 deletions
Large diffs are not rendered by default.

Doc/installing/index.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
Installing Python Modules
77
*************************
88

9-
:Email: distutils-sig@python.org
10-
119
As a popular open source development project, Python has an active
1210
supporting community of contributors and users that also make their software
1311
available for other Python developers to use under open source license terms.

Lib/test/test_listcomps.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,18 @@ def test_references___class___defined(self):
180180
code, outputs={"res": [2]}, scopes=["module", "function"])
181181
self._check_in_scopes(code, raises=NameError, scopes=["class"])
182182

183+
def test_references___classdict__(self):
184+
code = """
185+
class i: [__classdict__ for x in y]
186+
"""
187+
self._check_in_scopes(code, raises=NameError)
188+
189+
def test_references___conditional_annotations__(self):
190+
code = """
191+
class i: [__conditional_annotations__ for x in y]
192+
"""
193+
self._check_in_scopes(code, raises=NameError)
194+
183195
def test_references___class___enclosing(self):
184196
code = """
185197
__class__ = 2

Makefile.pre.in

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,9 +1729,6 @@ FROZEN_FILES_IN = \
17291729
Lib/zipimport.py \
17301730
Lib/abc.py \
17311731
Lib/codecs.py \
1732-
Lib/encodings/__init__.py \
1733-
Lib/encodings/aliases.py \
1734-
Lib/encodings/utf_8.py \
17351732
Lib/io.py \
17361733
Lib/_collections_abc.py \
17371734
Lib/_sitebuiltins.py \
@@ -1741,7 +1738,6 @@ FROZEN_FILES_IN = \
17411738
Lib/os.py \
17421739
Lib/site.py \
17431740
Lib/stat.py \
1744-
Lib/linecache.py \
17451741
Lib/importlib/util.py \
17461742
Lib/importlib/machinery.py \
17471743
Lib/runpy.py \
@@ -1758,9 +1754,6 @@ FROZEN_FILES_OUT = \
17581754
Python/frozen_modules/zipimport.h \
17591755
Python/frozen_modules/abc.h \
17601756
Python/frozen_modules/codecs.h \
1761-
Python/frozen_modules/encodings.h \
1762-
Python/frozen_modules/encodings.aliases.h \
1763-
Python/frozen_modules/encodings.utf_8.h \
17641757
Python/frozen_modules/io.h \
17651758
Python/frozen_modules/_collections_abc.h \
17661759
Python/frozen_modules/_sitebuiltins.h \
@@ -1770,7 +1763,6 @@ FROZEN_FILES_OUT = \
17701763
Python/frozen_modules/os.h \
17711764
Python/frozen_modules/site.h \
17721765
Python/frozen_modules/stat.h \
1773-
Python/frozen_modules/linecache.h \
17741766
Python/frozen_modules/importlib.util.h \
17751767
Python/frozen_modules/importlib.machinery.h \
17761768
Python/frozen_modules/runpy.h \
@@ -1810,15 +1802,6 @@ Python/frozen_modules/abc.h: Lib/abc.py $(FREEZE_MODULE_DEPS)
18101802
Python/frozen_modules/codecs.h: Lib/codecs.py $(FREEZE_MODULE_DEPS)
18111803
$(FREEZE_MODULE) codecs $(srcdir)/Lib/codecs.py Python/frozen_modules/codecs.h
18121804

1813-
Python/frozen_modules/encodings.h: Lib/encodings/__init__.py $(FREEZE_MODULE_DEPS)
1814-
$(FREEZE_MODULE) encodings $(srcdir)/Lib/encodings/__init__.py Python/frozen_modules/encodings.h
1815-
1816-
Python/frozen_modules/encodings.aliases.h: Lib/encodings/aliases.py $(FREEZE_MODULE_DEPS)
1817-
$(FREEZE_MODULE) encodings.aliases $(srcdir)/Lib/encodings/aliases.py Python/frozen_modules/encodings.aliases.h
1818-
1819-
Python/frozen_modules/encodings.utf_8.h: Lib/encodings/utf_8.py $(FREEZE_MODULE_DEPS)
1820-
$(FREEZE_MODULE) encodings.utf_8 $(srcdir)/Lib/encodings/utf_8.py Python/frozen_modules/encodings.utf_8.h
1821-
18221805
Python/frozen_modules/io.h: Lib/io.py $(FREEZE_MODULE_DEPS)
18231806
$(FREEZE_MODULE) io $(srcdir)/Lib/io.py Python/frozen_modules/io.h
18241807

@@ -1846,9 +1829,6 @@ Python/frozen_modules/site.h: Lib/site.py $(FREEZE_MODULE_DEPS)
18461829
Python/frozen_modules/stat.h: Lib/stat.py $(FREEZE_MODULE_DEPS)
18471830
$(FREEZE_MODULE) stat $(srcdir)/Lib/stat.py Python/frozen_modules/stat.h
18481831

1849-
Python/frozen_modules/linecache.h: Lib/linecache.py $(FREEZE_MODULE_DEPS)
1850-
$(FREEZE_MODULE) linecache $(srcdir)/Lib/linecache.py Python/frozen_modules/linecache.h
1851-
18521832
Python/frozen_modules/importlib.util.h: Lib/importlib/util.py $(FREEZE_MODULE_DEPS)
18531833
$(FREEZE_MODULE) importlib.util $(srcdir)/Lib/importlib/util.py Python/frozen_modules/importlib.util.h
18541834

Misc/NEWS.d/next/Core_and_Builtins/2026-02-26-21-22-34.gh-issue-145278.DHkYqt.rst

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix :exc:`SystemError` when ``__classdict__`` or
2+
``__conditional_annotations__`` is in a class-scope inlined comprehension.
3+
Found by OSS Fuzz in :oss-fuzz:`491105000`.

Modules/_xxtestfuzz/fuzzer.c

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ static int fuzz_pycompile(const char* data, size_t size) {
517517
return 0;
518518
}
519519

520-
// Need 2 bytes for parameter selection
521-
if (size < 2) {
520+
// Need 3 bytes for parameter selection
521+
if (size < 3) {
522522
return 0;
523523
}
524524

@@ -530,25 +530,39 @@ static int fuzz_pycompile(const char* data, size_t size) {
530530
unsigned char optimize_idx = (unsigned char) data[1];
531531
int optimize = optimize_vals[optimize_idx % NUM_OPTIMIZE_VALS];
532532

533+
// Use third byte to determine compiler flags to use.
534+
unsigned char flags_byte = (unsigned char) data[2];
535+
PyCompilerFlags flags = _PyCompilerFlags_INIT;
536+
if (flags_byte & 0x01) {
537+
flags.cf_flags |= PyCF_DONT_IMPLY_DEDENT;
538+
}
539+
if (flags_byte & 0x02) {
540+
flags.cf_flags |= PyCF_ONLY_AST;
541+
}
542+
if (flags_byte & 0x04) {
543+
flags.cf_flags |= PyCF_IGNORE_COOKIE;
544+
}
545+
if (flags_byte & 0x08) {
546+
flags.cf_flags |= PyCF_TYPE_COMMENTS;
547+
}
548+
if (flags_byte & 0x10) {
549+
flags.cf_flags |= PyCF_ALLOW_TOP_LEVEL_AWAIT;
550+
}
551+
if (flags_byte & 0x20) {
552+
flags.cf_flags |= PyCF_ALLOW_INCOMPLETE_INPUT;
553+
}
554+
if (flags_byte & 0x40) {
555+
flags.cf_flags |= PyCF_OPTIMIZED_AST;
556+
}
557+
533558
char pycompile_scratch[MAX_PYCOMPILE_TEST_SIZE];
534559

535560
// Create a NUL-terminated C string from the remaining input
536-
memcpy(pycompile_scratch, data + 2, size - 2);
561+
memcpy(pycompile_scratch, data + 3, size - 3);
537562
// Put a NUL terminator just after the copied data. (Space was reserved already.)
538-
pycompile_scratch[size - 2] = '\0';
539-
540-
// XXX: instead of always using NULL for the `flags` value to
541-
// `Py_CompileStringExFlags`, there are many flags that conditionally
542-
// change parser behavior:
543-
//
544-
// #define PyCF_TYPE_COMMENTS 0x1000
545-
// #define PyCF_ALLOW_TOP_LEVEL_AWAIT 0x2000
546-
// #define PyCF_ONLY_AST 0x0400
547-
//
548-
// It would be good to test various combinations of these, too.
549-
PyCompilerFlags *flags = NULL;
550-
551-
PyObject *result = Py_CompileStringExFlags(pycompile_scratch, "<fuzz input>", start, flags, optimize);
563+
pycompile_scratch[size - 3] = '\0';
564+
565+
PyObject *result = Py_CompileStringExFlags(pycompile_scratch, "<fuzz input>", start, &flags, optimize);
552566
if (result == NULL) {
553567
/* Compilation failed, most likely from a syntax error. If it was a
554568
SystemError we abort. There's no non-bug reason to raise a

Modules/getpath.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,9 @@ def search_up(prefix, *landmarks, test=isfile):
776776
# Warn if the standard library is missing, unless pythonpath_was_set was set, as
777777
# that skips parts of the stdlib directories calculation — assume the provided
778778
# pythonpath is correct. This is how subinterpreters initialize the path for eg.
779-
if not py_setpath and not pythonpath_was_set and (not stdlib_zip or not isfile(stdlib_zip)):
779+
if not py_setpath and not pythonpath_was_set:
780780
home_hint = f"The Python 'home' directory was set to {home!r}, is this correct?"
781-
if not stdlib_dir or not isdir(stdlib_dir):
781+
if (not stdlib_zip or not isfile(stdlib_zip)) and (not stdlib_dir or not isdir(stdlib_dir)):
782782
hint = home_hint if home else f'sys.prefix is set to {prefix}, is this correct?'
783783
warn('WARN: Could not find the standard library directory! ' + hint)
784784
elif not platstdlib_dir or not isdir(platstdlib_dir):

Objects/typeobject.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,6 @@ clear_tp_bases(PyTypeObject *self, int final)
647647
static inline PyObject *
648648
lookup_tp_mro(PyTypeObject *self)
649649
{
650-
ASSERT_NEW_TYPE_OR_LOCKED(self);
651650
return self->tp_mro;
652651
}
653652

@@ -664,8 +663,19 @@ set_tp_mro(PyTypeObject *self, PyObject *mro, int initial)
664663
/* Other checks are done via set_tp_bases. */
665664
_Py_SetImmortal(mro);
666665
}
666+
else {
667+
PyUnstable_Object_EnableDeferredRefcount(mro);
668+
}
669+
}
670+
if (!initial) {
671+
type_lock_prevent_release();
672+
types_stop_world();
667673
}
668674
self->tp_mro = mro;
675+
if (!initial) {
676+
types_start_world();
677+
type_lock_allow_release();
678+
}
669679
}
670680

671681
static inline void
@@ -1728,18 +1738,11 @@ static PyObject *
17281738
type_get_mro(PyObject *tp, void *Py_UNUSED(closure))
17291739
{
17301740
PyTypeObject *type = PyTypeObject_CAST(tp);
1731-
PyObject *mro;
1732-
1733-
BEGIN_TYPE_LOCK();
1734-
mro = lookup_tp_mro(type);
1741+
PyObject *mro = lookup_tp_mro(type);
17351742
if (mro == NULL) {
1736-
mro = Py_None;
1737-
} else {
1738-
Py_INCREF(mro);
1743+
Py_RETURN_NONE;
17391744
}
1740-
1741-
END_TYPE_LOCK();
1742-
return mro;
1745+
return Py_NewRef(mro);
17431746
}
17441747

17451748
static PyTypeObject *find_best_base(PyObject *);

PCbuild/_freeze_module.vcxproj

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -310,21 +310,6 @@
310310
<IntFile>$(IntDir)codecs.g.h</IntFile>
311311
<OutFile>$(GeneratedFrozenModulesDir)Python\frozen_modules\codecs.h</OutFile>
312312
</None>
313-
<None Include="..\Lib\encodings\__init__.py">
314-
<ModName>encodings</ModName>
315-
<IntFile>$(IntDir)encodings.g.h</IntFile>
316-
<OutFile>$(GeneratedFrozenModulesDir)Python\frozen_modules\encodings.h</OutFile>
317-
</None>
318-
<None Include="..\Lib\encodings\aliases.py">
319-
<ModName>encodings.aliases</ModName>
320-
<IntFile>$(IntDir)encodings.aliases.g.h</IntFile>
321-
<OutFile>$(GeneratedFrozenModulesDir)Python\frozen_modules\encodings.aliases.h</OutFile>
322-
</None>
323-
<None Include="..\Lib\encodings\utf_8.py">
324-
<ModName>encodings.utf_8</ModName>
325-
<IntFile>$(IntDir)encodings.utf_8.g.h</IntFile>
326-
<OutFile>$(GeneratedFrozenModulesDir)Python\frozen_modules\encodings.utf_8.h</OutFile>
327-
</None>
328313
<None Include="..\Lib\io.py">
329314
<ModName>io</ModName>
330315
<IntFile>$(IntDir)io.g.h</IntFile>
@@ -370,11 +355,6 @@
370355
<IntFile>$(IntDir)stat.g.h</IntFile>
371356
<OutFile>$(GeneratedFrozenModulesDir)Python\frozen_modules\stat.h</OutFile>
372357
</None>
373-
<None Include="..\Lib\linecache.py">
374-
<ModName>linecache</ModName>
375-
<IntFile>$(IntDir)linecache.g.h</IntFile>
376-
<OutFile>$(GeneratedFrozenModulesDir)Python\frozen_modules\linecache.h</OutFile>
377-
</None>
378358
<None Include="..\Lib\importlib\util.py">
379359
<ModName>importlib.util</ModName>
380360
<IntFile>$(IntDir)importlib.util.g.h</IntFile>

0 commit comments

Comments
 (0)