knx/include/pybind11/detail/common.h
Thomas Kunze 0db5119fbe Squashed 'examples/knxPython/pybind11/' changes from 59a2ac27..941f45bc
941f45bc chore: prepare for 2.13.1
63020d33 docs: prepare for 2.13.1 (#5203)
dd0e4a0b feat(types): add support for Typing.Callable Special Case (#5202)
3b47b464 fix: use manual padding of instance_map_shard (#5200)
0c69e1eb chore: prepare for 2.13.0 (#5198)
2be85c60 feat(types): adds support for TypeGuard and TypeIs (#5194)
b5ec7c71 ci: release with trusted publisher and attestations (#5196)
26281c79 feat(types): adds support for Never and NoReturn from python Typing (#5193)
183059f9 feat(types): add support for typing.Literal type (#5192)
aebcd704 Add TypeVars / method generics typing (#5167)
9ec64e37 docs: prepare for 2.13.0 (#5187)
a406a62e fix: use `std::addressof` in type_caster_base.h (#5189)
f1a2e03d feat: remove Python 3.6 support (#5177)
5552cbf2 Add Python 3.10, 3.11, 3.12 to win32 job matrix. (#5179)
186df220 docs: building suggestions update (#5168)
baa540ec fix: support free-threaded CPython with GIL disabled (#5148)
1961b96a chore(deps): bump urllib3 from 2.2.1 to 2.2.2 in /docs (#5170)
fdd20d69 chore(deps): bump seanmiddleditch/gha-setup-ninja in the actions group (#5169)
7c4ac91d Add type[T] support to typing.h (#5166)
68405a11 Add `Union` and `Optional` to typing.h (#5165)
ab955f15 Fix refcount bug involving trampoline functions with `PyObject *` return type. (#5156)
35ff42b5 Add a pybind function to clear a list. (#5153)
9b3a2000 fix(cmake): improved cross-compilation support (#5083)
b9794be4 chore(deps): update pre-commit hooks (#5154)
1a0ff405 tests: avoid immortal objects in tests (#5150)
7187894e fix(cmake): old cmake boost bug (#5149)
ae6432b8 fix: Python 3.13t with GIL (#5139)
a5b9e50f fix: added check on iterator end position (#5129)
ce08e370 fix: handle NULL correctly (#5145)
86a64290 chore: some cleanup (#5137)
4d0fcedc fix: support Python 3.13.0b1 (PEP 667 fix) (#5127)
b07fddb2 --- (#5130)
aa98d957 chore(deps): update pre-commit hooks (#5123)
ede061ca chore(deps): bump the actions group with 1 update (#5082)
75025779 chore(deps): bump jinja2 from 3.1.3 to 3.1.4 in /docs (#5122)
c9747570 chore(deps): bump idna from 3.6 to 3.7 in /docs (#5121)
6497b3f2 docs(numpy): drop duplicated ndim (#5119)
a9256a6d chore: docs and nox bump (#5071)
f3984794 ci: macos-latest is changing to macos-14 ARM runners (#5109)
19a6b9f4 Fix typo in changelog date (#5096)
f33f6afb chore(deps): update pre-commit hooks (#5084)
7f2214bc chore: bump cmake to 3.29 (#5075)
7af193e7 chore: get back to work
b91b584d docs: remove extra space
3e9dfa28 docs: a few missed changes for 2.12 (#5074)
6b5674f3 chore: prepare 2.12.0 (#5070)
67c9c568 fix: fully qualify usages of concat to protect against ADL (#4955)
0efff79f Bug fixes: Add missing `handle_type_name` specializations. (#5073)
705efcce feat: make `numpy.h` compatible with both NumPy 1.x and 2.x (#5050)
e0f2c715 tests: hide warning on clang (#5069)
65370f33 Create handle_type_name specialization to type-hint variable length tuples (#5051)
ddb8b67a fix(cmake): allow forcing old FindPython (#5042)
ec73bdaf ci: skipping test for Windows Clang failure (#5062)
8b48ff87 chore(deps): bump the actions group with 3 updates (#5024)
0518bf9f ci: ignore actions/checkout until v5 comes out
e84d446d ci: Ignore v1 updates for checkout (#5023)
416f7a44 chore(deps): update pre-commit hooks (#5018)
768cebe1 doc: add litgen to the automatic generators list (compiling.rst) (#5012)
869cc1ff install mingw-w64-${{matrix.env}}-python-scipy only for mingw64 (#5006)
39e65e10 ci: group dependabot updates (#4986)
31b7e140 bugfix: removing typing and duplicate ``class_`` for KeysView/ValuesView/ItemsView. Fix #4529 (#4985)
aec6cc54 fix(cmake): skip empty PYBIND11_PYTHON_EXECUTABLE_LAST for the first cmake run (#4856)
f29def9e chore(deps): update pre-commit hooks (#4994)
b583336c chore(deps): bump ilammy/msvc-dev-cmd from 1.12.1 to 1.13.0 (#4995)
976fea05 Fix Clazy warnings (#4988)
eeac2f45 chore(deps): bump actions/upload-artifact from 3 to 4 (#4975)
e8a43ea9 chore(deps): bump actions/download-artifact from 3 to 4 (#4976)
dc477fac fix: Use PyObject_VisitManagedDict() of Python 3.13 (#4973)
daea1130 fix(cmake): upgrade maximum supported CMake version to 3.27 (#4786)
7d538a42 fix: make_static_property_type() (#4971)
68322895 chore(deps): bump actions/setup-python from 4 to 5 (#4965)
c1e06f5b chore(deps): update pre-commit hooks (#4963)
a67d7865 fix(stl_bind): Enable `bind_map` with `using` declarations. (#4952)
4bb6163b chore(deps): bump deadsnakes/action from 3.0.1 to 3.1.0 (#4951)
dc9b3959 pybind11.pc: use pcfiledir for relative destinations (#4830)
9591cfb0 fix(cmake): findpython issues and 3.12 support for pybind11_find_import (#4941)
6831666f ci: add more versions of numpy/scipy/pypy (#4714)
6cf90e72 fix(cmake): avoid really slow compile on emscripten (#4642)
b389ae77 chore: update changelog script for categories (#4942)
e250155a Fix a long-standing bug in the handling of Python multiple inheritance (#4762)
2c35fde3 Fix refcount bug introduced with PR #4916. (#4927)
c758b81f chore: move to ruff-format (#4912)
0a974fed chore(deps): update pre-commit hooks (#4923)
f2606930 Use newer PyCode API and other fixes (#4916)
31b0a5d9 fix doc typo
76b7f536 Python_ADDITIONAL_VERSIONS: 3.12 (#4909)
a18c10f6 fix(cmake): make library component optional (#4805)
3aece819 chore: update hooks and Ruff config (#4904)
1e28599e fix: Add missing spaces to error string (#4906)
fa27d2fd Adapt to changed function name in Python 3.13 (#4902)
bf88e29c Bug fix: Replace bare `static exception<T>` with `gil_safe_call_once_and_store`. (#4897)
3414c56b Workaround NVCC parse failure in `cast_op` (#4893)
7969049d Comment out failing job, with link to #4889 (#4890)
74439a64 feature: Use typed iterators in `make_*iterator` (#4876)
0cbd92ba Update pytest to version 7.2.0 (which removes their dependency on py) (#4880)
0e2c3e5d Add pybind11/gil_safe_call_once.h (to fix deadlocks in pybind11/numpy.h) (#4877)
6c772085 chore(deps): bump seanmiddleditch/gha-setup-ninja from 3 to 4 (#4875)
2b2e4ca4 chore(deps): update pre-commit hooks (#4868)
dd64df73 MAINT: Remove np.int_ (#4867)
0a756c0b MAINT: Include `numpy._core` imports (#4857)
f468b070 Add 2 missing `throw error_already_set();` (#4863)
7e5edbc9 Avoid copy in iteration by using const auto & (#4861)
5891867e fix(cmake): support DEBUG_POSTFIX correctly (#4761)
4fb111bd fix(cmake): correctly detect FindPython policy and better warning (#4806)
d06d5369 Fix small bug introduced with PR #4735 (#4845)
8c7b8dd0 fix: Missing typed variants of `iterator` and `iterable` (#4832)
b4573674 Update render for buffer sequence and handle  (#4831)
c9149d99 fix: Use lowercase builtin collection names (#4833)
c8360593 feature: Support move-only iterators in `py::make_*iterator` (#4834)
4a2f7e46 chore(deps): bump actions/checkout from 1 to 4 (#4836)
467fe27b chore(deps): update pre-commit hooks (#4838)
c9638a19 Help Coverty avoid generating a false positive. (#4817)
db412e6e fix: Render `py::function` as `Callable` (#4829)
e705fb5f Fix enum's `__str__` docstring (#4827)
1adac5a5 `PYBIND11_INTERNALS_VERSION` bump for MSVC, piggy-backed on PR #4779. See comments there. (#4819)
76b88581 fix: Different MSVC versions may be ABI incompatible, guard with _MSC_VER (#2898) (#4779)
b9359cea Remove newlines from docstring signature (#4735)
f47ff328 Fix grammar in functions.rst (#4791)
80bcd21f [ci skip] Adopt nanobind config. (#4792)
add281a2 Migrate to readthedocs configuration file v2¶ (#4789)
9039e6ac chore: use 2x faster black mirror (#4784)
4bf60c60 Disable strip when build type is unset (#4454) (#4780)
690a115d Add `py::set_error()`, use in updated `py::exception<>` documentation (#4772)
824dc27a CI: Reenable an NVHPC Test (#4764)
f8703154 Provide better type hints for a variety of generic types (#4259)
9ad7e827 docs: Remove upper bound on pybind11 in example pyproject.toml for setuptools (#4774)
413e6328 chore(deps): update pre-commit hooks (#4770)
17b61430 clang 17 compatibility fixes (#4767)
f3e06028 Add command to check for vX.Y.Z tag vs pybind11/_version.py consistency. (#4757)
8d08dc64 Copy v2.11.1 changelog section as released. (#4755)
99131a85 Provide `PYBIND11_NO_ASSERT_GIL_HELD_INCREF_DECREF` as an option (#4753)
ec1b57c5 Disable `PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF` generally for PyPy (not just PyPy Windows). (#4751)
0620d716 Update README.rst - Add missing comma in the list of acknowlegements (#4750)
e85696e8 Post release version bump (#4747)
1a917f18 docs: preparation for v2.11.0 release (#4744)
b33d06f6 bugfix: fixes a test suite bug in the __new__ example (#4698)
2e5f5c4c fix: support CMake 3.27, drop 3.4 (#4719)
6d22dba8 Warning on comparing wrapper enums with is (#4732)
b2732c6e chore(deps): bump pypa/gh-action-pypi-publish from 1.8.6 to 1.8.7 (#4718)
47dc0c4b chore(deps): update pre-commit hooks (#4727)
d462dd91 chore(deps): bump scipy from 1.8.0 to 1.10.0 in /tests (#4731)
782b6281 Drop PyPy 3.7 from GitHub Actions (ci.yml) (#4728)
5ccb9e41 chore: ruff moved to astral-sh (#4726)
2fb3d7cb Trivial refactoring to make the capsule API more user friendly. (#4720)
e10da79b Undo ci.yml gcc10 workaround after docker-library/gcc#95 was resolved. (#4717)
bc1bcf7c chore: 3.12 + cleanup (#4713)
84932280 Systematically add `PIP_BREAK_SYSTEM_PACKAGES` to all .yml files from which pip is called. (#4705)
86f60a0c pre-commit markdown-it-py<3 (for Python 3.7 compatibility) (#4704)
0e43fcc7 Python 3.12b2 testing (#4695)
c679a920 chore(deps): bump deadsnakes/action from 3.0.0 to 3.0.1 (#4687)
3617f355 chore(deps): update pre-commit hooks (#4689)
29487dee Disable 🐍 3 • CentOS7 / PGI 22.9 • x64 (#4691)
d0232b11 Use annotated for array (#4679)
8e1f9d5c Add `format_descriptor<>` & `npy_format_descriptor<>` `PyObject *` specializations. (#4674)
6e6bcca5 Create s Security Policy (#4671)
ce9bbc0a Python 3.11+: Add `__notes__` to `error_already_set::what()` output. (#4678)
19816f0d chore: update changelog, with target date for v2.11.0 release (#4677)
d72ffb44 ci: set minimal permissions to github workflows (#4665)
cca4c51c Update errors in string "Explicit conversions" docs (#4658)
e9b961d9 Elide to-python conversion of setter return values (#4621)
90312a6e Add `type_caster<PyObject>` (#4601)
f7016546 Introduce recursive_container_traits (#4623)
b3e88ecf chore(deps): update pre-commit hooks (#4648)
dff75a62 chore(deps): bump pypa/gh-action-pypi-publish from 1.8.5 to 1.8.6 (#4650)
da919262 fix: remove -stdlib=libc++ from setup helpers, not needed on modern Pythons (#4639)
956390a8 fix(cmake): only define lto if CMAKE's IPO setting is unset (#4643)
5e946c2f chore(deps): update pre-commit hooks (#4605)
3f366ff8 Remove stray comment. (Oversight in PR #4631. Noticed by chance.) (#4641)
6de6191a Use `std::hash<std::type_index>`, `std::equal_to<std::type_index>` everywhere **except when libc++ is in use** (#4319)
ff7f5dfc 1. Fully test unstable ABI (#4635)
07725c28 Introduce `pybind11::detail::is_move_constructible` (#4631)
071f35ab chore(deps): bump jwlawson/actions-setup-cmake from 1.13 to 1.14 (#4632)
ed466da5 chore(deps): bump pypa/gh-action-pypi-publish from 1.8.4 to 1.8.5 (#4604)
7ab88d2e chore(deps): bump pypa/gh-action-pypi-publish from 1.8.3 to 1.8.4 (#4602)
4ce05175 ci: Python 3.12 optional test job (#4575)
654fe926 Introduce `get_python_state_dict()` for Python 3.12 compatibility. (#4570)
1e8b52a9 bugfix: allow noexcept lambdas in C++17. Fix #4565 (#4593)
66f12df0 chore: make #4587 use proper cpp17 feature macro (#4592)
5bbcba54 use C++17 syntax to get rid of recursive template instantiations for concatenating type signatures (#4587)
286873ec chore(deps): bump pypa/gh-action-pypi-publish from 1.8.1 to 1.8.3 (#4584)
cf7d2e6f Change `always_forkserver_on_unix()` to `use_multiprocessing_forkserver_on_linux()` (#4577)
c4c15d4b docs: changelog for 2.10.4 (#4532)
04ef4e42 chore(deps): bump pypa/gh-action-pypi-publish from 1.6.4 to 1.8.1 (#4576)
442261da Remove test code that does not exercise anything in pybind11, but breaks between Python 3.12alpha3 (still working) and 3.12alpha6 (broken): (#4559)
cbb876cc chore(deps): update pre-commit hooks (#4552)
3cc7e425 add --version option to pybind11-config (#4526)
438034c5 chore: move to Ruff and add rules (#4483)
a19daeac Inconsistent comments between 2 templates of `unchecked()`. (#4519)
68211d41 fix: nicer stack level for warning (#4516)
6a5e6007 Make warning suppressions MINGW-specific again. (#4515)
d1956eab Appease new flake8 B028 error: (#4513)
08a4a47a Revert "Go back to CMake 3.25.2 (#4496)" (#4503)
535f81a1 fix: tests dir has started to show up in packaging (#4510)
8dcced29 Always display python type information in cast errors (#4463)
531144dd Replace "whitelist" with "allowlist" (#4506)
b8f28551 Go back to CMake 3.25.2 (#4496)
f8713ec4 Revert "bugfix: Keep registered types until after Py_Finalize(). Fix #4459 (#4486)" (#4501)
8a90b367 chore(deps): update pre-commit hooks (#4495)
b2c1978c bugfix: Keep registered types until after Py_Finalize(). Fix #4459 (#4486)
9ef65cee chore(deps): bump ilammy/msvc-dev-cmd from 1.12.0 to 1.12.1 (#4493)
08a89fac bugfix: delete proper ctors in gil.h (#4490)
3efe9d4c chore: update to black 23 (#4482)
44e93682 Use PyConfig_InitPythonConfig instead of PyConfig_InitIsolatedConfig (#4473)
c71e3af7 Bump isort version to 5.12.0 (#4480)
a500f439 Resolve new flake8 error (#4462)
c709d2a8 Make sure to properly untrack gc objects before freeing them (#4461)
e53d58af Ensure `import pybind11_tests` traceback is shown. (#4455)
d821788b Add clang15 C++20 job (#4443)
a34596bf chore: back to work
b2d7ad72 chore: prepare for 2.10.3 (#4437)
769fd3b8 chore(deps): update pre-commit hooks (#4439)
e3e24f3f fix: issuses detected by static analyzer (#4440)
6da268a5 ci: remove clang 10 C++20 (it broke recently) (#4438)
f12e098f Fix `detail::obj_class_name()` to work correctly for meta classes. (#4436)
60f02f5f fix: improve the error reporting for inc_ref GIL failures (#4427)
70af9873 docs: fixed typo in spelling of first (#4428)
7f23e9f3 chore: update clang-tidy to 15 (#4387)
0694ec6a chore: preapre for 2.10.2 release (#4414)
3fd1520d docs: changelog for next version (#4413)
ee4b9f5d Fix ODR violations in our Eigen Tensor tests (#4412)
a97c4d22 fix(cmake): support Windows ARM cross-compilation (#4406)
09db6445 IPO/LTO support for ICX (IntelLLVM) compiler (#4402)
ece1206b ci: set `env: VERBOSE: 1` (#4405)
89c3561d Fix multi-context new Python linking mode (#4401)
ff42f525 Systematically add `-DCMAKE_VERBOSE_MAKEFILE=ON` to obtain full command lines related to `-Wodr` (#4398)
9727dcda chore: future safe bugbear opinionated warnings (#4393)
663b86c2 Add flake8 `B905` to `extend-ignore` in setup.cfg (#4391)
9db98801 Correct class names for KeysView, ValuesView and ItemsView in bind_map (#4353)
00126859 Add option for enable/disable enum members in docstring. (#2768)
65374c8e `pybind11::handle` `inc_ref()` & `dec_ref()` `PyGILState_Check()` **excluding** `nullptr` (#4246)
65cc9d2a chore(deps): bump pypa/gh-action-pypi-publish from 1.6.1 to 1.6.4 (#4389)
4768a6f8 chore(deps): update pre-commit hooks (#4386)
a672de7c Fix source comment typo (#4388)
a6e75e4d chore(deps): bump pypa/gh-action-pypi-publish from 1.5.2 to 1.6.1 (#4384)
6a1023e3 chore(deps): bump deadsnakes/action from 2.1.1 to 3.0.0 (#4383)
5b55f8fe Replace `ubuntu-latest` with `ubuntu-22.04` (#4382)
e133c33d chore: Convert direct multiprocessing.set_start_method("forkserver") call to a pytest fixture. (#4377)
358ba459 Fix test added with PR #4330 (#4372)
b14d58b6 chore(deps): bump pypa/gh-action-pypi-publish from 1.5.1 to 1.5.2 (#4370)
88699849 scoped_interpreter. overloaded constructor: PyConfig param (#4330)
06003e82 Introduce a new style of warning suppression based on push/pop (#4285)
9907bedc fix(.github): fix bug-report issue template (#4363)
9c18a74e Use `multiprocessing` `start_method` `"forkserver"` (#4306)
48949222 Use `PyEval_InitThreads()` as intended (#4350)
296615ad Add macos_brew_install_llvm to ci.yml (#4326)
88b019a8 fix pybind11Tools.cmake typo causing Unknown arguments (#4327)
1f04cc70 Add windows_clang to ci.yml (#4323)
ee2b5226 Fix functional.h bug + introduce test to verify that it is fixed (#4254)
0176632e chore: sync blacken-docs hook with black (#4304)
2441d25b chore(deps): update pre-commit hooks (#4302)
252ed8fb docs: prepare for 2.10.1 release (#4279)
b1bd7f26 fix: define (non-empty) `PYBIND11_EXPORT_EXCEPTION` only under macOS. (#4298)
3a2c96bd fix: unicode surrogate character in Python exception message. (#4297)
5bc0943e Ensure config, build, toolchain, spelling, etc. issues are not masked. (#4255)
b07d08f6 Add `PYBIND11_SIMPLE_GIL_MANAGEMENT` option (cmake, C++ define) (#4216)
b07223fa fix: improve bytes to str decoding error handling (#4294)
fcb5554d ci: move to final release of 3.11 (#4286)
07a61aa1 Fix char8_t support (#4278)
d1c31e9a chore: improve issue template (#4276)
4fe905d4 fix: add flag for overriding classic Python search values (#4195)
8ea75ab4 Fix casts to void* (#4275)
17c1e27b fix: Revert pfect args make iterator (#4234)
91cfb770 Revert "feat: add entrypoint for cmake modules dir" (#4270)
2ce76f78 Cleanup casters to release none() to avoid ref counting (#4269)
36ccb08b docs: update changelog (#4265)
128d988e ci: fix labeler
1d4a65e2 feat: add entrypoint for cmake modules dir (#4258)
c3854682 ci(fix): don't label weekly dep updates & ci fixes (#4264)
17c68091 ci: update PGI build (old one no longer signed) (#4260)
fab1eebe First draft of Eigen::Tensor support (#4201)
b926396b bugfix: py contains raises errors when appropiate (#4209)
5b5547bc chore(deps): bump ilammy/msvc-dev-cmd from 1.11.0 to 1.12.0 (#4242)
964c4997 Minor `py::capsule` cleanup. No functional change. (#4238)
8781daf6 chore: Optimize iterator advance() call (#4237)
0927c4d1 chore: Improve PyCapsule exception handling (#4232)
ff7b6971 chore(deps): bump jwlawson/actions-setup-cmake from 1.12 to 1.13 (#4233)
da104a9e Reproducer and fix for issue encountered in smart_holder update. (#4228)
7c6f2f80 fix: PyCapsule_GetDestructor is allowed to return a nullptr destructor (#4221)
4a421562 test_eigen.py test_nonunit_stride_to_python bug fix (ASAN failure) (#4217)
6cb21474 fix: NVCC 11.4.0 - 11.8.0 host bug workaround (#4220)
864ed112 chore: steal arg_v.value from copied arg in unpacking_collector (#4219)
8275b769 ci: update pre-commit schedule (#4212)
600d6976 [pre-commit.ci] pre-commit autoupdate (#4210)
c78dfe69 bugfix: Add error checking to list append and insert (#4208)
da8c730a [pre-commit.ci] pre-commit autoupdate (#4197)
5aa0fad5 perf: call reserve method in set and map casters (#4194)
f743bdf8 Avoid local_internals destruction (#4192)
95d0e71a test C++14 on MSVC (#4191)
424ac4fe fix: Windows compiler, missing object initializer (#4188)
d02f219f [pre-commit.ci] pre-commit autoupdate (#4189)
9c04c7b0 chore: Delete copy ctor/assign for GIL RAIIs (#4183)
1874f8fa Clarify GIL documentation (#4057)
8524b20c fix: Python-3.12 compatibility (#4168)
64f72818 [pre-commit.ci] pre-commit autoupdate (#4178)
aa8f8baa [pre-commit.ci] pre-commit autoupdate (#4171)
8756f16e [pre-commit.ci] pre-commit autoupdate (#4151)
283f10dc chore(deps): bump ilammy/msvc-dev-cmd from 1.10.0 to 1.11.0 (#4161)
0b4c1bc2 test: ConstructorStats newline (PyPy) (#4167)
fac23b6f `error_fetch_and_normalize`: PyPy 7.3.10+ does not need the PR #4079 workaround anymore. (#4154)
a48ec3e8 Words matter updates (#4155)
68e6fdaa embed.h Python 3.11 `config.use_environment=1` + `PYTHONPATH` test (#4119)
81f35d29 chore: Mark detail:forward_like as constexpr (#4147)
2d59b43c Qualify detail::forward_like to avoid conflict. (#4136)
b884b9dc chore: Add pytests for constructing pytypes from iterable (#4138)
bbb89da1 fix(cmake): support vcpkg, try 2 (#4123)
5bdd3d59 feat(cmake): add installation support for pkg-config dependency detection (#4077)
14c84654 [pre-commit.ci] pre-commit autoupdate (#4126)
6abb7de6 chore: Use PyObject_GenericGetDict and PyObject_GenericSetDict functions (#4106)
8a4bca82 fix(cmake): use case-insensitive CMAKE_BUILD_TYPE comparisons (#4078)
29f4940c Fix copy-paste oversight (#4118)
ba5ccd84 [pre-commit.ci] pre-commit autoupdate (#4104)
88a1bb92 chore: remove unnecessary temporary std::pair (#4103)
f8e8403b Open pybind11 namespace with consistent visility. (#4098)
aa953710 [pre-commit.ci] pre-commit autoupdate (#4090)
36655302 Add `-DPYBIND11_WERROR=ON` to mingw cmake commands (#4073)
1e3400b6 chore(deps): bump pypa/gh-action-pypi-publish from 1.5.0 to 1.5.1 (#4091)
d70f54b0 docs: Missing semicolons (#4094)
b07975f4 Fix missing undef in pytypes (#4087)
9a296373 More systematic gcc & clang coverage (#4083)
cb35a3c1 For PyPy only, re-enable old behavior (runs the risk of masking bugs) (#4079)
42b54507 chore: use explicit defaulting in pyobject macros (#4017)
f47f1edf Fix #3812 and fix const of inplace assignments (#4065)
ef7d971e [pre-commit.ci] pre-commit autoupdate (#4082)
59f03ee3 tests: include pypy3.9 in nox if present
5116a629 fix(spelling): PYTHON_VERSIONS
8d82f298 chore: back to work
aa304c9c chore: preapre for 2.10.0 release (#4068)
87f64c43 docs: update changelog for 2.10.0 (#4066)
1d811910 Disable implicit conversion of `0` to `pybind11::handle`. (#4008)
bc9315fe chore: optimize sparse matrix casting with python tuple (#4064)
6b60d97d docs: use Furo (#3109)
7c3a0317 chore: bump clang-tidy to 13 (#3997)
023b3f32 Undo accidental one-line change under PR #3913 (#4060)
790241bc [pre-commit.ci] pre-commit autoupdate (#4058)
f9f00495 Properly visit self in >=3.9 traverse (#4051)
432bc5cf Add `std::string clean_type_id(const char *typeid_name)` overload (in namespace detail). (#4049)
85bc0884 Report `C++ Info:` via `pytest_report_header()` (#4046)
cd08869d PYBIND11_NAMESPACE consistency fixes. (#4043)
0ab1fcfb docs: update changelog (#4042)
2af163d9 Fix: 3.11 beta support (#3923)
c42e3ab7 [pre-commit.ci] pre-commit autoupdate (#4041)
bc1f9f9b chore(deps): bump actions/setup-python from 3 to 4 (#3999)
5a3a1e34 chore: simpler dependabot (#4035)
479e9a50 Fix arrays with zero-size dimensions (#4038)
374a5b00 [docs] Fix "Enumerations and internal types" example (#4034)
dd3bf7fd [pre-commit.ci] pre-commit autoupdate (#4030)
c3e9173f ci: use almalinux instead of centos, add 9 (#4020)
2ad974c9 [pre-commit.ci] pre-commit autoupdate (#4021)
0964a909 Add a missing std::move in numpy.h (#4005)
21f0e72b [pre-commit.ci] pre-commit autoupdate (#4003)
0e956a2e chore(deps): bump pre-commit/action from 2.0.3 to 3.0.0 (#3992)
e2dcd954 chore: optimize dictionary access in strip_padding numpy (#3994)
918892b9 Make dtype::num() return type consistent with other functions (#3995)
c5fa3436 [pre-commit.ci] pre-commit autoupdate (#3951)
554c0453 enable two new clang-tidy checks (#3988)
42a41bf3 remove useless ctor (#3989)
a05bc3d2 error_already_set::what() is now constructed lazily (#1895)
58802de4 perf: Add object rvalue overload for accessors. Enables reference stealing (#3970)
9f7b3f73 addl unit tests for PR #3970 (#3977)
b24c5ed2 Replace "Unknown internal error occurred" with a more helpful message. (#3982)
de4ba92c Add `error_scope` to `detail::get_internals()` (#3981)
8da58da5 chore: perfectly forward all make_iterator args (#3980)
748ae227 Add missing error handling to `module_::def_submodule` (#3973)
68f80105 chore: add err guard to capsule destructor and add a move to iostream (#3958)
8d14e666 fix: avoid `catch (...)` for expected `import numpy` failures (#3974)
2c549eb7 Move `PyErr_NormalizeException()` up a few lines (#3971)
2d4a20c8 chore: add missing moves for buffer_func and staticmethod in pybind11.h (#3969)
4624e8e1 Don't return pointers to static objects with return_value_policy::take_ownership. (#3946)
c42414db (perf): use a rvalue cast in func_wrapper (#3966)
918d4481 fix(cmake): support cross-compiles with classic Python (#3959)
1e4bd22b fix(cmake): support release and debug at the same time (#3948)
a8b3ff30 chore: add a couple of moves in pybind11.h (#3941)
dff6fa05 fix(cmake): avoid issue with NVCC + Windows (#3947)
1a7b1298 ci: fix cuda issue & MSVC spurious warning (#3950)
72eea20a Fix py::cast from pytype rvalue to pytype (#3949)
48c7be4a Undoing previous accidental commit. Sorry I forgot to git branch.
5621ab85 Do we have a unit test for the traceback code in error_string()?
ad146b2a [pre-commit.ci] pre-commit autoupdate (#3933)
2e331308 chore: remove unused include from stl.h (#3928)
68a0b2df Add anyset & frozenset, enable copying (cast) to std::set (#3901)
9a16e55a [pre-commit.ci] pre-commit autoupdate (#3903)
f306012b fix: file extension on windows with cp36 and cp37 (#3919)
bdc7dd8c chore: update NVIDIA-PGI CI workflow (#3922)
287e4f23 Test pickling a simple callable (does not work). (#3906)
f0b9f755 Replace error printing code gated by NDEBUG with a new flag: PYBIND11_DETAILED_ERROR_MESSAGES  (#3913)
75007dda chore: rule of 3 for strdup guard (#3905)
9bc27044 Add tests for cast from tuple to sequence containers (#3900)
03252067 chore(deps): bump actions/upload-artifact from 2 to 3 (#3899)
be4a634c chore(deps): bump actions/checkout from 2 to 3 (#3896)
82455a41 Minor opt to cache tuple casting (#3894)
2a7cb008 chore(deps): bump actions/download-artifact from 2 to 3 (#3897)
e79293cf chore(deps): bump actions/cache from 2 to 3 (#3898)
b58b772b chore(deps): bump actions/setup-python from 2 to 3 (#3895)
1a8603e4 ci: dependabot major versions for official actions (#3888)
e8e229fa [pre-commit.ci] pre-commit autoupdate (#3885)
1c636f4d chore: Change numpy dtype from_args call sig to const ref (#3878)
fbcde3f0 chore: enable clang-tidy check modernize-use-nullptr (#3881)
30716c67 Also add error_scope assignment operator to complete the rule-of-3 (follow-on to PR #3870). (#3872)
3829b762 chore: simplify numpy dtype ctor (#3869)
45164c1f Added deleted copy constructor for error_scope to comply with rule of 3. (#3870)
ba7a0fac Expand dtype accessors (#3868)
fa98804a Adds set_name method of pybind11::capsule class (#3866)
ad0de0f5 [pre-commit.ci] pre-commit autoupdate (#3863)
9969f3b5 ci: drop win2016 (#3854)
088ad4f2 Cleanup cast_safe<void> specialization (#3861)
e3aa215b Add perfect forwarding to make_iterator calls (#3860)
1b27b744 chore: Make stl_bind take slice as const_ref (#3852)
ab59f45d Prefer make_caster<T> to type_caster<T> (#3859)
c4e29528 perf: Add more moves and optimize (#3845)
f2f0c690 [pre-commit.ci] pre-commit autoupdate (#3848)
b3ebd11d feature: support compilers that use std::experimental::filesystem  (#3840)
65ec5de5 chore: bump changelog for 2.9.2 (#3834)
42d8593a style: bump black (#3831)
3a183d4b fix: improve str exceptions and consistency with python (#3826)
7742be02 Revert "ci: test pypy 3.9" (#3828)
461937d3 ci: test pypy 3.9 (#3789)
146695a9 fix: better exception and error handling for capsules (#3825)
47079b9e (perf): Add missing move in sp matrix caster and microopt char concats (#3823)
b22ee64c Add type_caster<std::monostate> (#3818)
67089cd3 [pre-commit.ci] pre-commit autoupdate (#3817)
b3a43d13 Use rvalue reference for std::variant cast_op<T> (#3811)
8b1944d3 Remove idioms in code comments (#3809)
a7e7a6e8 Docs: No Strip in Debug (#3779)
f8a532a7 [pre-commit.ci] pre-commit autoupdate (#3800)
91a6e129 PYBIND11_OBJECT_CVT should use namespace for error_already_set() (#3797)
d75b3536 CI: MSVC Debug Build (#3784)
2dd52544 fix: missing move in eval.h (#3775)
af08a95b fix: potential memory leak in pypy (#3774)
42a8e312 Improve Python 3.11 support (#3694)
465b2e0b Use sysconfig in Python >= 3.10 (#3764)
5f9b090a ci: fix PyPy (#3768)
061c6177 [pre-commit.ci] pre-commit autoupdate (#3765)
f495dfc4 cast: Qualify symbol usage in PYBIND11_TYPE_CASTER (#3758)
da15bb20 Cast bytearray to string  (#3707)
91f597be [pre-commit.ci] pre-commit autoupdate (#3754)
9aa676d3 fix: clear local internals after finalizing interpreter #2101 (#3744)
44596bc4 Fix exception handling when pybind11::weakref() fails. (#3739)
009ffc33 MSVC C++20 test_eigen (#3741)
4b42c371 style: pylint (#3720)
c14170a7 Removing `// clang-format off` - `on` directives from test_pickling.cpp (#3738)
0986af61 [pre-commit.ci] pre-commit autoupdate (#3672)
a25d40c7 tests: use 'build' in tests instead of running setup.py (#3734)
a97e9d8c Dropping MSVC 2015 (#3722)
44156477 Adding MSVC 2022 C++20 GitHub Action (#3732)
522c59ce chore: drop Python 3.5 (#3719)
1a432b42 docs: Correct minor typos (#3721)
6493f496 Python 2 removal part 1: tests (C++ code is intentionally ~untouched) (#3688)
46dcd9bc fix: minor CMake warning fix for unused variable (#3718)
ec24786e Fully-automatic clang-format with include reordering (#3713)
e96221be Final manual curation in preparation for global `clang-format`ing (#3712)
d6c66d25 chore(clang-tidy): Add clang-tidy rules: prefer-member-initializer and optin.performance.Padding (#3716)
dc9803ce Add missing clang-tidy fixes (#3715)
7f975816 chore(clang-tidy): Enable static downcast and decl naming check (#3709)
abc38690 Manually applying two clang-format changes that need fix-ups for clang-tidy. (#3705)
7769e771 clang-tidy readability-qualified-auto (#3702)
b4f5350d chore: use member initializer (#3704)
ddbc74c6 Adding .clang-tidy readability-braces-around-statements option.
8581584e Manual fix-ups in preparation for clang-tidy readability-braces-around-statements.
af056b65 fix: __index__ on Enum should always be present. (#3700)
1b841883 Minor change to improve readability (#3695)
96b943be tests: update catch to 2.13.5 to fix glibc 2.34 failures (#3679)
94a94872 docs: fix imported target name (#3689)
36813cfa chore: back to work
1d3b04e8 test: Strip whitespace when comparing numpy dtypes for 1.22 compat (#3682)
ffa34686 chore: bump to 2.9.1
3899dc65 Documenting missing unit test coverage. (#3673)
0f6ad910 docs: update changelog for 2.9.1 (#3670)
21e10945 ci: move centos 8 to stream (#3675)
ce18721d Ensure TypeError use raise_from for C++->Python overload res. (#3671)
978617f6 fix issue 3668 by removing bool casts in numpy.h (#3669)
3a8d9230 Fix caster optimization regression introduced in #3650 (#3659)
bf7e5f92 fix(setup): support overriding CMake args (#3577)
dc4717ba fix: module extension detection for python 3.10 (#3663)
07103d65 Remove extra semicolon (#3666)
17792884 Document how to bind templates (#3665)
ec81e8e7 Propagate py::multiple_inheritance to all children (#3650)
bcb6d63c fix msys ci python issue (#3651)
dedda228 Fix a typo in class.rst (#3648)
9ec1128c Fix typo in doc (#3628)
3a1eddab chore(deps): bump jwlawson/actions-setup-cmake from 1.11 to 1.12 (#3625)
51948559 Render `py::bool_` and `py::float_` without `_` in docstrings (#3622)
7e7c5585 Fixing obvious minor typo (missing `D` in `-DOWNLOAD_EIGEN=ON`).
d2ec8367 Add support for nested C++11 exceptions (#3608)
f8d4aa47 Add clang-tidy readability checks for sus args (#3611)
21911e12 A way to register additional test targets and support .py only tests. (#3590)
d434b5f3 (chore): Remove deprecated c-headers (#3610)
f5888108 Replacing ICC C++14 with C++17 (#3570)
ef070f77 Add additional info to TypeError when C++->Python casting fails (#3605)
b66328b0 [pre-commit.ci] pre-commit autoupdate (#3609)
fb9a222d chore(deps): bump pypa/gh-action-pypi-publish from 1.4.2 to 1.5.0 (#3606)
2cd32e5d [pre-commit.ci] pre-commit autoupdate (#3589)
1bbaeb34 Adding dedicated test_const_name. (#3578)
9b4f71d1 docs: remove duplication in changelog for 2.9.0
93716147 Merge branch 'master' into stable
45f792ef chore: prepare for 2.9
89769e6e [pre-commit.ci] pre-commit autoupdate (#3574)
cb302305 fix: restore full range of _ functions (#3571)
d4b9f347 docs: update changelog (#3556)
e50f841d fix: do not use LTS on mips64 and ppc64le (#3557)
39fbc799 fix: avoiding usage of _ if already defined (#3423)
b3d9c354 vi: replacing currently broken ICC Latest C++17 with C++14. (#3551)
d0406c74 [pre-commit.ci] pre-commit autoupdate (#3563)
75168113 fix(setup_helpers): ensure ThreadPool is closed (#3548)
59aa9986 [pre-commit.ci] pre-commit autoupdate (#3533)
a224d0cc fix: vs2022 compilation, issue #3477 (#3497)
b4939fcb Expand std::string_view support to str, bytes, memoryview (#3521)
cd176cee chore: update changelog with recent PRs (#3524)
70a58c57 Replace usage of deprecated Eigen class MappedSparseMatrix. (#3499)
fe65693c [pre-commit.ci] pre-commit autoupdate (#3500)
5d067e87 fix: remove redundant copy operation to fix warning (#3486)
9281faf4 Fixing `stict` vs `strict` typo. (#3493)
673b4be3 Fix py::kw_only when used before the first arg of a method (#3488)
56322daf fixed include for filesystem::path (#3482)
15f8d7c1 fix(build): cleaner CMake printouts & IDE folders (#3479)
ff51fcb7 docs: fix broken link (again)
72282f75 ci: support development releases of Python (#3419)
1eb59963 Removed duplicated word in docs/advanced/exceptions.rst (#3476)
d2b21316 cmake: report version type in the version string (#3472)
9422d98f [pre-commit.ci] pre-commit autoupdate (#3473)
afdc09de [master] Wrong caching of overrides  (#3465)
270b11d5 Revert "style: drop pycln" (#3466)
e450eb62 Removed duplicated word in docs/advanced/cast/eigen.rst (#3458)
aebd21b5 docs: rework CI a bit, more modern skipping (#3424)
b11ff912 fix(setup =_helpers): don't add -g0 CFLAGS sets -g (#3436)
b322018e [pre-commit.ci] pre-commit autoupdate (#3449)
01f938e7 fix: add missing std::forward calls (#3443)
a61e354e docs: touch up manual release suggestion (#3422)
6de30d31 [pre-commit.ci] pre-commit autoupdate (#3432)
dd2d1272 Correct "which" versus "that" error. (#3430)
e7c9753f feat: allow kw-only args after a py::args (#3402)
a80b2237 chore: get back to work after 2.8.1
acae9301 Merge branch 'master' into stable
f7b49961 [skip ci] Tweaks in preparation for the 2.8.1 release. (#3421)
f1594cb9 docs: changelog update for 2.8.1 (#3416)
90707b46 fix(build): support conan's multiple includes of all files (#3420)
e7e2c79f fix: improve support for Python 3.11-dev (#3368)
c2d3e220 fix: the types for return_value_policy_override in optional_caster (#3376)
d45a8810 [pre-commit.ci] pre-commit autoupdate (#3409)
9379b399 fix: MSVC 2017 C++17 on Python 3 regression (#3407)
78ee782b feat: Add C++ binding to throw AttributeError (#3387)
076c89fc tests: test recursive dispatch using visitor pattern (#3365)
606f81a9 style: drop pycln (#3397)
2d6014e4 docs: fix minor typo (#3390)
f791dc86 fix: deprecate make_simple_namespace, fix Python 3.11 (#3374)
931f6644 ci: cancel in-progress on repeated pushes (#3370)
56b49c2b ci: fix mingw checks by pinning (#3375)
7c580586 Correct options on Eigen::MappedSparseMatrix & adding MSVC C4127 suppression around Eigen includes. (#3352)
02c05573 [pre-commit.ci] pre-commit autoupdate (#3353)
8a7c266d Fix make_key_iterator/make_value_iterator for prvalue iterators (#3348)
750e38dc Update eval.h (#3344)
f4c81e08 maint: Add additional linter-related pre-commit hooks (#3337)
ed09664f chore(deps): bump ilammy/msvc-dev-cmd from 1.9.0 to 1.10.0 (#3338)
47ed124f Fix some formatting in the v2.8.0 changelog (#3339)
ba9f919b chore: get back to work after 2.8.0
e315e1fe Merge branch 'master' into stable
97976c16 [pre-commit.ci] pre-commit autoupdate (#3325)
3747dc2c Revert "All `-DDOWNLOAD_EIGEN=OFF` (to work around gitlab eigen outage)." (#3326)
c9a319c6 chore: version 2.8.0 final
20aae3e6 ci: disable Eigen due to Cert issue on CentOS
591db0b9 docs: update CHANGELOG for 2.8
9f146a56 All `-DDOWNLOAD_EIGEN=OFF` (to work around gitlab eigen outage).
d7a7edc1 tests: support Eigen configuration
ad966556 fix: replace free() with std::free() (#3321)
b3573ac9 feat: add `.keys` and `.values` to bind_map (#3310)
b4e1ab8c Docs: Demonstrate non-enum internal types in example (#3314)
a1830d5e docs: mention title conventions in PR template (#3313)
c9bbf8d2 docs: fix minor typo (#3311)
71fd5241 docs: fix minor typo (#3311)
6be64304 [pre-commit.ci] pre-commit autoupdate (#3312)
6bce3bd7 docs: update CHANGELOG (#3304)
d58699c9 fix(cmake): reduce chance for variable collision (#3302)
62c4909c Add `custom_type_setup` attribute (#3287)
409be833 CMake: react to python version changes
6ad3f874 fix(build): avoid a possible warning about shadowed variables and changing behaviors (#3220)
21282e64 feat: reapply fixed version of #3271 (#3293)
2a78abff Ensure PYBIND11_TLS_REPLACE_VALUE evaluates its arguments only once (#3290)
5f46e47d tests: check simple iteration of pairs (#3296)
2fa3fcfd Revert "Add make_value_iterator (#3271)"
1dc9a23c chore(deps): bump jwlawson/actions-setup-cmake from 1.10 to 1.11 (#3294)
b06a6f4f feat: Slice allowing None with py::object or std::optional (#1101)
0fb981b2 Add blacken-docs and pycln pre-commit hooks (#3292)
ee0c5ee4 Add make_value_iterator (#3271)
077a16e9 [pre-commit.ci] pre-commit autoupdate (#3286)
6e6975e2 Fix test case with __new__ (#3285)
d0f3c51f Enable defining custom __new__ (#3265)
14976c85 Eliminate duplicate TLS keys for loader_life_support stack (#3275)
04dd3262 docs: update CHANGELOG (#3276)
e0031bfc include/pybind11/numpy.h: gcc 4.8.4 does not have is_trivially_copyable (#3270)
3ed31e92 [pre-commit.ci] pre-commit autoupdate (#3266)
6c65ab59 Follow-on to PR #3254, to address user code breakages. (#3263)
9978ed58 Fix capsule bug (#3261)
0e599589 Fix thread safety for pybind11 loader_life_support (#3237)
121b91f9 Fixing NOLINT mishap (#3260)
ae07d4c6 maint(Clang-Tidy): readability-const-return (#3254)
4d5ad03e Avoid use of temporary `bytes` object in string_caster for UTF-8 (#3257)
4c6bee35 fix: Set __file__ constant when using eval_file (#1300) (#3233)
6abf2baa CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250)
39a0aac8 docs fix to avoid nonexistent SmartCompile (#3241)
d71ba0cb (perf): Add a missing noexcept to a pytype constructor (#3236)
49173e47 Minor follow-on to PR #1334 (Fix enum value's __int__ returning non-int when underlying type is bool or of char type) (#3232)
a46f6237 Minor tweaks. (#3230)
d6474ed7 fix: memory leak in cpp_function (#3228) (#3229)
76d939de [pre-commit.ci] pre-commit autoupdate (#3231)
777352fc Adding `ssize_t_cast` to support passing `size_t` or `ssize_t` values where `ssize_t` is needed. (#3219)
cb60ed49 Fix enum value's __int__ returning non-int when underlying type is bool or of char type (#1334)
930bb16c Call PySys_SetArgv when initializing interpreter. (#2341)
503ff2a6 view for numpy arrays (#987)
db44afa3 tests: fix pytest usage on Python 3.10 (#3221)
59ad1e7d reshape for numpy arrays (#984)
031a700d Add make_simple_namespace function and tests (#2840)
c8ce4b8d Clone of @virtuald's PR #2112 with minor enhancements. (#3215)
6cbabc4b maint(clang-tidy): Enable cpp-coreguideline slicing checks (#3210)
fdac5fbf chore: support targeting different Python versions with nox (#3214)
b3d18f38 [pre-commit.ci] pre-commit autoupdate (#3213)
4f29b8a4 ci: extend msys2 mingw CI (#3207)
998d45e4 Cleanup of file-scoped and globally-scoped warning suppression pragmas across pybind11 header files. (#3201)
774b5ff9 Removing obsolete eigen.h warning suppression pragmas. (#3198)
617cb653 [Bugfix] Fix errant const methods (#3194)
1bcd94c4 Removing last remnants of pragma block at the top of pybind11.h (#3186)
9df2f1ff maint(precommit): Apply isort (#3195)
d6841f60 chore(deps): bump jwlawson/actions-setup-cmake from 1.9 to 1.10 (#3196)
7d3b0571 Improved workaround for Centos 8 failure (follow-on to PR #3030). (#3193)
0be2ea06 [pre-commit.ci] pre-commit autoupdate (#3185)
4c7e509f PYBIND11_NOINLINE-related cleanup. (#3179)
ff590c12 maint(perf): Optimize Numpy constructor to remove copies by value. (#3183)
61ee923b Consistent step name "Python tests". (#3180)
6ac8efe5 test_eval: Show example of working closure (#2743)
af700733 Removing GCC -Wunused-but-set-parameter from pragma block at the top of pybind11.h (#3164)
3893f37b maint(clang-tidy): Bugprone enable checks (#3166)
089328f7 Revert "fix: apply simpler expression with fewer workarounds"
1fafd1b4 fix: apply simpler expression with fewer workarounds
5f4d7259 fix: version number hex
c30f57d2 chore: start development for 2.8.0
787d2c88 fix: include hex version in bump
82adacb3 fix: include hex version in bump
5f34c42d chore: bump to version 2.7.1
078c1167 chore: bump to version 2.7.1
90959848 chore: changelog update (#3163)
9f204a18 fix: func_handle for rule of two (#3169)
ada6b791 [pre-commit.ci] pre-commit autoupdate (#3167)
a2b78a8c chore: changelog update (#3163)
c0756ccd fix: func_handle for rule of two (#3169)
f4f4632e [pre-commit.ci] pre-commit autoupdate (#3167)
dcbda8d7 Removing MSVC C4127 from pragma block at the top of pybind11.h (#3152)
b961ac64 Moving pragma for MSVC warning C4505 from pybind11.h to existing list in detail/common.h (#3160)
c80e0593 fix: Mingw64 corrected and add a CI job to test it (#3132)
46c51fc0 Limiting pragma for ignoring GCC 7 -Wnoexcept-type to the scope of pybind11.h. (#3161)
e2573dc9 Moving pragma for MSVC warning C4505 from pybind11.h to existing list in detail/common.h (#3160)
9e8a741b fix: Mingw64 corrected and add a CI job to test it (#3132)
b4259729 Limiting pragma for ignoring GCC 7 -Wnoexcept-type to the scope of pybind11.h. (#3161)
b1fdbe69 chore: add discussions link (#3159)
05852fb6 Accommodating environments that define __STDC_WANT_LIB_EXT1__ even if __STDC_LIB_EXT1__ is not defined by the implementation. (#3151)
ed5fb66b Removing __INTEL_COMPILER section from pragma block at the top of pybind11.h (#3135)
0ac4c8af maint(clang-tidy): Improve code readability with explicit boolean casts (#3148)
5c6bdb72 fix: the CMake config in Python package had a hard coded path (#3144)
fd71bd48 Allow python builtins to be used as callbacks (#1413)
e93d9459 Removing MSVC C4800 from pragma block at the top of pybind11.h (#3141)
c973660d [pre-commit.ci] pre-commit autoupdate (#3143)
85b38c69 Adding pragma warning(disable: 4522) for MSVC <= 2017. (#3142)
b193d42c Removing MSVC C4996 from pragma block at the top of pybind11.h (#3129)
ee3ecb8a Specified encoding in setup.py calls of open() (#3137)
c14b1933 chore: increase CMake upper limit (#3124)
b72ca7d1 Removing MSVC C4100 from pragma block at the top of pybind11.h (#3150)
f4721a7b Accommodating environments that define __STDC_WANT_LIB_EXT1__ even if __STDC_LIB_EXT1__ is not defined by the implementation. (#3151)
2164c2e0 Removing __INTEL_COMPILER section from pragma block at the top of pybind11.h (#3135)
9beaa925 maint(clang-tidy): Improve code readability with explicit boolean casts (#3148)
7cc0ebb4 fix: the CMake config in Python package had a hard coded path (#3144)
a0b97596 Allow python builtins to be used as callbacks (#1413)
a0f862d4 Removing MSVC C4800 from pragma block at the top of pybind11.h (#3141)
7f76d795 [pre-commit.ci] pre-commit autoupdate (#3143)
7904ba1a Adding pragma warning(disable: 4522) for MSVC <= 2017. (#3142)
ff97f101 Removing MSVC C4996 from pragma block at the top of pybind11.h (#3129)
e58c6897 Specified encoding in setup.py calls of open() (#3137)
d65edfb0 Feature/local exception translator (#2650)
6d5d4e73 Move object in pop method of List. (#3116)
9626483c [pre-commit.ci] pre-commit autoupdate (#3134)
34f587dd Removing all warning pragmas that have not effect. (#3127)
74935f8d chore: post-release (#3128)
65e95ea8 chore: bump to 2.7.0 (#3123)
6642f389 docs: update changelog (#3122)
4359e00b Introducing PYBIND11_VERSION_HEX (#3120)
1b10292c chore: support PDF from nox (#3121)
55f6f6e9 Fix: RTD Docutils Build (#3119)
2415c094 feat(package): support pipx run (#3117)
31843d45 docs: reduce visibility of 3.9.0 warning (#3105)
5cd37507 Enable -Wstrict-aliasing warning (#2816)
c4b0dc7c Add shellcheck style checking (#3114)
cd061aee style: pre-commit cleanup (#3111)
7331d381 Raise codec errors when casting to std::string (#2903)
aca6c3ba * Removing stray semicolons (discovered by running clang-format v12 followed by tools/check-style.sh). (#3087)
1be0a0a6 Add helper to build in-tree extensions. (#2831)
2b7985e5 Improve documentation of discard_as_unraisable() API (#2697)
25e470c5 fix(clang-tidy): Add cppcoreguidelines-init-vars,slicing, and throw-by-value-catch-by-reference checks (#3094)
6a644c8f docs: update changelog (#3099)
0e2e0035 style: add pyupgrade check, 2.7+
11e12fe4 chore: move some config to pyproject.toml
84fdadfb chore: update pre-commit hooks
75090647 More precise return_value_policy::automatic documentation. (#2920)
ddf0efb9 chore: add nox support (#3101)
9f11951b Fixing spelling errors that went undetected because the pre-commit spell check was added after the CI for PR #2995 last ran. (#3103)
f0a65c89 docs(fix): spelling mistake in recent commit
7472d37a Adding iostream.h thread-safety documentation. (#2995)
2d468697 NOLINT reduction (#3096)
7a64b8ad docs: fix script issues for changelog compilation (#3100)
0f4761b4 Rollback of DOWNLOAD_CATCH=OFF change merged via PR #3059. (#3092)
cf006af2 Fix typos and docs style (#3088)
bac5a0c3 Go all the way fixing clang-tidy issues to avoid the NOLINTNEXTLINE clutter and clang-format issues. This was really meant to be part of PR #3051 but was held back either out of an abundance of caution, or because of confusion caused by stray semicolons. (#3086)
b5357d1f fix(clang-tidy): Enable clang-tidy else-after-return and redundant void checks (#3080)
6d1b197b Splitting out pybind11/stl/filesystem.h. (#3077)
c090c8c4 Unify cast_error message thrown by [simple|unpacking]_collector (#3013)
0ad116d3 Adding codespell to .pre-commit-config.yaml (follow-on to PR #3075). (#3076)
8bee61b6 docs: fix various typos (#3075)
795e3c4c Removing `AlignConsecutiveAssignments: true`. (#3067)
6d440946 Check dict item accesses where it isn't already checked (#2863)
5bcaaa04 Add a std::filesystem::path <-> os.PathLike caster. (#2730)
f067deb5 avoid unnecessary strlen (#3058)
733f8de2 Avoid string copy if possible when passing a Python object to std::ostream (#3042)
cad79c11 tests: remove very minor oversight in PR #3059. (#3066)
fbae8f31 pickle setstate: setattr __dict__ only if not empty (#2972)
93e69191 fix: enable py::implicitly_convertible<py::none, ...> for py::class_-wrapped types (#3059)
484b0f04 Updating and slightly enhancing instructions for running clang-tidy. (#3055)
dac74ebd fix(clang-tidy): performance fixes applied in tests and CI (#3051)
3b30b0a5 fix(clang-tidy): clang-tidy readability and misc fixes, like adding const (#3052)
d00fc629 use CMAKE_INSTALL_FULL_INCLUDEDIR (#3005)
9b3b3577 chore(deps): bump ilammy/msvc-dev-cmd from 1.8.1 to 1.9.0 (#3027)
e0b5cbd4 chore(clang-tidy): add more modernize clang-tidy checks (#3049)
af6218ff fix(clang-tidy): Apply performance fixes from clang-tidy (#3046)
79178e71 fix(setup_helpers): try import multiprocessing.synchronize too (#3043)
19d99a87 Working around Centos 8 failure. (#3030)
b4b67f02 Fix typos (#3044)
cd4b49a2 Update py::kwargs examples to pass by reference (#3038)
4c7697db Add const T to docstring generation. (#3020)
e25b1505 Adjusting valgrind suppression for pypocketfft to resolve systematic failures that started to appear on 2020-05-27. (#3022)
3ac690b8 Explicitly export exception types. (#2999)
14023c9c chore(deps): bump ilammy/msvc-dev-cmd from 1.8.0 to 1.8.1 (#3021)
f61855b9 chore(deps): bump ilammy/msvc-dev-cmd from 1 to 1.8.0 (#3001)
bc7cf6ef chore(deps): bump jwlawson/actions-setup-cmake from 1.8 to 1.9 (#3000)
b6ec0e95 functions: Add doc on incorrect argument index (#2979)
417fd120 Fix: fix typo of WITHOUT_SOABI (#2992)
0c93a0f3 Fix Unicode support for ostream redirects (#2982)
54430436 ci: install Boost for boost checks (#2968)
bca4b36b chore(deps): bump pre-commit/action from v2.0.2 to v2.0.3 (#2964)
5e4804bb tests: use master commit for pytest on 3.10 (#2967)
e08a5811 Fix compilation with gcc < 5 (#2956)
114be7f4 docs: remove recommonmark (#2955)
62976cfc fix: using -Werror-all for Intel (#2948)
6709abba Allow function pointer extraction from overloaded functions (#2944)
e0c1dadb chore: add myself to CODEOWNERS (#2940)
4f0727f2 Fix the enabling of default extension handling (#2938)
16c23fef chore(deps): bump pre-commit/action from v2.0.0 to v2.0.2 (#2935)
ad6bf5cd Adding PyGILState_Check() in object_api<>::operator(). (#2919)
f676782b env: Add surrogate for pytest.deprecated_call for ptyest<3.9 (#2923)
1259db6f Fix Pybind11Extension on mingw64 (#2921)
c2db53da fix: catch missing self argument in overloads constructor (#2914)
3df0ee6f docs: typo in classes.rst (#2926)
0e01c243 Generalizing suppression for pypocketfft. (#2896)
f110889d Use correct duration representation when casting from datetime.timdelta to std::chrono::duration (#2870)
44678e54 Shuffling code in test_multiple_inheritance.cpp to separate struct/class definitions from bindings code. (#2890)
9c0aa699 Pointing out namespace in docs (#2874)
e2e819b2 Shuffling code in test_smart_ptr.cpp to separate struct/class definitions from bindings code. Back-porting from smart_holder branch, to minimize diffs and potential for merge conflicts. (#2875)
74a767d4 Dtype kind vs char  (#2864)
c0fbb02c Extract gil management functions to separate header (#2845)
0c42250a Splitting out detail/type_caster_base.h from cast.h, with iwyu cleanup. (#2841)
98f9a33c Correct typo in FAQ (#2868)
59f8d7f1 chore(deps): bump jwlawson/actions-setup-cmake from v1.7 to v1.8 (#2865)
417067ee Add pybind11::bytearray (#2799)
cbae6d55 docs: fix CMake status for DOWNLOAD_EIGEN (#2857)
c2362393 chore(deps): bump pypa/gh-action-pypi-publish from v1.4.1 to v1.4.2 (#2851)
c78dfb69 MSVC but not Clang: /MP (#2824)
e791ec4e fix: add null pointer check with std::localtime (#2846)
948d09d6 test: Test against Python 3.10 (#2848)
fe845878 Make sure all warnings in pytest get turned into errors (#2838)
721834b4 chore: get PyPy 3.7 wheels using NumPy 1.20 (#2837)
6cf6bf20 Fix confusing weakref constructor overload (#2832)
932769b0 Adding holder_caster `typename SFINAE = void` hooks to help work around the current lack of smart-pointer interoperability (#2833)
23c3edcf When determining if a shared_ptr already exists, use a test on the we… (#2819)
0432ae7c Changing pybind11::str to exclusively hold PyUnicodeObject (#2409)
587d5f84 Update breathe to 4.26.1, add make_tuple, make_iterator, and make_key_iterator (#2828)
9b7bfef8 Factoring out find_registered_python_instance() from type_caster_generic::cast. (#2822)
87954e7a fix: corrected dev versioning
4a5b81b1 chore: get back to work
8de7772c chore: prepare for the 2.6.2 release (#2821)
732bf88d fix: avoid changing class outside of GIL
dff9b3b4 chore: add pytest-timeout, mypy
8e5d3d23 docs: prepare for 2.6.2 (#2820)
42e73807 chore(deps): bump jwlawson/actions-setup-cmake from v1.6 to v1.7 (#2818)
0bb8ca26 Always call PyNumber_Index when casting from Python to a C++ integral type, also pre-3.8 (#2801)
9ea39dc3 Force the builtin module key to be the correct type. (#2814)
08bca374 docs: update changelog, nicer output for script (#2811)
44105ca1 docs: mention that the changelog block in PR is special
5b43ac42 docs: fix missing line from #2310
2db0264a style: add clang-format file (#2310)
130c9954 fix: support basic dual includes (#2804)
eb83feef style: avoid using unintialized variables (#2806)
87f5aff4 ci: update to setup-cmake v1.6 (#2805)
e8c4f543 fix: prepend Pybind11Extension flags rather than appending them. (#2808)
48534089 fix: Intel ICC C++17 compatibility (#2729)
8449a808 fix: only allow integer type_caster to call __int__ method when conversion is allowed; always call __index__ (#2698)
0df11d85 docs: update build description slightly (#2794)
0b3df7f9 ci: Intel icc/icpc via oneAPI (#2573)
0f8d5f2e Add a Valgrind build on debug Python 3.9  (#2746)
76a16007 fix: STATIC and SHARED flags not being detected (#2796)
08551463 Plug leaking function_records in cpp_function initialization in case of exceptions (found by Valgrind in #2746) (#2756)
230fa53f fix: Don't override global settings for VISIBILITY if set (#2793)
1faf4a8a docs: the order of alternatives for variant types matters, and follows the same rules as overload resolution (#2784)
40931961 docs: fix spelling in some comments/docs (#2777)
df8494dc fix: a clang warning [-Wshadow-field-in-constructor-modified] (#2780)
14b37512 docs: fix example code in Exceptions section (match vs. matches) (#2781)
210c8c21 fix: a warning found by static code analyzer (#2783)
f243450e ci: disable builds for 3.10.0a4, and enable a nightly 3.10-dev build (#2792)
5abce7fc ci: use fixed action (#2791)
7b7ec664 ci: pin CMake to 3.19.2, fixes  issues with 3.19.3 on Linux (aarch64) and macOS (universal) (#2790)
98f1bbb8 Ignore deprecation warnings about old-style __init__/__setstate__ constructors in the tests (originally done in #2746) (#2759)
e57dd471 Fix various minor memory leaks in the tests (found by Valgrind in #2746) (#2758)
e612043d Fix invalid access when reinterpret_casting a non-pybind11 PyObject* to instance* (found by Valgrind in #2746) (#2755)
2110d2d8 enum: add missing Enum.value property (#2739)
b7dfe5cc chore: changelog update (#2750)
d587a2fd fix: do not set docstring for function when empty (#2745)
830f8eda tests: update pytest 6.2.1 and fix test_python_alreadyset_in_destructor (#2741)
6f66e760 docs: add a note about compiling the example (#2737)
635e3fc9 CONTRIBUTING: Add suggestion about passing pytest flags (#2738)
79b0e2c0 docs: fix pdf build, simpler start page (#2736)
6b4297fd fix: don't trigger -Wunused-parameter in flagcheck.cpp. (#2735)
5bd766bf docs: update changelog and add script to help generate it (#2733)
d5af536f ci: update cmake action (#2734)
79cb013f fix: allow users to avoid thread termination in scoped_released (#2657)
cecdfadc minor cleanup: fixing or silencing flake8 errors (#2731)
30eb39ed fix: also throw in the move-constructor added by the PYBIND11_OBJECT macro, after the argument has been moved-out (if necessary) (#2701)
d9fa7056 style: remove redundant instance->owned = true (#2723)
ffb113d1 fix: regression with installed pybind11 overriding local one (#2716)
499fcd54 ci: drop pypy2 linux, PGI 20.7, add Python 10 dev (#2724)
5469c238 Adjusting `type_caster<std::reference_wrapper<T>>` to support const/non-const propagation in `cast_op`. (#2705)
91a69720 docs: Update warning about Python 3.9.0 UB, now that 3.9.1 has been released (#2719)
d068ab28 docs: pybind11/numpy.h does not require numpy at build time. (#2720)
028812ae docs: add warning about FindPython's Development component when libraries don't exist (e.g. on manylinux) (#2689)
d57c1fab docs: update installing.rst (#2691)
8adef2c7 fix: workaround for #2682 and #2422 by simply clearing the TypeError (#2685)
087b07c8 Remove workaround code that is not needed since #1211 (#2683)
7bd4b397 fix: define PYBIND11_CPP14 for recent intel compilers (#2679)
af8849f4 docs: list all pybind11 exceptions (#2671)
2fa4747c pythonbuf fix (#2675)
17c22b9e docs: mention branch update in checklist (#2670)
32d11c96 fix typo in pickle example (#2669)
de78bddd docs: better badges (#2656)
f8b8107b fix: make FindPython2 and FindPython3 work (#2662)
02746cb6 docs: add a little more information for releases
b7c741b5 docs: back to work after 2.6.1
f1abf5d9 docs: changelog update (#2652)
ebd5c5b4 feat: way to only recompile changed files (#2643)
c58758d0 fix: add reasonable argument names to enum_ methods (#2637)
b72cebeb style: clang-tidy: modernize-use-using (#2645)
06b673a0 Allow NULL value in pybind11_meta_setattro (#2629)
3e4d54bc fix: match new extension discovery with changes to classic discovery (#2640)
6d4854a5 ci: correct types statement
6cc233cc ci: label PRs when merged only for now
b8dc60ec fix: Python include directory was missing from DIRS (#2636)
7d6713a4 Use weakref to clean up captured function object in def_buffer (#2634)
06a54018 fix: min macos (#2622)
139c05da ci: test on NumPy + Python 3.9 (#2628)
8290a5a0 clang -Wnon-virtual-dtor compatibility (#2626)
f2e79986 [common.h] Mark another entry point as "unused". (#2625)
3a37d338 Add __builtins__ to globals argument of `py::exec` and `py::eval` if not present (#2616)
ace4deb4 ci: add more jobs (#2610)
4d037439 fix: missing identifier for Python 3.9
7c26c718 Fix mispelling in basics.rst (#2614)
86d3e9eb begin working towards a future v2.6.1 patch release

git-subtree-dir: examples/knxPython/pybind11
git-subtree-split: 941f45bcb51457884fa1afd6e24a67377d70f75c
2024-06-29 16:48:45 +02:00

1269 lines
53 KiB
C++

/*
pybind11/detail/common.h -- Basic macros
Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
All rights reserved. Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.
*/
#pragma once
#define PYBIND11_VERSION_MAJOR 2
#define PYBIND11_VERSION_MINOR 13
#define PYBIND11_VERSION_PATCH 1
// Similar to Python's convention: https://docs.python.org/3/c-api/apiabiversion.html
// Additional convention: 0xD = dev
#define PYBIND11_VERSION_HEX 0x020D0100
// Define some generic pybind11 helper macros for warning management.
//
// Note that compiler-specific push/pop pairs are baked into the
// PYBIND11_NAMESPACE_BEGIN/PYBIND11_NAMESPACE_END pair of macros. Therefore manual
// PYBIND11_WARNING_PUSH/PYBIND11_WARNING_POP are usually only needed in `#include` sections.
//
// If you find you need to suppress a warning, please try to make the suppression as local as
// possible using these macros. Please also be sure to push/pop with the pybind11 macros. Please
// only use compiler specifics if you need to check specific versions, e.g. Apple Clang vs. vanilla
// Clang.
#if defined(_MSC_VER)
# define PYBIND11_COMPILER_MSVC
# define PYBIND11_PRAGMA(...) __pragma(__VA_ARGS__)
# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(warning(push))
# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(warning(pop))
#elif defined(__INTEL_COMPILER)
# define PYBIND11_COMPILER_INTEL
# define PYBIND11_PRAGMA(...) _Pragma(#__VA_ARGS__)
# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(warning push)
# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(warning pop)
#elif defined(__clang__)
# define PYBIND11_COMPILER_CLANG
# define PYBIND11_PRAGMA(...) _Pragma(#__VA_ARGS__)
# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(clang diagnostic push)
# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(clang diagnostic push)
#elif defined(__GNUC__)
# define PYBIND11_COMPILER_GCC
# define PYBIND11_PRAGMA(...) _Pragma(#__VA_ARGS__)
# define PYBIND11_WARNING_PUSH PYBIND11_PRAGMA(GCC diagnostic push)
# define PYBIND11_WARNING_POP PYBIND11_PRAGMA(GCC diagnostic pop)
#endif
#ifdef PYBIND11_COMPILER_MSVC
# define PYBIND11_WARNING_DISABLE_MSVC(name) PYBIND11_PRAGMA(warning(disable : name))
#else
# define PYBIND11_WARNING_DISABLE_MSVC(name)
#endif
#ifdef PYBIND11_COMPILER_CLANG
# define PYBIND11_WARNING_DISABLE_CLANG(name) PYBIND11_PRAGMA(clang diagnostic ignored name)
#else
# define PYBIND11_WARNING_DISABLE_CLANG(name)
#endif
#ifdef PYBIND11_COMPILER_GCC
# define PYBIND11_WARNING_DISABLE_GCC(name) PYBIND11_PRAGMA(GCC diagnostic ignored name)
#else
# define PYBIND11_WARNING_DISABLE_GCC(name)
#endif
#ifdef PYBIND11_COMPILER_INTEL
# define PYBIND11_WARNING_DISABLE_INTEL(name) PYBIND11_PRAGMA(warning disable name)
#else
# define PYBIND11_WARNING_DISABLE_INTEL(name)
#endif
#define PYBIND11_NAMESPACE_BEGIN(name) \
namespace name { \
PYBIND11_WARNING_PUSH
#define PYBIND11_NAMESPACE_END(name) \
PYBIND11_WARNING_POP \
}
// Robust support for some features and loading modules compiled against different pybind versions
// requires forcing hidden visibility on pybind code, so we enforce this by setting the attribute
// on the main `pybind11` namespace.
#if !defined(PYBIND11_NAMESPACE)
# ifdef __GNUG__
# define PYBIND11_NAMESPACE pybind11 __attribute__((visibility("hidden")))
# else
# define PYBIND11_NAMESPACE pybind11
# endif
#endif
#if !(defined(_MSC_VER) && __cplusplus == 199711L)
# if __cplusplus >= 201402L
# define PYBIND11_CPP14
# if __cplusplus >= 201703L
# define PYBIND11_CPP17
# if __cplusplus >= 202002L
# define PYBIND11_CPP20
// Please update tests/pybind11_tests.cpp `cpp_std()` when adding a macro here.
# endif
# endif
# endif
#elif defined(_MSC_VER) && __cplusplus == 199711L
// MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard is fully
// implemented). Unless you use the /Zc:__cplusplus flag on Visual Studio 2017 15.7 Preview 3
// or newer.
# if _MSVC_LANG >= 201402L
# define PYBIND11_CPP14
# if _MSVC_LANG > 201402L
# define PYBIND11_CPP17
# if _MSVC_LANG >= 202002L
# define PYBIND11_CPP20
# endif
# endif
# endif
#endif
#if defined(PYBIND11_CPP20)
# define PYBIND11_CONSTINIT constinit
# define PYBIND11_DTOR_CONSTEXPR constexpr
#else
# define PYBIND11_CONSTINIT
# define PYBIND11_DTOR_CONSTEXPR
#endif
// Compiler version assertions
#if defined(__INTEL_COMPILER)
# if __INTEL_COMPILER < 1800
# error pybind11 requires Intel C++ compiler v18 or newer
# elif __INTEL_COMPILER < 1900 && defined(PYBIND11_CPP14)
# error pybind11 supports only C++11 with Intel C++ compiler v18. Use v19 or newer for C++14.
# endif
/* The following pragma cannot be pop'ed:
https://community.intel.com/t5/Intel-C-Compiler/Inline-and-no-inline-warning/td-p/1216764 */
# pragma warning disable 2196 // warning #2196: routine is both "inline" and "noinline"
#elif defined(__clang__) && !defined(__apple_build_version__)
# if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 3)
# error pybind11 requires clang 3.3 or newer
# endif
#elif defined(__clang__)
// Apple changes clang version macros to its Xcode version; the first Xcode release based on
// (upstream) clang 3.3 was Xcode 5:
# if __clang_major__ < 5
# error pybind11 requires Xcode/clang 5.0 or newer
# endif
#elif defined(__GNUG__)
# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
# error pybind11 requires gcc 4.8 or newer
# endif
#elif defined(_MSC_VER)
# if _MSC_VER < 1910
# error pybind11 2.10+ requires MSVC 2017 or newer
# endif
#endif
#if !defined(PYBIND11_EXPORT)
# if defined(WIN32) || defined(_WIN32)
# define PYBIND11_EXPORT __declspec(dllexport)
# else
# define PYBIND11_EXPORT __attribute__((visibility("default")))
# endif
#endif
#if !defined(PYBIND11_EXPORT_EXCEPTION)
# if defined(__apple_build_version__)
# define PYBIND11_EXPORT_EXCEPTION PYBIND11_EXPORT
# else
# define PYBIND11_EXPORT_EXCEPTION
# endif
#endif
// For CUDA, GCC7, GCC8:
// PYBIND11_NOINLINE_FORCED is incompatible with `-Wattributes -Werror`.
// When defining PYBIND11_NOINLINE_FORCED, it is best to also use `-Wno-attributes`.
// However, the measured shared-library size saving when using noinline are only
// 1.7% for CUDA, -0.2% for GCC7, and 0.0% for GCC8 (using -DCMAKE_BUILD_TYPE=MinSizeRel,
// the default under pybind11/tests).
#if !defined(PYBIND11_NOINLINE_FORCED) \
&& (defined(__CUDACC__) || (defined(__GNUC__) && (__GNUC__ == 7 || __GNUC__ == 8)))
# define PYBIND11_NOINLINE_DISABLED
#endif
// The PYBIND11_NOINLINE macro is for function DEFINITIONS.
// In contrast, FORWARD DECLARATIONS should never use this macro:
// https://stackoverflow.com/questions/9317473/forward-declaration-of-inline-functions
#if defined(PYBIND11_NOINLINE_DISABLED) // Option for maximum portability and experimentation.
# define PYBIND11_NOINLINE inline
#elif defined(_MSC_VER)
# define PYBIND11_NOINLINE __declspec(noinline) inline
#else
# define PYBIND11_NOINLINE __attribute__((noinline)) inline
#endif
#if defined(__MINGW32__)
// For unknown reasons all PYBIND11_DEPRECATED member trigger a warning when declared
// whether it is used or not
# define PYBIND11_DEPRECATED(reason)
#elif defined(PYBIND11_CPP14)
# define PYBIND11_DEPRECATED(reason) [[deprecated(reason)]]
#else
# define PYBIND11_DEPRECATED(reason) __attribute__((deprecated(reason)))
#endif
#if defined(PYBIND11_CPP17)
# define PYBIND11_MAYBE_UNUSED [[maybe_unused]]
#elif defined(_MSC_VER) && !defined(__clang__)
# define PYBIND11_MAYBE_UNUSED
#else
# define PYBIND11_MAYBE_UNUSED __attribute__((__unused__))
#endif
/* Don't let Python.h #define (v)snprintf as macro because they are implemented
properly in Visual Studio since 2015. */
#if defined(_MSC_VER)
# define HAVE_SNPRINTF 1
#endif
/// Include Python header, disable linking to pythonX_d.lib on Windows in debug mode
#if defined(_MSC_VER)
PYBIND11_WARNING_PUSH
PYBIND11_WARNING_DISABLE_MSVC(4505)
// C4505: 'PySlice_GetIndicesEx': unreferenced local function has been removed (PyPy only)
# if defined(_DEBUG) && !defined(Py_DEBUG)
// Workaround for a VS 2022 issue.
// NOTE: This workaround knowingly violates the Python.h include order requirement:
// https://docs.python.org/3/c-api/intro.html#include-files
// See https://github.com/pybind/pybind11/pull/3497 for full context.
# include <yvals.h>
# if _MSVC_STL_VERSION >= 143
# include <crtdefs.h>
# endif
# define PYBIND11_DEBUG_MARKER
# undef _DEBUG
# endif
#endif
// https://en.cppreference.com/w/c/chrono/localtime
#if defined(__STDC_LIB_EXT1__) && !defined(__STDC_WANT_LIB_EXT1__)
# define __STDC_WANT_LIB_EXT1__
#endif
#ifdef __has_include
// std::optional (but including it in c++14 mode isn't allowed)
# if defined(PYBIND11_CPP17) && __has_include(<optional>)
# define PYBIND11_HAS_OPTIONAL 1
# endif
// std::experimental::optional (but not allowed in c++11 mode)
# if defined(PYBIND11_CPP14) && (__has_include(<experimental/optional>) && \
!__has_include(<optional>))
# define PYBIND11_HAS_EXP_OPTIONAL 1
# endif
// std::variant
# if defined(PYBIND11_CPP17) && __has_include(<variant>)
# define PYBIND11_HAS_VARIANT 1
# endif
#elif defined(_MSC_VER) && defined(PYBIND11_CPP17)
# define PYBIND11_HAS_OPTIONAL 1
# define PYBIND11_HAS_VARIANT 1
#endif
#if defined(PYBIND11_CPP17)
# if defined(__has_include)
# if __has_include(<string_view>)
# define PYBIND11_HAS_STRING_VIEW
# endif
# elif defined(_MSC_VER)
# define PYBIND11_HAS_STRING_VIEW
# endif
#endif
#include <Python.h>
#if PY_VERSION_HEX < 0x03070000
# error "PYTHON < 3.7 IS UNSUPPORTED. pybind11 v2.12 was the last to support Python 3.6."
#endif
#include <frameobject.h>
#include <pythread.h>
/* Python #defines overrides on all sorts of core functions, which
tends to weak havok in C++ codebases that expect these to work
like regular functions (potentially with several overloads) */
#if defined(isalnum)
# undef isalnum
# undef isalpha
# undef islower
# undef isspace
# undef isupper
# undef tolower
# undef toupper
#endif
#if defined(copysign)
# undef copysign
#endif
#if defined(PYBIND11_NUMPY_1_ONLY)
# define PYBIND11_INTERNAL_NUMPY_1_ONLY_DETECTED
#endif
#if defined(PYPY_VERSION) && !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
# define PYBIND11_SIMPLE_GIL_MANAGEMENT
#endif
#if defined(_MSC_VER)
# if defined(PYBIND11_DEBUG_MARKER)
# define _DEBUG
# undef PYBIND11_DEBUG_MARKER
# endif
PYBIND11_WARNING_POP
#endif
#include <cstddef>
#include <cstring>
#include <exception>
#include <forward_list>
#include <memory>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#if defined(__has_include)
# if __has_include(<version>)
# include <version>
# endif
#endif
// Must be after including <version> or one of the other headers specified by the standard
#if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
# define PYBIND11_HAS_U8STRING
#endif
// See description of PR #4246:
#if !defined(PYBIND11_NO_ASSERT_GIL_HELD_INCREF_DECREF) && !defined(NDEBUG) \
&& !defined(PYPY_VERSION) && !defined(PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF)
# define PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
#endif
// #define PYBIND11_STR_LEGACY_PERMISSIVE
// If DEFINED, pybind11::str can hold PyUnicodeObject or PyBytesObject
// (probably surprising and never documented, but this was the
// legacy behavior until and including v2.6.x). As a side-effect,
// pybind11::isinstance<str>() is true for both pybind11::str and
// pybind11::bytes.
// If UNDEFINED, pybind11::str can only hold PyUnicodeObject, and
// pybind11::isinstance<str>() is true only for pybind11::str.
// However, for Python 2 only (!), the pybind11::str caster
// implicitly decoded bytes to PyUnicodeObject. This was to ease
// the transition from the legacy behavior to the non-permissive
// behavior.
/// Compatibility macros for Python 2 / Python 3 versions TODO: remove
#define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_) PyInstanceMethod_New(ptr)
#define PYBIND11_INSTANCE_METHOD_CHECK PyInstanceMethod_Check
#define PYBIND11_INSTANCE_METHOD_GET_FUNCTION PyInstanceMethod_GET_FUNCTION
#define PYBIND11_BYTES_CHECK PyBytes_Check
#define PYBIND11_BYTES_FROM_STRING PyBytes_FromString
#define PYBIND11_BYTES_FROM_STRING_AND_SIZE PyBytes_FromStringAndSize
#define PYBIND11_BYTES_AS_STRING_AND_SIZE PyBytes_AsStringAndSize
#define PYBIND11_BYTES_AS_STRING PyBytes_AsString
#define PYBIND11_BYTES_SIZE PyBytes_Size
#define PYBIND11_LONG_CHECK(o) PyLong_Check(o)
#define PYBIND11_LONG_AS_LONGLONG(o) PyLong_AsLongLong(o)
#define PYBIND11_LONG_FROM_SIGNED(o) PyLong_FromSsize_t((ssize_t) (o))
#define PYBIND11_LONG_FROM_UNSIGNED(o) PyLong_FromSize_t((size_t) (o))
#define PYBIND11_BYTES_NAME "bytes"
#define PYBIND11_STRING_NAME "str"
#define PYBIND11_SLICE_OBJECT PyObject
#define PYBIND11_FROM_STRING PyUnicode_FromString
#define PYBIND11_STR_TYPE ::pybind11::str
#define PYBIND11_BOOL_ATTR "__bool__"
#define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_bool)
#define PYBIND11_BUILTINS_MODULE "builtins"
// Providing a separate declaration to make Clang's -Wmissing-prototypes happy.
// See comment for PYBIND11_MODULE below for why this is marked "maybe unused".
#define PYBIND11_PLUGIN_IMPL(name) \
extern "C" PYBIND11_MAYBE_UNUSED PYBIND11_EXPORT PyObject *PyInit_##name(); \
extern "C" PYBIND11_EXPORT PyObject *PyInit_##name()
#define PYBIND11_TRY_NEXT_OVERLOAD ((PyObject *) 1) // special failure return code
#define PYBIND11_STRINGIFY(x) #x
#define PYBIND11_TOSTRING(x) PYBIND11_STRINGIFY(x)
#define PYBIND11_CONCAT(first, second) first##second
#define PYBIND11_ENSURE_INTERNALS_READY pybind11::detail::get_internals();
#define PYBIND11_CHECK_PYTHON_VERSION \
{ \
const char *compiled_ver \
= PYBIND11_TOSTRING(PY_MAJOR_VERSION) "." PYBIND11_TOSTRING(PY_MINOR_VERSION); \
const char *runtime_ver = Py_GetVersion(); \
size_t len = std::strlen(compiled_ver); \
if (std::strncmp(runtime_ver, compiled_ver, len) != 0 \
|| (runtime_ver[len] >= '0' && runtime_ver[len] <= '9')) { \
PyErr_Format(PyExc_ImportError, \
"Python version mismatch: module was compiled for Python %s, " \
"but the interpreter version is incompatible: %s.", \
compiled_ver, \
runtime_ver); \
return nullptr; \
} \
}
#define PYBIND11_CATCH_INIT_EXCEPTIONS \
catch (pybind11::error_already_set & e) { \
pybind11::raise_from(e, PyExc_ImportError, "initialization failed"); \
return nullptr; \
} \
catch (const std::exception &e) { \
::pybind11::set_error(PyExc_ImportError, e.what()); \
return nullptr; \
}
/** \rst
***Deprecated in favor of PYBIND11_MODULE***
This macro creates the entry point that will be invoked when the Python interpreter
imports a plugin library. Please create a `module_` in the function body and return
the pointer to its underlying Python object at the end.
.. code-block:: cpp
PYBIND11_PLUGIN(example) {
pybind11::module_ m("example", "pybind11 example plugin");
/// Set up bindings here
return m.ptr();
}
\endrst */
#define PYBIND11_PLUGIN(name) \
PYBIND11_DEPRECATED("PYBIND11_PLUGIN is deprecated, use PYBIND11_MODULE") \
static PyObject *pybind11_init(); \
PYBIND11_PLUGIN_IMPL(name) { \
PYBIND11_CHECK_PYTHON_VERSION \
PYBIND11_ENSURE_INTERNALS_READY \
try { \
return pybind11_init(); \
} \
PYBIND11_CATCH_INIT_EXCEPTIONS \
} \
PyObject *pybind11_init()
/** \rst
This macro creates the entry point that will be invoked when the Python interpreter
imports an extension module. The module name is given as the first argument and it
should not be in quotes. The second macro argument defines a variable of type
`py::module_` which can be used to initialize the module.
The entry point is marked as "maybe unused" to aid dead-code detection analysis:
since the entry point is typically only looked up at runtime and not referenced
during translation, it would otherwise appear as unused ("dead") code.
.. code-block:: cpp
PYBIND11_MODULE(example, m) {
m.doc() = "pybind11 example module";
// Add bindings here
m.def("foo", []() {
return "Hello, World!";
});
}
\endrst */
#define PYBIND11_MODULE(name, variable, ...) \
static ::pybind11::module_::module_def PYBIND11_CONCAT(pybind11_module_def_, name) \
PYBIND11_MAYBE_UNUSED; \
PYBIND11_MAYBE_UNUSED \
static void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ &); \
PYBIND11_PLUGIN_IMPL(name) { \
PYBIND11_CHECK_PYTHON_VERSION \
PYBIND11_ENSURE_INTERNALS_READY \
auto m = ::pybind11::module_::create_extension_module( \
PYBIND11_TOSTRING(name), \
nullptr, \
&PYBIND11_CONCAT(pybind11_module_def_, name), \
##__VA_ARGS__); \
try { \
PYBIND11_CONCAT(pybind11_init_, name)(m); \
return m.ptr(); \
} \
PYBIND11_CATCH_INIT_EXCEPTIONS \
} \
void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ & (variable))
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
using ssize_t = Py_ssize_t;
using size_t = std::size_t;
template <typename IntType>
inline ssize_t ssize_t_cast(const IntType &val) {
static_assert(sizeof(IntType) <= sizeof(ssize_t), "Implicit narrowing is not permitted.");
return static_cast<ssize_t>(val);
}
/// Approach used to cast a previously unknown C++ instance into a Python object
enum class return_value_policy : uint8_t {
/** This is the default return value policy, which falls back to the policy
return_value_policy::take_ownership when the return value is a pointer.
Otherwise, it uses return_value::move or return_value::copy for rvalue
and lvalue references, respectively. See below for a description of what
all of these different policies do. */
automatic = 0,
/** As above, but use policy return_value_policy::reference when the return
value is a pointer. This is the default conversion policy for function
arguments when calling Python functions manually from C++ code (i.e. via
handle::operator()). You probably won't need to use this. */
automatic_reference,
/** Reference an existing object (i.e. do not create a new copy) and take
ownership. Python will call the destructor and delete operator when the
object's reference count reaches zero. Undefined behavior ensues when
the C++ side does the same.. */
take_ownership,
/** Create a new copy of the returned object, which will be owned by
Python. This policy is comparably safe because the lifetimes of the two
instances are decoupled. */
copy,
/** Use std::move to move the return value contents into a new instance
that will be owned by Python. This policy is comparably safe because the
lifetimes of the two instances (move source and destination) are
decoupled. */
move,
/** Reference an existing object, but do not take ownership. The C++ side
is responsible for managing the object's lifetime and deallocating it
when it is no longer used. Warning: undefined behavior will ensue when
the C++ side deletes an object that is still referenced and used by
Python. */
reference,
/** This policy only applies to methods and properties. It references the
object without taking ownership similar to the above
return_value_policy::reference policy. In contrast to that policy, the
function or property's implicit this argument (called the parent) is
considered to be the the owner of the return value (the child).
pybind11 then couples the lifetime of the parent to the child via a
reference relationship that ensures that the parent cannot be garbage
collected while Python is still using the child. More advanced
variations of this scheme are also possible using combinations of
return_value_policy::reference and the keep_alive call policy */
reference_internal
};
PYBIND11_NAMESPACE_BEGIN(detail)
inline static constexpr int log2(size_t n, int k = 0) {
return (n <= 1) ? k : log2(n >> 1, k + 1);
}
// Returns the size as a multiple of sizeof(void *), rounded up.
inline static constexpr size_t size_in_ptrs(size_t s) {
return 1 + ((s - 1) >> log2(sizeof(void *)));
}
/**
* The space to allocate for simple layout instance holders (see below) in multiple of the size of
* a pointer (e.g. 2 means 16 bytes on 64-bit architectures). The default is the minimum required
* to holder either a std::unique_ptr or std::shared_ptr (which is almost always
* sizeof(std::shared_ptr<T>)).
*/
constexpr size_t instance_simple_holder_in_ptrs() {
static_assert(sizeof(std::shared_ptr<int>) >= sizeof(std::unique_ptr<int>),
"pybind assumes std::shared_ptrs are at least as big as std::unique_ptrs");
return size_in_ptrs(sizeof(std::shared_ptr<int>));
}
// Forward declarations
struct type_info;
struct value_and_holder;
struct nonsimple_values_and_holders {
void **values_and_holders;
uint8_t *status;
};
/// The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
struct instance {
PyObject_HEAD
/// Storage for pointers and holder; see simple_layout, below, for a description
union {
void *simple_value_holder[1 + instance_simple_holder_in_ptrs()];
nonsimple_values_and_holders nonsimple;
};
/// Weak references
PyObject *weakrefs;
/// If true, the pointer is owned which means we're free to manage it with a holder.
bool owned : 1;
/**
* An instance has two possible value/holder layouts.
*
* Simple layout (when this flag is true), means the `simple_value_holder` is set with a
* pointer and the holder object governing that pointer, i.e. [val1*][holder]. This layout is
* applied whenever there is no python-side multiple inheritance of bound C++ types *and* the
* type's holder will fit in the default space (which is large enough to hold either a
* std::unique_ptr or std::shared_ptr).
*
* Non-simple layout applies when using custom holders that require more space than
* `shared_ptr` (which is typically the size of two pointers), or when multiple inheritance is
* used on the python side. Non-simple layout allocates the required amount of memory to have
* multiple bound C++ classes as parents. Under this layout, `nonsimple.values_and_holders` is
* set to a pointer to allocated space of the required space to hold a sequence of value
* pointers and holders followed `status`, a set of bit flags (1 byte each), i.e.
* [val1*][holder1][val2*][holder2]...[bb...] where each [block] is rounded up to a multiple
* of `sizeof(void *)`. `nonsimple.status` is, for convenience, a pointer to the beginning of
* the [bb...] block (but not independently allocated).
*
* Status bits indicate whether the associated holder is constructed (&
* status_holder_constructed) and whether the value pointer is registered (&
* status_instance_registered) in `registered_instances`.
*/
bool simple_layout : 1;
/// For simple layout, tracks whether the holder has been constructed
bool simple_holder_constructed : 1;
/// For simple layout, tracks whether the instance is registered in `registered_instances`
bool simple_instance_registered : 1;
/// If true, get_internals().patients has an entry for this object
bool has_patients : 1;
/// Initializes all of the above type/values/holders data (but not the instance values
/// themselves)
void allocate_layout();
/// Destroys/deallocates all of the above
void deallocate_layout();
/// Returns the value_and_holder wrapper for the given type (or the first, if `find_type`
/// omitted). Returns a default-constructed (with `.inst = nullptr`) object on failure if
/// `throw_if_missing` is false.
value_and_holder get_value_and_holder(const type_info *find_type = nullptr,
bool throw_if_missing = true);
/// Bit values for the non-simple status flags
static constexpr uint8_t status_holder_constructed = 1;
static constexpr uint8_t status_instance_registered = 2;
};
static_assert(std::is_standard_layout<instance>::value,
"Internal error: `pybind11::detail::instance` is not standard layout!");
/// from __cpp_future__ import (convenient aliases from C++14/17)
#if defined(PYBIND11_CPP14)
using std::conditional_t;
using std::enable_if_t;
using std::remove_cv_t;
using std::remove_reference_t;
#else
template <bool B, typename T = void>
using enable_if_t = typename std::enable_if<B, T>::type;
template <bool B, typename T, typename F>
using conditional_t = typename std::conditional<B, T, F>::type;
template <typename T>
using remove_cv_t = typename std::remove_cv<T>::type;
template <typename T>
using remove_reference_t = typename std::remove_reference<T>::type;
#endif
#if defined(PYBIND11_CPP20)
using std::remove_cvref;
using std::remove_cvref_t;
#else
template <class T>
struct remove_cvref {
using type = remove_cv_t<remove_reference_t<T>>;
};
template <class T>
using remove_cvref_t = typename remove_cvref<T>::type;
#endif
/// Example usage: is_same_ignoring_cvref<T, PyObject *>::value
template <typename T, typename U>
using is_same_ignoring_cvref = std::is_same<detail::remove_cvref_t<T>, U>;
/// Index sequences
#if defined(PYBIND11_CPP14)
using std::index_sequence;
using std::make_index_sequence;
#else
template <size_t...>
struct index_sequence {};
template <size_t N, size_t... S>
struct make_index_sequence_impl : make_index_sequence_impl<N - 1, N - 1, S...> {};
template <size_t... S>
struct make_index_sequence_impl<0, S...> {
using type = index_sequence<S...>;
};
template <size_t N>
using make_index_sequence = typename make_index_sequence_impl<N>::type;
#endif
/// Make an index sequence of the indices of true arguments
template <typename ISeq, size_t, bool...>
struct select_indices_impl {
using type = ISeq;
};
template <size_t... IPrev, size_t I, bool B, bool... Bs>
struct select_indices_impl<index_sequence<IPrev...>, I, B, Bs...>
: select_indices_impl<conditional_t<B, index_sequence<IPrev..., I>, index_sequence<IPrev...>>,
I + 1,
Bs...> {};
template <bool... Bs>
using select_indices = typename select_indices_impl<index_sequence<>, 0, Bs...>::type;
/// Backports of std::bool_constant and std::negation to accommodate older compilers
template <bool B>
using bool_constant = std::integral_constant<bool, B>;
template <typename T>
struct negation : bool_constant<!T::value> {};
// PGI/Intel cannot detect operator delete with the "compatible" void_t impl, so
// using the new one (C++14 defect, so generally works on newer compilers, even
// if not in C++17 mode)
#if defined(__PGIC__) || defined(__INTEL_COMPILER)
template <typename...>
using void_t = void;
#else
template <typename...>
struct void_t_impl {
using type = void;
};
template <typename... Ts>
using void_t = typename void_t_impl<Ts...>::type;
#endif
/// Compile-time all/any/none of that check the boolean value of all template types
#if defined(__cpp_fold_expressions) && !(defined(_MSC_VER) && (_MSC_VER < 1916))
template <class... Ts>
using all_of = bool_constant<(Ts::value && ...)>;
template <class... Ts>
using any_of = bool_constant<(Ts::value || ...)>;
#elif !defined(_MSC_VER)
template <bool...>
struct bools {};
template <class... Ts>
using all_of = std::is_same<bools<Ts::value..., true>, bools<true, Ts::value...>>;
template <class... Ts>
using any_of = negation<all_of<negation<Ts>...>>;
#else
// MSVC has trouble with the above, but supports std::conjunction, which we can use instead (albeit
// at a slight loss of compilation efficiency).
template <class... Ts>
using all_of = std::conjunction<Ts...>;
template <class... Ts>
using any_of = std::disjunction<Ts...>;
#endif
template <class... Ts>
using none_of = negation<any_of<Ts...>>;
template <class T, template <class> class... Predicates>
using satisfies_all_of = all_of<Predicates<T>...>;
template <class T, template <class> class... Predicates>
using satisfies_any_of = any_of<Predicates<T>...>;
template <class T, template <class> class... Predicates>
using satisfies_none_of = none_of<Predicates<T>...>;
/// Strip the class from a method type
template <typename T>
struct remove_class {};
template <typename C, typename R, typename... A>
struct remove_class<R (C::*)(A...)> {
using type = R(A...);
};
template <typename C, typename R, typename... A>
struct remove_class<R (C::*)(A...) const> {
using type = R(A...);
};
#ifdef __cpp_noexcept_function_type
template <typename C, typename R, typename... A>
struct remove_class<R (C::*)(A...) noexcept> {
using type = R(A...);
};
template <typename C, typename R, typename... A>
struct remove_class<R (C::*)(A...) const noexcept> {
using type = R(A...);
};
#endif
/// Helper template to strip away type modifiers
template <typename T>
struct intrinsic_type {
using type = T;
};
template <typename T>
struct intrinsic_type<const T> {
using type = typename intrinsic_type<T>::type;
};
template <typename T>
struct intrinsic_type<T *> {
using type = typename intrinsic_type<T>::type;
};
template <typename T>
struct intrinsic_type<T &> {
using type = typename intrinsic_type<T>::type;
};
template <typename T>
struct intrinsic_type<T &&> {
using type = typename intrinsic_type<T>::type;
};
template <typename T, size_t N>
struct intrinsic_type<const T[N]> {
using type = typename intrinsic_type<T>::type;
};
template <typename T, size_t N>
struct intrinsic_type<T[N]> {
using type = typename intrinsic_type<T>::type;
};
template <typename T>
using intrinsic_t = typename intrinsic_type<T>::type;
/// Helper type to replace 'void' in some expressions
struct void_type {};
/// Helper template which holds a list of types
template <typename...>
struct type_list {};
/// Compile-time integer sum
#ifdef __cpp_fold_expressions
template <typename... Ts>
constexpr size_t constexpr_sum(Ts... ns) {
return (0 + ... + size_t{ns});
}
#else
constexpr size_t constexpr_sum() { return 0; }
template <typename T, typename... Ts>
constexpr size_t constexpr_sum(T n, Ts... ns) {
return size_t{n} + constexpr_sum(ns...);
}
#endif
PYBIND11_NAMESPACE_BEGIN(constexpr_impl)
/// Implementation details for constexpr functions
constexpr int first(int i) { return i; }
template <typename T, typename... Ts>
constexpr int first(int i, T v, Ts... vs) {
return v ? i : first(i + 1, vs...);
}
constexpr int last(int /*i*/, int result) { return result; }
template <typename T, typename... Ts>
constexpr int last(int i, int result, T v, Ts... vs) {
return last(i + 1, v ? i : result, vs...);
}
PYBIND11_NAMESPACE_END(constexpr_impl)
/// Return the index of the first type in Ts which satisfies Predicate<T>.
/// Returns sizeof...(Ts) if none match.
template <template <typename> class Predicate, typename... Ts>
constexpr int constexpr_first() {
return constexpr_impl::first(0, Predicate<Ts>::value...);
}
/// Return the index of the last type in Ts which satisfies Predicate<T>, or -1 if none match.
template <template <typename> class Predicate, typename... Ts>
constexpr int constexpr_last() {
return constexpr_impl::last(0, -1, Predicate<Ts>::value...);
}
/// Return the Nth element from the parameter pack
template <size_t N, typename T, typename... Ts>
struct pack_element {
using type = typename pack_element<N - 1, Ts...>::type;
};
template <typename T, typename... Ts>
struct pack_element<0, T, Ts...> {
using type = T;
};
/// Return the one and only type which matches the predicate, or Default if none match.
/// If more than one type matches the predicate, fail at compile-time.
template <template <typename> class Predicate, typename Default, typename... Ts>
struct exactly_one {
static constexpr auto found = constexpr_sum(Predicate<Ts>::value...);
static_assert(found <= 1, "Found more than one type matching the predicate");
static constexpr auto index = found ? constexpr_first<Predicate, Ts...>() : 0;
using type = conditional_t<found, typename pack_element<index, Ts...>::type, Default>;
};
template <template <typename> class P, typename Default>
struct exactly_one<P, Default> {
using type = Default;
};
template <template <typename> class Predicate, typename Default, typename... Ts>
using exactly_one_t = typename exactly_one<Predicate, Default, Ts...>::type;
/// Defer the evaluation of type T until types Us are instantiated
template <typename T, typename... /*Us*/>
struct deferred_type {
using type = T;
};
template <typename T, typename... Us>
using deferred_t = typename deferred_type<T, Us...>::type;
/// Like is_base_of, but requires a strict base (i.e. `is_strict_base_of<T, T>::value == false`,
/// unlike `std::is_base_of`)
template <typename Base, typename Derived>
using is_strict_base_of
= bool_constant<std::is_base_of<Base, Derived>::value && !std::is_same<Base, Derived>::value>;
/// Like is_base_of, but also requires that the base type is accessible (i.e. that a Derived
/// pointer can be converted to a Base pointer) For unions, `is_base_of<T, T>::value` is False, so
/// we need to check `is_same` as well.
template <typename Base, typename Derived>
using is_accessible_base_of
= bool_constant<(std::is_same<Base, Derived>::value || std::is_base_of<Base, Derived>::value)
&& std::is_convertible<Derived *, Base *>::value>;
template <template <typename...> class Base>
struct is_template_base_of_impl {
template <typename... Us>
static std::true_type check(Base<Us...> *);
static std::false_type check(...);
};
/// Check if a template is the base of a type. For example:
/// `is_template_base_of<Base, T>` is true if `struct T : Base<U> {}` where U can be anything
template <template <typename...> class Base, typename T>
// Sadly, all MSVC versions incl. 2022 need the workaround, even in C++20 mode.
// See also: https://github.com/pybind/pybind11/pull/3741
#if !defined(_MSC_VER)
using is_template_base_of
= decltype(is_template_base_of_impl<Base>::check((intrinsic_t<T> *) nullptr));
#else
struct is_template_base_of
: decltype(is_template_base_of_impl<Base>::check((intrinsic_t<T> *) nullptr)){};
#endif
/// Check if T is an instantiation of the template `Class`. For example:
/// `is_instantiation<shared_ptr, T>` is true if `T == shared_ptr<U>` where U can be anything.
template <template <typename...> class Class, typename T>
struct is_instantiation : std::false_type {};
template <template <typename...> class Class, typename... Us>
struct is_instantiation<Class, Class<Us...>> : std::true_type {};
/// Check if T is std::shared_ptr<U> where U can be anything
template <typename T>
using is_shared_ptr = is_instantiation<std::shared_ptr, T>;
/// Check if T looks like an input iterator
template <typename T, typename = void>
struct is_input_iterator : std::false_type {};
template <typename T>
struct is_input_iterator<T,
void_t<decltype(*std::declval<T &>()), decltype(++std::declval<T &>())>>
: std::true_type {};
template <typename T>
using is_function_pointer
= bool_constant<std::is_pointer<T>::value
&& std::is_function<typename std::remove_pointer<T>::type>::value>;
template <typename F>
struct strip_function_object {
// If you are encountering an
// 'error: name followed by "::" must be a class or namespace name'
// with the Intel compiler and a noexcept function here,
// try to use noexcept(true) instead of plain noexcept.
using type = typename remove_class<decltype(&F::operator())>::type;
};
// Extracts the function signature from a function, function pointer or lambda.
template <typename Function, typename F = remove_reference_t<Function>>
using function_signature_t = conditional_t<
std::is_function<F>::value,
F,
typename conditional_t<std::is_pointer<F>::value || std::is_member_pointer<F>::value,
std::remove_pointer<F>,
strip_function_object<F>>::type>;
/// Returns true if the type looks like a lambda: that is, isn't a function, pointer or member
/// pointer. Note that this can catch all sorts of other things, too; this is intended to be used
/// in a place where passing a lambda makes sense.
template <typename T>
using is_lambda = satisfies_none_of<remove_reference_t<T>,
std::is_function,
std::is_pointer,
std::is_member_pointer>;
// [workaround(intel)] Internal error on fold expression
/// Apply a function over each element of a parameter pack
#if defined(__cpp_fold_expressions) && !defined(__INTEL_COMPILER)
// Intel compiler produces an internal error on this fold expression (tested with ICC 19.0.2)
# define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) (((PATTERN), void()), ...)
#else
using expand_side_effects = bool[];
# define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) \
(void) pybind11::detail::expand_side_effects { ((PATTERN), void(), false)..., false }
#endif
PYBIND11_NAMESPACE_END(detail)
/// C++ bindings of builtin Python exceptions
class PYBIND11_EXPORT_EXCEPTION builtin_exception : public std::runtime_error {
public:
using std::runtime_error::runtime_error;
/// Set the error using the Python C API
virtual void set_error() const = 0;
};
#define PYBIND11_RUNTIME_EXCEPTION(name, type) \
class PYBIND11_EXPORT_EXCEPTION name : public builtin_exception { \
public: \
using builtin_exception::builtin_exception; \
name() : name("") {} \
void set_error() const override { PyErr_SetString(type, what()); } \
};
PYBIND11_RUNTIME_EXCEPTION(stop_iteration, PyExc_StopIteration)
PYBIND11_RUNTIME_EXCEPTION(index_error, PyExc_IndexError)
PYBIND11_RUNTIME_EXCEPTION(key_error, PyExc_KeyError)
PYBIND11_RUNTIME_EXCEPTION(value_error, PyExc_ValueError)
PYBIND11_RUNTIME_EXCEPTION(type_error, PyExc_TypeError)
PYBIND11_RUNTIME_EXCEPTION(buffer_error, PyExc_BufferError)
PYBIND11_RUNTIME_EXCEPTION(import_error, PyExc_ImportError)
PYBIND11_RUNTIME_EXCEPTION(attribute_error, PyExc_AttributeError)
PYBIND11_RUNTIME_EXCEPTION(cast_error, PyExc_RuntimeError) /// Thrown when pybind11::cast or
/// handle::call fail due to a type
/// casting error
PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError) /// Used internally
[[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const char *reason) {
assert(!PyErr_Occurred());
throw std::runtime_error(reason);
}
[[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const std::string &reason) {
assert(!PyErr_Occurred());
throw std::runtime_error(reason);
}
template <typename T, typename SFINAE = void>
struct format_descriptor {};
template <typename T>
struct format_descriptor<
T,
detail::enable_if_t<detail::is_same_ignoring_cvref<T, PyObject *>::value>> {
static constexpr const char c = 'O';
static constexpr const char value[2] = {c, '\0'};
static std::string format() { return std::string(1, c); }
};
PYBIND11_NAMESPACE_BEGIN(detail)
// Returns the index of the given type in the type char array below, and in the list in numpy.h
// The order here is: bool; 8 ints ((signed,unsigned)x(8,16,32,64)bits); float,double,long double;
// complex float,double,long double. Note that the long double types only participate when long
// double is actually longer than double (it isn't under MSVC).
// NB: not only the string below but also complex.h and numpy.h rely on this order.
template <typename T, typename SFINAE = void>
struct is_fmt_numeric {
static constexpr bool value = false;
};
template <typename T>
struct is_fmt_numeric<T, enable_if_t<std::is_arithmetic<T>::value>> {
static constexpr bool value = true;
static constexpr int index
= std::is_same<T, bool>::value
? 0
: 1
+ (std::is_integral<T>::value
? detail::log2(sizeof(T)) * 2 + std::is_unsigned<T>::value
: 8
+ (std::is_same<T, double>::value ? 1
: std::is_same<T, long double>::value ? 2
: 0));
};
PYBIND11_NAMESPACE_END(detail)
template <typename T>
struct format_descriptor<T, detail::enable_if_t<std::is_arithmetic<T>::value>> {
static constexpr const char c = "?bBhHiIqQfdg"[detail::is_fmt_numeric<T>::index];
static constexpr const char value[2] = {c, '\0'};
static std::string format() { return std::string(1, c); }
};
#if !defined(PYBIND11_CPP17)
template <typename T>
constexpr const char
format_descriptor<T, detail::enable_if_t<std::is_arithmetic<T>::value>>::value[2];
#endif
/// RAII wrapper that temporarily clears any Python error state
struct error_scope {
PyObject *type, *value, *trace;
error_scope() { PyErr_Fetch(&type, &value, &trace); }
error_scope(const error_scope &) = delete;
error_scope &operator=(const error_scope &) = delete;
~error_scope() { PyErr_Restore(type, value, trace); }
};
/// Dummy destructor wrapper that can be used to expose classes with a private destructor
struct nodelete {
template <typename T>
void operator()(T *) {}
};
PYBIND11_NAMESPACE_BEGIN(detail)
template <typename... Args>
struct overload_cast_impl {
template <typename Return>
constexpr auto operator()(Return (*pf)(Args...)) const noexcept -> decltype(pf) {
return pf;
}
template <typename Return, typename Class>
constexpr auto operator()(Return (Class::*pmf)(Args...),
std::false_type = {}) const noexcept -> decltype(pmf) {
return pmf;
}
template <typename Return, typename Class>
constexpr auto operator()(Return (Class::*pmf)(Args...) const,
std::true_type) const noexcept -> decltype(pmf) {
return pmf;
}
};
PYBIND11_NAMESPACE_END(detail)
// overload_cast requires variable templates: C++14
#if defined(PYBIND11_CPP14)
# define PYBIND11_OVERLOAD_CAST 1
/// Syntax sugar for resolving overloaded function pointers:
/// - regular: static_cast<Return (Class::*)(Arg0, Arg1, Arg2)>(&Class::func)
/// - sweet: overload_cast<Arg0, Arg1, Arg2>(&Class::func)
template <typename... Args>
static constexpr detail::overload_cast_impl<Args...> overload_cast{};
#endif
/// Const member function selector for overload_cast
/// - regular: static_cast<Return (Class::*)(Arg) const>(&Class::func)
/// - sweet: overload_cast<Arg>(&Class::func, const_)
static constexpr auto const_ = std::true_type{};
#if !defined(PYBIND11_CPP14) // no overload_cast: providing something that static_assert-fails:
template <typename... Args>
struct overload_cast {
static_assert(detail::deferred_t<std::false_type, Args...>::value,
"pybind11::overload_cast<...> requires compiling in C++14 mode");
};
#endif // overload_cast
PYBIND11_NAMESPACE_BEGIN(detail)
// Adaptor for converting arbitrary container arguments into a vector; implicitly convertible from
// any standard container (or C-style array) supporting std::begin/std::end, any singleton
// arithmetic type (if T is arithmetic), or explicitly constructible from an iterator pair.
template <typename T>
class any_container {
std::vector<T> v;
public:
any_container() = default;
// Can construct from a pair of iterators
template <typename It, typename = enable_if_t<is_input_iterator<It>::value>>
any_container(It first, It last) : v(first, last) {}
// Implicit conversion constructor from any arbitrary container type
// with values convertible to T
template <typename Container,
typename = enable_if_t<
std::is_convertible<decltype(*std::begin(std::declval<const Container &>())),
T>::value>>
// NOLINTNEXTLINE(google-explicit-constructor)
any_container(const Container &c) : any_container(std::begin(c), std::end(c)) {}
// initializer_list's aren't deducible, so don't get matched by the above template;
// we need this to explicitly allow implicit conversion from one:
template <typename TIn, typename = enable_if_t<std::is_convertible<TIn, T>::value>>
any_container(const std::initializer_list<TIn> &c) : any_container(c.begin(), c.end()) {}
// Avoid copying if given an rvalue vector of the correct type.
// NOLINTNEXTLINE(google-explicit-constructor)
any_container(std::vector<T> &&v) : v(std::move(v)) {}
// Moves the vector out of an rvalue any_container
// NOLINTNEXTLINE(google-explicit-constructor)
operator std::vector<T> &&() && { return std::move(v); }
// Dereferencing obtains a reference to the underlying vector
std::vector<T> &operator*() { return v; }
const std::vector<T> &operator*() const { return v; }
// -> lets you call methods on the underlying vector
std::vector<T> *operator->() { return &v; }
const std::vector<T> *operator->() const { return &v; }
};
// Forward-declaration; see detail/class.h
std::string get_fully_qualified_tp_name(PyTypeObject *);
template <typename T>
inline static std::shared_ptr<T>
try_get_shared_from_this(std::enable_shared_from_this<T> *holder_value_ptr) {
// Pre C++17, this code path exploits undefined behavior, but is known to work on many platforms.
// Use at your own risk!
// See also https://en.cppreference.com/w/cpp/memory/enable_shared_from_this, and in particular
// the `std::shared_ptr<Good> gp1 = not_so_good.getptr();` and `try`-`catch` parts of the example.
#if defined(__cpp_lib_enable_shared_from_this) && (!defined(_MSC_VER) || _MSC_VER >= 1912)
return holder_value_ptr->weak_from_this().lock();
#else
try {
return holder_value_ptr->shared_from_this();
} catch (const std::bad_weak_ptr &) {
return nullptr;
}
#endif
}
// For silencing "unused" compiler warnings in special situations.
template <typename... Args>
#if defined(_MSC_VER) && _MSC_VER < 1920 // MSVC 2017
constexpr
#endif
inline void
silence_unused_warnings(Args &&...) {
}
// MSVC warning C4100: Unreferenced formal parameter
#if defined(_MSC_VER) && _MSC_VER <= 1916
# define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...) \
detail::silence_unused_warnings(__VA_ARGS__)
#else
# define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...)
#endif
// GCC -Wunused-but-set-parameter All GCC versions (as of July 2021).
#if defined(__GNUG__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
# define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(...) \
detail::silence_unused_warnings(__VA_ARGS__)
#else
# define PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(...)
#endif
#if defined(__clang__) \
&& (defined(__apple_build_version__) /* AppleClang 13.0.0.13000029 was the only data point \
available. */ \
|| (__clang_major__ >= 7 \
&& __clang_major__ <= 12) /* Clang 3, 5, 13, 14, 15 do not generate the warning. */ \
)
# define PYBIND11_DETECTED_CLANG_WITH_MISLEADING_CALL_STD_MOVE_EXPLICITLY_WARNING
// Example:
// tests/test_kwargs_and_defaults.cpp:46:68: error: local variable 'args' will be copied despite
// being returned by name [-Werror,-Wreturn-std-move]
// m.def("args_function", [](py::args args) -> py::tuple { return args; });
// ^~~~
// test_kwargs_and_defaults.cpp:46:68: note: call 'std::move' explicitly to avoid copying
// m.def("args_function", [](py::args args) -> py::tuple { return args; });
// ^~~~
// std::move(args)
#endif
// Pybind offers detailed error messages by default for all builts that are debug (through the
// negation of NDEBUG). This can also be manually enabled by users, for any builds, through
// defining PYBIND11_DETAILED_ERROR_MESSAGES. This information is primarily useful for those
// who are writing (as opposed to merely using) libraries that use pybind11.
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) && !defined(NDEBUG)
# define PYBIND11_DETAILED_ERROR_MESSAGES
#endif
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)