Skip to content

Commit

Permalink
pythongh-108727: Fix segfault due to missing tp_dealloc definition fo…
Browse files Browse the repository at this point in the history
…r CounterOptimizer_Type
  • Loading branch information
iritkatriel committed Aug 31, 2023
1 parent 13a0007 commit 33b1880
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Lib/test/test_capi/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,13 @@ def clear_executors(func):

class TestOptimizerAPI(unittest.TestCase):

def test_get_counter_optimizer_dealloc(self):
# See gh-108727
def f():
_testinternalcapi.get_counter_optimizer()

f()

def test_get_set_optimizer(self):
old = _testinternalcapi.get_optimizer()
opt = _testinternalcapi.get_counter_optimizer()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Define ``tp_dealloc`` for ``CounterOptimizer_Type``. This fixes a segfault
on deallocation.
1 change: 1 addition & 0 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ static PyTypeObject CounterOptimizer_Type = {
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
.tp_methods = counter_methods,
.tp_dealloc = (destructor)PyObject_Del,
};

PyObject *
Expand Down

0 comments on commit 33b1880

Please sign in to comment.