summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2023-07-06 22:45:56 (GMT)
committerGitHub <noreply@github.com>2023-07-06 22:45:56 (GMT)
commit76fac7bce55302a8e9a524d72f5384fd89e6dfde (patch)
tree6ecdbd5e8168c24ad71269961ce20469aa091107 /Python
parent67a798888dcde13bbb1e17cfcc3c742c94e67a07 (diff)
downloadcpython-76fac7bce55302a8e9a524d72f5384fd89e6dfde.zip
cpython-76fac7bce55302a8e9a524d72f5384fd89e6dfde.tar.gz
cpython-76fac7bce55302a8e9a524d72f5384fd89e6dfde.tar.bz2
gh-104584: Clean up and fix uops tests and fix crash (#106492)
The uops test wasn't testing anything by default, and was failing when run with -Xuops. Made the two executor-related context managers global, so TestUops can use them (notably `with temporary_optimizer(opt)`). Made clear_executor() a little more thorough. Fixed a crash upon finalizing a uop optimizer, by adding a `tp_dealloc` handler.
Diffstat (limited to 'Python')
-rw-r--r--Python/optimizer.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/Python/optimizer.c b/Python/optimizer.c
index 2c1be61..d2fdca5 100644
--- a/Python/optimizer.c
+++ b/Python/optimizer.c
@@ -532,7 +532,7 @@ uop_optimize(
return trace_length;
}
OBJECT_STAT_INC(optimization_traces_created);
- _PyUOpExecutorObject *executor = (_PyUOpExecutorObject *)_PyObject_New(&UOpExecutor_Type);
+ _PyUOpExecutorObject *executor = PyObject_New(_PyUOpExecutorObject, &UOpExecutor_Type);
if (executor == NULL) {
return -1;
}
@@ -542,18 +542,24 @@ uop_optimize(
return 1;
}
+static void
+uop_opt_dealloc(PyObject *self) {
+ PyObject_Free(self);
+}
+
static PyTypeObject UOpOptimizer_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
.tp_name = "uop_optimizer",
.tp_basicsize = sizeof(_PyOptimizerObject),
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
+ .tp_dealloc = uop_opt_dealloc,
};
PyObject *
PyUnstable_Optimizer_NewUOpOptimizer(void)
{
- _PyOptimizerObject *opt = (_PyOptimizerObject *)_PyObject_New(&UOpOptimizer_Type);
+ _PyOptimizerObject *opt = PyObject_New(_PyOptimizerObject, &UOpOptimizer_Type);
if (opt == NULL) {
return NULL;
}