descrobject.h 2.63 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 */

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

46 47 48 49 50
#define PyDescr_COMMON PyDescrObject d_common

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

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

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

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

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

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

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

89 90
PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *);
PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *);
91 92


93
PyAPI_DATA(PyTypeObject) PyProperty_Type;
94 95 96 97 98
#ifdef __cplusplus
}
#endif
#endif /* !Py_DESCROBJECT_H */