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 3f6222b

Browse filesBrowse files
committed
Bug fix for type_lock_prevent_release().
If the two mutex form of the critical section is used, need to put the other mutex into '_cs_mutex'.
1 parent a1c6b05 commit 3f6222b
Copy full SHA for 3f6222b

File tree

Expand file treeCollapse file tree

1 file changed

+12
-15
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-15
lines changed

‎Objects/typeobject.c

Copy file name to clipboardExpand all lines: Objects/typeobject.c
+12-15Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,18 @@ type_lock_prevent_release(void)
144144
PyThreadState *tstate = _PyThreadState_GET();
145145
uintptr_t *tagptr = &tstate->critical_section;
146146
PyCriticalSection *c = (PyCriticalSection *)(*tagptr & ~_Py_CRITICAL_SECTION_MASK);
147-
if (c->_cs_mutex == TYPE_LOCK) {
147+
if (!(*tagptr & _Py_CRITICAL_SECTION_TWO_MUTEXES)) {
148+
assert(c->_cs_mutex == TYPE_LOCK);
148149
c->_cs_mutex = NULL;
149150
}
150151
else {
151-
assert(*tagptr & _Py_CRITICAL_SECTION_TWO_MUTEXES);
152152
PyCriticalSection2 *c2 = (PyCriticalSection2 *)c;
153-
if (c2->_cs_mutex2 == TYPE_LOCK) {
154-
c2->_cs_mutex2 = NULL;
155-
}
156-
else {
157-
assert(0); // TYPE_LOCK must be one of the mutexes
153+
if (c->_cs_mutex == TYPE_LOCK) {
154+
c->_cs_mutex = c2->_cs_mutex2;
155+
c2->_cs_mutex2 = NULL;
156+
} else {
157+
assert(c2->_cs_mutex2 == TYPE_LOCK);
158+
c2->_cs_mutex2 = NULL;
158159
}
159160
}
160161
}
@@ -165,18 +166,14 @@ type_lock_allow_release(void)
165166
PyThreadState *tstate = _PyThreadState_GET();
166167
uintptr_t *tagptr = &tstate->critical_section;
167168
PyCriticalSection *c = (PyCriticalSection *)(*tagptr & ~_Py_CRITICAL_SECTION_MASK);
168-
if (c->_cs_mutex == NULL) {
169+
if (!(*tagptr & _Py_CRITICAL_SECTION_TWO_MUTEXES)) {
170+
assert(c->_cs_mutex == NULL);
169171
c->_cs_mutex = TYPE_LOCK;
170172
}
171173
else {
172-
assert(*tagptr & _Py_CRITICAL_SECTION_TWO_MUTEXES);
173174
PyCriticalSection2 *c2 = (PyCriticalSection2 *)c;
174-
if (c2->_cs_mutex2 == NULL) {
175-
c2->_cs_mutex2 = TYPE_LOCK;
176-
}
177-
else {
178-
assert(0);
179-
}
175+
assert(c2->_cs_mutex2 == NULL);
176+
c2->_cs_mutex2 = TYPE_LOCK;
180177
}
181178
}
182179

0 commit comments

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