Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | #ifndef Py_WEAKREFOBJECT_H |
2 | #define Py_WEAKREFOBJECT_H | |
3 | #ifdef __cplusplus | |
4 | extern "C" { | |
5 | #endif | |
6 | ||
7 | ||
8 | typedef struct _PyWeakReference PyWeakReference; | |
9 | ||
10 | /* PyWeakReference is the base struct for the Python ReferenceType, ProxyType, | |
11 | * and CallableProxyType. | |
12 | */ | |
13 | struct _PyWeakReference { | |
14 | PyObject_HEAD | |
15 | ||
16 | /* The object to which this is a weak reference, or Py_None if none. | |
17 | * Note that this is a stealth reference: wr_object's refcount is | |
18 | * not incremented to reflect this pointer. | |
19 | */ | |
20 | PyObject *wr_object; | |
21 | ||
22 | /* A callable to invoke when wr_object dies, or NULL if none. */ | |
23 | PyObject *wr_callback; | |
24 | ||
25 | /* A cache for wr_object's hash code. As usual for hashes, this is -1 | |
26 | * if the hash code isn't known yet. | |
27 | */ | |
28 | long hash; | |
29 | ||
30 | /* If wr_object is weakly referenced, wr_object has a doubly-linked NULL- | |
31 | * terminated list of weak references to it. These are the list pointers. | |
32 | * If wr_object goes away, wr_object is set to Py_None, and these pointers | |
33 | * have no meaning then. | |
34 | */ | |
35 | PyWeakReference *wr_prev; | |
36 | PyWeakReference *wr_next; | |
37 | }; | |
38 | ||
39 | PyAPI_DATA(PyTypeObject) _PyWeakref_RefType; | |
40 | PyAPI_DATA(PyTypeObject) _PyWeakref_ProxyType; | |
41 | PyAPI_DATA(PyTypeObject) _PyWeakref_CallableProxyType; | |
42 | ||
43 | #define PyWeakref_CheckRef(op) PyObject_TypeCheck(op, &_PyWeakref_RefType) | |
44 | #define PyWeakref_CheckRefExact(op) \ | |
45 | ((op)->ob_type == &_PyWeakref_RefType) | |
46 | #define PyWeakref_CheckProxy(op) \ | |
47 | (((op)->ob_type == &_PyWeakref_ProxyType) || \ | |
48 | ((op)->ob_type == &_PyWeakref_CallableProxyType)) | |
49 | ||
50 | /* This macro calls PyWeakref_CheckRef() last since that can involve a | |
51 | function call; this makes it more likely that the function call | |
52 | will be avoided. */ | |
53 | #define PyWeakref_Check(op) \ | |
54 | (PyWeakref_CheckRef(op) || PyWeakref_CheckProxy(op)) | |
55 | ||
56 | ||
57 | PyAPI_FUNC(PyObject *) PyWeakref_NewRef(PyObject *ob, | |
58 | PyObject *callback); | |
59 | PyAPI_FUNC(PyObject *) PyWeakref_NewProxy(PyObject *ob, | |
60 | PyObject *callback); | |
61 | PyAPI_FUNC(PyObject *) PyWeakref_GetObject(PyObject *ref); | |
62 | ||
63 | PyAPI_FUNC(long) _PyWeakref_GetWeakrefCount(PyWeakReference *head); | |
64 | ||
65 | PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self); | |
66 | ||
67 | #define PyWeakref_GET_OBJECT(ref) (((PyWeakReference *)(ref))->wr_object) | |
68 | ||
69 | ||
70 | #ifdef __cplusplus | |
71 | } | |
72 | #endif | |
73 | #endif /* !Py_WEAKREFOBJECT_H */ |