descrobject.h 2.42 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

typedef PyObject *(*wrapperfunc)(PyObject *self, PyObject *args,
20
                                 void *wrapped);
21

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

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

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

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

#define PyDescr_COMMON \
41 42 43
    PyObject_HEAD \
    PyTypeObject *d_type; \
    PyObject *d_name
44 45

typedef struct {
46
    PyDescr_COMMON;
47 48 49
} PyDescrObject;

typedef struct {
50 51
    PyDescr_COMMON;
    PyMethodDef *d_method;
52 53 54
} PyMethodDescrObject;

typedef struct {
55 56
    PyDescr_COMMON;
    struct PyMemberDef *d_member;
57 58 59
} PyMemberDescrObject;

typedef struct {
60 61
    PyDescr_COMMON;
    PyGetSetDef *d_getset;
62 63 64
} PyGetSetDescrObject;

typedef struct {
65 66 67
    PyDescr_COMMON;
    struct wrapperbase *d_base;
    void *d_wrapped; /* This can be any function pointer */
68 69
} PyWrapperDescrObject;

70
PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
71 72 73
PyAPI_DATA(PyTypeObject) PyDictProxy_Type;
PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type;
PyAPI_DATA(PyTypeObject) PyMemberDescr_Type;
74

75
PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
76
PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);
77
PyAPI_FUNC(PyObject *) PyDescr_NewMember(PyTypeObject *,
78
                                               struct PyMemberDef *);
79
PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *,
80
                                               struct PyGetSetDef *);
81
PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *,
82
                                                struct wrapperbase *, void *);
83
#define PyDescr_IsData(d) (Py_TYPE(d)->tp_descr_set != NULL)
84

85 86
PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *);
PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *);
87 88


89
PyAPI_DATA(PyTypeObject) PyProperty_Type;
90 91 92 93 94
#ifdef __cplusplus
}
#endif
#endif /* !Py_DESCROBJECT_H */