Skip to content

Commit 7a44c77

Browse files
committed
Only lock if we're not self.
1 parent c31a405 commit 7a44c77

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

Modules/_ctypes/_ctypes.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5499,10 +5499,14 @@ Pointer_set_contents(PyObject *op, PyObject *value, void *closure)
54995499
}
55005500

55015501
dst = (CDataObject *)value;
5502-
assert(dst != self); // XXX Can the user do this?
5503-
LOCK_PTR(dst);
5504-
locked_deref_assign(self, dst->b_ptr);
5505-
UNLOCK_PTR(dst);
5502+
if (dst != self) {
5503+
LOCK_PTR(dst);
5504+
locked_deref_assign(self, dst->b_ptr);
5505+
UNLOCK_PTR(dst);
5506+
} else {
5507+
// We already hold the lock
5508+
*((void **)self->b_ptr) = dst->b_ptr;
5509+
}
55065510

55075511
/*
55085512
A Pointer instance must keep the value it points to alive. So, a

0 commit comments

Comments
 (0)