blob: b6fc389f6717e6631777792ad987aa27a84e8242 [file] [log] [blame]
Fred Drake8844d522001-10-05 21:52:26 +00001/* Weak references objects for Python. */
2
3#ifndef Py_WEAKREFOBJECT_H
4#define Py_WEAKREFOBJECT_H
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9
10typedef struct _PyWeakReference PyWeakReference;
11
12struct _PyWeakReference {
13 PyObject_HEAD
14 PyObject *wr_object;
15 PyObject *wr_callback;
16 long hash;
17 PyWeakReference *wr_prev;
18 PyWeakReference *wr_next;
19};
20
Mark Hammond91a681d2002-08-12 07:21:58 +000021PyAPI_DATA(PyTypeObject) _PyWeakref_RefType;
22PyAPI_DATA(PyTypeObject) _PyWeakref_ProxyType;
23PyAPI_DATA(PyTypeObject) _PyWeakref_CallableProxyType;
Fred Drake8844d522001-10-05 21:52:26 +000024
Fred Drake8844d522001-10-05 21:52:26 +000025#define PyWeakref_CheckRef(op) \
26 ((op)->ob_type == &_PyWeakref_RefType)
27#define PyWeakref_CheckProxy(op) \
28 (((op)->ob_type == &_PyWeakref_ProxyType) || \
29 ((op)->ob_type == &_PyWeakref_CallableProxyType))
30#define PyWeakref_Check(op) \
31 (PyWeakref_CheckRef(op) || PyWeakref_CheckProxy(op))
32
33
Mark Hammond91a681d2002-08-12 07:21:58 +000034PyAPI_FUNC(PyObject *) PyWeakref_NewRef(PyObject *ob,
Fred Drake8844d522001-10-05 21:52:26 +000035 PyObject *callback);
Mark Hammond91a681d2002-08-12 07:21:58 +000036PyAPI_FUNC(PyObject *) PyWeakref_NewProxy(PyObject *ob,
Fred Drake8844d522001-10-05 21:52:26 +000037 PyObject *callback);
Mark Hammond91a681d2002-08-12 07:21:58 +000038PyAPI_FUNC(PyObject *) PyWeakref_GetObject(PyObject *ref);
Fred Drake8844d522001-10-05 21:52:26 +000039
Mark Hammond91a681d2002-08-12 07:21:58 +000040PyAPI_FUNC(long) _PyWeakref_GetWeakrefCount(PyWeakReference *head);
Fred Drake8844d522001-10-05 21:52:26 +000041
42#define PyWeakref_GET_OBJECT(ref) (((PyWeakReference *)(ref))->wr_object)
43
44
45#ifdef __cplusplus
46}
47#endif
48#endif /* !Py_WEAKREFOBJECT_H */