Commit Graph

4 Commits

Author SHA1 Message Date
William S Fulton 3438289cad Python weakref support for builtin wrappers and limited API
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.
2025-07-23 22:32:54 +01:00
Jim Easterbrook 0242c35936 Tweak weakref tests for Python 2 2025-07-22 10:20:55 +01:00
Jim Easterbrook 18b3b62d43 More tests of weakref implementation
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.
2025-07-22 10:05:22 +01:00
Jim Easterbrook 976205ef0d Python: add weakref support to builtin types
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).
2025-07-10 08:11:38 +01:00