* [docs/advanced] A document about deadlock potential with C++ statics
* [docs/advanced] Refer to deadlock.md from misc.rst
* [docs/advanced] Fix tables in deadlock.md
* Use :ref:`deadlock-reference-label`
* Revert "Use :ref:`deadlock-reference-label`"
This reverts commit e5734d275f.
* Add simple references to docs/advanced/deadlock.md filename. (Maybe someone can work on clickable links later.)
---------
Co-authored-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
* Print key in map.getitem/delitem KeyError
* Add tests
* Fix tests
* Make robust
* Make clang-tidy happy
* Return a Python str
* Show beginning and end of the message
* Avoid implicit conversion
* Split out `format_message_key_error_key_object()` to reduce amount of templated code.
* Use `"✄✄✄"` instead of `"..."`
Also rename variable to `cut_length`, to not get into even/odd issues with the meaning of "half".
---------
Co-authored-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
* Initial support for GraalPy
* Mark tests that currently fail on GraalPy with xfail
* Add graalpy to CI
* Limit test deps on graalpy to available binary wheels
* Skip cmake test installed_function on GraalPy
CMake won't find libpython on GraalPy, it either fails or silently picks
CPython's libpython.
* Factor out setting function docstrings into a macro
* Try to narrow down skipped tests
* Allow subclasses of py::args and py::kwargs
The current implementation does not allow subclasses of args or kwargs.
This change allows subclasses to be used.
* Added test case
* style: pre-commit fixes
* Added missing semi-colons
* style: pre-commit fixes
* Added handle_type_name
* Moved classes outside of function
* Added namespaces
* style: pre-commit fixes
* Refactored tests
Added more tests and moved tests to more appropriate locations.
* style: pre-commit fixes
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Issue: #5224
The `internals.registered_types_py...` line in pybind11.h triggers a
false-positive bounds checking warning in GCC 12.
This is discussed in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115824.
The workaround implemented is taken from suggestions then refactored to
use the `PYBIND11_WARNING_PUSH` and `PYBIND11_WARNING_POP` MACROS.
* `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>
* 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
* 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>
* 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.
* Allow specializations based on callback function return values.
* clang-tidy auto fix
* Add a test case for function specialization.
* Add test for callback function that raises Python exception.
* Fix test failures.
* style: pre-commit fixes
* Add `#define PYBIND11_HAS_TYPE_CASTER_STD_FUNCTION_SPECIALIZATIONS`
---------
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>
* `container: silkeh/clang:18-bookworm` in .github/workflows/format.yml
* clang-tidy auto-fix (trivial, in test only)
* Disable `performance-enum-size` (noisy, low value)
* Temporarily turn off 3 diagnostics (to be tackled one-by-one).
* Add explicit `switch` `default` to resolve clang-tidy `bugprone-switch-missing-default-case`
Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143)
Target: x86_64-pc-linux-gnu
tests/test_numpy_dtypes.cpp:212:5: warning: switching on non-enum value without default case may not cover all cases [bugprone-switch-missing-default-case]
* Add clang-17 and clang-18 testing.
* Add `NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)` in test_tagbased_polymorphic.cpp
Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143)
Target: x86_64-pc-linux-gnu
tests/test_tagbased_polymorphic.cpp:77:40: warning: The value '150' provided to the cast expression is not in the valid range of values for 'Kind' [clang-analyzer-optin.core.EnumCastOutOfRange]
* Fix inconsistent pybind11/eigen/tensor.h behavior:
This existing comment in pybind11/eigen/tensor.h
```
// move, take_ownership don't make any sense for a ref/map:
```
is at odds with the `delete src;` three lines up.
In real-world client code `take_ownership` will not exist (unless the client code is untested and unused). I.e. the `delete` is essentially only useful to avoid leaks in the pybind11 unit tests.
While upgrading to clang-tidy 18, the warning below appeared. Apparently it is produced during LTO, and it appears difficult to suppress. Regardless, the best way to resolve this is to remove the `delete` and to simply make the test objects `static` in the unit test code.
________
Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143)
Target: x86_64-pc-linux-gnu
________
```
lto-wrapper: warning: using serial compilation of 3 LTRANS jobs
lto-wrapper: note: see the ‘-flto’ option documentation for more information
In function ‘cast_impl’,
inlined from ‘cast’ at /mounted_pybind11/include/pybind11/eigen/tensor.h:414:25,
inlined from ‘operator()’ at /mounted_pybind11/include/pybind11/eigen/../pybind11.h:296:40,
inlined from ‘_FUN’ at /mounted_pybind11/include/pybind11/eigen/../pybind11.h:267:21:
/mounted_pybind11/include/pybind11/eigen/tensor.h:475:17: warning: ‘operator delete’ called on unallocated object ‘<anonymous>’ [-Wfree-nonheap-object]
475 | delete src;
| ^
/mounted_pybind11/include/pybind11/eigen/../pybind11.h: In function ‘_FUN’:
/mounted_pybind11/include/pybind11/eigen/../pybind11.h:297:75: note: declared here
297 | std::move(args_converter).template call<Return, Guard>(cap->f),
| ^
```
* Disable `bugprone-chained-comparison`: this clang-tidy check is incompatible with the Catch2 `REQUIRE` macro (26 warnings like the one below).
________
Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143)
Target: x86_64-pc-linux-gnu
________
```
/mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:9: warning: chained comparison 'v0 <= v1 == v2' may generate unintended results, use parentheses to specify order of evaluation or a logical operator to separate comparison expressions [bugprone-chained-comparison]
127 | REQUIRE(ret == 42);
| ^
/build/tests/catch/catch.hpp:17670:24: note: expanded from macro 'REQUIRE'
17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/build/tests/catch/catch.hpp:2710:47: note: expanded from macro 'INTERNAL_CATCH_TEST'
2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:9: note: operand 'v0' is here
127 | REQUIRE(ret == 42);
| ^
/build/tests/catch/catch.hpp:17670:24: note: expanded from macro 'REQUIRE'
17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/build/tests/catch/catch.hpp:2710:47: note: expanded from macro 'INTERNAL_CATCH_TEST'
2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
| ^~~~~~~~~~~~~~~~~~~
/mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:17: note: operand 'v1' is here
127 | REQUIRE(ret == 42);
| ^
/build/tests/catch/catch.hpp:17670:90: note: expanded from macro 'REQUIRE'
17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )
| ^~~~~~~~~~~
/build/tests/catch/catch.hpp:2710:70: note: expanded from macro 'INTERNAL_CATCH_TEST'
2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
| ^~~~~~~~~~~
/mounted_pybind11/tests/test_embed/test_interpreter.cpp:127:24: note: operand 'v2' is here
127 | REQUIRE(ret == 42);
| ^
/build/tests/catch/catch.hpp:17670:90: note: expanded from macro 'REQUIRE'
17670 | #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )
| ^~~~~~~~~~~
/build/tests/catch/catch.hpp:2710:70: note: expanded from macro 'INTERNAL_CATCH_TEST'
2710 | catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
| ^~~~~~~~~~~
```
* Add 8 `// NOLINT(bugprone-empty-catch)`
* Resolve clang-tidy `bugprone-multi-level-implicit-pointer-conversion` warnings.
________
Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143)
Target: x86_64-pc-linux-gnu
________
```
pybind11/detail/internals.h:556:53: warning: multilevel pointer conversion from 'internals **' to 'const void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
pybind11/detail/type_caster_base.h:431:20: warning: multilevel pointer conversion from 'void **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
pybind11/numpy.h:904:81: warning: multilevel pointer conversion from '_object *const *' to 'const void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
pybind11/numpy.h:1989:39: warning: multilevel pointer conversion from 'typename vectorize_arg<const double *>::type *' (aka 'const double **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
pybind11/numpy.h:1989:39: warning: multilevel pointer conversion from 'typename vectorize_arg<const VectorizeTestClass *>::type *' (aka 'const VectorizeTestClass **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
pybind11/stl/filesystem.h:75:44: warning: multilevel pointer conversion from 'PyObject **' (aka '_object **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
pybind11/stl/filesystem.h:83:42: warning: multilevel pointer conversion from 'PyObject **' (aka '_object **') to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]
```
* Introduce `PYBIND11_REINTERPRET_CAST_VOID_PTR_IF_NOT_PYPY` to resolve PyPy build errors:
```
In file included from /Users/runner/work/pybind11/pybind11/tests/test_stl.cpp:18:
/Users/runner/work/pybind11/pybind11/include/pybind11/stl/filesystem.h:75:17: error: no matching function for call to 'PyPyUnicode_FSConverter'
if (PyUnicode_FSConverter(buf, reinterpret_cast<void *>(&native)) != 0) {
^~~~~~~~~~~~~~~~~~~~~
/Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:969:31: note: expanded from macro 'PyUnicode_FSConverter'
^~~~~~~~~~~~~~~~~~~~~~~
/Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:970:17: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'struct _object **' for 2nd argument
PyAPI_FUNC(int) PyUnicode_FSConverter(struct _object *arg0, struct _object **arg1);
^
/Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:969:31: note: expanded from macro 'PyUnicode_FSConverter'
^
In file included from /Users/runner/work/pybind11/pybind11/tests/test_stl.cpp:18:
/Users/runner/work/pybind11/pybind11/include/pybind11/stl/filesystem.h:83:17: error: no matching function for call to 'PyPyUnicode_FSDecoder'
if (PyUnicode_FSDecoder(buf, reinterpret_cast<void *>(&native)) != 0) {
^~~~~~~~~~~~~~~~~~~
/Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:971:29: note: expanded from macro 'PyUnicode_FSDecoder'
^~~~~~~~~~~~~~~~~~~~~
/Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:972:17: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'struct _object **' for 2nd argument
PyAPI_FUNC(int) PyUnicode_FSDecoder(struct _object *arg0, struct _object **arg1);
^
/Users/runner/hostedtoolcache/PyPy/3.10.14/x64/include/pypy3.10/pypy_decl.h:971:29: note: expanded from macro 'PyUnicode_FSDecoder'
^
```
* clang-tidy auto-fix
* Fix silly oversight.
* 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).
* 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>
* Use PyMutex instead of std::mutex in free-threaded build.
PyMutex is now part of the public C API as of 3.13.0b3 and generally has
slightly less overhead than std::mutex.
* style: pre-commit fixes
* Fix instance_map_shard padding
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Use manual padding of instance_map_shard.
The alignas(64) specifier requires aligned allocation, which is not
available on macOS when targeting versions before 10.14.
* Add 'see #5200'
* Update include/pybind11/detail/internals.h
* Update include/pybind11/detail/internals.h
---------
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
* Adds support for TypeGuard and TypeIs
* style: pre-commit fixes
---------
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Support free-threaded CPython (PEP 703)
Some additional locking is added in the free-threaded build when
`Py_GIL_DISABLED` is defined:
- Most accesses to internals are protected by a single mutex
- The registered_instances uses a striped lock to improve concurrency
Pybind11 modules can indicate support for running with the GIL disabled
by calling `set_gil_not_used()`.
* refactor: use PYBIND11_MODULE (#11)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* Address code review
* Suppress MSVC warning
* Changes from review
* style: pre-commit fixes
* `py::mod_gil_not_used()` suggestion.
* Update include/pybind11/pybind11.h
---------
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
* Transfer diff from pybind11k fork as-is. New tests are still missing.
* Add `PYBIND11_WARNING_DISABLE_MSVC(4127)` into `PYBIND11_OVERRIDE_IMPL` macro.
* Add test_trampoline_with_pyobject_ptr_return()
* Resolve clang-tidy error: use auto when initializing with a template cast to avoid duplicating the type name [modernize-use-auto,-warnings-as-errors]
* Disabled checking refcount when building with PyPy.
* Clang 3.6, 3.7, 3.9 compatibility.
```
/__w/pybind11/pybind11/tests/test_type_caster_pyobject_ptr.cpp:23:13: error: definition of implicit copy constructor for 'WithPyObjectPtrReturn' is deprecated because it has a user-declared destructor [-Werror,-Wdeprecated]
virtual ~WithPyObjectPtrReturn() = default;
^
```
* Minor clean-up of production code changes.
* Add missing `override` (to resolve clang-tidy error).
* Move PYBIND11_WARNING_POP for a better clang-format outcome.
* Add a pybing function to clear a list.
* Add required error handling.
* Add `/* py-non-const */` as suggested by @Skylion007
---------
Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
* ci: try Python 3.13t
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* fix: support Python 3.13t
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* fix: patch PyPy
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* tests: one more int cast
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* tests: cleanup
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* refactor: use named constant in tests for immortal refcounts
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* docs: move comment about free threaded Python
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
---------
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* ci: add Python 3.13
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* tests: run the gc for 3.13+
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* Revert "tests: run the gc for 3.13+"
This reverts commit fe8a3ce3d1.
* ci: drop macos ARM for now, need pin updates
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* fix: use Python 3.13 API if on 3.13
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
---------
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* Call concat with proper namespace in cast.h
* Apply suggestions from code review
* tests: add test for ADL on concat
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
* fix: fully qualify all usages of concat
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
---------
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
* Transfer bug fixes from #4888 wholesale. Full test coverage for all fixes is still missing.
* Add cmake option(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION) and use in some tests.