Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9223351

Browse files
committed
Marc-Andre Lemburg's patch to move the typedef for PyCFunctionObject
to the .h file and add macros there for inlined access to the fields.
1 parent eeb6428 commit 9223351

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

Include/methodobject.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ extern PyCFunction PyCFunction_GetFunction Py_PROTO((PyObject *));
4949
extern PyObject *PyCFunction_GetSelf Py_PROTO((PyObject *));
5050
extern int PyCFunction_GetFlags Py_PROTO((PyObject *));
5151

52+
/* Macros for direct access to these values. Type checks are *not*
53+
done, so use with care. */
54+
#define PyCFunction_GET_FUNCTION(func) \
55+
(((PyCFunctionObject *)func) -> m_ml -> ml_meth)
56+
#define PyCFunction_GET_SELF(func) \
57+
(((PyCFunctionObject *)func) -> m_self)
58+
#define PyCFunction_GET_FLAGS(func) \
59+
(((PyCFunctionObject *)func) -> m_ml -> ml_flags)
60+
5261
struct PyMethodDef {
5362
char *ml_name;
5463
PyCFunction ml_meth;
@@ -75,6 +84,12 @@ typedef struct PyMethodChain {
7584
extern PyObject *Py_FindMethodInChain
7685
Py_PROTO((PyMethodChain *, PyObject *, char *));
7786

87+
typedef struct {
88+
PyObject_HEAD
89+
PyMethodDef *m_ml;
90+
PyObject *m_self;
91+
} PyCFunctionObject;
92+
7893
#ifdef __cplusplus
7994
}
8095
#endif

Objects/methodobject.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ PERFORMANCE OF THIS SOFTWARE.
3535

3636
#include "token.h"
3737

38-
typedef struct {
39-
PyObject_HEAD
40-
PyMethodDef *m_ml;
41-
PyObject *m_self;
42-
} PyCFunctionObject;
43-
4438
static PyCFunctionObject *free_list = NULL;
4539

4640
PyObject *

0 commit comments

Comments
 (0)