descrobject.h 2.77 KB
Newer Older
1
/* Descriptors */
2 3 4 5 6
#ifndef Py_DESCROBJECT_H
#define Py_DESCROBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
7 8 9 10

typedef PyObject *(*getter)(PyObject *, void *);
typedef int (*setter)(PyObject *, PyObject *, void *);

11
typedef struct PyGetSetDef {
12 13 14 15 16
    char *name;
    getter get;
    setter set;
    char *doc;
    void *closure;
17
} PyGetSetDef;
18

19
#ifndef Py_LIMITED_API
20
typedef PyObject *(*wrapperfunc)(PyObject *self, PyObject *args,
21
                                 void *wrapped);
22

23
typedef PyObject *(*wrapperfunc_kwds)(PyObject *self, PyObject *args,
24
                                      void *wrapped, PyObject *kwds);
25

26
struct wrapperbase {
27 28 29 30 31 32 33
    char *name;
    int offset;
    void *function;
    wrapperfunc wrapper;
    char *doc;
    int flags;
    PyObject *name_strobj;
34 35
};

36 37 38
/* Flags for above struct */
#define PyWrapperFlag_KEYWORDS 1 /* wrapper function takes keyword args */

39 40 41
/* Various kinds of descriptor objects */

typedef struct {
42 43 44
    PyObject_HEAD
    PyTypeObject *d_type;
    PyObject *d_name;
45 46
} PyDescrObject;

47 48 49 50 51
#define PyDescr_COMMON PyDescrObject d_common

#define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type)
#define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name)

52
typedef struct {
53 54
    PyDescr_COMMON;
    PyMethodDef *d_method;
55 56 57
} PyMethodDescrObject;

typedef struct {
58 59
    PyDescr_COMMON;
    struct PyMemberDef *d_member;
60 61 62
} PyMemberDescrObject;

typedef struct {
63 64
    PyDescr_COMMON;
    PyGetSetDef *d_getset;
65 66 67
} PyGetSetDescrObject;

typedef struct {
68 69 70
    PyDescr_COMMON;
    struct wrapperbase *d_base;
    void *d_wrapped; /* This can be any function pointer */
71
} PyWrapperDescrObject;
72
#endif /* Py_LIMITED_API */
73

74 75 76 77
PyAPI_DATA(PyTypeObject) PyClassMethodDescr_Type;
PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type;
PyAPI_DATA(PyTypeObject) PyMemberDescr_Type;
PyAPI_DATA(PyTypeObject) PyMethodDescr_Type;
78
PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
79
PyAPI_DATA(PyTypeObject) PyDictProxy_Type;
80

81
PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
82
PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);
83
struct PyMemberDef; /* forward declaration for following prototype */
84
PyAPI_FUNC(PyObject *) PyDescr_NewMember(PyTypeObject *,
85
                                               struct PyMemberDef *);
86
PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *,
87
                                               struct PyGetSetDef *);
88
#ifndef Py_LIMITED_API
89
PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *,
90
                                                struct wrapperbase *, void *);
91
#define PyDescr_IsData(d) (Py_TYPE(d)->tp_descr_set != NULL)
92
#endif
93

94 95
PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *);
PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *);
96 97


98
PyAPI_DATA(PyTypeObject) PyProperty_Type;
99 100 101 102 103
#ifdef __cplusplus
}
#endif
#endif /* !Py_DESCROBJECT_H */