弱参照オブジェクト
******************

Python は *弱参照* を第一級オブジェクト (first-class object) としてサ
ポートします。弱参照を直接実装する二種類の固有のオブジェクト型がありま
す。第一は単純な参照オブジェクトで、第二はオリジナルのオブジェクトに対
して可能な限りプロキシとして振舞うオブジェクトです。

int PyWeakref_Check(PyObject *ob)

   "ob" が弱参照オブジェクトまたはプロキシオブジェクトの場合に非ゼロを
   返します。 この関数は常に成功します。

int PyWeakref_CheckRef(PyObject *ob)

   Return non-zero if *ob* is a reference object or a subclass of the
   reference type.  This function always succeeds.

int PyWeakref_CheckRefExact(PyObject *ob)

   Return non-zero if *ob* is a reference object, but not a subclass
   of the reference type.  This function always succeeds.

int PyWeakref_CheckProxy(PyObject *ob)

   "ob" がプロキシオブジェクトの場合に非ゼロを返します。 この関数は常
   に成功します。

PyObject *PyWeakref_NewRef(PyObject *ob, PyObject *callback)
    *戻り値: 新しい参照。** 次に属します: Stable ABI.*

   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 "None" or "NULL".  If *ob* is not a
   weakly referenceable object, this will raise "TypeError" and return
   "NULL".

   参考:

     "PyType_SUPPORTS_WEAKREFS()" for checking if *ob* is weakly
     referenceable.

PyObject *PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
    *戻り値: 新しい参照。** 次に属します: Stable ABI.*

   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* weakly
   referenceable object, this will raise "TypeError" and return
   "NULL".

   参考:

     "PyType_SUPPORTS_WEAKREFS()" for checking if *ob* is weakly
     referenceable.

int PyWeakref_GetRef(PyObject *ref, PyObject **pobj)
    * 次に属します: Stable ABI (バージョン 3.13 より).*

   弱参照 "ref" から参照先のオブジェクトへの *強参照* を取得し、
   "*pobj" に格納します。

   * 成功した場合は、参照先のオブジェクトへの新しい *強参照* を
     "*pobj" に設定し、1 を返します。

   * 参照先が消滅している場合は、"*pobj" を "NULL" に設定し、0 を返し
     ます。

   * エラーの場合は例外を送出し、-1 を返します。

   Added in version 3.13.

PyObject *PyWeakref_GetObject(PyObject *ref)
    *戻り値: 借用参照。** 次に属します: Stable ABI.*

   Return a *borrowed reference* to the referenced object from a weak
   reference, *ref*.  If the referent is no longer live, returns
   "Py_None".

   注釈:

     This function returns a *borrowed reference* to the referenced
     object. This means that you should always call "Py_INCREF()" on
     the object except when it cannot be destroyed before the last
     usage of the borrowed reference.

   Deprecated since version 3.13, will be removed in version 3.15: Use
   "PyWeakref_GetRef()" instead.

PyObject *PyWeakref_GET_OBJECT(PyObject *ref)
    *戻り値: 借用参照。*

   Similar to "PyWeakref_GetObject()", but does no error checking.

   Deprecated since version 3.13, will be removed in version 3.15: Use
   "PyWeakref_GetRef()" instead.

void PyObject_ClearWeakRefs(PyObject *object)
    * 次に属します: Stable ABI.*

   この関数は、弱参照をクリアするために "tp_dealloc" ハンドラから呼び
   出されます。

   "object" への弱参照を順に調べ、コールバックを持つものについてはその
   コールバックを呼び出します。 すべてのコールバックの呼び出しを試みた
   後で戻ります。

void PyUnstable_Object_ClearWeakRefsNoCallbacks(PyObject *object)

   *これは Unstable APIです。マイナーリリースで予告なく変更されること
   があります。*

   コールバックを呼び出さずに "object" への弱参照をクリアします。

   この関数は、ファイナライザ (つまり "__del__()") を持つ型の
   "tp_dealloc" ハンドラから呼び出されます。 このようなオブジェクトの
   ハンドラは、まず "PyObject_ClearWeakRefs()" を呼び出して弱参照をク
   リアし、そのコールバックを呼び出します。 次にファイナライザを呼び出
   し、最後にこの関数を呼び出してファイナライザが作成した可能性のある
   弱参照をクリアします。

   ほとんどの場合、弱参照のクリアにはこの関数よりも
   "PyObject_ClearWeakRefs()" を使う方が適切です。

   Added in version 3.13.
