pybind11/tests
Ralf W. Grosse-Kunstleve ef5a9560bb
Enable type-safe interoperability between different independent Python/C++ bindings systems. (#5296)
* `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>
2024-09-13 00:18:29 -04:00
..
extra_python_package Enable type-safe interoperability between different independent Python/C++ bindings systems. (#5296) 2024-09-13 00:18:29 -04:00
extra_setuptools feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_cmake_build feat: require CMake 3.15+ (#5304) 2024-08-14 18:21:04 -04:00
test_embed feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
CMakeLists.txt Enable type-safe interoperability between different independent Python/C++ bindings systems. (#5296) 2024-09-13 00:18:29 -04:00
conftest.py chore(deps): update pre-commit hooks (#5350) 2024-09-03 10:51:21 -04:00
constructor_stats.h clang-tidy upgrade (to version 18) (#5272) 2024-07-29 11:10:03 -07:00
cross_module_gil_utils.cpp fix: support free-threaded CPython with GIL disabled (#5148) 2024-06-18 13:54:38 -07:00
cross_module_interleaved_error_already_set.cpp fix: support free-threaded CPython with GIL disabled (#5148) 2024-06-18 13:54:38 -07:00
eigen_tensor_avoid_stl_array.cpp fix: support free-threaded CPython with GIL disabled (#5148) 2024-06-18 13:54:38 -07:00
env.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
exo_planet_c_api.cpp Enable type-safe interoperability between different independent Python/C++ bindings systems. (#5296) 2024-09-13 00:18:29 -04:00
exo_planet_pybind11.cpp Enable type-safe interoperability between different independent Python/C++ bindings systems. (#5296) 2024-09-13 00:18:29 -04:00
home_planet_very_lonely_traveler.cpp Enable type-safe interoperability between different independent Python/C++ bindings systems. (#5296) 2024-09-13 00:18:29 -04:00
local_bindings.h fix: allow -Wpedantic in C++20 mode (#5322) 2024-08-22 00:27:50 -04:00
object.h Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
pybind11_cross_module_tests.cpp fix: support free-threaded CPython with GIL disabled (#5148) 2024-06-18 13:54:38 -07:00
pybind11_tests.cpp fix: support free-threaded CPython with GIL disabled (#5148) 2024-06-18 13:54:38 -07:00
pybind11_tests.h fix: use std::addressof in type_caster_base.h (#5189) 2024-06-24 08:59:55 -07:00
pyproject.toml feat: require CMake 3.15+ (#5304) 2024-08-14 18:21:04 -04:00
pytest.ini chore: some cleanup (#5137) 2024-05-24 12:26:40 -04:00
requirements.txt feat: remove Python 3.7 support (#5191) 2024-07-30 09:18:35 -07:00
test_async.cpp Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
test_async.py chore(deps): update pre-commit hooks (#5350) 2024-09-03 10:51:21 -04:00
test_buffers.cpp Properly translate C++ exception to Python exception when creating Python buffer from wrapped object (#5324) 2024-09-02 09:01:59 -07:00
test_buffers.py Properly translate C++ exception to Python exception when creating Python buffer from wrapped object (#5324) 2024-09-02 09:01:59 -07:00
test_builtin_casters.cpp chore(deps): update pre-commit hooks (#5084) 2024-04-02 11:14:08 -04:00
test_builtin_casters.py feat: remove Python 3.7 support (#5191) 2024-07-30 09:18:35 -07:00
test_call_policies.cpp feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_call_policies.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_callbacks.cpp fix: allow -Wpedantic in C++20 mode (#5322) 2024-08-22 00:27:50 -04:00
test_callbacks.py tests: run on pyodide (#4745) 2024-07-18 14:50:38 -04:00
test_chrono.cpp Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
test_chrono.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_class.cpp chore(deps): update pre-commit hooks (#5123) 2024-05-10 17:03:51 -04:00
test_class.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_const_name.cpp Dropping MSVC 2015 (#3722) 2022-02-14 11:36:22 -08:00
test_const_name.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_constants_and_functions.cpp tests: hide warning on clang (#5069) 2024-03-26 13:57:05 -04:00
test_constants_and_functions.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_copy_move.cpp fix: use std::addressof in type_caster_base.h (#5189) 2024-06-24 08:59:55 -07:00
test_copy_move.py fix: use std::addressof in type_caster_base.h (#5189) 2024-06-24 08:59:55 -07:00
test_cpp_conduit_traveler_bindings.h Enable type-safe interoperability between different independent Python/C++ bindings systems. (#5296) 2024-09-13 00:18:29 -04:00
test_cpp_conduit_traveler_types.h Enable type-safe interoperability between different independent Python/C++ bindings systems. (#5296) 2024-09-13 00:18:29 -04:00
test_cpp_conduit.cpp Enable type-safe interoperability between different independent Python/C++ bindings systems. (#5296) 2024-09-13 00:18:29 -04:00
test_cpp_conduit.py Enable type-safe interoperability between different independent Python/C++ bindings systems. (#5296) 2024-09-13 00:18:29 -04:00
test_custom_type_casters.cpp chore(deps): update pre-commit hooks (#5084) 2024-04-02 11:14:08 -04:00
test_custom_type_casters.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_custom_type_setup.cpp Add custom_type_setup attribute (#3287) 2021-09-24 12:08:22 -07:00
test_custom_type_setup.py chore(deps): update pre-commit hooks (#5350) 2024-09-03 10:51:21 -04:00
test_docstring_options.cpp chore(deps): update pre-commit hooks (#5084) 2024-04-02 11:14:08 -04:00
test_docstring_options.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_eigen_matrix.cpp fix: allow -Wpedantic in C++20 mode (#5322) 2024-08-22 00:27:50 -04:00
test_eigen_matrix.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_eigen_tensor.cpp Fix ODR violations in our Eigen Tensor tests (#4412) 2022-12-20 05:34:00 -08:00
test_eigen_tensor.inl clang-tidy upgrade (to version 18) (#5272) 2024-07-29 11:10:03 -07:00
test_eigen_tensor.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_enum.cpp Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
test_enum.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_eval_call.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_eval.cpp Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
test_eval.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_exceptions.cpp Bug fixes: Add missing handle_type_name specializations. (#5073) 2024-03-27 12:39:05 -07:00
test_exceptions.h Add py::set_error(), use in updated py::exception<> documentation (#4772) 2023-08-07 20:48:20 -07:00
test_exceptions.py feat: remove Python 3.7 support (#5191) 2024-07-30 09:18:35 -07:00
test_factory_constructors.cpp Dropping MSVC 2015 (#3722) 2022-02-14 11:36:22 -08:00
test_factory_constructors.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_gil_scoped.cpp Add PYBIND11_SIMPLE_GIL_MANAGEMENT option (cmake, C++ define) (#4216) 2022-10-30 08:57:23 -07:00
test_gil_scoped.py tests: run on pyodide (#4745) 2024-07-18 14:50:38 -04:00
test_iostream.cpp Dropping MSVC 2015 (#3722) 2022-02-14 11:36:22 -08:00
test_iostream.py tests: run on pyodide (#4745) 2024-07-18 14:50:38 -04:00
test_kwargs_and_defaults.cpp fix: Python 3.13t with GIL (#5139) 2024-05-28 09:07:59 -04:00
test_kwargs_and_defaults.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_local_bindings.cpp Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
test_local_bindings.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_methods_and_attributes.cpp chore(deps): update pre-commit hooks (#5084) 2024-04-02 11:14:08 -04:00
test_methods_and_attributes.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_modules.cpp clang-tidy upgrade (to version 18) (#5272) 2024-07-29 11:10:03 -07:00
test_modules.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_multiple_inheritance.cpp Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
test_multiple_inheritance.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_numpy_array.cpp chore(deps): update pre-commit hooks (#5084) 2024-04-02 11:14:08 -04:00
test_numpy_array.py chore(deps): update pre-commit hooks (#5350) 2024-09-03 10:51:21 -04:00
test_numpy_dtypes.cpp clang-tidy upgrade (to version 18) (#5272) 2024-07-29 11:10:03 -07:00
test_numpy_dtypes.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_numpy_vectorize.cpp fix: avoid catch (...) for expected import numpy failures (#3974) 2022-05-26 11:07:40 -04:00
test_numpy_vectorize.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_opaque_types.cpp fix: allow -Wpedantic in C++20 mode (#5322) 2024-08-22 00:27:50 -04:00
test_opaque_types.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_operator_overloading.cpp Introduce a new style of warning suppression based on push/pop (#4285) 2022-11-28 07:39:38 -08:00
test_operator_overloading.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_pickling.cpp Test pickling a simple callable (does not work). (#3906) 2022-05-02 12:39:36 -07:00
test_pickling.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_python_multiple_inheritance.cpp Fix a long-standing bug in the handling of Python multiple inheritance (#4762) 2023-11-08 12:44:04 -08:00
test_python_multiple_inheritance.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_pytypes.cpp fix: <ranges> support for py::tuple and py::list (#5314) 2024-08-21 15:33:06 -04:00
test_pytypes.py fix: using __cpp_nontype_template_args instead of __cpp_nontype_template_parameter_class (#5330) 2024-08-25 23:36:03 -04:00
test_sequences_and_iterators.cpp fix: allow -Wpedantic in C++20 mode (#5322) 2024-08-22 00:27:50 -04:00
test_sequences_and_iterators.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_smart_ptr.cpp fix: allow -Wpedantic in C++20 mode (#5322) 2024-08-22 00:27:50 -04:00
test_smart_ptr.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_stl_binders.cpp chore(deps): update pre-commit hooks (#5084) 2024-04-02 11:14:08 -04:00
test_stl_binders.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_stl.cpp fix: allow -Wpedantic in C++20 mode (#5322) 2024-08-22 00:27:50 -04:00
test_stl.py Backport of https://github.com/google/pywrapcc/pull/30034 (#5305) 2024-08-14 22:30:29 -07:00
test_tagbased_polymorphic.cpp fix: allow -Wpedantic in C++20 mode (#5322) 2024-08-22 00:27:50 -04:00
test_tagbased_polymorphic.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_thread.cpp chore(deps): update pre-commit hooks (#5123) 2024-05-10 17:03:51 -04:00
test_thread.py tests: run on pyodide (#4745) 2024-07-18 14:50:38 -04:00
test_type_caster_pyobject_ptr.cpp Fix refcount bug involving trampoline functions with PyObject * return type. (#5156) 2024-06-11 14:00:52 -07:00
test_type_caster_pyobject_ptr.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_type_caster_std_function_specializations.cpp Add type_caster_std_function_specializations feature. (#4597) 2024-08-09 13:28:12 -07:00
test_type_caster_std_function_specializations.py Add type_caster_std_function_specializations feature. (#4597) 2024-08-09 13:28:12 -07:00
test_union.cpp Fix assertion failure for unions (#1685) (#1709) 2019-06-11 23:28:58 +02:00
test_union.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_unnamed_namespace_a.cpp Use std::hash<std::type_index>, std::equal_to<std::type_index> everywhere **except when libc++ is in use** (#4319) 2023-04-25 14:03:24 -07:00
test_unnamed_namespace_a.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_unnamed_namespace_b.cpp Use std::hash<std::type_index>, std::equal_to<std::type_index> everywhere **except when libc++ is in use** (#4319) 2023-04-25 14:03:24 -07:00
test_unnamed_namespace_b.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_vector_unique_ptr_member.cpp Remove stray comment. (Oversight in PR #4631. Noticed by chance.) (#4641) 2023-04-27 07:24:48 -07:00
test_vector_unique_ptr_member.py feat: remove Python 3.6 support (#5177) 2024-06-22 00:55:00 -04:00
test_virtual_functions.cpp fix: allow -Wpedantic in C++20 mode (#5322) 2024-08-22 00:27:50 -04:00
test_virtual_functions.py tests: run on pyodide (#4745) 2024-07-18 14:50:38 -04:00
test_warnings.cpp Warnings wrappers to use from C++ (#5291) 2024-08-28 20:55:50 -07:00
test_warnings.py Warnings wrappers to use from C++ (#5291) 2024-08-28 20:55:50 -07:00
valgrind-numpy-scipy.supp docs: fix various typos (#3075) 2021-07-04 19:58:35 -04:00
valgrind-python.supp chore: get PyPy 3.7 wheels using NumPy 1.20 (#2837) 2021-01-31 17:29:09 -05:00