Skip to content

Commit b0e06a0

Browse files
improve comments
1 parent 4db3e36 commit b0e06a0

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

Modules/_ctypes/_ctypes.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,14 +712,16 @@ StructUnionType_init(PyObject *self, PyObject *args, PyObject *kwds, int isStruc
712712
return 0;
713713
}
714714
int ret = 0;
715-
STGINFO_LOCK2(info, baseinfo);
715+
STGINFO_LOCK(baseinfo);
716716
/* copy base info */
717717
ret = PyCStgInfo_clone(info, baseinfo);
718718
if (ret >= 0) {
719-
stginfo_clear_dict_final_lock_held(info);
720-
stginfo_set_dict_final_lock_held(baseinfo);
719+
// clear the 'final' bit in the subclass info
720+
// safe to modify without atomics as it is not exposed to other threads
721+
info->dict_final = 0;
722+
stginfo_set_dict_final_lock_held(baseinfo); /* set the 'final' flag in the baseclass info */
721723
}
722-
STGINFO_UNLOCK2();
724+
STGINFO_UNLOCK();
723725
return ret;
724726
}
725727
return 0;

Modules/_ctypes/ctypes.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,7 @@ typedef struct {
424424
*/
425425

426426
#define STGINFO_LOCK(stginfo) Py_BEGIN_CRITICAL_SECTION_MUT(&(stginfo)->mutex)
427-
#define STGINFO_LOCK2(stginfo1, stginfo2) Py_BEGIN_CRITICAL_SECTION2_MUT(&(stginfo1)->mutex, &(stginfo2)->mutex)
428427
#define STGINFO_UNLOCK() Py_END_CRITICAL_SECTION()
429-
#define STGINFO_UNLOCK2() Py_END_CRITICAL_SECTION2()
430428

431429
static inline int
432430
stginfo_get_dict_final(StgInfo *info)
@@ -455,13 +453,6 @@ stginfo_set_dict_final(StgInfo *info)
455453
STGINFO_UNLOCK();
456454
}
457455

458-
static inline void
459-
stginfo_clear_dict_final_lock_held(StgInfo *info)
460-
{
461-
_Py_CRITICAL_SECTION_ASSERT_MUTEX_LOCKED(&info->mutex);
462-
FT_ATOMIC_STORE_INT(info->dict_final, 0);
463-
}
464-
465456
extern int PyCStgInfo_clone(StgInfo *dst_info, StgInfo *src_info);
466457
extern void ctype_clear_stginfo(StgInfo *info);
467458

Modules/_ctypes/stgdict.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
int
2424
PyCStgInfo_clone(StgInfo *dst_info, StgInfo *src_info)
2525
{
26-
_Py_CRITICAL_SECTION_ASSERT_MUTEX_LOCKED(&src_info->mutex);
27-
_Py_CRITICAL_SECTION_ASSERT_MUTEX_LOCKED(&dst_info->mutex);
2826
Py_ssize_t size;
2927

3028
ctype_clear_stginfo(dst_info);
@@ -36,6 +34,9 @@ PyCStgInfo_clone(StgInfo *dst_info, StgInfo *src_info)
3634
dst_info->ffi_type_pointer.elements = NULL;
3735

3836
memcpy(dst_info, src_info, sizeof(StgInfo));
37+
#ifdef Py_GIL_DISABLED
38+
dst_info->mutex = (PyMutex){0};
39+
#endif
3940

4041
Py_XINCREF(dst_info->proto);
4142
Py_XINCREF(dst_info->argtypes);

0 commit comments

Comments
 (0)