@@ -82,22 +82,45 @@ PyAPI_FUNC(PyObject *) _PyFunction_Vectorcall(
82
82
size_t nargsf ,
83
83
PyObject * kwnames );
84
84
85
- /* Macros for direct access to these values. Type checks are *not*
86
- done, so use with care. */
87
- #define PyFunction_GET_CODE (func ) \
88
- (((PyFunctionObject *)func) -> func_code)
89
- #define PyFunction_GET_GLOBALS (func ) \
90
- (((PyFunctionObject *)func) -> func_globals)
91
- #define PyFunction_GET_MODULE (func ) \
92
- (((PyFunctionObject *)func) -> func_module)
93
- #define PyFunction_GET_DEFAULTS (func ) \
94
- (((PyFunctionObject *)func) -> func_defaults)
95
- #define PyFunction_GET_KW_DEFAULTS (func ) \
96
- (((PyFunctionObject *)func) -> func_kwdefaults)
97
- #define PyFunction_GET_CLOSURE (func ) \
98
- (((PyFunctionObject *)func) -> func_closure)
99
- #define PyFunction_GET_ANNOTATIONS (func ) \
100
- (((PyFunctionObject *)func) -> func_annotations)
85
+ #define _PyFunction_CAST (func ) \
86
+ (assert(PyFunction_Check(func)), _Py_CAST(PyFunctionObject*, func))
87
+
88
+ /* Static inline functions for direct access to these values.
89
+ Type checks are *not* done, so use with care. */
90
+ static inline PyObject * PyFunction_GET_CODE (PyObject * func ) {
91
+ return _PyFunction_CAST (func )-> func_code ;
92
+ }
93
+ #define PyFunction_GET_CODE (func ) PyFunction_GET_CODE(_PyObject_CAST(func))
94
+
95
+ static inline PyObject * PyFunction_GET_GLOBALS (PyObject * func ) {
96
+ return _PyFunction_CAST (func )-> func_globals ;
97
+ }
98
+ #define PyFunction_GET_GLOBALS (func ) PyFunction_GET_GLOBALS(_PyObject_CAST(func))
99
+
100
+ static inline PyObject * PyFunction_GET_MODULE (PyObject * func ) {
101
+ return _PyFunction_CAST (func )-> func_module ;
102
+ }
103
+ #define PyFunction_GET_MODULE (func ) PyFunction_GET_MODULE(_PyObject_CAST(func))
104
+
105
+ static inline PyObject * PyFunction_GET_DEFAULTS (PyObject * func ) {
106
+ return _PyFunction_CAST (func )-> func_defaults ;
107
+ }
108
+ #define PyFunction_GET_DEFAULTS (func ) PyFunction_GET_DEFAULTS(_PyObject_CAST(func))
109
+
110
+ static inline PyObject * PyFunction_GET_KW_DEFAULTS (PyObject * func ) {
111
+ return _PyFunction_CAST (func )-> func_kwdefaults ;
112
+ }
113
+ #define PyFunction_GET_KW_DEFAULTS (func ) PyFunction_GET_KW_DEFAULTS(_PyObject_CAST(func))
114
+
115
+ static inline PyObject * PyFunction_GET_CLOSURE (PyObject * func ) {
116
+ return _PyFunction_CAST (func )-> func_closure ;
117
+ }
118
+ #define PyFunction_GET_CLOSURE (func ) PyFunction_GET_CLOSURE(_PyObject_CAST(func))
119
+
120
+ static inline PyObject * PyFunction_GET_ANNOTATIONS (PyObject * func ) {
121
+ return _PyFunction_CAST (func )-> func_annotations ;
122
+ }
123
+ #define PyFunction_GET_ANNOTATIONS (func ) PyFunction_GET_ANNOTATIONS(_PyObject_CAST(func))
101
124
102
125
/* The classmethod and staticmethod types lives here, too */
103
126
PyAPI_DATA (PyTypeObject ) PyClassMethod_Type ;
0 commit comments