8
Python supports *weak references* as first-class objects. There are two
9
specific object types which directly implement weak references. The first is a
10
simple reference object, and the second acts as a proxy for the original object
14
.. cfunction:: int PyWeakref_Check(ob)
16
Return true if *ob* is either a reference or proxy object.
19
.. cfunction:: int PyWeakref_CheckRef(ob)
21
Return true if *ob* is a reference object.
24
.. cfunction:: int PyWeakref_CheckProxy(ob)
26
Return true if *ob* is a proxy object.
29
.. cfunction:: PyObject* PyWeakref_NewRef(PyObject *ob, PyObject *callback)
31
Return a weak reference object for the object *ob*. This will always return
32
a new reference, but is not guaranteed to create a new object; an existing
33
reference object may be returned. The second parameter, *callback*, can be a
34
callable object that receives notification when *ob* is garbage collected; it
35
should accept a single parameter, which will be the weak reference object
36
itself. *callback* may also be ``None`` or *NULL*. If *ob* is not a
37
weakly-referencable object, or if *callback* is not callable, ``None``, or
38
*NULL*, this will return *NULL* and raise :exc:`TypeError`.
41
.. cfunction:: PyObject* PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
43
Return a weak reference proxy object for the object *ob*. This will always
44
return a new reference, but is not guaranteed to create a new object; an
45
existing proxy object may be returned. The second parameter, *callback*, can
46
be a callable object that receives notification when *ob* is garbage
47
collected; it should accept a single parameter, which will be the weak
48
reference object itself. *callback* may also be ``None`` or *NULL*. If *ob*
49
is not a weakly-referencable object, or if *callback* is not callable,
50
``None``, or *NULL*, this will return *NULL* and raise :exc:`TypeError`.
53
.. cfunction:: PyObject* PyWeakref_GetObject(PyObject *ref)
55
Return the referenced object from a weak reference, *ref*. If the referent is
56
no longer live, returns ``None``.
59
.. cfunction:: PyObject* PyWeakref_GET_OBJECT(PyObject *ref)
61
Similar to :cfunc:`PyWeakref_GetObject`, but implemented as a macro that does no