summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-06-05 08:44:23 (GMT)
committerGitHub <noreply@github.com>2023-06-05 08:44:23 (GMT)
commite8ecb9ee6bec03d0c4490f3e7f1524e56e2f6a0f (patch)
tree5d88f25105eb2d0dc9fe5034ac9257e2da86db8e /Python
parent9efaff5fd31a55e3beaa1fa430058de36a145566 (diff)
downloadcpython-e8ecb9ee6bec03d0c4490f3e7f1524e56e2f6a0f.zip
cpython-e8ecb9ee6bec03d0c4490f3e7f1524e56e2f6a0f.tar.gz
cpython-e8ecb9ee6bec03d0c4490f3e7f1524e56e2f6a0f.tar.bz2
GH-104584: Allow optimizers to opt out of optimizing. (GH-105244)
Diffstat (limited to 'Python')
-rw-r--r--Python/optimizer.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/Python/optimizer.c b/Python/optimizer.c
index f29e072..d721bfa 100644
--- a/Python/optimizer.c
+++ b/Python/optimizer.c
@@ -93,14 +93,15 @@ PyUnstable_Replace_Executor(PyCodeObject *code, _Py_CODEUNIT *instr, _PyExecutor
return 0;
}
-static _PyExecutorObject *
+static int
error_optimize(
_PyOptimizerObject* self,
PyCodeObject *code,
- _Py_CODEUNIT *instr)
+ _Py_CODEUNIT *instr,
+ _PyExecutorObject **exec)
{
PyErr_Format(PyExc_SystemError, "Should never call error_optimize");
- return NULL;
+ return -1;
}
static PyTypeObject DefaultOptimizer_Type = {
@@ -154,15 +155,19 @@ _PyOptimizer_BackEdge(_PyInterpreterFrame *frame, _Py_CODEUNIT *src, _Py_CODEUNI
return frame;
}
_PyOptimizerObject *opt = interp->optimizer;
- _PyExecutorObject *executor = opt->optimize(opt, frame->f_code, dest);
- if (executor == NULL) {
- return NULL;
+ _PyExecutorObject *executor;
+ int err = opt->optimize(opt, frame->f_code, dest, &executor);
+ if (err <= 0) {
+ if (err < 0) {
+ return NULL;
+ }
+ _PyFrame_SetStackPointer(frame, stack_pointer);
+ return frame;
}
insert_executor(frame->f_code, src, index, executor);
return executor->execute(executor, frame, stack_pointer);
}
-
/** Test support **/
@@ -202,21 +207,23 @@ counter_execute(_PyExecutorObject *self, _PyInterpreterFrame *frame, PyObject **
return frame;
}
-static _PyExecutorObject *
+static int
counter_optimize(
_PyOptimizerObject* self,
PyCodeObject *code,
- _Py_CODEUNIT *instr)
+ _Py_CODEUNIT *instr,
+ _PyExecutorObject **exec_ptr)
{
_PyCounterExecutorObject *executor = (_PyCounterExecutorObject *)_PyObject_New(&CounterExecutor_Type);
if (executor == NULL) {
- return NULL;
+ return -1;
}
executor->executor.execute = counter_execute;
Py_INCREF(self);
executor->optimizer = (_PyCounterOptimizerObject *)self;
executor->next_instr = instr;
- return (_PyExecutorObject *)executor;
+ *exec_ptr = (_PyExecutorObject *)executor;
+ return 1;
}
static PyObject *