Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Python 3.13t with GIL #5139

Merged
merged 7 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,38 @@ jobs:
pytest tests/extra_setuptools
if: "!(matrix.runs-on == 'windows-2022')"

manylinux:
name: Manylinux on 🐍 ${{ matrix.python }}
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.13t", "3.13"]
timeout-minutes: 40
container: quay.io/pypa/musllinux_1_2_x86_64:latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Prepare venv
run: python${{ matrix.python }} -m venv .venv

- name: Install Python deps
run: .venv/bin/pip install -r tests/requirements.txt

- name: Configure C++11
run: >
cmake -S. -Bbuild
-DPYBIND11_WERROR=ON
-DDOWNLOAD_CATCH=ON
-DDOWNLOAD_EIGEN=ON
-DPython_ROOT_DIR=.venv

- name: Build C++11
run: cmake --build build -j2

- name: Python tests C++11
run: cmake --build build --target pytest -j2

deadsnakes:
strategy:
Expand Down
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()); }
henryiii marked this conversation as resolved.
Show resolved Hide resolved

// 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)
henryiii marked this conversation as resolved.
Show resolved Hide resolved


def test_reentrant_implicit_conversion_failure(msg):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_embed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ if("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STR
return()
endif()

if(TARGET Python::Module AND NOT TARGET Python::Python)
message(STATUS "Skipping embed test since no embed libs found")
add_custom_target(cpptest) # Dummy target since embedding is not supported.
set(_suppress_unused_variable_warning "${DOWNLOAD_CATCH}")
return()
endif()

find_package(Catch 2.13.9)

if(CATCH_FOUND)
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
Loading