Skip to content

Commit 2652de2

Browse files
committed
Remove usage of locked_deref_assign()
1 parent a17024c commit 2652de2

2 files changed

Lines changed: 13 additions & 20 deletions

File tree

Modules/_ctypes/_ctypes.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3472,9 +3472,9 @@ _PyCData_set(ctypes_state *st,
34723472
}
34733473
Py_BEGIN_CRITICAL_SECTION(src);
34743474
*(void **)ptr = src->b_ptr;
3475-
Py_END_CRITICAL_SECTION();
34763475

34773476
keep = GetKeepedObjects(src);
3477+
Py_END_CRITICAL_SECTION();
34783478
if (keep == NULL)
34793479
return NULL;
34803480

@@ -5563,7 +5563,7 @@ Pointer_get_contents(PyObject *self, void *closure)
55635563
}
55645564

55655565
static int
5566-
Pointer_set_contents(PyObject *op, PyObject *value, void *closure)
5566+
Pointer_set_contents_lock_held(PyObject *op, PyObject *value, void *closure)
55675567
{
55685568
CDataObject *dst;
55695569
PyObject *keep;
@@ -5595,15 +5595,7 @@ Pointer_set_contents(PyObject *op, PyObject *value, void *closure)
55955595
}
55965596

55975597
dst = (CDataObject *)value;
5598-
if (dst != self) {
5599-
Py_BEGIN_CRITICAL_SECTION(dst);
5600-
locked_deref_assign(self, dst->b_ptr);
5601-
Py_END_CRITICAL_SECTION();
5602-
} else {
5603-
Py_BEGIN_CRITICAL_SECTION(self);
5604-
*((void **)self->b_ptr) = dst->b_ptr;
5605-
Py_END_CRITICAL_SECTION();
5606-
}
5598+
*((void **)self->b_ptr) = dst->b_ptr;
56075599

56085600
/*
56095601
A Pointer instance must keep the value it points to alive. So, a
@@ -5622,6 +5614,16 @@ Pointer_set_contents(PyObject *op, PyObject *value, void *closure)
56225614
return KeepRef(self, 0, keep);
56235615
}
56245616

5617+
static int
5618+
Pointer_set_contents(PyObject *op, PyObject *value, void *closure)
5619+
{
5620+
int res;
5621+
Py_BEGIN_CRITICAL_SECTION2(op, value);
5622+
res = Pointer_set_contents_lock_held(op, value, closure);
5623+
Py_END_CRITICAL_SECTION2();
5624+
return res;
5625+
}
5626+
56255627
static PyGetSetDef Pointer_getsets[] = {
56265628
{ "contents", Pointer_get_contents, Pointer_set_contents,
56275629
"the object this pointer points to (read-write)", NULL },

Modules/_ctypes/ctypes.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -654,12 +654,3 @@ locked_deref(CDataObject *self)
654654
Py_END_CRITICAL_SECTION();
655655
return ptr;
656656
}
657-
658-
/* Equivalent to *self->b_ptr = new_ptr with a lock. */
659-
static inline void
660-
locked_deref_assign(CDataObject *self, void *new_ptr)
661-
{
662-
Py_BEGIN_CRITICAL_SECTION(self);
663-
*(void **)self->b_ptr = new_ptr;
664-
Py_END_CRITICAL_SECTION();
665-
}

0 commit comments

Comments
 (0)