Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit eecafc3

Browse filesBrowse files
authored
Revert gh-127266: avoid data races when updating type slots (gh-131174) (gh-133129)
This is triggering deadlocks in test_opcache. See GH-133130 for stack trace.
1 parent 219b1f9 commit eecafc3
Copy full SHA for eecafc3

File tree

Expand file treeCollapse file tree

10 files changed

+112
-233
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+112
-233
lines changed

‎Include/internal/pycore_interp_structs.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_interp_structs.h
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,8 @@ struct _Py_interp_cached_objects {
667667

668668
/* object.__reduce__ */
669669
PyObject *objreduce;
670-
#ifndef Py_GIL_DISABLED
671-
/* resolve_slotdups() */
672670
PyObject *type_slots_pname;
673671
pytype_slotdef *type_slots_ptrs[MAX_EQUIV];
674-
#endif
675672

676673
/* TypeVar and related types */
677674
PyTypeObject *generic_type;

‎Include/internal/pycore_object.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_object.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ extern int _PyDict_CheckConsistency(PyObject *mp, int check_content);
313313
// Fast inlined version of PyType_HasFeature()
314314
static inline int
315315
_PyType_HasFeature(PyTypeObject *type, unsigned long feature) {
316-
return ((type->tp_flags) & feature) != 0;
316+
return ((FT_ATOMIC_LOAD_ULONG_RELAXED(type->tp_flags) & feature) != 0);
317317
}
318318

319319
extern void _PyType_InitCache(PyInterpreterState *interp);

‎Include/internal/pycore_typeobject.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_typeobject.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ extern int _PyType_AddMethod(PyTypeObject *, PyMethodDef *);
134134
extern void _PyType_SetFlagsRecursive(PyTypeObject *self, unsigned long mask,
135135
unsigned long flags);
136136

137+
extern unsigned int _PyType_GetVersionForCurrentState(PyTypeObject *tp);
137138
PyAPI_FUNC(void) _PyType_SetVersion(PyTypeObject *tp, unsigned int version);
138139
PyTypeObject *_PyType_LookupByVersion(unsigned int version);
139140

‎Include/object.h

Copy file name to clipboardExpand all lines: Include/object.h
+5-7Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,6 @@ given type object has a specified feature.
620620
#define Py_TPFLAGS_HAVE_FINALIZE (1UL << 0)
621621
#define Py_TPFLAGS_HAVE_VERSION_TAG (1UL << 18)
622622

623-
// Flag values for ob_flags (16 bits available, if SIZEOF_VOID_P > 4).
624-
#define _Py_IMMORTAL_FLAGS (1 << 0)
625-
#define _Py_STATICALLY_ALLOCATED_FLAG (1 << 2)
626-
#if defined(Py_GIL_DISABLED) && defined(Py_DEBUG)
627-
#define _Py_TYPE_REVEALED_FLAG (1 << 3)
628-
#endif
629623

630624
#define Py_CONSTANT_NONE 0
631625
#define Py_CONSTANT_FALSE 1
@@ -782,7 +776,11 @@ PyType_HasFeature(PyTypeObject *type, unsigned long feature)
782776
// PyTypeObject is opaque in the limited C API
783777
flags = PyType_GetFlags(type);
784778
#else
785-
flags = type->tp_flags;
779+
# ifdef Py_GIL_DISABLED
780+
flags = _Py_atomic_load_ulong_relaxed(&type->tp_flags);
781+
# else
782+
flags = type->tp_flags;
783+
# endif
786784
#endif
787785
return ((flags & feature) != 0);
788786
}

‎Include/refcount.h

Copy file name to clipboardExpand all lines: Include/refcount.h
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ immortal. The latter should be the only instances that require
1919
cleanup during runtime finalization.
2020
*/
2121

22+
#define _Py_STATICALLY_ALLOCATED_FLAG 4
23+
#define _Py_IMMORTAL_FLAGS 1
24+
2225
#if SIZEOF_VOID_P > 4
2326
/*
2427
In 64+ bit systems, any object whose 32 bit reference count is >= 2**31

‎Lib/test/test_opcache.py

Copy file name to clipboardExpand all lines: Lib/test/test_opcache.py
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,6 @@ class TestRacesDoNotCrash(TestBase):
576576
# Careful with these. Bigger numbers have a higher chance of catching bugs,
577577
# but you can also burn through a *ton* of type/dict/function versions:
578578
ITEMS = 1000
579-
SMALL_ITEMS = 100
580579
LOOPS = 4
581580
WRITERS = 2
582581

@@ -620,7 +619,7 @@ class C:
620619
__getitem__ = lambda self, item: None
621620

622621
items = []
623-
for _ in range(self.SMALL_ITEMS):
622+
for _ in range(self.ITEMS):
624623
item = C()
625624
items.append(item)
626625
return items
@@ -791,7 +790,7 @@ class C:
791790
__getattribute__ = lambda self, name: None
792791

793792
items = []
794-
for _ in range(self.SMALL_ITEMS):
793+
for _ in range(self.ITEMS):
795794
item = C()
796795
items.append(item)
797796
return items

‎Misc/NEWS.d/next/Core_and_Builtins/2025-03-14-13-08-20.gh-issue-127266._tyfBp.rst

Copy file name to clipboardExpand all lines: Misc/NEWS.d/next/Core_and_Builtins/2025-03-14-13-08-20.gh-issue-127266._tyfBp.rst
-6Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.