mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
gh-89653: PEP 670: Convert PyFunction macros (#93765)
Convert PyFunction macros to static inline functions.
This commit is contained in:
parent
c5d0517ea4
commit
272bec4adf
1 changed files with 39 additions and 16 deletions
|
@ -82,22 +82,45 @@ PyAPI_FUNC(PyObject *) _PyFunction_Vectorcall(
|
|||
size_t nargsf,
|
||||
PyObject *kwnames);
|
||||
|
||||
/* Macros for direct access to these values. Type checks are *not*
|
||||
done, so use with care. */
|
||||
#define PyFunction_GET_CODE(func) \
|
||||
(((PyFunctionObject *)func) -> func_code)
|
||||
#define PyFunction_GET_GLOBALS(func) \
|
||||
(((PyFunctionObject *)func) -> func_globals)
|
||||
#define PyFunction_GET_MODULE(func) \
|
||||
(((PyFunctionObject *)func) -> func_module)
|
||||
#define PyFunction_GET_DEFAULTS(func) \
|
||||
(((PyFunctionObject *)func) -> func_defaults)
|
||||
#define PyFunction_GET_KW_DEFAULTS(func) \
|
||||
(((PyFunctionObject *)func) -> func_kwdefaults)
|
||||
#define PyFunction_GET_CLOSURE(func) \
|
||||
(((PyFunctionObject *)func) -> func_closure)
|
||||
#define PyFunction_GET_ANNOTATIONS(func) \
|
||||
(((PyFunctionObject *)func) -> func_annotations)
|
||||
#define _PyFunction_CAST(func) \
|
||||
(assert(PyFunction_Check(func)), _Py_CAST(PyFunctionObject*, func))
|
||||
|
||||
/* Static inline functions for direct access to these values.
|
||||
Type checks are *not* done, so use with care. */
|
||||
static inline PyObject* PyFunction_GET_CODE(PyObject *func) {
|
||||
return _PyFunction_CAST(func)->func_code;
|
||||
}
|
||||
#define PyFunction_GET_CODE(func) PyFunction_GET_CODE(_PyObject_CAST(func))
|
||||
|
||||
static inline PyObject* PyFunction_GET_GLOBALS(PyObject *func) {
|
||||
return _PyFunction_CAST(func)->func_globals;
|
||||
}
|
||||
#define PyFunction_GET_GLOBALS(func) PyFunction_GET_GLOBALS(_PyObject_CAST(func))
|
||||
|
||||
static inline PyObject* PyFunction_GET_MODULE(PyObject *func) {
|
||||
return _PyFunction_CAST(func)->func_module;
|
||||
}
|
||||
#define PyFunction_GET_MODULE(func) PyFunction_GET_MODULE(_PyObject_CAST(func))
|
||||
|
||||
static inline PyObject* PyFunction_GET_DEFAULTS(PyObject *func) {
|
||||
return _PyFunction_CAST(func)->func_defaults;
|
||||
}
|
||||
#define PyFunction_GET_DEFAULTS(func) PyFunction_GET_DEFAULTS(_PyObject_CAST(func))
|
||||
|
||||
static inline PyObject* PyFunction_GET_KW_DEFAULTS(PyObject *func) {
|
||||
return _PyFunction_CAST(func)->func_kwdefaults;
|
||||
}
|
||||
#define PyFunction_GET_KW_DEFAULTS(func) PyFunction_GET_KW_DEFAULTS(_PyObject_CAST(func))
|
||||
|
||||
static inline PyObject* PyFunction_GET_CLOSURE(PyObject *func) {
|
||||
return _PyFunction_CAST(func)->func_closure;
|
||||
}
|
||||
#define PyFunction_GET_CLOSURE(func) PyFunction_GET_CLOSURE(_PyObject_CAST(func))
|
||||
|
||||
static inline PyObject* PyFunction_GET_ANNOTATIONS(PyObject *func) {
|
||||
return _PyFunction_CAST(func)->func_annotations;
|
||||
}
|
||||
#define PyFunction_GET_ANNOTATIONS(func) PyFunction_GET_ANNOTATIONS(_PyObject_CAST(func))
|
||||
|
||||
/* The classmethod and staticmethod types lives here, too */
|
||||
PyAPI_DATA(PyTypeObject) PyClassMethod_Type;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue