Adds weakref support to the SwigPyObject class used as a base for all
builtin wrapper types defined as heap types (the default).
However, like __dictoffset__, the __weaklistoffset__ members slot is only
available in the limited API from python-3.9 onwards.
Document the previous commit which adds the bulk of the weakref support
to builtin wrappers.
Ensure the object is accessible via the weak reference, that the
object's weak ref count is incremented and decremented correctly, that
the weak refs are invalidated when the object is deleted, and that any
weak ref callback is called when the object is deleted.
These changes add a weakreflist member to SwigPyObject, and set
tp_weaklistoffset to its offset. This fixes#1792.
The Py_TPFLAGS_MANAGED_WEAKREF introduced in Python 3.12 requires
Py_TPFLAGS_HAVE_GC to be set as well, which it currently isn't for
SwigPyObjectType. (See https://github.com/python/cpython/issues/134786).