Skip to content

Commit 26b0482

Browse files
authored
bpo-46476: Simplify and fix _PyStaticCode_Dealloc (GH-30965)
1 parent 247480a commit 26b0482

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

Include/internal/pycore_code.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
277277
void _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr, SpecializedCacheEntry *cache);
278278

279279
/* Deallocator function for static codeobjects used in deepfreeze.py */
280-
void _PyStaticCode_Dealloc(PyCodeObject *co, _Py_CODEUNIT *firstinstr);
280+
void _PyStaticCode_Dealloc(PyCodeObject *co);
281281

282282
#ifdef Py_STATS
283283

Objects/codeobject.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,16 +1908,19 @@ _PyCode_ConstantKey(PyObject *op)
19081908
}
19091909

19101910
void
1911-
_PyStaticCode_Dealloc(PyCodeObject *co, _Py_CODEUNIT *firstinstr)
1911+
_PyStaticCode_Dealloc(PyCodeObject *co)
19121912
{
1913-
PyMem_Free(co->co_quickened);
1914-
co->co_quickened = NULL;
1913+
if (co->co_quickened) {
1914+
PyMem_Free(co->co_quickened);
1915+
co->co_quickened = NULL;
1916+
_Py_QuickenedCount--;
1917+
}
1918+
co->co_warmup = QUICKENING_INITIAL_WARMUP_VALUE;
19151919
PyMem_Free(co->co_extra);
19161920
co->co_extra = NULL;
1917-
co->co_firstinstr = firstinstr;
1921+
co->co_firstinstr = (_Py_CODEUNIT *)PyBytes_AS_STRING(co->co_code);
19181922
if (co->co_weakreflist != NULL) {
19191923
PyObject_ClearWeakRefs((PyObject *)co);
19201924
co->co_weakreflist = NULL;
19211925
}
1922-
co->co_warmup = QUICKENING_INITIAL_WARMUP_VALUE;
19231926
}

Tools/scripts/deepfreeze.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def generate_code(self, name: str, code: types.CodeType) -> str:
278278
self.write(f".co_varnames = {co_varnames},")
279279
self.write(f".co_cellvars = {co_cellvars},")
280280
self.write(f".co_freevars = {co_freevars},")
281-
self.deallocs.append(f"_PyStaticCode_Dealloc(&{name}, (_Py_CODEUNIT *) {removesuffix(co_code, '.ob_base.ob_base')}.ob_sval);")
281+
self.deallocs.append(f"_PyStaticCode_Dealloc(&{name});")
282282
return f"& {name}.ob_base"
283283

284284
def generate_tuple(self, name: str, t: Tuple[object, ...]) -> str:

0 commit comments

Comments
 (0)