[Python-checkins] bpo-46476: Simplify and fix _PyStaticCode_Dealloc (GH-30965)
markshannon
webhook-mailer at python.org
Thu Jan 27 14:32:29 EST 2022
https://github.com/python/cpython/commit/26b0482393a313e3bda364a35e7417e9db52c1c4
commit: 26b0482393a313e3bda364a35e7417e9db52c1c4
branch: main
author: Christian Heimes <christian at python.org>
committer: markshannon <mark at hotpy.org>
date: 2022-01-27T19:32:12Z
summary:
bpo-46476: Simplify and fix _PyStaticCode_Dealloc (GH-30965)
files:
M Include/internal/pycore_code.h
M Objects/codeobject.c
M Tools/scripts/deepfreeze.py
diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h
index 884a91f3fb7ed..bbf7a06189ba1 100644
--- a/Include/internal/pycore_code.h
+++ b/Include/internal/pycore_code.h
@@ -277,7 +277,7 @@ void _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
void _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr, SpecializedCacheEntry *cache);
/* Deallocator function for static codeobjects used in deepfreeze.py */
-void _PyStaticCode_Dealloc(PyCodeObject *co, _Py_CODEUNIT *firstinstr);
+void _PyStaticCode_Dealloc(PyCodeObject *co);
#ifdef Py_STATS
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index f983d66db05d6..bb8ffa794a96d 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -1908,16 +1908,19 @@ _PyCode_ConstantKey(PyObject *op)
}
void
-_PyStaticCode_Dealloc(PyCodeObject *co, _Py_CODEUNIT *firstinstr)
+_PyStaticCode_Dealloc(PyCodeObject *co)
{
- PyMem_Free(co->co_quickened);
- co->co_quickened = NULL;
+ if (co->co_quickened) {
+ PyMem_Free(co->co_quickened);
+ co->co_quickened = NULL;
+ _Py_QuickenedCount--;
+ }
+ co->co_warmup = QUICKENING_INITIAL_WARMUP_VALUE;
PyMem_Free(co->co_extra);
co->co_extra = NULL;
- co->co_firstinstr = firstinstr;
+ co->co_firstinstr = (_Py_CODEUNIT *)PyBytes_AS_STRING(co->co_code);
if (co->co_weakreflist != NULL) {
PyObject_ClearWeakRefs((PyObject *)co);
co->co_weakreflist = NULL;
}
- co->co_warmup = QUICKENING_INITIAL_WARMUP_VALUE;
}
diff --git a/Tools/scripts/deepfreeze.py b/Tools/scripts/deepfreeze.py
index 78849390f1260..db44ba89c671e 100644
--- a/Tools/scripts/deepfreeze.py
+++ b/Tools/scripts/deepfreeze.py
@@ -278,7 +278,7 @@ def generate_code(self, name: str, code: types.CodeType) -> str:
self.write(f".co_varnames = {co_varnames},")
self.write(f".co_cellvars = {co_cellvars},")
self.write(f".co_freevars = {co_freevars},")
- self.deallocs.append(f"_PyStaticCode_Dealloc(&{name}, (_Py_CODEUNIT *) {removesuffix(co_code, '.ob_base.ob_base')}.ob_sval);")
+ self.deallocs.append(f"_PyStaticCode_Dealloc(&{name});")
return f"& {name}.ob_base"
def generate_tuple(self, name: str, t: Tuple[object, ...]) -> str:
More information about the Python-checkins
mailing list