gh-108727: Fix segfault due to missing tp_dealloc definition for CounterOptimizer_Type (GH-108734)
https://github.com/python/cpython/commit/844f4c2e12a7c637d1de93dbbb0718be065... commit: 844f4c2e12a7c637d1de93dbbb0718be06553510 branch: main author: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> committer: markshannon <mark@hotpy.org> date: 2023-09-01T10:16:09+01:00 summary: gh-108727: Fix segfault due to missing tp_dealloc definition for CounterOptimizer_Type (GH-108734) files: A Misc/NEWS.d/next/Core and Builtins/2023-08-31-21-29-28.gh-issue-108727.blNRGM.rst M Lib/test/test_capi/test_misc.py M Python/optimizer.c diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py index 4148f15b2aa66..004ce39769655 100644 --- a/Lib/test/test_capi/test_misc.py +++ b/Lib/test/test_capi/test_misc.py @@ -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() diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-08-31-21-29-28.gh-issue-108727.blNRGM.rst b/Misc/NEWS.d/next/Core and Builtins/2023-08-31-21-29-28.gh-issue-108727.blNRGM.rst new file mode 100644 index 0000000000000..34959ae3bb99a --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-08-31-21-29-28.gh-issue-108727.blNRGM.rst @@ -0,0 +1,2 @@ +Define ``tp_dealloc`` for ``CounterOptimizer_Type``. This fixes a segfault +on deallocation. diff --git a/Python/optimizer.c b/Python/optimizer.c index c311a03fa59a2..7472f52c50b76 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -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 *
participants (1)
-
markshannon