Commit Graph

3036 Commits

Author SHA1 Message Date
Ralf W. Grosse-Kunstleve
18b72c0ffa Tie PYBIND11_INTERNALS_VERSION 6 to PYBIND11_VERSION_MAJOR >= 3 2024-07-20 19:57:52 -07:00
Ralf W. Grosse-Kunstleve
89d0ddd6ff test_class.cpp: simpler approach, leveraging new PYBIND11_ACTUALLY_USING_SMART_HOLDER_AS_DEFAULT 2024-07-20 19:40:38 -07:00
Ralf W. Grosse-Kunstleve
d0003f5660 Move classh into pybind11/pybind11.h and update test_classh_mock.cpp accordingly. 2024-07-20 17:53:37 -07:00
Ralf W. Grosse-Kunstleve
9f9a698ee9 Remove redundant test_class_sh_property_bakein.cpp,py 2024-07-20 00:48:35 -07:00
Ralf W. Grosse-Kunstleve
84f71f1b69 Import https://github.com/pybind/pybind11/pull/5256 from smart_holder branch back here (same test code as in test_class_sh_property_bakein.cpp,py). 2024-07-20 00:45:06 -07:00
Ralf W. Grosse-Kunstleve
df54a82dab Introduce PYBIND11_SMART_HOLDER_PADDING_ON (as the only way to turn on padding). 2024-07-19 20:05:53 -07:00
Ralf W. Grosse-Kunstleve
5566c63ebf Move try_initialization_using_shared_from_this into PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT block. 2024-07-19 19:42:12 -07:00
Ralf W. Grosse-Kunstleve
35b1177f42 Small cleanup in detail/init.h: strip originally_smart_holder_type_casters_h namespace. 2024-07-19 19:11:13 -07:00
Ralf W. Grosse-Kunstleve
62b6c8e404 Revert "Add "_sh_baked_in" to PYBIND11_INTERNALS_ID, PYBIND11_MODULE_LOCAL_ID"
`"_sh_baked_in"` is no longer needed because the smart_holder functionality is now tied to the `PYBIND11_INTERNALS_VERSION`.

