Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Lib/test/test_ctypes/test_delattr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from ctypes import Structure, c_char, c_int
from ctypes import POINTER, Structure, c_char, c_int


class X(Structure):
Expand All @@ -16,6 +16,11 @@ def test_chararray(self):
with self.assertRaises(TypeError):
del chararray.value

def test_pointer_contents(self):
ptr = POINTER(c_int)(c_int(42))
with self.assertRaises(TypeError):
del ptr.contents

def test_struct(self):
struct = X()
with self.assertRaises(TypeError):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a crash in the free-threaded build when deleting the :attr:`!contents`
attribute of a :mod:`ctypes` pointer.
10 changes: 5 additions & 5 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -5713,11 +5713,6 @@ Pointer_set_contents_lock_held(PyObject *op, PyObject *value, void *closure)
PyObject *keep;
CDataObject *self = _CDataObject_CAST(op);

if (value == NULL) {
PyErr_SetString(PyExc_TypeError,
"Pointer does not support item deletion");
return -1;
}
ctypes_state *st = get_module_state_by_def(Py_TYPE(Py_TYPE(self)));
StgInfo *stginfo;
if (PyStgInfo_FromObject(st, op, &stginfo) < 0) {
Expand Down Expand Up @@ -5761,6 +5756,11 @@ Pointer_set_contents_lock_held(PyObject *op, PyObject *value, void *closure)
static int
Pointer_set_contents(PyObject *op, PyObject *value, void *closure)
{
if (value == NULL) {
PyErr_SetString(PyExc_TypeError,
"Pointer does not support item deletion");
return -1;
}
int res;
Py_BEGIN_CRITICAL_SECTION2(op, value);
res = Pointer_set_contents_lock_held(op, value, closure);
Expand Down
Loading