Skip to content

Commit

Permalink
fix: support Python 3.13t
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed May 24, 2024
1 parent 15bc5f3 commit c57a840
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/pybind11/pytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class object_api : public pyobject_tag {
str_attr_accessor doc() const;

/// Return the object's current reference count
int ref_count() const { return static_cast<int>(Py_REFCNT(derived().ptr())); }
ssize_t ref_count() const { return Py_REFCNT(derived().ptr()); }

// TODO PYBIND11_DEPRECATED(
// "Call py::type::handle_of(h) or py::type::of(h) instead of h.get_type()")
Expand Down
3 changes: 2 additions & 1 deletion tests/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ class PyDog(m.Dog):
refcount_3 = getrefcount(cls)

assert refcount_1 == refcount_3
assert refcount_2 > refcount_1
# Free-threaded Python uses UINT32_MAX for immortal objects
assert (refcount_2 > refcount_1) or (refcount_2 == refcount_1 == 2**32 - 1)


def test_reentrant_implicit_conversion_failure(msg):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_pytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,8 @@ def test_memoryview_refcount(method):
ref_before = sys.getrefcount(buf)
view = method(buf)
ref_after = sys.getrefcount(buf)
assert ref_before < ref_after
# Free threaded Python uses UINT32_MAX
assert ref_before < ref_after or ref_before == ref_after == 2**32 - 1
assert list(view) == list(buf)


Expand Down

0 comments on commit c57a840

Please sign in to comment.