summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSavannah Ostrowski <savannahostrowski@gmail.com>2023-10-29 20:53:25 (GMT)
committerGitHub <noreply@github.com>2023-10-29 20:53:25 (GMT)
commit4a929d432b48775096d40f5c72bcd9be052b0a2d (patch)
treed173b58d3a38aeb2013c15c9292084214e56061d
parent4d6bdf8aabcc92303041420a96750fbc52c9f213 (diff)
downloadcpython-4a929d432b48775096d40f5c72bcd9be052b0a2d.zip
cpython-4a929d432b48775096d40f5c72bcd9be052b0a2d.tar.gz
cpython-4a929d432b48775096d40f5c72bcd9be052b0a2d.tar.bz2
GH-111339: Fix initialization and finalization of static optimizer types (GH-111430)
-rw-r--r--Include/internal/pycore_optimizer.h5
-rw-r--r--Objects/object.c6
-rw-r--r--Python/optimizer.c24
-rw-r--r--Tools/c-analyzer/cpython/ignored.tsv10
4 files changed, 26 insertions, 19 deletions
diff --git a/Include/internal/pycore_optimizer.h b/Include/internal/pycore_optimizer.h
index f9f16c4..b052460 100644
--- a/Include/internal/pycore_optimizer.h
+++ b/Include/internal/pycore_optimizer.h
@@ -13,6 +13,11 @@ extern "C" {
int _Py_uop_analyze_and_optimize(PyCodeObject *code,
_PyUOpInstruction *trace, int trace_len, int curr_stackentries);
+extern PyTypeObject _PyCounterExecutor_Type;
+extern PyTypeObject _PyCounterOptimizer_Type;
+extern PyTypeObject _PyDefaultOptimizer_Type;
+extern PyTypeObject _PyUOpExecutor_Type;
+extern PyTypeObject _PyUOpOptimizer_Type;
#ifdef __cplusplus
}
diff --git a/Objects/object.c b/Objects/object.c
index 3ed272a..791db75 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -13,6 +13,7 @@
#include "pycore_memoryobject.h" // _PyManagedBuffer_Type
#include "pycore_namespace.h" // _PyNamespace_Type
#include "pycore_object.h" // PyAPI_DATA() _Py_SwappedOp definition
+#include "pycore_optimizer.h" // _PyUOpExecutor_Type, _PyUOpOptimizer_Type, ...
#include "pycore_pyerrors.h" // _PyErr_Occurred()
#include "pycore_pymem.h" // _PyMem_IsPtrFreed()
#include "pycore_pystate.h" // _PyThreadState_GET()
@@ -2157,6 +2158,9 @@ static PyTypeObject* static_types[] = {
&_PyBufferWrapper_Type,
&_PyContextTokenMissing_Type,
&_PyCoroWrapper_Type,
+ &_PyCounterExecutor_Type,
+ &_PyCounterOptimizer_Type,
+ &_PyDefaultOptimizer_Type,
&_Py_GenericAliasIterType,
&_PyHamtItems_Type,
&_PyHamtKeys_Type,
@@ -2176,6 +2180,8 @@ static PyTypeObject* static_types[] = {
&_PyPositionsIterator,
&_PyUnicodeASCIIIter_Type,
&_PyUnion_Type,
+ &_PyUOpExecutor_Type,
+ &_PyUOpOptimizer_Type,
&_PyWeakref_CallableProxyType,
&_PyWeakref_ProxyType,
&_PyWeakref_RefType,
diff --git a/Python/optimizer.c b/Python/optimizer.c
index 6402287..c239b03 100644
--- a/Python/optimizer.c
+++ b/Python/optimizer.c
@@ -111,7 +111,7 @@ error_optimize(
return -1;
}
-static PyTypeObject DefaultOptimizer_Type = {
+PyTypeObject _PyDefaultOptimizer_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
.tp_name = "noop_optimizer",
.tp_basicsize = sizeof(_PyOptimizerObject),
@@ -120,7 +120,7 @@ static PyTypeObject DefaultOptimizer_Type = {
};
_PyOptimizerObject _PyOptimizer_Default = {
- PyObject_HEAD_INIT(&DefaultOptimizer_Type)
+ PyObject_HEAD_INIT(&_PyDefaultOptimizer_Type)
.optimize = error_optimize,
.resume_threshold = UINT16_MAX,
.backedge_threshold = UINT16_MAX,
@@ -236,7 +236,7 @@ static PyMethodDef executor_methods[] = {
{ NULL, NULL },
};
-static PyTypeObject CounterExecutor_Type = {
+PyTypeObject _PyCounterExecutor_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
.tp_name = "counting_executor",
.tp_basicsize = sizeof(_PyCounterExecutorObject),
@@ -265,7 +265,7 @@ counter_optimize(
int Py_UNUSED(curr_stackentries)
)
{
- _PyCounterExecutorObject *executor = (_PyCounterExecutorObject *)_PyObject_New(&CounterExecutor_Type);
+ _PyCounterExecutorObject *executor = (_PyCounterExecutorObject *)_PyObject_New(&_PyCounterExecutor_Type);
if (executor == NULL) {
return -1;
}
@@ -291,7 +291,7 @@ static PyMethodDef counter_optimizer_methods[] = {
{ NULL, NULL },
};
-static PyTypeObject CounterOptimizer_Type = {
+PyTypeObject _PyCounterOptimizer_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
.tp_name = "Counter optimizer",
.tp_basicsize = sizeof(_PyCounterOptimizerObject),
@@ -304,9 +304,7 @@ static PyTypeObject CounterOptimizer_Type = {
PyObject *
PyUnstable_Optimizer_NewCounter(void)
{
- PyType_Ready(&CounterExecutor_Type);
- PyType_Ready(&CounterOptimizer_Type);
- _PyCounterOptimizerObject *opt = (_PyCounterOptimizerObject *)_PyObject_New(&CounterOptimizer_Type);
+ _PyCounterOptimizerObject *opt = (_PyCounterOptimizerObject *)_PyObject_New(&_PyCounterOptimizer_Type);
if (opt == NULL) {
return NULL;
}
@@ -375,7 +373,7 @@ PySequenceMethods uop_as_sequence = {
.sq_item = (ssizeargfunc)uop_item,
};
-static PyTypeObject UOpExecutor_Type = {
+PyTypeObject _PyUOpExecutor_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
.tp_name = "uop_executor",
.tp_basicsize = sizeof(_PyUOpExecutorObject) - sizeof(_PyUOpInstruction),
@@ -929,7 +927,7 @@ uop_optimize(
trace_length = _Py_uop_analyze_and_optimize(code, trace, trace_length, curr_stackentries);
}
trace_length = remove_unneeded_uops(trace, trace_length);
- _PyUOpExecutorObject *executor = PyObject_NewVar(_PyUOpExecutorObject, &UOpExecutor_Type, trace_length);
+ _PyUOpExecutorObject *executor = PyObject_NewVar(_PyUOpExecutorObject, &_PyUOpExecutor_Type, trace_length);
if (executor == NULL) {
return -1;
}
@@ -946,7 +944,7 @@ uop_opt_dealloc(PyObject *self) {
PyObject_Free(self);
}
-static PyTypeObject UOpOptimizer_Type = {
+PyTypeObject _PyUOpOptimizer_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
.tp_name = "uop_optimizer",
.tp_basicsize = sizeof(_PyOptimizerObject),
@@ -958,9 +956,7 @@ static PyTypeObject UOpOptimizer_Type = {
PyObject *
PyUnstable_Optimizer_NewUOpOptimizer(void)
{
- PyType_Ready(&UOpExecutor_Type);
- PyType_Ready(&UOpOptimizer_Type);
- _PyOptimizerObject *opt = PyObject_New(_PyOptimizerObject, &UOpOptimizer_Type);
+ _PyOptimizerObject *opt = PyObject_New(_PyOptimizerObject, &_PyUOpOptimizer_Type);
if (opt == NULL) {
return NULL;
}
diff --git a/Tools/c-analyzer/cpython/ignored.tsv b/Tools/c-analyzer/cpython/ignored.tsv
index d436886..eea633a 100644
--- a/Tools/c-analyzer/cpython/ignored.tsv
+++ b/Tools/c-analyzer/cpython/ignored.tsv
@@ -374,11 +374,11 @@ Python/sysmodule.c - perf_map_state -
Python/sysmodule.c - _PySys_ImplCacheTag -
Python/sysmodule.c - _PySys_ImplName -
Python/sysmodule.c - whatstrings -
-Python/optimizer.c - DefaultOptimizer_Type -
-Python/optimizer.c - CounterExecutor_Type -
-Python/optimizer.c - CounterOptimizer_Type -
-Python/optimizer.c - UOpExecutor_Type -
-Python/optimizer.c - UOpOptimizer_Type -
+Python/optimizer.c - _PyDefaultOptimizer_Type -
+Python/optimizer.c - _PyCounterExecutor_Type -
+Python/optimizer.c - _PyCounterOptimizer_Type -
+Python/optimizer.c - _PyUOpExecutor_Type -
+Python/optimizer.c - _PyUOpOptimizer_Type -
Python/optimizer.c - _PyOptimizer_Default -
##-----------------------