descrobject.h 2.06 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
	char *name;
	getter get;
	setter set;
15
	char *doc;
16
	void *closure;
17
} PyGetSetDef;
18 19 20 21

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

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

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

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

38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
/* Various kinds of descriptor objects */

#define PyDescr_COMMON \
	PyObject_HEAD \
	PyTypeObject *d_type; \
	PyObject *d_name

typedef struct {
	PyDescr_COMMON;
} PyDescrObject;

typedef struct {
	PyDescr_COMMON;
	PyMethodDef *d_method;
} PyMethodDescrObject;

typedef struct {
	PyDescr_COMMON;
	struct PyMemberDef *d_member;
} PyMemberDescrObject;

typedef struct {
	PyDescr_COMMON;
	PyGetSetDef *d_getset;
} PyGetSetDescrObject;

typedef struct {
	PyDescr_COMMON;
	struct wrapperbase *d_base;
	void *d_wrapped; /* This can be any function pointer */
} PyWrapperDescrObject;

70
PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
71

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

82 83
PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *);
PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *);
84 85


86
PyAPI_DATA(PyTypeObject) PyProperty_Type;
87 88 89 90 91
#ifdef __cplusplus
}
#endif
#endif /* !Py_DESCROBJECT_H */