blob: 3503892e0e67d65e00280f1c312b879ef4d3c2b5 [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 Drake0a4dd392004-07-02 18:57:45 +000025#define PyWeakref_CheckRef(op) PyObject_TypeCheck(op, &_PyWeakref_RefType)
26#define PyWeakref_CheckRefExact(op) \
Fred Drake8844d522001-10-05 21:52:26 +000027 ((op)->ob_type == &_PyWeakref_RefType)
28#define PyWeakref_CheckProxy(op) \
29 (((op)->ob_type == &_PyWeakref_ProxyType) || \
30 ((op)->ob_type == &_PyWeakref_CallableProxyType))
Fred Drake0a4dd392004-07-02 18:57:45 +000031
32/* This macro calls PyWeakref_CheckRef() last since that can involve a
33 function call; this makes it more likely that the function call
34 will be avoided. */
Fred Drake8844d522001-10-05 21:52:26 +000035#define PyWeakref_Check(op) \
36 (PyWeakref_CheckRef(op) || PyWeakref_CheckProxy(op))
37
38
Mark Hammond91a681d2002-08-12 07:21:58 +000039PyAPI_FUNC(PyObject *) PyWeakref_NewRef(PyObject *ob,
Fred Drake8844d522001-10-05 21:52:26 +000040 PyObject *callback);
Mark Hammond91a681d2002-08-12 07:21:58 +000041PyAPI_FUNC(PyObject *) PyWeakref_NewProxy(PyObject *ob,
Fred Drake8844d522001-10-05 21:52:26 +000042 PyObject *callback);
Mark Hammond91a681d2002-08-12 07:21:58 +000043PyAPI_FUNC(PyObject *) PyWeakref_GetObject(PyObject *ref);
Fred Drake8844d522001-10-05 21:52:26 +000044
Mark Hammond91a681d2002-08-12 07:21:58 +000045PyAPI_FUNC(long) _PyWeakref_GetWeakrefCount(PyWeakReference *head);
Fred Drake8844d522001-10-05 21:52:26 +000046
Tim Peters403a2032003-11-20 21:21:46 +000047PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self);
48
Fred Drake8844d522001-10-05 21:52:26 +000049#define PyWeakref_GET_OBJECT(ref) (((PyWeakReference *)(ref))->wr_object)
50
51
52#ifdef __cplusplus
53}
54#endif
55#endif /* !Py_WEAKREFOBJECT_H */