Skip to content

Commit 50a5ab2

Browse files
gh-93382: Sync up co_code changes with 3.11 (GH-94227)
Sync up co_code changes with 3.11 commit 852b4d4.
1 parent a91ffcf commit 50a5ab2

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

Include/cpython/code.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ typedef uint16_t _Py_CODEUNIT;
9090
PyObject *co_qualname; /* unicode (qualname, for reference) */ \
9191
PyObject *co_linetable; /* bytes object that holds location info */ \
9292
PyObject *co_weakreflist; /* to support weakrefs to code objects */ \
93-
void *_co_code; /* cached co_code object/attribute */ \
93+
PyObject *_co_code; /* cached co_code object/attribute */ \
9494
int _co_firsttraceable; /* index of first traceable instruction */ \
9595
char *_co_linearray; /* array of line offsets */ \
9696
/* Scratch space for extra data relating to the code object. \
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Speed up the :c:func:`PyCode_GetCode` function which also improves accessing the :attr:`~types.CodeType.co_code` attribute in Python.
1+
Cache the result of :c:func:`PyCode_GetCode` function to restore the O(1)
2+
lookup of the :attr:`~types.CodeType.co_code` attribute.

Objects/codeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ _PyCode_GetCode(PyCodeObject *co)
14401440
}
14411441
deopt_code((_Py_CODEUNIT *)PyBytes_AS_STRING(code), Py_SIZE(co));
14421442
assert(co->_co_code == NULL);
1443-
co->_co_code = (void *)Py_NewRef(code);
1443+
co->_co_code = Py_NewRef(code);
14441444
return code;
14451445
}
14461446

Tools/scripts/deepfreeze.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ def generate_code(self, name: str, code: types.CodeType) -> str:
274274
self.write(f".co_name = {co_name},")
275275
self.write(f".co_qualname = {co_qualname},")
276276
self.write(f".co_linetable = {co_linetable},")
277+
self.write(f"._co_code = NULL,")
277278
self.write("._co_linearray = NULL,")
278279
self.write(f".co_code_adaptive = {co_code_adaptive},")
279280
for i, op in enumerate(code.co_code[::2]):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy