* Add `type_caster<PyObject>` (tests are still incomplete).
* Fix oversight (`const PyObject *`).
* Ensure `type_caster<PyObject>` only works for `PyObject *`
* Move `is_same_ignoring_cvref` into `detail` namespace.
* Add test_cast_nullptr
* Change is_same_ignoring_cvref from variable template to using.
```
test_type_caster_pyobject_ptr.cpp:8:23: error: variable templates only available with ‘-std=c++14’ or ‘-std=gnu++14’ [-Werror]
8 | static constexpr bool is_same_ignoring_cvref = std::is_same<detail::remove_cvref_t<T>, U>::value;
| ^~~~~~~~~~~~~~~~~~~~~~
```
* Remove `return_value_policy::reference_internal` `keep_alive` feature (because of doubts about it actually being useful).
* Add missing test, fix bug (missing `throw error_already_set();`), various cosmetic changes.
* Move `type_caster<PyObject>` from test to new include (pybind11/type_caster_pyobject_ptr.h)
* Add new header file to CMakeLists.txt and tests/extra_python_package/test_files.py
* Backport changes from https://github.com/google/pywrapcc/pull/30021 to https://github.com/pybind/pybind11/pull/4601
* Fix oversight in test (to resolve a valgrind leak detection error) and add a related comment in cast.h.
No production code changes.
Make tests more sensitive by using `ValueHolder` instead of empty tuples and dicts.
Manual leak checks with `while True:` & top command repeated for all tests.
* Add tests for interop with stl.h `list_caster`
(No production code changes.)
* Bug fix in test. Minor comment enhancements.
* Change `type_caster<PyObject>::name` to `object`, as suggested by @Skylion007
* Expand comment for the new `T cast(const handle &handle)` [`T` = `PyObject *`]
* Add `T cast(object &&obj)` overload as suggested by @Skylion007
The original suggestion leads to `error: call to 'cast' is ambiguous` (full error message below), therefore SFINAE guarding is needed.
```
clang++ -o pybind11/tests/test_type_caster_pyobject_ptr.os -c -std=c++17 -fPIC -fvisibility=hidden -O0 -g -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -Wundef -Wnon-virtual-dtor -Wunused-result -Werror -isystem /usr/include/python3.10 -isystem /usr/include/eigen3 -DPYBIND11_STRICT_ASSERTS_CLASS_HOLDER_VS_TYPE_CASTER_MIX -DPYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD_IF_AVAILABLE -DPYBIND11_TEST_BOOST -Ipybind11/include -I/usr/local/google/home/rwgk/forked/pybind11/include -I/usr/local/google/home/rwgk/clone/pybind11/include /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp
In file included from /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:1:
In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/functional.h:12:
In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:13:
In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/class.h:12:
In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/attr.h:14:
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1165:12: error: call to 'cast' is ambiguous
return pybind11::cast<T>(std::move(*this));
^~~~~~~~~~~~~~~~~
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/functional.h:109:70: note: in instantiation of function template specialization 'pybind11::object::cast<_object *>' requested here
return hfunc.f(std::forward<Args>(args)...).template cast<Return>();
^
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/functional.h:103:16: note: in instantiation of member function 'pybind11::detail::type_caster<std::function<_object *(int)>>::load(pybind11::handle, bool)::func_wrapper::operator()' requested here
struct func_wrapper {
^
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1456:47: note: in instantiation of member function 'pybind11::detail::type_caster<std::function<_object *(int)>>::load' requested here
if ((... || !std::get<Is>(argcasters).load(call.args[Is], call.args_convert[Is]))) {
^
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1434:50: note: in instantiation of function template specialization 'pybind11::detail::argument_loader<const std::function<_object *(int)> &, int>::load_impl_sequence<0UL, 1UL>' requested here
bool load_args(function_call &call) { return load_impl_sequence(call, indices{}); }
^
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:227:33: note: in instantiation of member function 'pybind11::detail::argument_loader<const std::function<_object *(int)> &, int>::load_args' requested here
if (!args_converter.load_args(call)) {
^
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:101:9: note: in instantiation of function template specialization 'pybind11::cpp_function::initialize<(lambda at /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:50:9), _object *, const std::function<_object *(int)> &, int, pybind11::name, pybind11::scope, pybind11::sibling, pybind11::return_value_policy>' requested here
initialize(
^
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:1163:22: note: in instantiation of function template specialization 'pybind11::cpp_function::cpp_function<(lambda at /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:50:9), pybind11::name, pybind11::scope, pybind11::sibling, pybind11::return_value_policy, void>' requested here
cpp_function func(std::forward<Func>(f),
^
/usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:48:7: note: in instantiation of function template specialization 'pybind11::module_::def<(lambda at /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:50:9), pybind11::return_value_policy>' requested here
m.def(
^
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1077:3: note: candidate function [with T = _object *, $1 = 0]
T cast(object &&obj) {
^
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1149:1: note: candidate function [with T = _object *]
cast(object &&object) {
^
1 error generated.
```
* Testing
* Similar fix for std::vector
* Fix infinite recursion check:
1) Apply to is_copy_assignable additionally
2) Check infinite recursion for map-like types
* style: pre-commit fixes
* Optional commit that demonstrates the limitations of this PR
* Fix positioning of container bindings
The bindings were previously in a block that was only activated if numpy
was available.
* Suggestions from code review: API side
* Suggestions from code review: Test side
* Suggestions from code review
1) Renaming: is_recursive_container and
MutuallyRecursiveContainerPair(MV|VM)
2) Avoid ambiguous specializations of is_recursive_container
* Some little fixes
* Reordering of structs
* Add recursive checks for is_move_constructible
* Static testing for pybind11 type traits
* More precise checking of recursive types
Instead of a trait `is_recursive_container`, use a trait
`recursive_container_traits` with dependent type
`recursive_container_traits::type_to_check_recursively`.
So, instead of just checking if a type is recursive and then trying to
somehow deal with it, recursively-defined traits such as
is_move_constructible can now directly ask this trait where the
recursion should proceed.
* Review suggestions
1. Use std::conditional
2. Fix typo
* Remove leftover include from test
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Inject -stdlib=libc++ on macOS only when it's supported, close#4637.
On macOS, by default, pybind11 currently unconditionally set the compiler
flag "-stdlib=libc++" in Pybind11Extension.__init__(), regardless of which
compiler is used. This flag is required for clang, but is invalid for GCC.
If GCC is used, it causes compilation failures in all Python projects that
use pybind11, with the error message:
arm64-apple-darwin22-gcc: error: unrecognized command-line option -stdlib=libc++.
This commit uses has_flag() to detect whether "-stdlib=libc++" on macOS,
and injects this flag from build_ext.build_extensions(), rather than
setting it unconditionally.
Signed-off-by: Yifeng Li <tomli@tomli.me>
* revert: just remove flags
---------
Signed-off-by: Yifeng Li <tomli@tomli.me>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
* Try using `std::hash<std::type_index>`, `std::equal_to<std::type_index>` everywhere.
From PR #4316 we know that types in the unnamed namespace in different translation units do not compare equal, as desired.
But do types in named namespaces compare equal, as desired?
* Revert "Try using `std::hash<std::type_index>`, `std::equal_to<std::type_index>` everywhere."
This reverts commit a06949a926.
* Use "our own name-based hash and equality functions" for `std::type_index` only under macOS, based on results shown under https://github.com/pybind/pybind11/pull/4316#issuecomment-1305097879
* Patch in PR #4313: Minimal reproducer for clash when binding types defined in the unnamed namespace.
* test_unnamed_namespace_b xfail for clang
* `PYBIND11_INTERNALS_VERSION 5`
* Add a note to docs/classes.rst
* For compatibility with Google-internal testing, test_unnamed_namespace_a & test_unnamed_namespace_b need to work when imported in any order.
* Trying "__GLIBCXX__ or Windows", based on observations from Google-internal testing.
* Try _LIBCPP_VERSION
* Account for libc++ behavior in tests and documentation.
* Adjust expectations for Windows Clang (and make code less redundant).
* Add WindowsClang to ci.yml
Added block transferred from PR #4321
* Add clang-latest to name that appears in the GitHub Actions web view.
* Tweak the note in classes.rst again.
* Add `pip install --upgrade pip`, Show env, cosmetic changes
Already tested under PR #4321
* Add macos_brew_install_llvm to ci.yml
Added block transferred from PR #4324
* `test_cross_module_exception_translator` xfail 'Homebrew Clang'
* Revert back to base version of .github/workflows/ci.yml (the ci.yml changes were merged under #4323 and #4326)
* Fixes for ruff
* Make updated condition in internals.h dependent on ABI version.
* Remove PYBIND11_TEST_OVERRIDE when testing with PYBIND11_INTERNALS_VERSION=10000000
* Selectively exercise cmake `-DPYBIND11_TEST_OVERRIDE`: ubuntu, macos, windows
Extra work added to quick jobs, based on timings below, to not increase the GHA start-to-last-job-finished time.
```
Duration
^ Number of pytest runs
^ ^ Job identifier
^ ^ ^
0:03:48.024227 1 1___3___Clang_3.6___C++11___x64.txt
0:03:58.992814 1 2___3___Clang_3.7___C++11___x64.txt
0:04:25.758942 1 1___3.7___Debian___x86____Install.txt
0:04:50.148276 1 4___3___Clang_7___C++11___x64.txt
0:04:55.784558 1 13___3___Clang_15___C++20___x64.txt
0:04:57.048754 1 6___3___Clang_dev___C++11___x64.txt
0:05:00.485181 1 7___3___Clang_5___C++14___x64.txt
0:05:03.744964 1 2___3___almalinux8___x64.txt
0:05:06.222752 1 5___3___Clang_9___C++11___x64.txt
0:05:11.767022 1 2___3___GCC_7___C++17__x64.txt
0:05:18.634930 1 2___3.11__deadsnakes____x64.txt
0:05:22.810995 1 1___3___GCC_7___C++11__x64.txt
0:05:25.275317 1 12___3___Clang_14___C++20___x64.txt
0:05:32.058174 1 5___3___GCC_10___C++17__x64.txt
0:05:39.381351 1 7___3___GCC_12___C++20__x64.txt
0:05:40.502252 1 8___3___Clang_10___C++17___x64.txt
0:05:59.344905 1 3___3___Clang_3.9___C++11___x64.txt
0:06:10.825147 1 6___3___GCC_11___C++20__x64.txt
0:06:20.655443 1 3___3___almalinux9___x64.txt
0:06:22.472061 1 3___3___GCC_8___C++14__x64.txt
0:06:42.647406 1 11___3___Clang_13___C++20___x64.txt
0:06:53.352720 1 1___3.10___CUDA_11.7___Ubuntu_22.04.txt
0:07:07.357801 1 2___3.7___MSVC_2019___x86_-DCMAKE_CXX_STANDARD=14.txt
0:07:09.057603 1 1___3___centos7___x64.txt
0:07:15.546282 1 1___3.8___MSVC_2019__Debug____x86_-DCMAKE_CXX_STANDARD=17.txt
0:07:22.566022 1 4___3___GCC_8___C++17__x64.txt
0:08:13.592674 1 2___3.9___MSVC_2019__Debug____x86_-DCMAKE_CXX_STANDARD=20.txt
0:08:16.422768 1 9___3___Clang_11___C++20___x64.txt
0:08:21.168457 1 3___3.8___MSVC_2019___x86_-DCMAKE_CXX_STANDARD=17.txt
0:08:27.129468 1 10___3___Clang_12___C++20___x64.txt
0:09:35.045470 1 1___3.10___windows-latest___clang-latest.txt
0:09:57.361843 1 1___3.9___MSVC_2022_C++20___x64.txt
0:10:35.187767 1 1___3.6___MSVC_2019___x86.txt
0:11:14.691200 4 2___3.9___ubuntu-20.04___x64.txt
0:11:37.701167 1 1_macos-latest___brew_install_llvm.txt
0:11:38.688299 4 4___3.11___ubuntu-20.04___x64.txt
0:11:52.720216 1 4___3.9___MSVC_2019___x86_-DCMAKE_CXX_STANDARD=20.txt
0:13:23.456591 4 6___pypy-3.8___ubuntu-20.04___x64_-DPYBIND11_FINDPYTHON=ON.txt
0:13:25.863592 2 1___3___ICC_latest___x64.txt
0:13:32.411758 3 9___3.9___windows-2022___x64.txt
0:13:45.473377 4 3___3.10___ubuntu-20.04___x64.txt
0:13:55.366447 4 5___pypy-3.7___ubuntu-20.04___x64.txt
0:13:57.969502 3 10___3.10___windows-2022___x64.txt
0:14:19.837475 3 11___3.11___windows-2022___x64.txt
0:14:33.316770 4 1___3.6___ubuntu-20.04___x64_-DPYBIND11_FINDPYTHON=ON_-DCMA.txt
0:15:34.449278 4 22___3.6___windows-2019___x64_-DPYBIND11_FINDPYTHON=ON.txt
0:16:25.189055 2 1___3.9-dbg__deadsnakes____Valgrind___x64.txt
0:17:20.956667 4 15___3.6___macos-latest___x64.txt
0:17:27.513891 4 23___3.9___windows-2019___x64.txt
0:17:58.783286 3 8___3.6___windows-2022___x64.txt
0:18:25.917828 4 7___pypy-3.9___ubuntu-20.04___x64.txt
0:19:17.399820 3 13___pypy-3.8___windows-2022___x64.txt
0:19:45.002122 3 12___pypy-3.7___windows-2022___x64.txt
0:20:03.201926 4 16___3.9___macos-latest___x64.txt
0:20:15.415178 4 17___3.10___macos-latest___x64.txt
0:20:20.263216 4 20___pypy-3.8___macos-latest___x64.txt
0:20:31.998226 3 1___3___windows-latest___mingw64.txt
0:20:40.812286 4 18___3.11___macos-latest___x64.txt
0:22:47.714749 4 19___pypy-3.7___macos-latest___x64.txt
0:23:04.435859 3 2___3___windows-latest___mingw32.txt
0:25:48.719597 3 14___pypy-3.9___windows-2022___x64.txt
0:26:01.211688 4 21___pypy-3.9___macos-latest___x64.txt
0:28:19.971015 1 1___3___CentOS7__PGI_22.9___x64.txt
```
* Update skipif for Python 3.12a7 (the WIP needs to be handled in a separate PR).
* Introduce `get_python_state_dict()`
* Conditional version bump for Python 3.12+
* Shuffle subexpressions to make the condition easier to understand (no change to logic).
* Make pybind11 ABI version 5 the minimum for Python 3.12+ (as suggested by @Lalaland)
* Add back condition for PYPY_VERSION, but keep it open for future PyPy versions.
* Fall back to simple `|| defined(PYPY_VERSION)`. `PY_VERSION_HEX` does not appear to be meaningful with PyPy.
Without this, it's impossible to get feature parity between detection
mechanisms. Both the pkg-config file and the cmake config set their
versions, but the python probe script didn't provide an option for this.
So you could print the compiler flags for using it, but you could not
check what you got.
```
flake8...................................................................Failed
- hook id: flake8
- exit code: 1
pybind11/setup_helpers.py:177:13: B028 No explicit stacklevel keyword argument found. The warn method from the warnings module uses a stacklevel of 1 by default. This will only show a stack trace for the line on which the warn method is called. It is therefore recommended to use a stacklevel of 2 or greater to provide more information to the user.
warnings.warn("You cannot safely change the cxx_level after setting it!")
^
```
* Use PyConfig_InitPythonConfig instead of PyConfig_InitIsolatedConfig
* add unit test for default python configuration
---------
Co-authored-by: Daniel Jacobs <daniel.jacobs@is4s.com>
* Resolve flake8 error by replacing `pytest.raises(Exception)` with `SystemError`
* Also remove the obsolete comment.
* Tweak comment instead of removing it.
* Make sure to properly untrack gc objects before freeing them
* style: pre-commit fixes
* Fix lint
* Add comment about where the original track comes from
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* docs: update changelog for v2.10.3
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* chore: bump versions for 2.10.3
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* chore: fix make changelog script with entry is empty
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>