8000 gh-108727: Fix segfault due to missing tp_dealloc definition for Coun… · python/cpython@844f4c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 844f4c2

Browse files
authored
gh-108727: Fix segfault due to missing tp_dealloc definition for CounterOptimizer_Type (GH-108734)
1 parent 044b8b3 commit 844f4c2

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

Lib/test/test_capi/test_misc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,6 +2284,13 @@ def clear_executors(func):
22842284

22852285
class TestOptimizerAPI(unittest.TestCase):
22862286

2287+
def test_get_counter_optimizer_dealloc(self):
2288+
# See gh-108727
2289+
def f():
2290+
_testinternalcapi.get_counter_optimizer()
2291+
2292+
f()
2293+
22872294
def test_get_set_optimizer(self):
22882295
old = _testinternalcapi.get_optimizer()
22892296
opt = _testinternalcapi.get_counter_optimizer()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Define ``tp_dealloc`` for ``CounterOptimizer_Type``. This fixes a segfault
2+
on deallocation.

Python/optimizer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ static PyTypeObject CounterOptimizer_Type = {
289289
.tp_itemsize = 0,
290290
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
291291
.tp_methods = counter_methods,
292+
.tp_dealloc = (destructor)PyObject_Del,
292293
};
293294

294295
PyObject *

0 commit comments

Comments
 (0)
0