This reverts commit 884305e953.
2024-07-19 18:55:18 -07:00
Ralf W. Grosse-Kunstleve
4a66b46080 ifdef out more code if PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT is not defined. 2024-07-19 11:21:35 -07:00
Ralf W. Grosse-Kunstleve
41433f632a ifdef out classh if PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT is not defined. 2024-07-19 10:41:11 -07:00
Ralf W. Grosse-Kunstleve
e4456197c4 Ignore PYBIND11_USE_SMART_HOLDER_AS_DEFAULT if PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT is not defined. 2024-07-19 10:18:05 -07:00
Ralf W. Grosse-Kunstleve
95e9053f7f Boilerplate changes: Skip all test_class_sh_* if PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT is not defined. 2024-07-19 09:54:40 -07:00
Ralf W. Grosse-Kunstleve
6fb8b5157d Add back original copyable_holder_caster check_holder_compat() in the std::shared_ptr specialization and remove pytest.skip("BAKEIN_EXPECTED: ...) in test_smart_ptr.py 2024-07-19 09:00:03 -07:00
Ralf W. Grosse-Kunstleve
cc2a428142 Bring in ci.yml, ci_sh_def.yml, ci_sh_def.yml.patch from smart_holder branch as-is. 2024-07-19 00:59:42 -07:00
Ralf W. Grosse-Kunstleve
7296c39705 Introduce detail/using_smart_holder.h and remove pybindit::memory:: in most places. 2024-07-19 00:55:15 -07:00
Ralf W. Grosse-Kunstleve
583c07bffd Use std::unique_ptr<T> as default holder again. 2024-07-19 00:03:49 -07:00
Ralf W. Grosse-Kunstleve
58a1b75e43 Reinterpret detail::type_info::default_holder as "uses std::unique_ptr holder" (which is the original meaning, and compatible with the original smart_holder branch). 2024-07-18 22:45:56 -07:00
Ralf W. Grosse-Kunstleve
cd4f5f6c5b PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT 2024-07-18 22:44:34 -07:00
Ralf W. Grosse-Kunstleve
1ea1787745 Remove overlooked BAKEIN_BREAK in test_class_sh_property_non_owning.cpp,py (tests pass without any further changes). 2024-07-18 22:43:39 -07:00
Ralf W. Grosse-Kunstleve
6d8952a283 Merge branch 'master' into bakein 2024-07-18 17:41:47 -07:00
Ralf W. Grosse-Kunstleve
6d4805ced1
Small cleanup/refactoring in support of PR #5213 (#5251)
* Factor out detail/value_and_holder.h (from detail/type_caster_base.h)

This is in support of PR #5213:

* trampoline_self_life_support.h depends on value_and_holder.h

* type_caster_base.h depends on trampoline_self_life_support.h

* Fix a minor and inconsequential inconsistency in `copyable_holder_caster`: the correct `load_value()` return type is `void` (as defined in `type_caster_generic`)

For easy future reference, this is the long-standing inconsistency:

* dbf848aff7/include/pybind11/detail/type_caster_base.h (L634)

* dbf848aff7/include/pybind11/cast.h (L797)

Noticed in passing while working on PR #5213.

* Add `DANGER ZONE` comment in detail/init.h, similar to a comment added on the smart_holder branch (all the way back in 2021).
2024-07-18 17:34:06 -07:00
Henry Schreiner
a582ca8a8e
tests: run on pyodide (#4745)
* tests: run on pyodide

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* ci: use cibuildwheel for pyodide test

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* tests: revert changes to test_embed

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2024-07-18 14:50:38 -04:00
Ralf W. Grosse-Kunstleve
4aa2f6b8eb Merge branch 'bakein_prep_on_master' into bakein 2024-07-18 01:29:47 -07:00
Ralf W. Grosse-Kunstleve
92d7724de4 Add DANGER ZONE comment in detail/init.h, similar to a comment added on the smart_holder branch (all the way back in 2021). 2024-07-18 01:25:36 -07:00
Ralf W. Grosse-Kunstleve
1ca810e8c7 Undo DANGER ZONE comment (brought in from smart_holder branch; before adding to PR #5251). 2024-07-18 01:21:38 -07:00
Ralf W. Grosse-Kunstleve
9a27e29ebd Leverage PR #5251 to bring back trampoline_self_life_support.h from smart_holder branch almost as-is.
This ensures IWYU correctness in client code.

The only change in trampoline_self_life_support.h is to replace `#include "detail/type_caster_base.h"` with "#include detail/value_and_holder.h".
2024-07-18 01:13:41 -07:00
Ralf W. Grosse-Kunstleve
7fa6dd9d1c Merge branch 'bakein_prep_on_master' into bakein 2024-07-18 01:01:05 -07:00
Ralf W. Grosse-Kunstleve
54fd559117 Fix a minor and inconsequential inconsistency in copyable_holder_caster: the correct load_value() return type is void (as defined in type_caster_generic)
For easy future reference, this is the long-standing inconsistency:

* dbf848aff7/include/pybind11/detail/type_caster_base.h (L634)

* dbf848aff7/include/pybind11/cast.h (L797)

Noticed in passing while working on PR #5213.
2024-07-18 00:51:10 -07:00
Ralf W. Grosse-Kunstleve
5e30064ee6 Factor out detail/value_and_holder.h (from detail/type_caster_base.h)
This is in support of PR #5213:

* trampoline_self_life_support.h depends on value_and_holder.h

* type_caster_base.h depends on trampoline_self_life_support.h
2024-07-18 00:41:39 -07:00
Ralf W. Grosse-Kunstleve
8ca559340c Merge branch 'master' into bakein 2024-07-18 00:12:07 -07:00
Ralf Gommers
dbf848aff7
docs: extend PYBIND11_MODULE documentation, mention mod_gil_not_used (#5250)
This follows up on PR 5148, which introduced support for free-threaded CPython.
2024-07-17 23:26:45 -07:00
Ralf W. Grosse-Kunstleve
ed27c37c4e Merge branch 'master' into bakein 2024-07-16 11:14:30 -07:00
Sam Gross
43de8014f9
fix: make gil_safe_call_once thread-safe in free-threaded CPython (#5246)
* fix: Make gil_safe_call_once thread-safe in free-threaded CPython

The "is_initialized_" flags is not protected by the GIL in free-threaded
Python, so it needs to be an atomic field.

Fixes #5245

* style: pre-commit fixes

* Apply changes from code review

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-07-16 11:06:54 -07:00
dependabot[bot]
ccefee4c31
chore(deps): bump actions/attest-build-provenance in the actions group (#5243)
Bumps the actions group with 1 update: [actions/attest-build-provenance](https://github.com/actions/attest-build-provenance).


Updates `actions/attest-build-provenance` from 1.3.2 to 1.3.3
- [Release notes](https://github.com/actions/attest-build-provenance/releases)
- [Changelog](https://github.com/actions/attest-build-provenance/blob/main/RELEASE.md)
- [Commits](bdd51370e0...5e9cb68e95)

---
updated-dependencies:
- dependency-name: actions/attest-build-provenance
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-07-15 16:51:27 -04:00
Ralf W. Grosse-Kunstleve
ecd01da7ac smart_holder_from_unique_ptr: also accept return_value_policy::take_ownership
There are no strong reasons for accepting or rejecting `return_value_policy::take_ownership`.

Accepting to accommodate existing use cases in the wild.
2024-07-15 01:33:15 -07:00
Ralf W. Grosse-Kunstleve
12f384bcbb smart_holder_from_unique_ptr: also accept return_value_policy::reference
There are no strong reasons for accepting or rejecting `return_value_policy::reference`.

Accepting to accommodate existing use cases in the wild.
2024-07-14 23:52:54 -07:00
Ralf W. Grosse-Kunstleve
884305e953 Add "_sh_baked_in" to PYBIND11_INTERNALS_ID, PYBIND11_MODULE_LOCAL_ID 2024-07-14 21:56:36 -07:00
Ralf W. Grosse-Kunstleve
0f874deee2 Move must_be_member_function_pointer to the detail namespace. 2024-07-14 21:39:33 -07:00
Ralf W. Grosse-Kunstleve
ff3693f1bb Introduce detail::both_t_and_d_use_type_caster_base<T, D> helper and use systematically in all property_cpp_function<> specializations.
This fixes a PyTorch build error (using the Google-internal toolchain):

```
In file included from third_party/py/torch/torch/csrc/distributed/c10d/init.cpp:15:
In file included from third_party/py/torch/torch/csrc/distributed/c10d/PyProcessGroup.hpp:4:
In file included from third_party/py/torch/torch/csrc/jit/python/pybind_utils.h:7:
In file included from third_party/pybind11/include/pybind11/complex.h:14:
In file included from third_party/pybind11/include/pybind11/pybind11.h:14:
In file included from third_party/pybind11/include/pybind11/detail/class.h:14:
In file included from third_party/pybind11/include/pybind11/detail/../attr.h:16:
third_party/pybind11/include/pybind11/detail/../cast.h:856:19: error: static assertion failed due to requirement 'std::is_base_of<pybind11::detail::type_caster_base<c10::intrusive_ptr<c10d::Store, c10::detail::intrusive_target_default_null_type<c10d::Store>>>, pybind11::detail::type_caster<c10::intrusive_ptr<c10d::Store, c10::detail::intrusive_target_default_null_type<c10d::Store>>, void>>::value': Holder classes are only supported for custom types
  856 |     static_assert(std::is_base_of<base, type_caster<type>>::value,
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
third_party/pybind11/include/pybind11/detail/../cast.h:982:48: note: in instantiation of template class 'pybind11::detail::copyable_holder_caster<c10::intrusive_ptr<c10d::Store>, std::shared_ptr<c10::intrusive_ptr<c10d::Store>>>' requested here
  982 | class type_caster<std::shared_ptr<T>> : public copyable_holder_caster<T, std::shared_ptr<T>> {};
      |                                                ^
third_party/crosstool/v18/stable/src/libcxx/include/__type_traits/is_base_of.h:22:91: note: in instantiation of template class 'pybind11::detail::type_caster<std::shared_ptr<c10::intrusive_ptr<c10d::Store>>>' requested here
   22 | struct _LIBCPP_TEMPLATE_VIS is_base_of : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
      |                                                                                           ^
third_party/pybind11/include/pybind11/detail/../cast.h:1382:30: note: in instantiation of template class 'std::is_base_of<pybind11::detail::type_caster_generic, pybind11::detail::type_caster<std::shared_ptr<c10::intrusive_ptr<c10d::Store>>>>' requested here
 1382 |     detail::enable_if_t<std::is_base_of<type_caster_generic, make_caster<Return>>::value, void>> {
      |                              ^
third_party/pybind11/include/pybind11/pybind11.h:287:19: note: during template argument deduction for class template partial specialization 'return_value_policy_override<Return, detail::enable_if_t<std::is_base_of<type_caster_generic, make_caster<Return>>::value, void>>' [with Return = std::shared_ptr<c10::intrusive_ptr<c10d::Store>>]
  287 |                 = return_value_policy_override<Return>::policy(call.func.policy);
      |                   ^
third_party/pybind11/include/pybind11/pybind11.h:287:19: note: in instantiation of template class 'pybind11::detail::return_value_policy_override<std::shared_ptr<c10::intrusive_ptr<c10d::Store>>>' requested here
third_party/pybind11/include/pybind11/pybind11.h:269:55: note: while substituting into a lambda expression here
  269 |         rec->impl = [](function_call &call) -> handle {
      |                                                       ^
third_party/pybind11/include/pybind11/pybind11.h:147:9: note: in instantiation of function template specialization 'pybind11::cpp_function::initialize<(lambda at third_party/pybind11/include/pybind11/pybind11.h:1714:17), std::shared_ptr<c10::intrusive_ptr<c10d::Store>>, pybind11::handle, pybind11::is_method>' requested here
  147 |         initialize(
      |         ^
third_party/pybind11/include/pybind11/pybind11.h:1713:20: note: in instantiation of function template specialization 'pybind11::cpp_function::cpp_function<(lambda at third_party/pybind11/include/pybind11/pybind11.h:1714:17), pybind11::is_method, void>' requested here
 1713 |             return cpp_function(
      |                    ^
third_party/pybind11/include/pybind11/pybind11.h:1964:54: note: in instantiation of function template specialization 'pybind11::property_cpp_function<c10d::DistributedBackendOptions, c10::intrusive_ptr<c10d::Store>>::read<c10::intrusive_ptr<c10d::Store> c10d::DistributedBackendOptions::*, 0>' requested here
 1964 |                      property_cpp_function<type, D>::read(pm, *this),
      |                                                      ^
third_party/py/torch/torch/csrc/distributed/c10d/init.cpp:945:8: note: in instantiation of function template specialization 'pybind11::class_<c10d::DistributedBackendOptions>::def_readwrite<c10d::DistributedBackendOptions, c10::intrusive_ptr<c10d::Store>>' requested here
  945 |       .def_readwrite("store", &::c10d::DistributedBackendOptions::store)
      |        ^
1 error generated.
```
2024-07-14 21:19:50 -07:00
Ralf W. Grosse-Kunstleve
89da1e2ef7 Use memcpy instead of strcpy to resolve MSVC errors. 2024-07-14 01:15:37 -07:00
Ralf W. Grosse-Kunstleve
c65d5dfaa8 Systematically use is_base_of<type_caster_generic, make_caster<D>> in property_cpp_function<> specializations. 2024-07-14 00:54:41 -07:00
Ralf W. Grosse-Kunstleve
3406be6877 New test_class_sh_property_bakein.py
Use cases in the wild:

* `test_readonly_char6_member()`: 4410c44ae6/torch/csrc/cuda/Module.cpp (L961)

* `test_readonly_const_char_ptr_member()`: 862a439a84/include/permonst.h (L43)
2024-07-13 23:46:36 -07:00
Ralf W. Grosse-Kunstleve
2600bb67c5 Remove test_ccccccccccccccccccccc.cpp,py (not needed anymore). 2024-07-13 01:15:09 -07:00
Ralf W. Grosse-Kunstleve
6fa0a2e439 PYBIND11_HAVE_HOLDER_CASTER_WITH_SMART_HOLDER_SUPPORT
Introduce two helper types:

* copyable_holder_caster_shared_ptr_with_smart_holder_support_enabled

* move_only_holder_caster_unique_ptr_with_smart_holder_support_enabled
2024-07-13 00:07:57 -07:00
Ralf W. Grosse-Kunstleve
092d236b4e Remove test_wip.cpp,py (not needed anymore). 2024-07-12 08:33:55 -07:00
Ralf W. Grosse-Kunstleve
d021bb10aa Remove redundant check_holder_compat() no-op implementation. 2024-07-12 08:31:35 -07:00
Ralf W. Grosse-Kunstleve
63044cc199 Bring in default_holder_type from smart_holder branch including using it in pybind11/stl_bind.h 2024-07-12 08:26:34 -07:00
Ralf W. Grosse-Kunstleve
d373a082ad Remove remaining BAKEIN_BREAK in test_class_sh_property.cpp,py and adjust (simplify) the property_cpp_function<...unique_ptr...>::write implementation (all tests pass).
This PR (#5213) at this commit also passes ASAN, MSAN, UBSAN testing with the Google-internal toolchain.
2024-07-12 02:38:14 -07:00
Ralf W. Grosse-Kunstleve
0b14d5bce9 test_class_sh_property.py test_valu_getter() works without any further changes. 2024-07-12 02:24:27 -07:00