-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
bpo-43693: Add _PyCode_New() and do some related cleanup. #26258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ericsnowcurrently
wants to merge
44
commits into
python:main
from
ericsnowcurrently:code-object-cleanup
Closed
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
dce5124
Re-organize the _PyCodeObject fields.
ericsnowcurrently e416918
Spell out the PyCode_New*() signatures.
ericsnowcurrently 6740572
Add a TODO to code.h.
ericsnowcurrently 4381869
Fix a memory leak.
ericsnowcurrently 19cfb8b
Add _PyCode_New().
ericsnowcurrently 8f10f5d
Factor out _PyCode_GetFastlocalOffsetId().
ericsnowcurrently 0c42221
Factor out _PyCode_HasFastlocals().
ericsnowcurrently 3315b28
Factor out _PyCode_CellForLocal().
ericsnowcurrently 2ac48ba
Add macros to hide away some of the PyCodeObject fields.
ericsnowcurrently 02e15a4
Move the fast locals section down.
ericsnowcurrently ad70f99
Store more counts on PyCodeObject.
ericsnowcurrently e38643f
Update a comment.
ericsnowcurrently 09fbe71
8000
Factor out macros related to co_code.
ericsnowcurrently 9b4ca77
Fix some smelly names.
ericsnowcurrently f00133f
Fix whitespace.
ericsnowcurrently acef742
Fix co_nlocals in code.replace().
ericsnowcurrently 559e408
Stop using statics in PyCode_NewEmpty().
ericsnowcurrently a923b5b
Actually fix whitespace.
ericsnowcurrently afcc944
Fix a typo.
ericsnowcurrently d304aba
Replace macros with inline functions.
ericsnowcurrently 23e5485
Unify all the PyCodeObject validation code.
ericsnowcurrently 81c4a49
Fix the logged function name.
ericsnowcurrently af51553
Fix the GDB script.
ericsnowcurrently cc3f435
-_PyCode_GetFastlocalOffsetId -> _PyCode_FastOffsetFromId().
ericsnowcurrently fcf4ea3
Fix CO_FAST_KWONLY.
ericsnowcurrently cb82a6a
Fix a typo.
ericsnowcurrently 672a75f
Make sure int is used for fast offsets and PyCodeObject counts.
ericsnowcurrently 32907b1
Fix the comment about fields in hash/comparision.
ericsnowcurrently aee3640
Drop co_nlocals from marshaled code objects.
ericsnowcurrently fd50f62
Regen a couple more files.
ericsnowcurrently 9736ff5
Fix test_ctypes.
ericsnowcurrently c95314c
Factor out CO_FAST_ARG.
ericsnowcurrently b419060
Fix a typo.
ericsnowcurrently 6195184
Add an assert for the return value of frame_nslots().
ericsnowcurrently 3c4ec94
Add a comment about using an arguments struct for _PyCode_New().
ericsnowcurrently ffc4b54
Drop some outdated TODO comments.
ericsnowcurrently 292b646
Fix a typo.
ericsnowcurrently cd9e34a
Add _PyCode_FastInfoFromOffset().
ericsnowcurrently cd4f587
Add _PyCode_GetFastFreevar().
ericsnowcurrently a4e6dd3
Use _PyCode_FastInfoFromOffset() elsewhere in ceval.c.
ericsnowcurrently f93b6df
Add _PyCode_OffsetFromIndex().
ericsnowcurrently f779627
_PyCode_FastInfoFromOffset() -> _PyCode_FastInfoFromOparg().
ericsnowcurrently 292e457
Add _PyCode_FastInfoFromOffset() and use it in frameobject.c.
ericsnowcurrently f6bafb4
Fix warnings.
ericsnowcurrently File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Replace macros with inline functions.
- Loading branch information
commit d304aba2f6d6dd55363f8318118c8f8090e9b036
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <stdbool.h> | ||
|
||
|
||
|
@@ -87,31 +87,56 @@ PyAPI_FUNC(bool) _PyCode_HasFastlocals(PyCodeObject *, _PyFastLocalKind); | |
PyAPI_FUNC(Py_ssize_t) _PyCode_CellForLocal(PyCodeObject *, Py_ssize_t); | ||
|
||
/* This does not fail. A negative result means "no match". */ | ||
PyAPI_FUNC(Py_ssize_t) _PyCode_GetFastlocalOffsetId(PyCodeObject *, | ||
_Py_Identifier *, | ||
_PyFastLocalKind); | ||
PyAPI_FUNC(Py_ssize_t) _PyCode_GetFastlocalOffsetId(PyCodeObject *, | ||
_Py_Identifier *, | ||
_PyFastLocalKind); | ||
|
||
// This is a speed hack for use in ceval.c. | ||
#define _PyCode_LOCALVARS_ARRAY(co) \ | ||
(((PyTupleObject *)((co)->co_varnames))->ob_item) | ||
#define _PyCode_GET_LOCALVAR(co, offset) \ | ||
(PyTuple_GetItem((co)->co_varnames, offset)) | ||
|
||
#define _PyCode_GET_CELLVAR(co, offset) \ | ||
(PyTuple_GetItem((co)->co_cellvars, offset)) | ||
|
||
#define _PyCode_GET_FREEVAR(co, offset) \ | ||
(PyTuple_GetItem((co)->co_freevars, offset)) | ||
|
||
#define _PyCode_CODE_IS_VALID(co) \ | ||
(PyBytes_Check((co)->co_code) && \ | ||
PyBytes_GET_SIZE((co)->co_code) <= INT_MAX && \ | ||
PyBytes_GET_SIZE((co)->co_code) % sizeof(_Py_CODEUNIT) == 0 && \ | ||
_Py_IS_ALIGNED(PyBytes_AS_STRING((co)->co_code), sizeof(_Py_CODEUNIT))) | ||
#define _PyCode_GET_INSTRUCTIONS(co) \ | ||
((_Py_CODEUNIT *) PyBytes_AS_STRING((co)->co_code)) | ||
#define _PyCode_NUM_INSTRUCTIONS(co) \ | ||
(PyBytes_Size((co)->co_code) / sizeof(_Py_CODEUNIT)) | ||
static inline PyObject ** | ||
_PyCode_LocalvarsArray(PyCodeObject *co) | ||
{ | ||
return ((PyTupleObject *)(co->co_varnames))->ob_item; | ||
} | ||
|
||
static inline PyObject * | ||
_PyCode_GetLocalvar(PyCodeObject *co, Py_ssize_t offset) | ||
{ | ||
return PyTuple_GetItem(co->co_varnames, offset); | ||
} | ||
|
||
static inline PyObject * | ||
_PyCode_GetCellvar(PyCodeObject *co, Py_ssize_t offset) | ||
{ | ||
return PyTuple_GetItem(co->co_cellvars, offset); | ||
} | ||
|
||
static inline PyObject * | ||
_PyCode_GetFreevar(PyCodeObject *co, Py_ssize_t offset) | ||
{ | ||
return PyTuple_GetItem(co->co_freevars, offset); | ||
} | ||
|
||
static inline bool | ||
_PyCode_CodeIsValid(PyCodeObject *co) | ||
{ | ||
return PyBytes_Check(co->co_code) && | ||
PyBytes_GET_SIZE(co->co_code) <= INT_MAX && | ||
PyBytes_GET_SIZE(co->co_code) % sizeof(_Py_CODEUNIT) == 0 && | ||
_Py_IS_ALIGNED(PyBytes_AS_STRING(co->co_code), | ||
sizeof(_Py_CODEUNIT)); | ||
} | ||
|
||
static inline _Py_CODEUNIT * | ||
_PyCode_GetInstructions(PyCodeObject *co) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is going to be misleading with quickening, so could you drop it for now. |
||
{ | ||
return (_Py_CODEUNIT *)PyBytes_AS_STRING(co->co_code); | ||
} | ||
|
||
static inline Py_ssize_t | ||
_PyCode_NumInstructions(PyCodeObject *co) | ||
{ | ||
return PyBytes_Size(co->co_code) / sizeof(_Py_CODEUNIT); | ||
} | ||
|
||
|
||
#ifdef __cplusplus | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't check for validity, at all. A full validity check would be large and slow. Maybe rename to reflect what it does?