-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-42990: Introduce 'frame constructor' struct to simplify 8000 API for PyEval_CodeEval and friends #24298
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
Conversation
Skipping NEWS as this is just an internal cleanup |
Include/funcobject.h
Outdated
PyObject *func_globals; /* A dictionary (other mappings won't do) */ | ||
PyObject *func_defaults; /* NULL or a tuple */ | ||
PyObject *func_kwdefaults; /* NULL or a dict */ | ||
PyObject *func_closure; /* NULL or a tuple of cell objects */ | ||
PyFrameConstructor func_descr; /* Frame descriptor fields for this function */ | ||
PyObject *func_doc; /* The __doc__ attribute, can be anything */ | ||
PyObject *func_name; /* The __name__ attribute, a string object */ | ||
PyObject *func_dict; /* The __dict__ attribute, a dict or NULL */ | ||
PyObject *func_weakreflist; /* List of weak references */ | ||
PyObject *func_module; /* The __module__ attribute, can be anything */ | ||
PyObject *func_annotations; /* Annotations, a dict or NULL */ | ||
PyObject *func_qualname; /* The qualified name */ | ||
vectorcallfunc vectorcall; |
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.
According to my reading of PEP 387, this change should go through the incompatible changes process.
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.
Not according to my reading. The internal layout of the PyFunctionObject
is not part of the API.
31cb312
to
8da2f02
Compare
@encukou Are you OK with me merging this, or do you think it represents an incompatible change? |
Well, there's nothing preventing people from using On the other hand, there are getter/setter functions for these fields, and those should be preferred. |
The internals of C structs aren't part of the API. That would just be too fragile. https://docs.python.org/3/c-api/structures.html lists some structs, like The internals of |
All these are defined in |
…rds compatibility.
I've modified |
This looks good, but IMO it's the first use of anonymous structs/unions. How is the compiler support for them? |
I've used a macro to make things C89, for now. |
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 PR is based on the fact that PyFunction_AS_FRAME_CONSTRUCTOR() is efficient, but it changes structures.
I suggest starting with a first PR which leaves structures unchanged and create a PyFrameConstructor from other structures by copying members. Something like:
PyFrameConstructor frame_constr = FrameConstructorFromFunction(func);
Oh. I didn't notice that this PR is already merged :-) |
Well, we will see if anyone rely on the ABI of these structures ;-) I'm in favor of making these structures opaque: https://www.python.org/dev/peps/pep-0620/ :-) |
…yEval_CodeEval and friends (pythonGH-24298) * Introduce 'frame constructor' to simplify API for frame creation * Embed struct using a macro to conform to PEP 7
Rather than pass the contents of a
PyFunctionObject
as 8 different parameters, this PR passes a pointer to a struct, and embeds that struct inPyFunctionObject
.Only saves a few lines of code, but should enable more refactorings in
_PyFunction_Vectorcall
and similar functions.https://bugs.python.org/issue42990