Skip to content

Commit 360303f

Browse files
Revert "Try to add thread safety to pointer_type"
This reverts commit 62d2deb.
1 parent 62d2deb commit 360303f

File tree

2 files changed

+11
-29
lines changed

2 files changed

+11
-29
lines changed

Modules/_ctypes/_ctypes.c

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,8 @@ ctype_get_pointer_type(PyObject *self, void *Py_UNUSED(ignored))
588588
return NULL;
589589
}
590590

591-
PyObject* pointer_type = FT_ATOMIC_LOAD_PTR_ACQUIRE(info->pointer_type);
592-
if (pointer_type) {
593-
return Py_NewRef(pointer_type);
591+
if (info->pointer_type) {
592+
return Py_NewRef(info->pointer_type);
594593
}
595594
Py_RETURN_NONE;
596595
}
@@ -1228,39 +1227,26 @@ PyCPointerType_SetProto(ctypes_state *st, PyObject *self, StgInfo *stginfo, PyOb
12281227
PyErr_Format(PyExc_TypeError, "%R must have storage info", proto);
12291228
return -1;
12301229
}
1231-
1232-
PyObject* pointer_type = FT_ATOMIC_LOAD_PTR_ACQUIRE(info->pointer_type);
1233-
PyObject* stginfo_proto = FT_ATOMIC_LOAD_PTR_ACQUIRE(stginfo->proto);
1234-
1235-
if (pointer_type && pointer_type != self) {
1230+
if (info->pointer_type && info->pointer_type != self) {
12361231
PyErr_Format(PyExc_TypeError,
12371232
"pointer type already set: old=%R, new=%R",
1238-
pointer_type, self);
1233+
info->pointer_type, self);
12391234
return -1;
12401235
}
1241-
if (stginfo_proto && stginfo_proto != proto) {
1236+
if (stginfo->proto && stginfo->proto != proto) {
12421237
PyErr_Format(PyExc_TypeError,
12431238
"cls type already set: old=%R, new=%R",
1244-
stginfo_proto, proto);
1239+
stginfo->proto, proto);
12451240
return -1;
12461241
}
12471242

1248-
if (!stginfo_proto || !pointer_type) {
1249-
STGINFO2_LOCK(stginfo, info);
1250-
1251-
stginfo_proto = FT_ATOMIC_LOAD_PTR_ACQUIRE(stginfo->proto);
1252-
if (!stginfo_proto) {
1253-
FT_ATOMIC_STORE_PTR_RELEASE(stginfo->proto, Py_NewRef(proto));
1254-
}
1255-
1256-
pointer_type = FT_ATOMIC_LOAD_PTR_ACQUIRE(info->pointer_type);
1257-
if (!pointer_type) {
1258-
FT_ATOMIC_STORE_PTR_RELEASE(info->pointer_type, Py_NewRef(self));
1259-
}
1260-
1261-
STGINFO2_UNLOCK();
1243+
if (!stginfo->proto) {
1244+
stginfo->proto = Py_NewRef(proto);
12621245
}
12631246

1247+
if (!info->pointer_type) {
1248+
info->pointer_type = Py_NewRef(self);
1249+
}
12641250
return 0;
12651251
}
12661252

Modules/_ctypes/ctypes.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,6 @@ typedef struct {
422422
#define STGINFO_LOCK(stginfo) Py_BEGIN_CRITICAL_SECTION_MUT(&(stginfo)->mutex)
423423
#define STGINFO_UNLOCK() Py_END_CRITICAL_SECTION()
424424

425-
#define STGINFO2_LOCK(stginfo_a, stginfo_b) \
426-
Py_BEGIN_CRITICAL_SECTION2_MUT(&(stginfo_a)->mutex, &(stginfo_b)->mutex)
427-
#define STGINFO2_UNLOCK() Py_END_CRITICAL_SECTION2()
428-
429425
static inline uint8_t
430426
stginfo_get_dict_final(StgInfo *info)
431427
{

0 commit comments

Comments
 (0)