From 4d077ecbbcace823f4d296ea276ea511ca51a2e8 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Mon, 17 Oct 2022 10:18:22 -0700 Subject: [PATCH 01/14] pybind11/pytypes.h `inc_ref()`, `dec_ref()` `PyGILState_Check()` **excluding** `nullptr` Guarded by `PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF` --- include/pybind11/detail/common.h | 5 +++++ include/pybind11/pytypes.h | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index 6da7ef859c..d4112cf6af 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -259,6 +259,11 @@ # endif #endif +#if !defined(NDEBUG) && !defined(PY_ASSERT_GIL_HELD_INCREF_DECREF) \ + && !defined(PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF) +# define PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF +#endif + // #define PYBIND11_STR_LEGACY_PERMISSIVE // If DEFINED, pybind11::str can hold PyUnicodeObject or PyBytesObject // (probably surprising and never documented, but this was the diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 37fc49a0e1..4ef0819a6f 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -246,6 +246,11 @@ class handle : public detail::object_api { const handle &inc_ref() const & { #ifdef PYBIND11_HANDLE_REF_DEBUG inc_ref_counter(1); +#endif +#if defined(PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF) + if (m_ptr != nullptr && !PyGILState_Check()) { + throw std::runtime_error("pybind11::handle::inc_ref() PyGILState_Check() failure."); + } #endif Py_XINCREF(m_ptr); return *this; @@ -257,6 +262,11 @@ class handle : public detail::object_api { this function automatically. Returns a reference to itself. \endrst */ const handle &dec_ref() const & { +#if defined(PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF) + if (m_ptr != nullptr && !PyGILState_Check()) { + throw std::runtime_error("pybind11::handle::dec_ref() PyGILState_Check() failure."); + } +#endif Py_XDECREF(m_ptr); return *this; } From 3cc9171aa4489781c790d30c5b8d2444c793631a Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Mon, 17 Oct 2022 12:07:10 -0700 Subject: [PATCH 02/14] Disable `PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF` for PyPy under Windows. --- include/pybind11/detail/common.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index d4112cf6af..49528ba849 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -259,7 +259,9 @@ # endif #endif +// See description of PR #4246: #if !defined(NDEBUG) && !defined(PY_ASSERT_GIL_HELD_INCREF_DECREF) \ + && !(defined(PYPY_VERSION) && defined(_MSC_VER)) /* Tests hang indefinitely at startup. */ \ && !defined(PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF) # define PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF #endif From 89833837331e4bcde0302a239f1fc5889b890017 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 20 Oct 2022 21:47:40 -0700 Subject: [PATCH 03/14] Strip down ci.yml to only test pypy-3.9 windows-2022 test_gil_scoped.cpp --- .github/workflows/ci.yml | 885 +-------------------------------------- 1 file changed, 4 insertions(+), 881 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2951a0ad19..33ffa4e9fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,41 +25,11 @@ jobs: strategy: fail-fast: false matrix: - runs-on: [ubuntu-latest, windows-2022, macos-latest] + runs-on: [windows-2022] python: - - '3.6' - - '3.9' - - '3.10' - - '3.11-dev' - - 'pypy-3.7' - - 'pypy-3.8' - 'pypy-3.9' - # Items in here will either be added to the build matrix (if not - # present), or add new keys to an existing matrix element if all the - # existing keys match. - # - # We support an optional key: args, for cmake args - include: - # Just add a key - - runs-on: ubuntu-latest - python: '3.6' - args: > - -DPYBIND11_FINDPYTHON=ON - -DCMAKE_CXX_FLAGS="-D_=1" - - runs-on: ubuntu-latest - python: 'pypy-3.8' - args: > - -DPYBIND11_FINDPYTHON=ON - - runs-on: windows-2019 - python: '3.6' - args: > - -DPYBIND11_FINDPYTHON=ON - # Inject a couple Windows 2019 runs - - runs-on: windows-2019 - python: '3.9' - - name: "🐍 ${{ matrix.python }} • ${{ matrix.runs-on }} • x64 ${{ matrix.args }}" + name: "🐍 ${{ matrix.python }} • ${{ matrix.runs-on }} • x64 REDUCED" runs-on: ${{ matrix.runs-on }} steps: @@ -102,864 +72,17 @@ jobs: run: python -m pip install pytest-github-actions-annotate-failures # First build - C++11 mode and inplace - - name: Configure C++11 ${{ matrix.args }} + - name: Configure C++11 run: > cmake -S . -B . -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON -DCMAKE_CXX_STANDARD=11 - ${{ matrix.args }} + -DPYBIND11_TEST_FILTER="test_gil_scoped.cpp" - name: Build C++11 run: cmake --build . -j 2 - name: Python tests C++11 run: cmake --build . --target pytest -j 2 - - - name: C++11 tests - # TODO: Figure out how to load the DLL on Python 3.8+ - if: "!(runner.os == 'Windows' && (matrix.python == 3.8 || matrix.python == 3.9 || matrix.python == '3.10' || matrix.python == '3.11-dev' || matrix.python == 'pypy-3.8'))" - run: cmake --build . --target cpptest -j 2 - - - name: Interface test C++11 - run: cmake --build . --target test_cmake_build - - - name: Clean directory - run: git clean -fdx - - # Second build - C++17 mode and in a build directory - - name: Configure C++17 - run: > - cmake -S . -B build2 - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=17 - ${{ matrix.args }} - - - name: Build - run: cmake --build build2 -j 2 - - - name: Python tests - run: cmake --build build2 --target pytest - - - name: C++ tests - # TODO: Figure out how to load the DLL on Python 3.8+ - if: "!(runner.os == 'Windows' && (matrix.python == 3.8 || matrix.python == 3.9 || matrix.python == '3.10' || matrix.python == '3.11-dev' || matrix.python == 'pypy-3.8'))" - run: cmake --build build2 --target cpptest - - # Third build - C++17 mode with unstable ABI - - name: Configure (unstable ABI) - run: > - cmake -S . -B build3 - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=17 - -DPYBIND11_INTERNALS_VERSION=10000000 - "-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp" - ${{ matrix.args }} - - - name: Build (unstable ABI) - run: cmake --build build3 -j 2 - - - name: Python tests (unstable ABI) - run: cmake --build build3 --target pytest - - - name: Interface test - run: cmake --build build2 --target test_cmake_build - - # This makes sure the setup_helpers module can build packages using - # setuptools - - name: Setuptools helpers test - run: pytest tests/extra_setuptools - if: "!(matrix.runs-on == 'windows-2022')" - - - deadsnakes: - strategy: - fail-fast: false - matrix: - include: - # TODO: Fails on 3.10, investigate - - python-version: "3.9" - python-debug: true - valgrind: true - - python-version: "3.11-dev" - python-debug: false - - name: "🐍 ${{ matrix.python-version }}${{ matrix.python-debug && '-dbg' || '' }} (deadsnakes)${{ matrix.valgrind && ' • Valgrind' || '' }} • x64" - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Setup Python ${{ matrix.python-version }} (deadsnakes) - uses: deadsnakes/action@v2.1.1 - with: - python-version: ${{ matrix.python-version }} - debug: ${{ matrix.python-debug }} - - - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.13 - - - name: Valgrind cache - if: matrix.valgrind - uses: actions/cache@v3 - id: cache-valgrind - with: - path: valgrind - key: 3.16.1 # Valgrind version - - - name: Compile Valgrind - if: matrix.valgrind && steps.cache-valgrind.outputs.cache-hit != 'true' - run: | - VALGRIND_VERSION=3.16.1 - curl https://sourceware.org/pub/valgrind/valgrind-$VALGRIND_VERSION.tar.bz2 -o - | tar xj - mv valgrind-$VALGRIND_VERSION valgrind - cd valgrind - ./configure - make -j 2 > /dev/null - - - name: Install Valgrind - if: matrix.valgrind - working-directory: valgrind - run: | - sudo make install - sudo apt-get update - sudo apt-get install libc6-dbg # Needed by Valgrind - - - name: Prepare env - run: | - python -m pip install -r tests/requirements.txt - - - name: Configure - env: - SETUPTOOLS_USE_DISTUTILS: stdlib - run: > - cmake -S . -B build - -DCMAKE_BUILD_TYPE=Debug - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=17 - - - name: Build - run: cmake --build build -j 2 - - - name: Python tests - run: cmake --build build --target pytest - - - name: C++ tests - run: cmake --build build --target cpptest - - - name: Run Valgrind on Python tests - if: matrix.valgrind - run: cmake --build build --target memcheck - - - # Testing on clang using the excellent silkeh clang docker images - clang: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - clang: - - 3.6 - - 3.7 - - 3.9 - - 7 - - 9 - - dev - std: - - 11 - include: - - clang: 5 - std: 14 - - clang: 10 - std: 20 - - clang: 10 - std: 17 - - clang: 11 - std: 20 - - clang: 12 - std: 20 - - clang: 13 - std: 20 - - clang: 14 - std: 20 - - name: "🐍 3 • Clang ${{ matrix.clang }} • C++${{ matrix.std }} • x64" - container: "silkeh/clang:${{ matrix.clang }}" - - steps: - - uses: actions/checkout@v3 - - - name: Add wget and python3 - run: apt-get update && apt-get install -y python3-dev python3-numpy python3-pytest libeigen3-dev - - - name: Configure - shell: bash - run: > - cmake -S . -B build - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DCMAKE_CXX_STANDARD=${{ matrix.std }} - -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - - - name: Build - run: cmake --build build -j 2 - - - name: Python tests - run: cmake --build build --target pytest - - - name: C++ tests - run: cmake --build build --target cpptest - - - name: Interface test - run: cmake --build build --target test_cmake_build - - - # Testing NVCC; forces sources to behave like .cu files - cuda: - runs-on: ubuntu-latest - name: "🐍 3.10 • CUDA 11.7 • Ubuntu 22.04" - container: nvidia/cuda:11.7.0-devel-ubuntu22.04 - - steps: - - uses: actions/checkout@v3 - - # tzdata will try to ask for the timezone, so set the DEBIAN_FRONTEND - - name: Install 🐍 3 - run: apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y cmake git python3-dev python3-pytest python3-numpy - - - name: Configure - run: cmake -S . -B build -DPYBIND11_CUDA_TESTS=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON - - - name: Build - run: cmake --build build -j2 --verbose - - - name: Python tests - run: cmake --build build --target pytest - - -# TODO: Internal compiler error - report to NVidia -# # Testing CentOS 8 + PGI compilers -# centos-nvhpc8: -# runs-on: ubuntu-latest -# name: "🐍 3 • CentOS8 / PGI 20.11 • x64" -# container: centos:8 -# -# steps: -# - uses: actions/checkout@v3 -# -# - name: Add Python 3 and a few requirements -# run: yum update -y && yum install -y git python3-devel python3-numpy python3-pytest make environment-modules -# -# - name: Install CMake with pip -# run: | -# python3 -m pip install --upgrade pip -# python3 -m pip install cmake --prefer-binary -# -# - name: Install NVidia HPC SDK -# run: > -# yum -y install -# https://developer.download.nvidia.com/hpc-sdk/20.11/nvhpc-20-11-20.11-1.x86_64.rpm -# https://developer.download.nvidia.com/hpc-sdk/20.11/nvhpc-2020-20.11-1.x86_64.rpm -# -# - name: Configure -# shell: bash -# run: | -# source /etc/profile.d/modules.sh -# module load /opt/nvidia/hpc_sdk/modulefiles/nvhpc/20.11 -# cmake -S . -B build -DDOWNLOAD_CATCH=ON -DCMAKE_CXX_STANDARD=14 -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") -# -# - name: Build -# run: cmake --build build -j 2 --verbose -# -# - name: Python tests -# run: cmake --build build --target pytest -# -# - name: C++ tests -# run: cmake --build build --target cpptest -# -# - name: Interface test -# run: cmake --build build --target test_cmake_build - - - # Testing on CentOS 7 + PGI compilers, which seems to require more workarounds - centos-nvhpc7: - runs-on: ubuntu-latest - name: "🐍 3 • CentOS7 / PGI 22.9 • x64" - container: centos:7 - - steps: - - uses: actions/checkout@v3 - - - name: Add Python 3 and a few requirements - run: yum update -y && yum install -y epel-release && yum install -y git python3-devel make environment-modules cmake3 yum-utils - - - name: Install NVidia HPC SDK - run: yum-config-manager --add-repo https://developer.download.nvidia.com/hpc-sdk/rhel/nvhpc.repo && yum -y install nvhpc-22.9 - - # On CentOS 7, we have to filter a few tests (compiler internal error) - # and allow deeper template recursion (not needed on CentOS 8 with a newer - # standard library). On some systems, you many need further workarounds: - # https://github.com/pybind/pybind11/pull/2475 - - name: Configure - shell: bash - run: | - source /etc/profile.d/modules.sh - module load /opt/nvidia/hpc_sdk/modulefiles/nvhpc/22.9 - cmake3 -S . -B build -DDOWNLOAD_CATCH=ON \ - -DCMAKE_CXX_STANDARD=11 \ - -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") \ - -DCMAKE_CXX_FLAGS="-Wc,--pending_instantiations=0" \ - -DPYBIND11_TEST_FILTER="test_smart_ptr.cpp" - - # Building before installing Pip should produce a warning but not an error - - name: Build - run: cmake3 --build build -j 2 --verbose - - - name: Install CMake with pip - run: | - python3 -m pip install --upgrade pip - python3 -m pip install pytest - - - name: Python tests - run: cmake3 --build build --target pytest - - - name: C++ tests - run: cmake3 --build build --target cpptest - - - name: Interface test - run: cmake3 --build build --target test_cmake_build - - - # Testing on GCC using the GCC docker images (only recent images supported) - gcc: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - include: - - { gcc: 7, std: 11 } - - { gcc: 7, std: 17 } - - { gcc: 8, std: 14 } - - { gcc: 8, std: 17 } - - { gcc: 10, std: 17 } - - { gcc: 11, std: 20 } - - { gcc: 12, std: 20 } - - name: "🐍 3 • GCC ${{ matrix.gcc }} • C++${{ matrix.std }}• x64" - container: "gcc:${{ matrix.gcc }}" - - steps: - - uses: actions/checkout@v3 - - - name: Add Python 3 - run: apt-get update; apt-get install -y python3-dev python3-numpy python3-pytest python3-pip libeigen3-dev - - - name: Update pip - run: python3 -m pip install --upgrade pip - - - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.13 - - - name: Configure - shell: bash - run: > - cmake -S . -B build - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DCMAKE_CXX_STANDARD=${{ matrix.std }} - -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - - - name: Build - run: cmake --build build -j 2 - - - name: Python tests - run: cmake --build build --target pytest - - - name: C++ tests - run: cmake --build build --target cpptest - - - name: Interface test - run: cmake --build build --target test_cmake_build - - - # Testing on ICC using the oneAPI apt repo - icc: - runs-on: ubuntu-20.04 - strategy: - fail-fast: false - - name: "🐍 3 • ICC latest • x64" - - steps: - - uses: actions/checkout@v3 - - - name: Add apt repo - run: | - sudo apt-get update - sudo apt-get install -y wget build-essential pkg-config cmake ca-certificates gnupg - wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB - sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB - echo "deb https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list - - - name: Add ICC & Python 3 - run: sudo apt-get update; sudo apt-get install -y intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic cmake python3-dev python3-numpy python3-pytest python3-pip - - - name: Update pip - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - python3 -m pip install --upgrade pip - - - name: Install dependencies - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - python3 -m pip install -r tests/requirements.txt - - - name: Configure C++11 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - cmake -S . -B build-11 \ - -DPYBIND11_WERROR=ON \ - -DDOWNLOAD_CATCH=ON \ - -DDOWNLOAD_EIGEN=OFF \ - -DCMAKE_CXX_STANDARD=11 \ - -DCMAKE_CXX_COMPILER=$(which icpc) \ - -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - - - name: Build C++11 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - cmake --build build-11 -j 2 -v - - - name: Python tests C++11 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - sudo service apport stop - cmake --build build-11 --target check - - - name: C++ tests C++11 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - cmake --build build-11 --target cpptest - - - name: Interface test C++11 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - cmake --build build-11 --target test_cmake_build - - - name: Configure C++17 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - cmake -S . -B build-17 \ - -DPYBIND11_WERROR=ON \ - -DDOWNLOAD_CATCH=ON \ - -DDOWNLOAD_EIGEN=OFF \ - -DCMAKE_CXX_STANDARD=17 \ - -DCMAKE_CXX_COMPILER=$(which icpc) \ - -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - - - name: Build C++17 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - cmake --build build-17 -j 2 -v - - - name: Python tests C++17 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - sudo service apport stop - cmake --build build-17 --target check - - - name: C++ tests C++17 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - cmake --build build-17 --target cpptest - - - name: Interface test C++17 - run: | - set +e; source /opt/intel/oneapi/setvars.sh; set -e - cmake --build build-17 --target test_cmake_build - - - # Testing on CentOS (manylinux uses a centos base, and this is an easy way - # to get GCC 4.8, which is the manylinux1 compiler). - centos: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - container: - - "centos:7" # GCC 4.8 - - "almalinux:8" - - "almalinux:9" - - name: "🐍 3 • ${{ matrix.container }} • x64" - container: "${{ matrix.container }}" - - steps: - - uses: actions/checkout@v3 - - - name: Add Python 3 (RHEL 7) - if: matrix.container == 'centos:7' - run: yum update -y && yum install -y python3-devel gcc-c++ make git - - - name: Add Python 3 (RHEL 8+) - if: matrix.container != 'centos:7' - run: dnf update -y && dnf install -y python3-devel gcc-c++ make git - - - name: Update pip - run: python3 -m pip install --upgrade pip - - - name: Install dependencies - run: | - python3 -m pip install cmake -r tests/requirements.txt - - - name: Configure - shell: bash - run: > - cmake -S . -B build - -DCMAKE_BUILD_TYPE=MinSizeRel - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=11 - -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - - - name: Build - run: cmake --build build -j 2 - - - name: Python tests - run: cmake --build build --target pytest - - - name: C++ tests - run: cmake --build build --target cpptest - - - name: Interface test - run: cmake --build build --target test_cmake_build - - - # This tests an "install" with the CMake tools - install-classic: - name: "🐍 3.7 • Debian • x86 • Install" - runs-on: ubuntu-latest - container: i386/debian:buster - - steps: - - uses: actions/checkout@v1 # Required to run inside docker - - - name: Install requirements - run: | - apt-get update - apt-get install -y git make cmake g++ libeigen3-dev python3-dev python3-pip - pip3 install "pytest==6.*" - - - name: Configure for install - run: > - cmake . - -DPYBIND11_INSTALL=1 -DPYBIND11_TEST=0 - -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - - - name: Make and install - run: make install - - - name: Copy tests to new directory - run: cp -a tests /pybind11-tests - - - name: Make a new test directory - run: mkdir /build-tests - - - name: Configure tests - run: > - cmake ../pybind11-tests - -DDOWNLOAD_CATCH=ON - -DPYBIND11_WERROR=ON - -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - working-directory: /build-tests - - - name: Python tests - run: make pytest -j 2 - working-directory: /build-tests - - - # This verifies that the documentation is not horribly broken, and does a - # basic validation check on the SDist. - doxygen: - name: "Documentation build test" - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-python@v4 - with: - python-version: "3.x" - - - name: Install Doxygen - run: sudo apt-get install -y doxygen librsvg2-bin # Changed to rsvg-convert in 20.04 - - - name: Build docs - run: pipx run nox -s docs - - - name: Make SDist - run: pipx run nox -s build -- --sdist - - - run: git status --ignored - - - name: Check local include dir - run: > - ls pybind11; - python3 -c "import pybind11, pathlib; assert (a := pybind11.get_include()) == (b := str(pathlib.Path('include').resolve())), f'{a} != {b}'" - - - name: Compare Dists (headers only) - working-directory: include - run: | - python3 -m pip install --user -U ../dist/*.tar.gz - installed=$(python3 -c "import pybind11; print(pybind11.get_include() + '/pybind11')") - diff -rq $installed ./pybind11 - - win32: - strategy: - fail-fast: false - matrix: - python: - - 3.6 - - 3.7 - - 3.8 - - 3.9 - - include: - - python: 3.9 - args: -DCMAKE_CXX_STANDARD=20 - - python: 3.8 - args: -DCMAKE_CXX_STANDARD=17 - - python: 3.7 - args: -DCMAKE_CXX_STANDARD=14 - - - name: "🐍 ${{ matrix.python }} • MSVC 2019 • x86 ${{ matrix.args }}" - runs-on: windows-2019 - - steps: - - uses: actions/checkout@v3 - - - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python }} - architecture: x86 - - - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.13 - - - name: Prepare MSVC - uses: ilammy/msvc-dev-cmd@v1.12.0 - with: - arch: x86 - - - name: Prepare env - run: | - python -m pip install -r tests/requirements.txt - - # First build - C++11 mode and inplace - - name: Configure ${{ matrix.args }} - run: > - cmake -S . -B build - -G "Visual Studio 16 2019" -A Win32 - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - ${{ matrix.args }} - - name: Build C++11 - run: cmake --build build -j 2 - - - name: Python tests - run: cmake --build build -t pytest - - win32-debug: - strategy: - fail-fast: false - matrix: - python: - - 3.8 - - 3.9 - - include: - - python: 3.9 - args: -DCMAKE_CXX_STANDARD=20 - - python: 3.8 - args: -DCMAKE_CXX_STANDARD=17 - - name: "🐍 ${{ matrix.python }} • MSVC 2019 (Debug) • x86 ${{ matrix.args }}" - runs-on: windows-2019 - - steps: - - uses: actions/checkout@v3 - - - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python }} - architecture: x86 - - - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.13 - - - name: Prepare MSVC - uses: ilammy/msvc-dev-cmd@v1.12.0 - with: - arch: x86 - - - name: Prepare env - run: | - python -m pip install -r tests/requirements.txt - - # First build - C++11 mode and inplace - - name: Configure ${{ matrix.args }} - run: > - cmake -S . -B build - -G "Visual Studio 16 2019" -A Win32 - -DCMAKE_BUILD_TYPE=Debug - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - ${{ matrix.args }} - - name: Build C++11 - run: cmake --build build --config Debug -j 2 - - - name: Python tests - run: cmake --build build --config Debug -t pytest - - - windows-2022: - strategy: - fail-fast: false - matrix: - python: - - 3.9 - - name: "🐍 ${{ matrix.python }} • MSVC 2022 C++20 • x64" - runs-on: windows-2022 - - steps: - - uses: actions/checkout@v3 - - - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python }} - - - name: Prepare env - run: | - python3 -m pip install -r tests/requirements.txt - - - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.13 - - - name: Configure C++20 - run: > - cmake -S . -B build - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=20 - - - name: Build C++20 - run: cmake --build build -j 2 - - - name: Python tests - run: cmake --build build --target pytest - - - name: C++20 tests - run: cmake --build build --target cpptest -j 2 - - - name: Interface test C++20 - run: cmake --build build --target test_cmake_build - - mingw: - name: "🐍 3 • windows-latest • ${{ matrix.sys }}" - runs-on: windows-latest - defaults: - run: - shell: msys2 {0} - strategy: - fail-fast: false - matrix: - include: - - { sys: mingw64, env: x86_64 } - - { sys: mingw32, env: i686 } - steps: - - uses: msys2/setup-msys2@v2 - with: - msystem: ${{matrix.sys}} - install: >- - git - mingw-w64-${{matrix.env}}-gcc - mingw-w64-${{matrix.env}}-python-pip - mingw-w64-${{matrix.env}}-python-numpy - mingw-w64-${{matrix.env}}-python-scipy - mingw-w64-${{matrix.env}}-cmake - mingw-w64-${{matrix.env}}-make - mingw-w64-${{matrix.env}}-python-pytest - mingw-w64-${{matrix.env}}-eigen3 - mingw-w64-${{matrix.env}}-boost - mingw-w64-${{matrix.env}}-catch - - - uses: actions/checkout@v3 - - - name: Configure C++11 - # LTO leads to many undefined reference like - # `pybind11::detail::function_call::function_call(pybind11::detail::function_call&&) - run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build - - - name: Build C++11 - run: cmake --build build -j 2 - - - name: Python tests C++11 - run: cmake --build build --target pytest -j 2 - - - name: C++11 tests - run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build --target cpptest -j 2 - - - name: Interface test C++11 - run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build --target test_cmake_build - - - name: Clean directory - run: git clean -fdx - - - name: Configure C++14 - run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build2 - - - name: Build C++14 - run: cmake --build build2 -j 2 - - - name: Python tests C++14 - run: cmake --build build2 --target pytest -j 2 - - - name: C++14 tests - run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build2 --target cpptest -j 2 - - - name: Interface test C++14 - run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build2 --target test_cmake_build - - - name: Clean directory - run: git clean -fdx - - - name: Configure C++17 - run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build3 - - - name: Build C++17 - run: cmake --build build3 -j 2 - - - name: Python tests C++17 - run: cmake --build build3 --target pytest -j 2 - - - name: C++17 tests - run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build3 --target cpptest -j 2 - - - name: Interface test C++17 - run: PYTHONHOME=/${{matrix.sys}} PYTHONPATH=/${{matrix.sys}} cmake --build build3 --target test_cmake_build From 118eff91fcddb237a749c0b2e781ecd4bcd1827d Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 20 Oct 2022 22:08:05 -0700 Subject: [PATCH 04/14] Disable appveyor --- .appveyor.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.appveyor.yml b/.appveyor.yml index 360760ac8d..fac0b10906 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,4 +1,7 @@ version: 1.0.{build} +branches: + except: + - assert_gil_held_incref_decref_pypy_windows image: - Visual Studio 2017 test: off From 2b546d1c3f3b6cb93cf8b4c6b925914d8fc2b49e Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 20 Oct 2022 22:09:55 -0700 Subject: [PATCH 05/14] Disable appveyor attempt 2 --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index fac0b10906..f3c3584102 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,7 +1,7 @@ version: 1.0.{build} branches: except: - - assert_gil_held_incref_decref_pypy_windows + - rwgk:assert_gil_held_incref_decref_pypy_windows image: - Visual Studio 2017 test: off From 35d9beb1b264b9dc3f588174b23522443eed6bcf Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 20 Oct 2022 21:54:21 -0700 Subject: [PATCH 06/14] Remove all .yml files except ci.yml --- .github/workflows/configure.yml | 80 ----------------------- .github/workflows/format.yml | 55 ---------------- .github/workflows/labeler.yml | 20 ------ .github/workflows/pip.yml | 110 ------------------------------- .github/workflows/upstream.yml | 112 -------------------------------- 5 files changed, 377 deletions(-) delete mode 100644 .github/workflows/configure.yml delete mode 100644 .github/workflows/format.yml delete mode 100644 .github/workflows/labeler.yml delete mode 100644 .github/workflows/pip.yml delete mode 100644 .github/workflows/upstream.yml diff --git a/.github/workflows/configure.yml b/.github/workflows/configure.yml deleted file mode 100644 index 5ec0dd462f..0000000000 --- a/.github/workflows/configure.yml +++ /dev/null @@ -1,80 +0,0 @@ -name: Config - -on: - workflow_dispatch: - pull_request: - push: - branches: - - master - - stable - - v* - -jobs: - # This tests various versions of CMake in various combinations, to make sure - # the configure step passes. - cmake: - strategy: - fail-fast: false - matrix: - runs-on: [ubuntu-latest, macos-latest, windows-latest] - arch: [x64] - cmake: ["3.23"] - - include: - - runs-on: ubuntu-latest - arch: x64 - cmake: 3.4 - - - runs-on: macos-latest - arch: x64 - cmake: 3.7 - - - runs-on: windows-2019 - arch: x64 # x86 compilers seem to be missing on 2019 image - cmake: 3.18 - - name: 🐍 3.7 • CMake ${{ matrix.cmake }} • ${{ matrix.runs-on }} - runs-on: ${{ matrix.runs-on }} - - steps: - - uses: actions/checkout@v3 - - - name: Setup Python 3.7 - uses: actions/setup-python@v4 - with: - python-version: 3.7 - architecture: ${{ matrix.arch }} - - - name: Prepare env - run: python -m pip install -r tests/requirements.txt - - # An action for adding a specific version of CMake: - # https://github.com/jwlawson/actions-setup-cmake - - name: Setup CMake ${{ matrix.cmake }} - uses: jwlawson/actions-setup-cmake@v1.13 - with: - cmake-version: ${{ matrix.cmake }} - - # These steps use a directory with a space in it intentionally - - name: Make build directories - run: mkdir "build dir" - - - name: Configure - working-directory: build dir - shell: bash - run: > - cmake .. - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)") - - # Only build and test if this was manually triggered in the GitHub UI - - name: Build - working-directory: build dir - if: github.event_name == 'workflow_dispatch' - run: cmake --build . --config Release - - - name: Test - working-directory: build dir - if: github.event_name == 'workflow_dispatch' - run: cmake --build . --config Release --target check diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml deleted file mode 100644 index 31d893c479..0000000000 --- a/.github/workflows/format.yml +++ /dev/null @@ -1,55 +0,0 @@ -# This is a format job. Pre-commit has a first-party GitHub action, so we use -# that: https://github.com/pre-commit/action - -name: Format - -on: - workflow_dispatch: - pull_request: - push: - branches: - - master - - stable - - "v*" - -env: - FORCE_COLOR: 3 - -jobs: - pre-commit: - name: Format - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.x" - - name: Add matchers - run: echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json" - - uses: pre-commit/action@v3.0.0 - with: - # Slow hooks are marked with manual - slow is okay here, run them too - extra_args: --hook-stage manual --all-files - - clang-tidy: - # When making changes here, please also review the "Clang-Tidy" section - # in .github/CONTRIBUTING.md and update as needed. - name: Clang-Tidy - runs-on: ubuntu-latest - container: silkeh/clang:13 - steps: - - uses: actions/checkout@v3 - - - name: Install requirements - run: apt-get update && apt-get install -y python3-dev python3-pytest - - - name: Configure - run: > - cmake -S . -B build - -DCMAKE_CXX_CLANG_TIDY="$(which clang-tidy);--use-color;--warnings-as-errors=*" - -DDOWNLOAD_EIGEN=ON - -DDOWNLOAD_CATCH=ON - -DCMAKE_CXX_STANDARD=17 - - - name: Build - run: cmake --build build -j 2 -- --keep-going diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml deleted file mode 100644 index 165a2fd87b..0000000000 --- a/.github/workflows/labeler.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Labeler -on: - pull_request_target: - types: [closed] - -jobs: - label: - name: Labeler - runs-on: ubuntu-latest - steps: - - - uses: actions/labeler@main - if: > - github.event.pull_request.merged == true && - !startsWith(github.event.pull_request.title, 'chore(deps):') && - !startsWith(github.event.pull_request.title, 'ci(fix):') && - !startsWith(github.event.pull_request.title, 'docs(changelog):') - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - configuration-path: .github/labeler_merged.yml diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml deleted file mode 100644 index f03a397019..0000000000 --- a/.github/workflows/pip.yml +++ /dev/null @@ -1,110 +0,0 @@ -name: Pip - -on: - workflow_dispatch: - pull_request: - push: - branches: - - master - - stable - - v* - release: - types: - - published - -env: - PIP_ONLY_BINARY: numpy - -jobs: - # This builds the sdists and wheels and makes sure the files are exactly as - # expected. Using Windows and Python 3.6, since that is often the most - # challenging matrix element. - test-packaging: - name: 🐍 3.6 • 📦 tests • windows-latest - runs-on: windows-latest - - steps: - - uses: actions/checkout@v3 - - - name: Setup 🐍 3.6 - uses: actions/setup-python@v4 - with: - python-version: 3.6 - - - name: Prepare env - run: | - python -m pip install -r tests/requirements.txt - - - name: Python Packaging tests - run: pytest tests/extra_python_package/ - - - # This runs the packaging tests and also builds and saves the packages as - # artifacts. - packaging: - name: 🐍 3.8 • 📦 & 📦 tests • ubuntu-latest - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Setup 🐍 3.8 - uses: actions/setup-python@v4 - with: - python-version: 3.8 - - - name: Prepare env - run: | - python -m pip install -r tests/requirements.txt build twine - - - name: Python Packaging tests - run: pytest tests/extra_python_package/ - - - name: Build SDist and wheels - run: | - python -m build - PYBIND11_GLOBAL_SDIST=1 python -m build - - - name: Check metadata - run: twine check dist/* - - - name: Save standard package - uses: actions/upload-artifact@v3 - with: - name: standard - path: dist/pybind11-* - - - name: Save global package - uses: actions/upload-artifact@v3 - with: - name: global - path: dist/pybind11_global-* - - - - # When a GitHub release is made, upload the artifacts to PyPI - upload: - name: Upload to PyPI - runs-on: ubuntu-latest - if: github.event_name == 'release' && github.event.action == 'published' - needs: [packaging] - - steps: - - uses: actions/setup-python@v4 - with: - python-version: "3.x" - - # Downloads all to directories matching the artifact names - - uses: actions/download-artifact@v3 - - - name: Publish standard package - uses: pypa/gh-action-pypi-publish@v1.5.1 - with: - password: ${{ secrets.pypi_password }} - packages_dir: standard/ - - - name: Publish global package - uses: pypa/gh-action-pypi-publish@v1.5.1 - with: - password: ${{ secrets.pypi_password_global }} - packages_dir: global/ diff --git a/.github/workflows/upstream.yml b/.github/workflows/upstream.yml deleted file mode 100644 index 366284acf4..0000000000 --- a/.github/workflows/upstream.yml +++ /dev/null @@ -1,112 +0,0 @@ - -name: Upstream - -on: - workflow_dispatch: - pull_request: - -concurrency: - group: upstream-${{ github.ref }} - cancel-in-progress: true - -env: - PIP_ONLY_BINARY: numpy - -jobs: - standard: - name: "🐍 3.11 latest internals • ubuntu-latest • x64" - runs-on: ubuntu-latest - if: "contains(github.event.pull_request.labels.*.name, 'python dev')" - - steps: - - uses: actions/checkout@v3 - - - name: Setup Python 3.11 - uses: actions/setup-python@v4 - with: - python-version: "3.11-dev" - - - name: Setup Boost (Linux) - if: runner.os == 'Linux' - run: sudo apt-get install libboost-dev - - - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.13 - - - name: Prepare env - run: | - python -m pip install -r tests/requirements.txt - - - name: Setup annotations on Linux - if: runner.os == 'Linux' - run: python -m pip install pytest-github-actions-annotate-failures - - # First build - C++11 mode and inplace - - name: Configure C++11 - run: > - cmake -S . -B . - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=11 - - - name: Build C++11 - run: cmake --build . -j 2 - - - name: Python tests C++11 - run: cmake --build . --target pytest -j 2 - - - name: C++11 tests - run: cmake --build . --target cpptest -j 2 - - - name: Interface test C++11 - run: cmake --build . --target test_cmake_build - - - name: Clean directory - run: git clean -fdx - - # Second build - C++17 mode and in a build directory - - name: Configure C++17 - run: > - cmake -S . -B build2 - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=17 - ${{ matrix.args }} - ${{ matrix.args2 }} - - - name: Build - run: cmake --build build2 -j 2 - - - name: Python tests - run: cmake --build build2 --target pytest - - - name: C++ tests - run: cmake --build build2 --target cpptest - - # Third build - C++17 mode with unstable ABI - - name: Configure (unstable ABI) - run: > - cmake -S . -B build3 - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=17 - -DPYBIND11_INTERNALS_VERSION=10000000 - "-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp" - ${{ matrix.args }} - - - name: Build (unstable ABI) - run: cmake --build build3 -j 2 - - - name: Python tests (unstable ABI) - run: cmake --build build3 --target pytest - - - name: Interface test - run: cmake --build build3 --target test_cmake_build - - # This makes sure the setup_helpers module can build packages using - # setuptools - - name: Setuptools helpers test - run: pytest tests/extra_setuptools From 55c4ea14e4e89cd40d108ca4d75288afd718e5ef Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 20 Oct 2022 21:59:02 -0700 Subject: [PATCH 07/14] Remove all PYBIND11_TEST_FILES except test_exceptions, test_gil_scoped --- .github/workflows/ci.yml | 1 - tests/CMakeLists.txt | 44 +--------------------------------------- 2 files changed, 1 insertion(+), 44 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33ffa4e9fc..f5a4a301fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,7 +79,6 @@ jobs: -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON -DCMAKE_CXX_STANDARD=11 - -DPYBIND11_TEST_FILTER="test_gil_scoped.cpp" - name: Build C++11 run: cmake --build . -j 2 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 491f215cef..e51b0df711 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -114,49 +114,7 @@ endif() # Full set of test files (you can override these; see below, overrides ignore extension) # Any test that has no extension is both .py and .cpp, so 'foo' will add 'foo.cpp' and 'foo.py'. # Any test that has an extension is exclusively that and handled as such. -set(PYBIND11_TEST_FILES - test_async - test_buffers - test_builtin_casters - test_call_policies - test_callbacks - test_chrono - test_class - test_const_name - test_constants_and_functions - test_copy_move - test_custom_type_casters - test_custom_type_setup - test_docstring_options - test_eigen_matrix - test_eigen_tensor - test_eigen_tensor_avoid_stl_array.cpp - test_enum - test_eval - test_exceptions - test_factory_constructors - test_gil_scoped - test_iostream - test_kwargs_and_defaults - test_local_bindings - test_methods_and_attributes - test_modules - test_multiple_inheritance - test_numpy_array - test_numpy_dtypes - test_numpy_vectorize - test_opaque_types - test_operator_overloading - test_pickling - test_pytypes - test_sequences_and_iterators - test_smart_ptr - test_stl - test_stl_binders - test_tagbased_polymorphic - test_thread - test_union - test_virtual_functions) +set(PYBIND11_TEST_FILES test_exceptions test_gil_scoped) # Invoking cmake with something like: # cmake -DPYBIND11_TEST_OVERRIDE="test_callbacks.cpp;test_pickling.cpp" .. From 3183d56612626f588d22351edcc9cbeab6a81320 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 20 Oct 2022 22:14:04 -0700 Subject: [PATCH 08/14] Revert "Remove all PYBIND11_TEST_FILES except test_exceptions, test_gil_scoped" This reverts commit 55c4ea14e4e89cd40d108ca4d75288afd718e5ef. --- .github/workflows/ci.yml | 1 + tests/CMakeLists.txt | 44 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5a4a301fc..33ffa4e9fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,6 +79,7 @@ jobs: -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON -DCMAKE_CXX_STANDARD=11 + -DPYBIND11_TEST_FILTER="test_gil_scoped.cpp" - name: Build C++11 run: cmake --build . -j 2 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e51b0df711..491f215cef 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -114,7 +114,49 @@ endif() # Full set of test files (you can override these; see below, overrides ignore extension) # Any test that has no extension is both .py and .cpp, so 'foo' will add 'foo.cpp' and 'foo.py'. # Any test that has an extension is exclusively that and handled as such. -set(PYBIND11_TEST_FILES test_exceptions test_gil_scoped) +set(PYBIND11_TEST_FILES + test_async + test_buffers + test_builtin_casters + test_call_policies + test_callbacks + test_chrono + test_class + test_const_name + test_constants_and_functions + test_copy_move + test_custom_type_casters + test_custom_type_setup + test_docstring_options + test_eigen_matrix + test_eigen_tensor + test_eigen_tensor_avoid_stl_array.cpp + test_enum + test_eval + test_exceptions + test_factory_constructors + test_gil_scoped + test_iostream + test_kwargs_and_defaults + test_local_bindings + test_methods_and_attributes + test_modules + test_multiple_inheritance + test_numpy_array + test_numpy_dtypes + test_numpy_vectorize + test_opaque_types + test_operator_overloading + test_pickling + test_pytypes + test_sequences_and_iterators + test_smart_ptr + test_stl + test_stl_binders + test_tagbased_polymorphic + test_thread + test_union + test_virtual_functions) # Invoking cmake with something like: # cmake -DPYBIND11_TEST_OVERRIDE="test_callbacks.cpp;test_pickling.cpp" .. From 910e3ae7a62b6e92090ca8a29e0bfa640bc5f3a7 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 20 Oct 2022 22:15:24 -0700 Subject: [PATCH 09/14] Remove `-DPYBIND11_TEST_FILTER="test_gil_scoped.cpp"` --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33ffa4e9fc..f5a4a301fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,7 +79,6 @@ jobs: -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON -DCMAKE_CXX_STANDARD=11 - -DPYBIND11_TEST_FILTER="test_gil_scoped.cpp" - name: Build C++11 run: cmake --build . -j 2 From 87c57ed7fe407227b508c87a62aca8dbfb5d749a Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 20 Oct 2022 22:27:39 -0700 Subject: [PATCH 10/14] Forgot to remove the `defined(PYPY_VERSION) && defined(_MSC_VER)` condition, silly mistake. --- include/pybind11/detail/common.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index 49528ba849..6abb47afd9 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -261,7 +261,6 @@ // See description of PR #4246: #if !defined(NDEBUG) && !defined(PY_ASSERT_GIL_HELD_INCREF_DECREF) \ - && !(defined(PYPY_VERSION) && defined(_MSC_VER)) /* Tests hang indefinitely at startup. */ \ && !defined(PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF) # define PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF #endif From cac15e8e92f9bf4aaea66182101e7187e389dcb0 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 20 Oct 2022 22:28:17 -0700 Subject: [PATCH 11/14] Revert "Revert "Remove all PYBIND11_TEST_FILES except test_exceptions, test_gil_scoped"" This reverts commit 3183d56612626f588d22351edcc9cbeab6a81320. --- tests/CMakeLists.txt | 44 +------------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 491f215cef..e51b0df711 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -114,49 +114,7 @@ endif() # Full set of test files (you can override these; see below, overrides ignore extension) # Any test that has no extension is both .py and .cpp, so 'foo' will add 'foo.cpp' and 'foo.py'. # Any test that has an extension is exclusively that and handled as such. -set(PYBIND11_TEST_FILES - test_async - test_buffers - test_builtin_casters - test_call_policies - test_callbacks - test_chrono - test_class - test_const_name - test_constants_and_functions - test_copy_move - test_custom_type_casters - test_custom_type_setup - test_docstring_options - test_eigen_matrix - test_eigen_tensor - test_eigen_tensor_avoid_stl_array.cpp - test_enum - test_eval - test_exceptions - test_factory_constructors - test_gil_scoped - test_iostream - test_kwargs_and_defaults - test_local_bindings - test_methods_and_attributes - test_modules - test_multiple_inheritance - test_numpy_array - test_numpy_dtypes - test_numpy_vectorize - test_opaque_types - test_operator_overloading - test_pickling - test_pytypes - test_sequences_and_iterators - test_smart_ptr - test_stl - test_stl_binders - test_tagbased_polymorphic - test_thread - test_union - test_virtual_functions) +set(PYBIND11_TEST_FILES test_exceptions test_gil_scoped) # Invoking cmake with something like: # cmake -DPYBIND11_TEST_OVERRIDE="test_callbacks.cpp;test_pickling.cpp" .. From d91a55849c99198e04c9bbe21cc65c4d04306940 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 20 Oct 2022 22:38:02 -0700 Subject: [PATCH 12/14] Revert "Disable appveyor attempt 2" This reverts commit 2b546d1c3f3b6cb93cf8b4c6b925914d8fc2b49e. --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index f3c3584102..fac0b10906 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,7 +1,7 @@ version: 1.0.{build} branches: except: - - rwgk:assert_gil_held_incref_decref_pypy_windows + - assert_gil_held_incref_decref_pypy_windows image: - Visual Studio 2017 test: off From 5d3652ec97d1b342d39d229f902d1013a87175ed Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 20 Oct 2022 22:38:09 -0700 Subject: [PATCH 13/14] Revert "Disable appveyor" This reverts commit 118eff91fcddb237a749c0b2e781ecd4bcd1827d. --- .appveyor.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index fac0b10906..360760ac8d 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,7 +1,4 @@ version: 1.0.{build} -branches: - except: - - assert_gil_held_incref_decref_pypy_windows image: - Visual Studio 2017 test: off From 96206b565c5cba7005610c5baf784d8f427ce826 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 20 Oct 2022 22:45:30 -0700 Subject: [PATCH 14/14] Remove all but `test_cross_module_gil()` from test_gil_scoped.py --- tests/test_gil_scoped.cpp | 10 +++++ tests/test_gil_scoped.py | 87 --------------------------------------- 2 files changed, 10 insertions(+), 87 deletions(-) diff --git a/tests/test_gil_scoped.cpp b/tests/test_gil_scoped.cpp index 97efdc1616..730996e017 100644 --- a/tests/test_gil_scoped.cpp +++ b/tests/test_gil_scoped.cpp @@ -38,10 +38,20 @@ TEST_SUBMODULE(gil_scoped, m) { m.def("test_callback_virtual_func", [](VirtClass &virt) { virt.virtual_func(); }); m.def("test_callback_pure_virtual_func", [](VirtClass &virt) { virt.pure_virtual_func(); }); m.def("test_cross_module_gil", []() { + printf("\nLOOOK %s:%d\n", __FILE__, __LINE__); + fflush(stdout); auto cm = py::module_::import("cross_module_gil_utils"); + printf("\nLOOOK %s:%d\n", __FILE__, __LINE__); + fflush(stdout); auto gil_acquire = reinterpret_cast( PyLong_AsVoidPtr(cm.attr("gil_acquire_funcaddr").ptr())); + printf("\nLOOOK %s:%d\n", __FILE__, __LINE__); + fflush(stdout); py::gil_scoped_release gil_release; + printf("\nLOOOK %s:%d\n", __FILE__, __LINE__); + fflush(stdout); gil_acquire(); + printf("\nLOOOK %s:%d\n", __FILE__, __LINE__); + fflush(stdout); }); } diff --git a/tests/test_gil_scoped.py b/tests/test_gil_scoped.py index 52374b0cce..49f945d59c 100644 --- a/tests/test_gil_scoped.py +++ b/tests/test_gil_scoped.py @@ -1,93 +1,6 @@ -import multiprocessing -import threading - from pybind11_tests import gil_scoped as m -def _run_in_process(target, *args, **kwargs): - """Runs target in process and returns its exitcode after 10s (None if still alive).""" - process = multiprocessing.Process(target=target, args=args, kwargs=kwargs) - process.daemon = True - try: - process.start() - # Do not need to wait much, 10s should be more than enough. - process.join(timeout=10) - return process.exitcode - finally: - if process.is_alive(): - process.terminate() - - -def _python_to_cpp_to_python(): - """Calls different C++ functions that come back to Python.""" - - class ExtendedVirtClass(m.VirtClass): - def virtual_func(self): - pass - - def pure_virtual_func(self): - pass - - extended = ExtendedVirtClass() - m.test_callback_py_obj(lambda: None) - m.test_callback_std_func(lambda: None) - m.test_callback_virtual_func(extended) - m.test_callback_pure_virtual_func(extended) - - -def _python_to_cpp_to_python_from_threads(num_threads, parallel=False): - """Calls different C++ functions that come back to Python, from Python threads.""" - threads = [] - for _ in range(num_threads): - thread = threading.Thread(target=_python_to_cpp_to_python) - thread.daemon = True - thread.start() - if parallel: - threads.append(thread) - else: - thread.join() - for thread in threads: - thread.join() - - -# TODO: FIXME, sometimes returns -11 (segfault) instead of 0 on macOS Python 3.9 -def test_python_to_cpp_to_python_from_thread(): - """Makes sure there is no GIL deadlock when running in a thread. - - It runs in a separate process to be able to stop and assert if it deadlocks. - """ - assert _run_in_process(_python_to_cpp_to_python_from_threads, 1) == 0 - - -# TODO: FIXME on macOS Python 3.9 -def test_python_to_cpp_to_python_from_thread_multiple_parallel(): - """Makes sure there is no GIL deadlock when running in a thread multiple times in parallel. - - It runs in a separate process to be able to stop and assert if it deadlocks. - """ - assert _run_in_process(_python_to_cpp_to_python_from_threads, 8, parallel=True) == 0 - - -# TODO: FIXME on macOS Python 3.9 -def test_python_to_cpp_to_python_from_thread_multiple_sequential(): - """Makes sure there is no GIL deadlock when running in a thread multiple times sequentially. - - It runs in a separate process to be able to stop and assert if it deadlocks. - """ - assert ( - _run_in_process(_python_to_cpp_to_python_from_threads, 8, parallel=False) == 0 - ) - - -# TODO: FIXME on macOS Python 3.9 -def test_python_to_cpp_to_python_from_process(): - """Makes sure there is no GIL deadlock when using processes. - - This test is for completion, but it was never an issue. - """ - assert _run_in_process(_python_to_cpp_to_python) == 0 - - def test_cross_module_gil(): """Makes sure that the GIL can be acquired by another module from a GIL-released state.""" m.test_cross_module_gil() # Should not raise a SIGSEGV