* fix: Use PyObject_VisitManagedDict() of Python 3.13
Use PyObject_VisitManagedDict() and PyObject_ClearManagedDict() in
pybind11_traverse() and pybind11_clear() on Python 3.13 and newer.
* Add Python 3.13 CI
* tests: don't get numpy/scipy on 3.13 yet
* ci: move 3.13 to upstream
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
---------
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
* Upgrade maximum supported CMake version to 3.27 to fix warning with CMP0148 policy (#4785)
* Update `macos_brew_install_llvm` pipeline to use expected Python installation
* Fix `Python_EXECUTABLE` Cmake variable typo
* Apply suggestions from code review
* fix: use FindPython for CMake 3.18+ by default for pybind11's tests
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* tests: fix issues with finding Python
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* tests: also set executable on subdir tests
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* fix(cmake): correct logic for FindPython
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* Update ci.yml
* Revert "Update ci.yml"
This reverts commit 33798adf3f.
---------
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
* pybind11.pc: use pcfiledir for relative destinations
If the datarootdir is absolute, just use the absolute path directly.
However, if it is relative, we can compute the prefix from the location
of the `.pc` file itself. This allows the install to be relocatable.
* chore: use 3.20's cmake_path if available
* style: pre-commit fixes
* Update CMakeLists.txt
---------
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* fix(cmake): findpython issues and 3.12 support for pybind11_find_import
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* Update pybind11NewTools.cmake
---------
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* Equivalent of 5718e4d080
* Resolve clang-tidy errors.
* Moving test_PPCCInit() first changes the behavior!
* Resolve new Clang dev C++11 errors:
```
The CXX compiler identification is Clang 17.0.0
```
```
pytypes.h:1615:23: error: identifier '_s' preceded by whitespace in a literal operator declaration is deprecated [-Werror,-Wdeprecated-literal-operator]
```
```
cast.h:1380:26: error: identifier '_a' preceded by whitespace in a literal operator declaration is deprecated [-Werror,-Wdeprecated-literal-operator]
```
* Resolve gcc 4.8.5 error:
```
pytypes.h:1615:12: error: missing space between '""' and suffix identifier
```
* Specifically exclude `__clang__`
* Snapshot of debugging code (does NOT pass pre-commit checks).
* Revert "Snapshot of debugging code (does NOT pass pre-commit checks)."
This reverts commit 1d4f9ff263.
* [ci skip] Order Dependence Demo
* Revert "[ci skip] Order Dependence Demo"
This reverts commit d37b5409d4.
* One way to deal with the order dependency issue. This is not the best way, more like a proof of concept.
* Move test_PC() first again.
* Add `all_type_info_add_base_most_derived_first()`, use in `all_type_info_populate()`
* Revert "One way to deal with the order dependency issue. This is not the best way, more like a proof of concept."
This reverts commit eb09c6c1b9.
* clang-tidy fixes (automatic)
* Add `is_redundant_value_and_holder()` and use to avoid forcing `__init__` overrides when they are not needed.
* Streamline implementation and avoid unsafe `reinterpret_cast<instance *>()` introduced with PR #2152
The `reinterpret_cast<instance *>(self)` is unsafe if `__new__` is mocked,
which was actually found in the wild: the mock returned `None` for `self`.
This was inconsequential because `inst` is currently cast straight back to
`PyObject *` to compute `all_type_info()`, which is empty if `self` is not
a pybind11 `instance`, and then `inst` is never dereferenced. However, the
unsafe detour through `instance *` is easily avoided and the updated
implementation is less prone to accidents while debugging or refactoring.
* Fix actual undefined behavior exposed by previous changes.
It turns out the previous commit message is incorrect, the `inst` pointer is actually dereferenced, in the `value_and_holder` ctor here:
f3e0602802/include/pybind11/detail/type_caster_base.h (L262-L263)
```
259 // Main constructor for a found value/holder:
260 value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index)
261 : inst{i}, index{index}, type{type},
262 vh{inst->simple_layout ? inst->simple_value_holder
263 : &inst->nonsimple.values_and_holders[vpos]} {}
```
* Add test_mock_new()
* Experiment: specify indirect bases
* Revert "Experiment: specify indirect bases"
This reverts commit 4f90d85f9f.
* Add `all_type_info_check_for_divergence()` and some tests.
* Call `all_type_info_check_for_divergence()` also from `type_caster_generic::load_impl<>`
* Resolve clang-tidy error:
```
include/pybind11/detail/type_caster_base.h:795:21: error: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty,-warnings-as-errors]
if (matching_bases.size() != 0) {
^~~~~~~~~~~~~~~~~~~~~~~~~~
!matching_bases.empty()
```
* Revert "Resolve clang-tidy error:"
This reverts commit df27188dc6.
* Revert "Call `all_type_info_check_for_divergence()` also from `type_caster_generic::load_impl<>`"
This reverts commit 5f5fd6a68e.
* Revert "Add `all_type_info_check_for_divergence()` and some tests."
This reverts commit 0a9599f775.
* Roundtrip through unique pointer with custom deleter.
Currently failing.
* Ensure the custom deleter is copied back to the unique pointer.
Feels like there's still a gap around the raw pointer flavour, but this at least
makes the unit test of the previous commit succeed.
* Add deleter roundtrip for const atyp.
Currently failing, custom deleter is lost.
* Fix storing deleter for const unique ptr.
Unit test from the previous commit passes.
* Remove SFINEA deleter assignment.
At the construction of the smart holder, it is either a del_fun, or a default constructed deleter, so this complexity is unnecessary.
* Clang format.
* Fixes for ci.
Clang 3.6 requires the extra constructors in the custom_deleter.
* fix(smart_holder): Loosen requirement on deleter to be default constructible.
And some other PR feedback.
* fix(smart_holder): Custom deleter in unit tests traces constructions.
* fix(smart_holder): Use pybind11_fail instead of assert.
* fix(smart_holder): Add unit tests for the default constructible deleter.
* fix(smart_holder): Use regex matching for deleter constructors in unit tests.
* Store `std::function<void (void *)>` del_fun; in `guarded_delete`
* Specialize the simple common case.
Using a `union` is complicated: https://en.cppreference.com/w/cpp/language/union
> If members of a union are classes with user-defined constructors and destructors, to switch the active member, explicit destructor and placement new are generally needed:
Using `std::variant` increases compile-time overhead.
It is currently unclear how much these effects matter in practice: optimization left for later.
* Add one test case (more later).
* Add `const` to resolve clang-tidy error.
```
-- The CXX compiler identification is Clang 15.0.7
/usr/bin/cmake -E __run_co_compile --tidy="/usr/bin/clang-tidy;--use-color;--warnings-as-errors=*;--extra-arg-before=--driver-mode=g++" --source=/__w/pybind11/pybind11/tests/test_class_sh_inheritance.cpp -- /usr/bin/c++ -DPYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD_IF_AVAILABLE -DPYBIND11_TEST_EIGEN -Dpybind11_tests_EXPORTS -I/__w/pybind11/pybind11/include -isystem /usr/include/python3.9 -isystem /__w/pybind11/pybind11/build/_deps/eigen-src -Os -DNDEBUG -fPIC -fvisibility=hidden -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -Wundef -Wnon-virtual-dtor -flto=thin -std=c++17 -o CMakeFiles/pybind11_tests.dir/test_class_sh_inheritance.cpp.o -c /__w/pybind11/pybind11/tests/test_class_sh_inheritance.cpp
/__w/pybind11/pybind11/tests/pure_cpp/smart_holder_poc_test.cpp:264:30: error: pointer parameter 'raw_ptr' can be pointer to const [readability-non-const-parameter,-warnings-as-errors]
new int(19), [](int *raw_ptr) { delete raw_ptr; });
^
const
```
* Introduce `struct custom_deleter` to ensure the deleter is moved as desired (the lambda function only captures a reference, which can become dangling).
* Resolve helpful clang-tidy errors.
```
/usr/bin/cmake -E __run_co_compile --tidy="/usr/bin/clang-tidy;--use-color;--warnings-as-errors=*;--extra-arg-before=--driver-mode=g++" --source=/__w/pybind11/pybind11/tests/test_class.cpp -- /usr/bin/c++ -DPYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD_IF_AVAILABLE -DPYBIND11_TEST_EIGEN -Dpybind11_tests_EXPORTS -I/__w/pybind11/pybind11/include -isystem /usr/include/python3.9 -isystem /__w/pybind11/pybind11/build/_deps/eigen-src -Os -DNDEBUG -fPIC -fvisibility=hidden -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -Wundef -Wnon-virtual-dtor -flto=thin -std=c++17 -o CMakeFiles/pybind11_tests.dir/test_class.cpp.o -c /__w/pybind11/pybind11/tests/test_class.cpp
/__w/pybind11/pybind11/include/pybind11/detail/smart_holder_poc.h:114:5: error: single-argument constructors must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor,-warnings-as-errors]
custom_deleter(D &&deleter) : deleter{std::move(deleter)} {}
^
explicit
/__w/pybind11/pybind11/include/pybind11/detail/smart_holder_poc.h:120:76: error: forwarding reference passed to std::move(), which may unexpectedly cause lvalues to be moved; use std::forward() instead [bugprone-move-forwarding-reference,-warnings-as-errors]
return guarded_delete(std::function<void(void *)>(custom_deleter<T, D>(std::move(uqp_del))),
^~~~~~~~~
std::forward<D>
```
* Workaround for gcc 4.8.5, clang 3.6
* Transfer reduced test here.
Reduced from a PyCLIF use case in the wild by @wangxf123456 (internal change cl/565476030).
* Add missing include (clangd Include Cleaner)
* Change `std::move` to `std::forward` as suggested by @iwanders.
* Add missing includes (clangd Include Cleaner)
* Use new `PYBIND11_TESTS_PURE_CPP_SMART_HOLDER_POC_TEST_CPP` to exclude `smart_holder::as_unique_ptr` method from production code.
* Systematically add `PYBIND11_TESTS_PURE_CPP_SMART_HOLDER_POC_TEST_CPP` to mark code that is not used from production code. Add comment to explain.
* Very simple experiment related to https://github.com/pybind/pybind11/pull/4850#issuecomment-1789780676
Does the `PYBIND11_TESTS_PURE_CPP_SMART_HOLDER_POC_TEST_CPP` define have anything to do with it?
* Revert "Very simple experiment related to https://github.com/pybind/pybind11/pull/4850#issuecomment-1789780676"
This reverts commit fe59369f40.
According to https://docs.python.org/3.13/whatsnew/3.13.html:
Add PyThreadState_GetUnchecked() function: similar to
PyThreadState_Get(), but don't kill the process with a fatal error if
it is NULL. The caller is responsible to check if the result is
NULL. Previously, the function was private and known as
_PyThreadState_UncheckedGet().
* Workaround NVCC parse failure in `cast_op`
There is a bug in some CUDA versions (observed in CUDA 12.1 and 11.7 w/ GCC 12.2),
that makes `cast_op` fail to compile:
`cast.h:45:120: error: expected template-name before ‘<’ token`
Defining the nested type as an alias and using it allows this to work
without any change in semantics.
Fixes#4606
* style: pre-commit fixes
* Add comments to result_t referencing PR
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Update pytest (which removes their dependency on py)
The py library through 1.11.0 for Python allows remote attackers to conduct a ReDoS (Regular expression Denial of Service) attack via a Subversion repository with crafted info data, because the InfoSvnCommand argument is mishandled.
The particular codepath in question is the regular expression at py._path.svnurl.InfoSvnCommand.lspattern and is only relevant when dealing with subversion (svn) projects. Notably the codepath is not used in the popular pytest project. The developers of the pytest package have released version 7.2.0 which removes their dependency on py. Users of pytest seeing alerts relating to this advisory may update to version 7.2.0 of pytest to resolve this issue. See https://github.com/pytest-dev/py/issues/287#issuecomment-1290407715 for additional context.
* Added conditions so that we keep using 7.0.0 on python 3.6