Skip to content

Commit 79ee4a4

Browse files
author
guido
committed
Move the definition of PyMethodObject to classobject.h, so it can define
macros for more efficient access to the fields. git-svn-id: http://svn.python.org/projects/python/trunk@11139 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 8277afd commit 79ee4a4

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

Include/classobject.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ typedef struct {
5656
PyObject *in_dict; /* A dictionary */
5757
} PyInstanceObject;
5858

59+
typedef struct {
60+
PyObject_HEAD
61+
PyObject *im_func; /* The callable object implementing the method */
62+
PyObject *im_self; /* The instance it is bound to, or NULL */
63+
PyObject *im_class; /* The class that defined the method */
64+
} PyMethodObject;
65+
5966
extern DL_IMPORT(PyTypeObject) PyClass_Type, PyInstance_Type, PyMethod_Type;
6067

6168
#define PyClass_Check(op) ((op)->ob_type == &PyClass_Type)
@@ -70,6 +77,15 @@ extern PyObject *PyMethod_Function Py_PROTO((PyObject *));
7077
extern PyObject *PyMethod_Self Py_PROTO((PyObject *));
7178
extern PyObject *PyMethod_Class Py_PROTO((PyObject *));
7279

80+
/* Macros for direct access to these values. Type checks are *not*
81+
done, so use with care. */
82+
#define PyMethod_GET_FUNCTION(meth) \
83+
(((PyMethodObject *)meth) -> im_func)
84+
#define PyMethod_GET_SELF(meth) \
85+
(((PyMethodObject *)meth) -> im_self)
86+
#define PyMethod_GET_CLASS(meth) \
87+
(((PyMethodObject *)meth) -> im_class)
88+
7389
extern int PyClass_IsSubclass Py_PROTO((PyObject *, PyObject *));
7490

7591
extern PyObject *PyInstance_DoBinOp

Objects/classobject.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,14 +1411,6 @@ PyTypeObject PyInstance_Type = {
14111411
In case (b), im_self is NULL
14121412
*/
14131413

1414-
typedef struct {
1415-
PyObject_HEAD
1416-
PyObject *im_func; /* The function implementing the method */
1417-
PyObject *im_self; /* The instance it is bound to, or NULL */
1418-
PyObject *im_class; /* The class that defined the method */
1419-
} PyMethodObject;
1420-
1421-
14221414
static PyMethodObject *free_list;
14231415

14241416
PyObject *

0 commit comments

Comments
 (0)