@@ -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
55655565static 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+
56255627static PyGetSetDef Pointer_getsets [] = {
56265628 { "contents" , Pointer_get_contents , Pointer_set_contents ,
56275629 "the object this pointer points to (read-write)" , NULL },
0 commit comments