8000 GH-111339: Fix initialization and finalization of static optimizer ty… · python/cpython@4a929d4 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4a929d4

Browse files
GH-111339: Fix initialization and finalization of static optimizer types (GH-111430)
1 parent 4d6bdf8 commit 4a929d4

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

Include/internal/pycore_optimizer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ extern "C" {
1313
int _Py_uop_analyze_and_optimize(PyCodeObject *code,
1414
_PyUOpInstruction *trace, int trace_len, int curr_stackentries);
1515

16+
extern PyTypeObject _PyCounterExecutor_Type;
17+
extern PyTypeObject _PyCounterOptimizer_Type;
18+
extern PyTypeObject _PyDefaultOptimizer_Type;
19+
extern PyTypeObject _PyUOpExecutor_Type;
20+
extern PyTypeObject _PyUOpOptimizer_Type;
1621

1722
#ifdef __cplusplus
1823
}

Objects/object.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "pycore_memoryobject.h" // _PyManagedBuffer_Type
1414
#include "pycore_namespace.h" // _PyNamespace_Type
1515
#include "pycore_object.h" // PyAPI_DATA() _Py_SwappedOp definition
16+
#include "pycore_optimizer.h" // _PyUOpExecutor_Type, _PyUOpOptimizer_Type, ...
1617
#include "pycore_pyerrors.h" // _PyErr_Occurred()
1718
#include "pycore_pymem.h" // _PyMem_IsPtrFreed()
1819
#include "pycore_pystate.h" // _PyThreadState_GET()
@@ -2157,6 +2158,9 @@ static PyTypeObject* static_types[] = {
21572158
&_PyBufferWrapper_Type,
21582159
&_PyContextTokenMissing_Type,
21592160
&_PyCoroWrapper_Type,
2161+
&_PyCounterExecutor_Type,
2162+
&_PyCounterOptimizer_Type,
2163+
&_PyDefaultOptimizer_Type,
21602164
&_Py_GenericAliasIterType,
21612165
&_PyHamtItems_Type,
21622166
&_PyHamtKeys_Type,
@@ -2176,6 +2180,8 @@ static PyTypeObject* static_types[] = {
21762180
&_PyPositionsIterator,
21772181
&_PyUnicodeASCIIIter_Type,
21782182
&_PyUnion_Type,
2183+
&_PyUOpExecutor_Type,
2184+
&_PyUOpOptimizer_Type,
21792185
&_PyWeakref_CallableProxyType,
21802186
&_PyWeakref_ProxyType,
21812187
&_PyWeakref_RefType,

Python/optimizer.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ error_optimize(
111111
return -1;
112112
}
113113

114-
static PyTypeObject DefaultOptimizer_Type = {
114+
PyTypeObject _PyDefaultOptimizer_Type = {
115115
PyVarObject_HEAD_INIT(&PyType_Type, 0)
116116
.tp_name = "noop_optimizer",
117117
.tp_basicsize = sizeof(_PyOptimizerObject),
@@ -120,7 +120,7 @@ static PyTypeObject DefaultOptimizer_Type = {
120120
};
121121

122122
_PyOptimizerObject _PyOptimizer_Default = {
123-
PyObject_HEAD_INIT(&DefaultOptimizer_Type)
123+
PyObject_HEAD_INIT(&_PyDefaultOptimizer_Type)
124124
.optimize = error_optimize,
125125
.resume_threshold = UINT16_MAX,
126126
.backedge_threshold = UINT16_MAX,
@@ -236,7 +236,7 @@ static PyMethodDef executor_methods[] = {
236236
{ NULL, NULL },
237237
};
238238

239-
static PyTypeObject CounterExecutor_Type = {
239+
PyTypeObject _PyCounterExecutor_Type = {
240240
PyVarObject_HEAD_INIT(&PyType_Type, 0)
241241
.tp_name = "counting_executor",
242242
.tp_basicsize = sizeof(_PyCounterExecutorObject),
@@ -265,7 +265,7 @@ counter_optimize(
265265
int Py_UNUSED(curr_stackentries)
266266
)
267267
{
268-
_PyCounterExecutorObject *executor = (_PyCounterExecutorObject *)_PyObject_New(&CounterExecutor_Type);
268+
_PyCounterExecutorObject *executor = (_PyCounterExecutorObject *)_PyObject_New(&_PyCounterExecutor_Type);
269269
if (executor == NULL) {
270270
return -1;
271271
}
@@ -291,7 +291,7 @@ static PyMethodDef counter_optimizer_methods[] = {
291291
{ NULL, NULL },
292292
};
293293

294-
static PyTypeObject CounterOptimizer_Type = {
294+
PyTypeObject _PyCounterOptimizer_Type = {
295295
PyVarObject_HEAD_INIT(&PyType_Type, 0)
296296
.tp_name = "Counter optimizer",
297297
.tp_basicsize< 629A /span> = sizeof(_PyCounterOptimizerObject),
@@ -304,9 +304,7 @@ static PyTypeObject CounterOptimizer_Type = {
304304
PyObject *
305305
PyUnstable_Optimizer_NewCounter(void)
306306
{
307-
PyType_Ready(&CounterExecutor_Type);
308-
PyType_Ready(&CounterOptimizer_Type);
309-
_PyCounterOptimizerObject *opt = (_PyCounterOptimizerObject *)_PyObject_New(&CounterOptimizer_Type);
307+
_PyCounterOptimizerObject *opt = (_PyCounterOptimizerObject *)_PyObject_New(&_PyCounterOptimizer_Type);
310308
if (opt == NULL) {
311309
return NULL;
312310
}
@@ -375,7 +373,7 @@ PySequenceMethods uop_as_sequence = {
375373
.sq_item = (ssizeargfunc)uop_item,
376374
};
377375

378-
static PyTypeObject UOpExecutor_Type = {
376+
PyTypeObject _PyUOpExecutor_Type = {
379377
PyVarObject_HEAD_INIT(&PyType_Type, 0)
380378
.tp_name = "uop_executor",
381379
.tp_basicsize = sizeof(_PyUOpExecutorObject) - sizeof(_PyUOpInstruction),
@@ -929,7 +927,7 @@ uop_optimize(
929927
trace_length = _Py_uop_analyze_and_optimize(code, trace, trace_length, curr_stackentries);
930928
}
931929
trace_length = remove_unneeded_uops(trace, trace_length);
932-
_PyUOpExecutorObject *executor = PyObject_NewVar(_PyUOpExecutorObject, &UOpExecutor_Type, trace_length);
930+
_PyUOpExecutorObject *executor = PyObject_NewVar(_PyUOpExecutorObject, &_PyUOpExecutor_Type, trace_length);
933931
if (executor == NULL) {
934932
return -1;
935933
}
@@ -946,7 +944,7 @@ uop_opt_dealloc(PyObject *self) {
946944
PyObject_Free(self);
947945
}
948946

949-
static PyTypeObject UOpOptimizer_Type = {
947+
PyTypeObject _PyUOpOptimizer_Type = {
950948
PyVarObject_HEAD_INIT(&PyType_Type, 0)
951949
.tp_name = "uop_optimizer",
952950
.tp_basicsize = sizeof(_PyOptimizerObject),
@@ -958,9 +956,7 @@ static PyTypeObject UOpOptimizer_Type = {
958956
PyObject *
959957
PyUnstable_Optimizer_NewUOpOptimizer(void)
960958
{
961-
PyType_Ready(&UOpExecutor_Type);
962-
PyType_Ready(&UOpOptimizer_Type);
963-
_PyOptimizerObject *opt = PyObject_New(_PyOptimizerObject, &UOpOptimizer_Type);
959+
_PyOptimizerObject *opt = PyObject_New(_PyOptimizerObject, &_PyUOpOptimizer_Type);
964960
if (opt == NULL) {
965961
return NULL;
966962
}

Tools/c-analyzer/cpython/ignored.tsv

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,11 @@ Python/sysmodule.c - perf_map_state -
374374
Python/sysmodule.c - _PySys_ImplCacheTag -
375375
Python/sysmodule.c - _PySys_ImplName -
376376
Python/sysmodule.c - whatstrings -
377-
Python/optimizer.c - DefaultOptimizer_Type -
378-
Python/optimizer.c - CounterExecutor_Type -
379-
Python/optimizer.c - CounterOptimizer_Type -
380-
Python/optimizer.c - UOpExecutor_Type -
381-
Python/optimizer.c - UOpOptimizer_Type -
377+
Python/optimizer.c - _PyDefaultOptimizer_Type -
378+
Python/optimizer.c - _PyCounterExecutor_Type -
379+
Python/optimizer.c - _PyCounterOptimizer_Type -
380+
Python/optimizer.c - _PyUOpExecutor_Type -
381+
Python/optimizer.c - _PyUOpOptimizer_Type -
382382
Python/optimizer.c - _PyOptimizer_Default -
383383

384384
##-----------------------

0 commit comments

Comments
 (0)
0