弱引用对象
int (ob)
如果 “ob” 是一个引用或者一个代理对象,则返回 true。
int PyWeakref_CheckRef
(ob)
如果 “ob” 是一个引用,则返回 true。
int PyWeakref_CheckProxy
(ob)
如果 “ob” 是一个代理对象,则返回 true。
Return value: New reference.
Return a weak reference object for the object ob. This will always return a new reference, but is not guaranteed to create a new object; an existing reference object may be returned. The second parameter, callback, can be a callable object that receives notification when ob is garbage collected; it should accept a single parameter, which will be the weak reference object itself. callback may also be or NULL. If ob is not a weakly-referencable object, or if callback is not callable, None
, or NULL, this will return NULL and raise TypeError.
PyWeakref_NewProxy
(PyObject **ob, *callback)
Return value: New reference.
Return a weak reference proxy object for the object ob. This will always return a new reference, but is not guaranteed to create a new object; an existing proxy object may be returned. The second parameter, callback, can be a callable object that receives notification when ob is garbage collected; it should accept a single parameter, which will be the weak reference object itself. callback may also be None
or NULL. If ob is not a weakly-referencable object, or if callback is not callable, , or NULL, this will return NULL and raise TypeError.
PyWeakref_GetObject
(PyObject **ref)
返回弱引用对象 ref 的被引用对象。如果被引用对象不再存在,则返回 Py_None
。
注解
该函数返回被引用对象的一个借来的引用。这意味着除非你很清楚在你使用期间这个对象不可能被销毁,否则你应该始终对该对象调用 。
PyObject PyWeakref_GET_OBJECT
( **ref)
Return value: Borrowed reference.
类似 PyWeakref_GetObject(),但实现为一个不做类型检查的宏。