* `self.__cpp_transporter__()` proof of concept: Enable passing C++ pointers across extensions even if the `PYBIND11_INTERNALS_VERSION`s do not match.
* Include cleanup (mainly to resolve PyPy build failures).
* Fix clang-tidy errors.
* Resolve `error: extra
* factor out platform_abi_id.h from internals.h (no functional changes)
* factor out internals_version.h from internals.h (no functional changes)
* Update CMakeLists.txt, tests/extra_python_package/test_files.py
* Revert "factor out internals_version.h from internals.h (no functional changes)"
This reverts commit 3ccea8cd43.
* Remove internals_version.h from CMakeLists.txt, tests/extra_python_package/test_files.py
* `.__cpp_transporter__()` implementation: compare `pybind11_platform_abi_id`, `cpp_typeid_name`
* Add PremiumTraveler
* Rename test_cpp_transporter_traveler_type.h -> test_cpp_transporter_traveler_types.h
* Expand tests: `PremiumTraveler`, `get_points()`
* Shuffle order of tests (no real changes).
* Move `__cpp_transporter__` lambda to `py::cpp_transporter()` regular function.
* Use `type_caster_generic::load(self)` instead of `cast<T *>(self)`
* Pass `const std::type_info *` via `py::capsule` (instead of `cpp_typeid_name`).
* Make platform_abi_id.h completely stand-alone.
* rename exo_planet.cpp -> exo_planet_pybind11.cpp
* Add exo_planet_c_api.cpp (incomplete).
* Fix silly oversight (wrong filename in `#include`).
* Resolve clang-tidy errors:
```
/__w/pybind11/pybind11/tests/exo_planet_c_api.cpp:10:18: error: 'wrapGetLuggage' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace,-warnings-as-errors]
10 | static PyObject *wrapGetLuggage(PyObject *, PyObject *) { return PyUnicode_FromString("TODO"); }
| ~~~~~~ ^
/__w/pybind11/pybind11/tests/exo_planet_c_api.cpp:14:20: error: 'ThisMethodDef' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace,-warnings-as-errors]
14 | static PyMethodDef ThisMethodDef[]
| ~~~~~~ ^
/__w/pybind11/pybind11/tests/exo_planet_c_api.cpp:17:27: error: 'ThisModuleDef' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace,-warnings-as-errors]
17 | static struct PyModuleDef ThisModuleDef = {
| ~~~~~~ ^
```
* Implement exo_planet_c_api GetLuggage(), GetPoints()
* Move new code from test_cpp_transporter_traveler_bindings.h to pybind11/detail/type_caster_base.h, under the name `class_dunder_cpp_transporter()`
* Fix oversight.
* Unconditionally add `__cpp_transporter__` method to all `py::class_` objects, but do not include that magic method in docstring signatures.
* Back out pybind11/detail/platform_abi_id.h for now. Maximizing reusability can be handled separately, later.
* Small cleanup.
* Restore and add to `test_call_cpp_transporter_*()`
* Ensure https://github.com/pybind/pybind11/issues/3788 does not bite again.
* `class_dunder_cpp_transporter()`: replace `obj.cast<std::string>()` with `std::string(obj)`
* Add (simple) copyright notices in all newly added files.
* Globally replace cpp_transporter with cpp_conduit
* style: pre-commit fixes
* IWYU fixes
* Rename `class_dunder_cpp_conduit()` -> `cpp_conduit_method()`
* Change `pybind11_platform_abi_id`, `pointer_kind` argument types from `str` to `bytes`.
This avoids the unicode decode/encode roundtrips:
* More robust (no decode/encode errors).
* Minor runtime optimization.
* Systematically rename `cap_cpp_type_info` -> `cpp_type_info_capsule` (no functional changes).
* Systematically replace `cpp_type_info_capsule` `name`: `"const std::type_info *"` -> `typeid(std::type_info).name()` (this IS a functional change).
This provides an extra layer of protection against C++ ABI mismatches:
* The first and most important layer is that the `PYBIND11_PLATFORM_ABI_ID`s must match between extensions.
* The second layer is that the `typeid(std::type_info).name()`s must match between extensions.
* Fix sort order accident in tests/CMakeLists.txt
* Apply suggestions from code review
Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com>
* style: pre-commit fixes
* refactor: rename to _pybind_conduit_v1_
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* Add test_home_planet_wrap_very_lonely_traveler(), test_exo_planet_pybind11_wrap_very_lonely_traveler()
* Resolve clang-tidy errors:
```
/__w/pybind11/pybind11/tests/test_cpp_conduit_traveler_bindings.h:39:32: error: parameter 'm' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param,-warnings-as-errors]
10 | py::class_<LonelyTraveler>(m, "LonelyTraveler");
| ^
| std::move( )
/__w/pybind11/pybind11/tests/test_cpp_conduit_traveler_bindings.h:43:52: error: parameter 'm' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param,-warnings-as-errors]
43 | py::class_<VeryLonelyTraveler, LonelyTraveler>(m, "VeryLonelyTraveler");
| ^
| std::move( )
```
---------
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com>
* Add test for throwing def_buffer case
* Translate C++ -> Python exceptions in buffer creation
This required a little refactoring to extract exception translation to a separate method
* Fix code formatting
* Fix "unused parameter" warning
* Refactor per review
* style: pre-commit fixes
* Address review comments
* Address review comments
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Step 1: Establish new `PYBIND11_SMART_HOLDER_ENABLED` macro, but only under include/pybind11/
At the stage `PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT` and `PYBIND11_SMART_HOLDER_ENABLED` are still equivalent.
* Systematically replace all `PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT` with `PYBIND11_SMART_HOLDER_ENABLED` under tests/ and ubench/
As at the previous stage, `PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT` and `PYBIND11_SMART_HOLDER_ENABLED` are still equivalent.
* Introduce `PYBIND11_SMART_HOLDER_DISABLE` option.
* `#ifdef` out entire `wrap()` function to avoid `unused-parameter` warning-as-error under macos-13
```
/Users/runner/work/pybind11/pybind11/tests/test_class_sh_trampoline_basic.cpp:67:23: error: unused parameter 'm' [-Werror,-Wunused-parameter]
void wrap(py::module_ m, const char *py_class_name) {
^
/Users/runner/work/pybind11/pybind11/tests/test_class_sh_trampoline_basic.cpp:67:38: error: unused parameter 'py_class_name' [-Werror,-Wunused-parameter]
void wrap(py::module_ m, const char *py_class_name) {
^
2 errors generated.
```
The SMART_HOLDER_WIP comments are mostly from 2021. In the meantime, the
smart_holder code was extremely thoroughly tested in the Google codebase
(production code). Additionally, testing via PyCLIF-pybind11 provided
thousands of diverse use cases that needed to satisfy many million unit tests
(the success rate was about 99.999%).
* fix: use `__cpp_nontype_template_args` instead of gnu extensions
* fix: add feature test value
* fix: change `PYBIND11_TYPING_H_HAS_STRING_LITERAL` skip reason
* Replace `unique_ptr_cref_roundtrip()` with `pass_unique_ptr_cref()`, `rtrn_unique_ptr_cref()` to make the current behavior obvious.
* add in unique_ptr_storage, unique_ptr_storage_deleter
* Add shared_ptr_storage (with that disowning fails as expected).
* Add load_as_const_unique_ptr()
* Restore original struct_smart_holder.h
* factor out `smart_holder::extract_deleter()`
* Better error message.
* Misc cleanup/tidying.
* Use `re.match("ctor_arg(_MvCtor)*_MvCtor", ...)` for compatibility with MSVC, NVHPC, ICC
* Add small comments.
* Fix small, inconsequential oversight in test code.
* Apply suggestion by @iwanders under PR #5334
* Remove `std::move()` in `smart_holder::extract_deleter()`
* Add `static_assert()` following a suggestion by @iwanders under PR #5334
PREPARATION for:
PR #5332 — Fix handling of const unique_ptr<T, D> & (do not disown).
Splitting out so that the functional changes under PR #5332 will be more obvious.
The only functional change under this PR is that
```
assert(custom_deleter_ptr != nullptr);
```
is replaced with:
```
if (custom_deleter_ptr == nullptr) {
throw std::runtime_error(
std::string("smart_holder::extract_deleter() precondition failure (") + context
+ ").");
}
```
PREPARATION for:
PR #5332 — Fix handling of const unique_ptr<T, D> & (do not disown).
Splitting out so that the functional changes under PR #5332 will be more obvious.
* DOC: Clarify requirements for including pybind11
Inherited from requirements for including Python.h
Closes#4999
* style: pre-commit fixes
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* fix: allow -Wpedantic again
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* tests: ignore pedantic warning for PYBIND11_DECLARE_HOLDER_TYPE
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* tests: try just turning off pedantic for one file
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* tests: only run pedantic in C++20 mode
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* Update tests/local_bindings.h
---------
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* feat: add `<ranges>` support for `py::tuple` and `py::list`
* fix: format the code
* fix: disable `ranges` in clang < 16
* refactor: move `<ranges>` test macro to `test_pytypes.h`
* refactor: seperate `ranges` test into 3 funcs
* style: compress the if statement
* style: pre-commit fixes
* style: better formatting
---------
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: never use `..` in a header include
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* fix: one more parent include
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
---------
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* fix: Escape paths with spaces in include list from --includes
* fix: --includes should not use shlex on Windows platforms
* Apply suggestions from code review
* fix: use custom impl
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* Support trailing backslashes
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
---------
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Markus Bauer <markus.bauer@cispa.saarland>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
* Configure only one job per OS kind to build and run tests with `-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT`
Remove ci_sh_def.yml
Piggy-backed: Add `smart_holder` to `branches` in emscripten.yaml
* Fix misunderstanding.
* Add `/GR /EHsc` for Windows.
* #error "Intentional Breakage" (to verify: PYBIND11_ACTUALLY_USING_SMART_HOLDER_AS_DEFAULT)
* Revert "#error "Intentional Breakage" (to verify: PYBIND11_ACTUALLY_USING_SMART_HOLDER_AS_DEFAULT)"
This reverts commit 4f6f5cb6e9.
* Add `test_pass_std_vector_int()`, `test_pass_std_set_int()` in test_stl
* Change `list_caster` to also accept generator objects (`PyGen_Check(src.ptr()`).
Note for completeness: This is a more conservative change than https://github.com/google/pywrapcc/pull/30042
* Drop in (currently unpublished) PyCLIF code, use in `list_caster`, adjust tests.
* Use `PyObjectTypeIsConvertibleToStdSet()` in `set_caster`, adjust tests.
* Use `PyObjectTypeIsConvertibleToStdMap()` in `map_caster`, add tests.
* Simplify `list_caster` `load()` implementation, push str/bytes check into `PyObjectTypeIsConvertibleToStdVector()`.
* clang-tidy cleanup with a few extra `(... != 0)` to be more consistent.
* Also use `PyObjectTypeIsConvertibleToStdVector()` in `array_caster`.
* Update comment pointing to clif/python/runtime.cc (code is unchanged).
* Comprehensive test coverage, enhanced set_caster load implementation.
* Resolve clang-tidy eror.
* Add a long C++ comment explaining what led to the `PyObjectTypeIsConvertibleTo*()` implementations.
* Minor function name change in test.
* strcmp -> std::strcmp (thanks @Skylion007 for catching this)
* Add `PyCallable_Check(items)` in `PyObjectTypeIsConvertibleToStdMap()`
* Resolve clang-tidy error
* Use `PyMapping_Items()` instead of `src.attr("items")()`, to be internally consistent with `PyMapping_Check()`
* Update link to PyCLIF sources.
* Fix typo (thanks @wangxf123456 for catching this)
* Add `test_pass_std_vector_int()`, `test_pass_std_set_int()` in test_stl
* Change `list_caster` to also accept generator objects (`PyGen_Check(src.ptr()`).
Note for completeness: This is a more conservative change than https://github.com/google/pywrapcc/pull/30042
* Drop in (currently unpublished) PyCLIF code, use in `list_caster`, adjust tests.
* Use `PyObjectTypeIsConvertibleToStdSet()` in `set_caster`, adjust tests.
* Use `PyObjectTypeIsConvertibleToStdMap()` in `map_caster`, add tests.
* Simplify `list_caster` `load()` implementation, push str/bytes check into `PyObjectTypeIsConvertibleToStdVector()`.
* clang-tidy cleanup with a few extra `(... != 0)` to be more consistent.
* Also use `PyObjectTypeIsConvertibleToStdVector()` in `array_caster`.
* Update comment pointing to clif/python/runtime.cc (code is unchanged).
* Comprehensive test coverage, enhanced set_caster load implementation.
* Resolve clang-tidy eror.
* Add a long C++ comment explaining what led to the `PyObjectTypeIsConvertibleTo*()` implementations.
* Minor function name change in test.
* strcmp -> std::strcmp (thanks @Skylion007 for catching this)
* Add `PyCallable_Check(items)` in `PyObjectTypeIsConvertibleToStdMap()`
* Resolve clang-tidy error
* Use `PyMapping_Items()` instead of `src.attr("items")()`, to be internally consistent with `PyMapping_Check()`
* Update link to PyCLIF sources.
* Fix typo (thanks @wangxf123456 for catching this)
* Fix typo discovered by new version of codespell.