Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 65604b5

Browse files
committed
Merge 3.2: Issue #12483: ctypes: Fix a crash when the destruction of a callback
object triggers the garbage collector.
2 parents aa2b442 + bbe46d6 commit 65604b5

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

Lib/ctypes/test/test_callbacks.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ def __init__(self):
134134
if isinstance(x, X)]
135135
self.assertEqual(len(live), 0)
136136

137+
def test_issue12483(self):
138+
import gc
139+
class Nasty:
140+
def __del__(self):
141+
gc.collect()
142+
CFUNCTYPE(None)(lambda x=Nasty(): None)
143+
144+
137145
try:
138146
WINFUNCTYPE
139147
except NameError:

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,9 @@ Tools/Demos
12741274
Extension Modules
12751275
-----------------
12761276

1277+
- Issue #12483: ctypes: Fix a crash when the destruction of a callback
1278+
object triggers the garbage collector.
1279+
12771280
- Issue #12950: Fix passing file descriptors in multiprocessing, under
12781281
OpenIndiana/Illumos.
12791282

Modules/_ctypes/callbacks.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ static void
1313
CThunkObject_dealloc(PyObject *_self)
1414
{
1515
CThunkObject *self = (CThunkObject *)_self;
16+
PyObject_GC_UnTrack(self);
1617
Py_XDECREF(self->converters);
1718
Py_XDECREF(self->callable);
1819
Py_XDECREF(self->restype);

0 commit comments

Comments
 (0)