knx/include/pybind11/detail/internals.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

750 lines
31 KiB
C++

/*
pybind11/detail/internals.h: Internal data structure and related functions
Copyright (c) 2017 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
#include "common.h"
#if defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
# include "../gil.h"
#endif
#include "../pytypes.h"
#include <exception>
#include <mutex>
#include <thread>
/// Tracks the `internals` and `type_info` ABI version independent of the main library version.
///
/// Some portions of the code use an ABI that is conditional depending on this
/// version number. That allows ABI-breaking changes to be "pre-implemented".
/// Once the default version number is incremented, the conditional logic that
/// no longer applies can be removed. Additionally, users that need not
/// maintain ABI compatibility can increase the version number in order to take
/// advantage of any functionality/efficiency improvements that depend on the
/// newer ABI.
///
/// WARNING: If you choose to manually increase the ABI version, note that
/// pybind11 may not be tested as thoroughly with a non-default ABI version, and
/// further ABI-incompatible changes may be made before the ABI is officially
/// changed to the new version.
#ifndef PYBIND11_INTERNALS_VERSION
# if PY_VERSION_HEX >= 0x030C0000 || defined(_MSC_VER)
// Version bump for Python 3.12+, before first 3.12 beta release.
// Version bump for MSVC piggy-backed on PR #4779. See comments there.
# define PYBIND11_INTERNALS_VERSION 5
# else
# define PYBIND11_INTERNALS_VERSION 4
# endif
#endif
// This requirement is mainly to reduce the support burden (see PR #4570).
static_assert(PY_VERSION_HEX < 0x030C0000 || PYBIND11_INTERNALS_VERSION >= 5,
"pybind11 ABI version 5 is the minimum for Python 3.12+");
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
using ExceptionTranslator = void (*)(std::exception_ptr);
PYBIND11_NAMESPACE_BEGIN(detail)
constexpr const char *internals_function_record_capsule_name = "pybind11_function_record_capsule";
// Forward declarations
inline PyTypeObject *make_static_property_type();
inline PyTypeObject *make_default_metaclass();
inline PyObject *make_object_base_type(PyTypeObject *metaclass);
// The old Python Thread Local Storage (TLS) API is deprecated in Python 3.7 in favor of the new
// Thread Specific Storage (TSS) API.
// Avoid unnecessary allocation of `Py_tss_t`, since we cannot use
// `Py_LIMITED_API` anyway.
#if PYBIND11_INTERNALS_VERSION > 4
# define PYBIND11_TLS_KEY_REF Py_tss_t &
# if defined(__clang__)
# define PYBIND11_TLS_KEY_INIT(var) \
_Pragma("clang diagnostic push") /**/ \
_Pragma("clang diagnostic ignored \"-Wmissing-field-initializers\"") /**/ \
Py_tss_t var \
= Py_tss_NEEDS_INIT; \
_Pragma("clang diagnostic pop")
# elif defined(__GNUC__) && !defined(__INTEL_COMPILER)
# define PYBIND11_TLS_KEY_INIT(var) \
_Pragma("GCC diagnostic push") /**/ \
_Pragma("GCC diagnostic ignored \"-Wmissing-field-initializers\"") /**/ \
Py_tss_t var \
= Py_tss_NEEDS_INIT; \
_Pragma("GCC diagnostic pop")
# else
# define PYBIND11_TLS_KEY_INIT(var) Py_tss_t var = Py_tss_NEEDS_INIT;
# endif
# define PYBIND11_TLS_KEY_CREATE(var) (PyThread_tss_create(&(var)) == 0)
# define PYBIND11_TLS_GET_VALUE(key) PyThread_tss_get(&(key))
# define PYBIND11_TLS_REPLACE_VALUE(key, value) PyThread_tss_set(&(key), (value))
# define PYBIND11_TLS_DELETE_VALUE(key) PyThread_tss_set(&(key), nullptr)
# define PYBIND11_TLS_FREE(key) PyThread_tss_delete(&(key))
#else
# define PYBIND11_TLS_KEY_REF Py_tss_t *
# define PYBIND11_TLS_KEY_INIT(var) Py_tss_t *var = nullptr;
# define PYBIND11_TLS_KEY_CREATE(var) \
(((var) = PyThread_tss_alloc()) != nullptr && (PyThread_tss_create((var)) == 0))
# define PYBIND11_TLS_GET_VALUE(key) PyThread_tss_get((key))
# define PYBIND11_TLS_REPLACE_VALUE(key, value) PyThread_tss_set((key), (value))
# define PYBIND11_TLS_DELETE_VALUE(key) PyThread_tss_set((key), nullptr)
# define PYBIND11_TLS_FREE(key) PyThread_tss_free(key)
#endif
// Python loads modules by default with dlopen with the RTLD_LOCAL flag; under libc++ and possibly
// other STLs, this means `typeid(A)` from one module won't equal `typeid(A)` from another module
// even when `A` is the same, non-hidden-visibility type (e.g. from a common include). Under
// libstdc++, this doesn't happen: equality and the type_index hash are based on the type name,
// which works. If not under a known-good stl, provide our own name-based hash and equality
// functions that use the type name.
#if (PYBIND11_INTERNALS_VERSION <= 4 && defined(__GLIBCXX__)) \
|| (PYBIND11_INTERNALS_VERSION >= 5 && !defined(_LIBCPP_VERSION))
inline bool same_type(const std::type_info &lhs, const std::type_info &rhs) { return lhs == rhs; }
using type_hash = std::hash<std::type_index>;
using type_equal_to = std::equal_to<std::type_index>;
#else
inline bool same_type(const std::type_info &lhs, const std::type_info &rhs) {
return lhs.name() == rhs.name() || std::strcmp(lhs.name(), rhs.name()) == 0;
}
struct type_hash {
size_t operator()(const std::type_index &t) const {
size_t hash = 5381;
const char *ptr = t.name();
while (auto c = static_cast<unsigned char>(*ptr++)) {
hash = (hash * 33) ^ c;
}
return hash;
}
};
struct type_equal_to {
bool operator()(const std::type_index &lhs, const std::type_index &rhs) const {
return lhs.name() == rhs.name() || std::strcmp(lhs.name(), rhs.name()) == 0;
}
};
#endif
template <typename value_type>
using type_map = std::unordered_map<std::type_index, value_type, type_hash, type_equal_to>;
struct override_hash {
inline size_t operator()(const std::pair<const PyObject *, const char *> &v) const {
size_t value = std::hash<const void *>()(v.first);
value ^= std::hash<const void *>()(v.second) + 0x9e3779b9 + (value << 6) + (value >> 2);
return value;
}
};
using instance_map = std::unordered_multimap<const void *, instance *>;
// Instance map shards are used to reduce mutex contention in free-threaded Python.
struct instance_map_shard {
std::mutex mutex;
instance_map registered_instances;
// alignas(64) would be better, but causes compile errors in macOS before 10.14 (see #5200)
char padding[64 - (sizeof(std::mutex) + sizeof(instance_map)) % 64];
};
/// Internal data structure used to track registered instances and types.
/// Whenever binary incompatible changes are made to this structure,
/// `PYBIND11_INTERNALS_VERSION` must be incremented.
struct internals {
#ifdef Py_GIL_DISABLED
std::mutex mutex;
#endif
// std::type_index -> pybind11's type information
type_map<type_info *> registered_types_cpp;
// PyTypeObject* -> base type_info(s)
std::unordered_map<PyTypeObject *, std::vector<type_info *>> registered_types_py;
#ifdef Py_GIL_DISABLED
std::unique_ptr<instance_map_shard[]> instance_shards; // void * -> instance*
size_t instance_shards_mask;
#else
instance_map registered_instances; // void * -> instance*
#endif
std::unordered_set<std::pair<const PyObject *, const char *>, override_hash>
inactive_override_cache;
type_map<std::vector<bool (*)(PyObject *, void *&)>> direct_conversions;
std::unordered_map<const PyObject *, std::vector<PyObject *>> patients;
std::forward_list<ExceptionTranslator> registered_exception_translators;
std::unordered_map<std::string, void *> shared_data; // Custom data to be shared across
// extensions
#if PYBIND11_INTERNALS_VERSION == 4
std::vector<PyObject *> unused_loader_patient_stack_remove_at_v5;
#endif
std::forward_list<std::string> static_strings; // Stores the std::strings backing
// detail::c_str()
PyTypeObject *static_property_type;
PyTypeObject *default_metaclass;
PyObject *instance_base;
// Unused if PYBIND11_SIMPLE_GIL_MANAGEMENT is defined:
PYBIND11_TLS_KEY_INIT(tstate)
#if PYBIND11_INTERNALS_VERSION > 4
PYBIND11_TLS_KEY_INIT(loader_life_support_tls_key)
#endif // PYBIND11_INTERNALS_VERSION > 4
// Unused if PYBIND11_SIMPLE_GIL_MANAGEMENT is defined:
PyInterpreterState *istate = nullptr;
#if PYBIND11_INTERNALS_VERSION > 4
// Note that we have to use a std::string to allocate memory to ensure a unique address
// We want unique addresses since we use pointer equality to compare function records
std::string function_record_capsule_name = internals_function_record_capsule_name;
#endif
internals() = default;
internals(const internals &other) = delete;
internals &operator=(const internals &other) = delete;
~internals() {
#if PYBIND11_INTERNALS_VERSION > 4
PYBIND11_TLS_FREE(loader_life_support_tls_key);
#endif // PYBIND11_INTERNALS_VERSION > 4
// This destructor is called *after* Py_Finalize() in finalize_interpreter().
// That *SHOULD BE* fine. The following details what happens when PyThread_tss_free is
// called. PYBIND11_TLS_FREE is PyThread_tss_free on python 3.7+. On older python, it does
// nothing. PyThread_tss_free calls PyThread_tss_delete and PyMem_RawFree.
// PyThread_tss_delete just calls TlsFree (on Windows) or pthread_key_delete (on *NIX).
// Neither of those have anything to do with CPython internals. PyMem_RawFree *requires*
// that the `tstate` be allocated with the CPython allocator.
PYBIND11_TLS_FREE(tstate);
}
};
/// Additional type information which does not fit into the PyTypeObject.
/// Changes to this struct also require bumping `PYBIND11_INTERNALS_VERSION`.
struct type_info {
PyTypeObject *type;
const std::type_info *cpptype;
size_t type_size, type_align, holder_size_in_ptrs;
void *(*operator_new)(size_t);
void (*init_instance)(instance *, const void *);
void (*dealloc)(value_and_holder &v_h);
std::vector<PyObject *(*) (PyObject *, PyTypeObject *)> implicit_conversions;
std::vector<std::pair<const std::type_info *, void *(*) (void *)>> implicit_casts;
std::vector<bool (*)(PyObject *, void *&)> *direct_conversions;
buffer_info *(*get_buffer)(PyObject *, void *) = nullptr;
void *get_buffer_data = nullptr;
void *(*module_local_load)(PyObject *, const type_info *) = nullptr;
/* A simple type never occurs as a (direct or indirect) parent
* of a class that makes use of multiple inheritance.
* A type can be simple even if it has non-simple ancestors as long as it has no descendants.
*/
bool simple_type : 1;
/* True if there is no multiple inheritance in this type's inheritance tree */
bool simple_ancestors : 1;
/* for base vs derived holder_type checks */
bool default_holder : 1;
/* true if this is a type registered with py::module_local */
bool module_local : 1;
};
/// On MSVC, debug and release builds are not ABI-compatible!
#if defined(_MSC_VER) && defined(_DEBUG)
# define PYBIND11_BUILD_TYPE "_debug"
#else
# define PYBIND11_BUILD_TYPE ""
#endif
/// Let's assume that different compilers are ABI-incompatible.
/// A user can manually set this string if they know their
/// compiler is compatible.
#ifndef PYBIND11_COMPILER_TYPE
# if defined(_MSC_VER)
# define PYBIND11_COMPILER_TYPE "_msvc"
# elif defined(__INTEL_COMPILER)
# define PYBIND11_COMPILER_TYPE "_icc"
# elif defined(__clang__)
# define PYBIND11_COMPILER_TYPE "_clang"
# elif defined(__PGI)
# define PYBIND11_COMPILER_TYPE "_pgi"
# elif defined(__MINGW32__)
# define PYBIND11_COMPILER_TYPE "_mingw"
# elif defined(__CYGWIN__)
# define PYBIND11_COMPILER_TYPE "_gcc_cygwin"
# elif defined(__GNUC__)
# define PYBIND11_COMPILER_TYPE "_gcc"
# else
# define PYBIND11_COMPILER_TYPE "_unknown"
# endif
#endif
/// Also standard libs
#ifndef PYBIND11_STDLIB
# if defined(_LIBCPP_VERSION)
# define PYBIND11_STDLIB "_libcpp"
# elif defined(__GLIBCXX__) || defined(__GLIBCPP__)
# define PYBIND11_STDLIB "_libstdcpp"
# else
# define PYBIND11_STDLIB ""
# endif
#endif
/// On Linux/OSX, changes in __GXX_ABI_VERSION__ indicate ABI incompatibility.
/// On MSVC, changes in _MSC_VER may indicate ABI incompatibility (#2898).
#ifndef PYBIND11_BUILD_ABI
# if defined(__GXX_ABI_VERSION)
# define PYBIND11_BUILD_ABI "_cxxabi" PYBIND11_TOSTRING(__GXX_ABI_VERSION)
# elif defined(_MSC_VER)
# define PYBIND11_BUILD_ABI "_mscver" PYBIND11_TOSTRING(_MSC_VER)
# else
# define PYBIND11_BUILD_ABI ""
# endif
#endif
#ifndef PYBIND11_INTERNALS_KIND
# define PYBIND11_INTERNALS_KIND ""
#endif
#define PYBIND11_INTERNALS_ID \
"__pybind11_internals_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB \
PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__"
#define PYBIND11_MODULE_LOCAL_ID \
"__pybind11_module_local_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB \
PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__"
/// Each module locally stores a pointer to the `internals` data. The data
/// itself is shared among modules with the same `PYBIND11_INTERNALS_ID`.
inline internals **&get_internals_pp() {
static internals **internals_pp = nullptr;
return internals_pp;
}
// forward decl
inline void translate_exception(std::exception_ptr);
template <class T,
enable_if_t<std::is_same<std::nested_exception, remove_cvref_t<T>>::value, int> = 0>
bool handle_nested_exception(const T &exc, const std::exception_ptr &p) {
std::exception_ptr nested = exc.nested_ptr();
if (nested != nullptr && nested != p) {
translate_exception(nested);
return true;
}
return false;
}
template <class T,
enable_if_t<!std::is_same<std::nested_exception, remove_cvref_t<T>>::value, int> = 0>
bool handle_nested_exception(const T &exc, const std::exception_ptr &p) {
if (const auto *nep = dynamic_cast<const std::nested_exception *>(std::addressof(exc))) {
return handle_nested_exception(*nep, p);
}
return false;
}
inline bool raise_err(PyObject *exc_type, const char *msg) {
if (PyErr_Occurred()) {
raise_from(exc_type, msg);
return true;
}
set_error(exc_type, msg);
return false;
}
inline void translate_exception(std::exception_ptr p) {
if (!p) {
return;
}
try {
std::rethrow_exception(p);
} catch (error_already_set &e) {
handle_nested_exception(e, p);
e.restore();
return;
} catch (const builtin_exception &e) {
// Could not use template since it's an abstract class.
if (const auto *nep = dynamic_cast<const std::nested_exception *>(std::addressof(e))) {
handle_nested_exception(*nep, p);
}
e.set_error();
return;
} catch (const std::bad_alloc &e) {
handle_nested_exception(e, p);
raise_err(PyExc_MemoryError, e.what());
return;
} catch (const std::domain_error &e) {
handle_nested_exception(e, p);
raise_err(PyExc_ValueError, e.what());
return;
} catch (const std::invalid_argument &e) {
handle_nested_exception(e, p);
raise_err(PyExc_ValueError, e.what());
return;
} catch (const std::length_error &e) {
handle_nested_exception(e, p);
raise_err(PyExc_ValueError, e.what());
return;
} catch (const std::out_of_range &e) {
handle_nested_exception(e, p);
raise_err(PyExc_IndexError, e.what());
return;
} catch (const std::range_error &e) {
handle_nested_exception(e, p);
raise_err(PyExc_ValueError, e.what());
return;
} catch (const std::overflow_error &e) {
handle_nested_exception(e, p);
raise_err(PyExc_OverflowError, e.what());
return;
} catch (const std::exception &e) {
handle_nested_exception(e, p);
raise_err(PyExc_RuntimeError, e.what());
return;
} catch (const std::nested_exception &e) {
handle_nested_exception(e, p);
raise_err(PyExc_RuntimeError, "Caught an unknown nested exception!");
return;
} catch (...) {
raise_err(PyExc_RuntimeError, "Caught an unknown exception!");
return;
}
}
#if !defined(__GLIBCXX__)
inline void translate_local_exception(std::exception_ptr p) {
try {
if (p) {
std::rethrow_exception(p);
}
} catch (error_already_set &e) {
e.restore();
return;
} catch (const builtin_exception &e) {
e.set_error();
return;
}
}
#endif
inline object get_python_state_dict() {
object state_dict;
#if PYBIND11_INTERNALS_VERSION <= 4 || PY_VERSION_HEX < 0x03080000 || defined(PYPY_VERSION)
state_dict = reinterpret_borrow<object>(PyEval_GetBuiltins());
#else
# if PY_VERSION_HEX < 0x03090000
PyInterpreterState *istate = _PyInterpreterState_Get();
# else
PyInterpreterState *istate = PyInterpreterState_Get();
# endif
if (istate) {
state_dict = reinterpret_borrow<object>(PyInterpreterState_GetDict(istate));
}
#endif
if (!state_dict) {
raise_from(PyExc_SystemError, "pybind11::detail::get_python_state_dict() FAILED");
throw error_already_set();
}
return state_dict;
}
inline object get_internals_obj_from_state_dict(handle state_dict) {
return reinterpret_steal<object>(
dict_getitemstringref(state_dict.ptr(), PYBIND11_INTERNALS_ID));
}
inline internals **get_internals_pp_from_capsule(handle obj) {
void *raw_ptr = PyCapsule_GetPointer(obj.ptr(), /*name=*/nullptr);
if (raw_ptr == nullptr) {
raise_from(PyExc_SystemError, "pybind11::detail::get_internals_pp_from_capsule() FAILED");
throw error_already_set();
}
return static_cast<internals **>(raw_ptr);
}
inline uint64_t round_up_to_next_pow2(uint64_t x) {
// Round-up to the next power of two.
// See https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
x--;
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
x |= (x >> 32);
x++;
return x;
}
/// Return a reference to the current `internals` data
PYBIND11_NOINLINE internals &get_internals() {
auto **&internals_pp = get_internals_pp();
if (internals_pp && *internals_pp) {
return **internals_pp;
}
#if defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
gil_scoped_acquire gil;
#else
// Ensure that the GIL is held since we will need to make Python calls.
// Cannot use py::gil_scoped_acquire here since that constructor calls get_internals.
struct gil_scoped_acquire_local {
gil_scoped_acquire_local() : state(PyGILState_Ensure()) {}
gil_scoped_acquire_local(const gil_scoped_acquire_local &) = delete;
gil_scoped_acquire_local &operator=(const gil_scoped_acquire_local &) = delete;
~gil_scoped_acquire_local() { PyGILState_Release(state); }
const PyGILState_STATE state;
} gil;
#endif
error_scope err_scope;
dict state_dict = get_python_state_dict();
if (object internals_obj = get_internals_obj_from_state_dict(state_dict)) {
internals_pp = get_internals_pp_from_capsule(internals_obj);
}
if (internals_pp && *internals_pp) {
// We loaded the internals through `state_dict`, which means that our `error_already_set`
// and `builtin_exception` may be different local classes than the ones set up in the
// initial exception translator, below, so add another for our local exception classes.
//
// libstdc++ doesn't require this (types there are identified only by name)
// libc++ with CPython doesn't require this (types are explicitly exported)
// libc++ with PyPy still need it, awaiting further investigation
#if !defined(__GLIBCXX__)
(*internals_pp)->registered_exception_translators.push_front(&translate_local_exception);
#endif
} else {
if (!internals_pp) {
internals_pp = new internals *();
}
auto *&internals_ptr = *internals_pp;
internals_ptr = new internals();
PyThreadState *tstate = PyThreadState_Get();
// NOLINTNEXTLINE(bugprone-assignment-in-if-condition)
if (!PYBIND11_TLS_KEY_CREATE(internals_ptr->tstate)) {
pybind11_fail("get_internals: could not successfully initialize the tstate TSS key!");
}
PYBIND11_TLS_REPLACE_VALUE(internals_ptr->tstate, tstate);
#if PYBIND11_INTERNALS_VERSION > 4
// NOLINTNEXTLINE(bugprone-assignment-in-if-condition)
if (!PYBIND11_TLS_KEY_CREATE(internals_ptr->loader_life_support_tls_key)) {
pybind11_fail("get_internals: could not successfully initialize the "
"loader_life_support TSS key!");
}
#endif
internals_ptr->istate = tstate->interp;
state_dict[PYBIND11_INTERNALS_ID] = capsule(internals_pp);
internals_ptr->registered_exception_translators.push_front(&translate_exception);
internals_ptr->static_property_type = make_static_property_type();
internals_ptr->default_metaclass = make_default_metaclass();
internals_ptr->instance_base = make_object_base_type(internals_ptr->default_metaclass);
#ifdef Py_GIL_DISABLED
// Scale proportional to the number of cores. 2x is a heuristic to reduce contention.
auto num_shards
= static_cast<size_t>(round_up_to_next_pow2(2 * std::thread::hardware_concurrency()));
if (num_shards == 0) {
num_shards = 1;
}
internals_ptr->instance_shards.reset(new instance_map_shard[num_shards]);
internals_ptr->instance_shards_mask = num_shards - 1;
#endif // Py_GIL_DISABLED
}
return **internals_pp;
}
// the internals struct (above) is shared between all the modules. local_internals are only
// for a single module. Any changes made to internals may require an update to
// PYBIND11_INTERNALS_VERSION, breaking backwards compatibility. local_internals is, by design,
// restricted to a single module. Whether a module has local internals or not should not
// impact any other modules, because the only things accessing the local internals is the
// module that contains them.
struct local_internals {
type_map<type_info *> registered_types_cpp;
std::forward_list<ExceptionTranslator> registered_exception_translators;
#if PYBIND11_INTERNALS_VERSION == 4
// For ABI compatibility, we can't store the loader_life_support TLS key in
// the `internals` struct directly. Instead, we store it in `shared_data` and
// cache a copy in `local_internals`. If we allocated a separate TLS key for
// each instance of `local_internals`, we could end up allocating hundreds of
// TLS keys if hundreds of different pybind11 modules are loaded (which is a
// plausible number).
PYBIND11_TLS_KEY_INIT(loader_life_support_tls_key)
// Holds the shared TLS key for the loader_life_support stack.
struct shared_loader_life_support_data {
PYBIND11_TLS_KEY_INIT(loader_life_support_tls_key)
shared_loader_life_support_data() {
// NOLINTNEXTLINE(bugprone-assignment-in-if-condition)
if (!PYBIND11_TLS_KEY_CREATE(loader_life_support_tls_key)) {
pybind11_fail("local_internals: could not successfully initialize the "
"loader_life_support TLS key!");
}
}
// We can't help but leak the TLS key, because Python never unloads extension modules.
};
local_internals() {
auto &internals = get_internals();
// Get or create the `loader_life_support_stack_key`.
auto &ptr = internals.shared_data["_life_support"];
if (!ptr) {
ptr = new shared_loader_life_support_data;
}
loader_life_support_tls_key
= static_cast<shared_loader_life_support_data *>(ptr)->loader_life_support_tls_key;
}
#endif // PYBIND11_INTERNALS_VERSION == 4
};
/// Works like `get_internals`, but for things which are locally registered.
inline local_internals &get_local_internals() {
// Current static can be created in the interpreter finalization routine. If the later will be
// destroyed in another static variable destructor, creation of this static there will cause
// static deinitialization fiasco. In order to avoid it we avoid destruction of the
// local_internals static. One can read more about the problem and current solution here:
// https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables
static auto *locals = new local_internals();
return *locals;
}
#ifdef Py_GIL_DISABLED
# define PYBIND11_LOCK_INTERNALS(internals) std::unique_lock<std::mutex> lock((internals).mutex)
#else
# define PYBIND11_LOCK_INTERNALS(internals)
#endif
template <typename F>
inline auto with_internals(const F &cb) -> decltype(cb(get_internals())) {
auto &internals = get_internals();
PYBIND11_LOCK_INTERNALS(internals);
return cb(internals);
}
inline std::uint64_t mix64(std::uint64_t z) {
// David Stafford's variant 13 of the MurmurHash3 finalizer popularized
// by the SplitMix PRNG.
// https://zimbry.blogspot.com/2011/09/better-bit-mixing-improving-on.html
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
return z ^ (z >> 31);
}
template <typename F>
inline auto with_instance_map(const void *ptr,
const F &cb) -> decltype(cb(std::declval<instance_map &>())) {
auto &internals = get_internals();
#ifdef Py_GIL_DISABLED
// Hash address to compute shard, but ignore low bits. We'd like allocations
// from the same thread/core to map to the same shard and allocations from
// other threads/cores to map to other shards. Using the high bits is a good
// heuristic because memory allocators often have a per-thread
// arena/superblock/segment from which smaller allocations are served.
auto addr = reinterpret_cast<std::uintptr_t>(ptr);
auto hash = mix64(static_cast<std::uint64_t>(addr >> 20));
auto idx = static_cast<size_t>(hash & internals.instance_shards_mask);
auto &shard = internals.instance_shards[idx];
std::unique_lock<std::mutex> lock(shard.mutex);
return cb(shard.registered_instances);
#else
(void) ptr;
return cb(internals.registered_instances);
#endif
}
// Returns the number of registered instances for testing purposes. The result may not be
// consistent if other threads are registering or unregistering instances concurrently.
inline size_t num_registered_instances() {
auto &internals = get_internals();
#ifdef Py_GIL_DISABLED
size_t count = 0;
for (size_t i = 0; i <= internals.instance_shards_mask; ++i) {
auto &shard = internals.instance_shards[i];
std::unique_lock<std::mutex> lock(shard.mutex);
count += shard.registered_instances.size();
}
return count;
#else
return internals.registered_instances.size();
#endif
}
/// Constructs a std::string with the given arguments, stores it in `internals`, and returns its
/// `c_str()`. Such strings objects have a long storage duration -- the internal strings are only
/// cleared when the program exits or after interpreter shutdown (when embedding), and so are
/// suitable for c-style strings needed by Python internals (such as PyTypeObject's tp_name).
template <typename... Args>
const char *c_str(Args &&...args) {
// GCC 4.8 doesn't like parameter unpack within lambda capture, so use
// PYBIND11_LOCK_INTERNALS.
auto &internals = get_internals();
PYBIND11_LOCK_INTERNALS(internals);
auto &strings = internals.static_strings;
strings.emplace_front(std::forward<Args>(args)...);
return strings.front().c_str();
}
inline const char *get_function_record_capsule_name() {
#if PYBIND11_INTERNALS_VERSION > 4
return get_internals().function_record_capsule_name.c_str();
#else
return nullptr;
#endif
}
// Determine whether or not the following capsule contains a pybind11 function record.
// Note that we use `internals` to make sure that only ABI compatible records are touched.
//
// This check is currently used in two places:
// - An important optimization in functional.h to avoid overhead in C++ -> Python -> C++
// - The sibling feature of cpp_function to allow overloads
inline bool is_function_record_capsule(const capsule &cap) {
// Pointer equality as we rely on internals() to ensure unique pointers
return cap.name() == get_function_record_capsule_name();
}
PYBIND11_NAMESPACE_END(detail)
/// Returns a named pointer that is shared among all extension modules (using the same
/// pybind11 version) running in the current interpreter. Names starting with underscores
/// are reserved for internal usage. Returns `nullptr` if no matching entry was found.
PYBIND11_NOINLINE void *get_shared_data(const std::string &name) {
return detail::with_internals([&](detail::internals &internals) {
auto it = internals.shared_data.find(name);
return it != internals.shared_data.end() ? it->second : nullptr;
});
}
/// Set the shared data that can be later recovered by `get_shared_data()`.
PYBIND11_NOINLINE void *set_shared_data(const std::string &name, void *data) {
return detail::with_internals([&](detail::internals &internals) {
internals.shared_data[name] = data;
return data;
});
}
/// Returns a typed reference to a shared data entry (by using `get_shared_data()`) if
/// such entry exists. Otherwise, a new object of default-constructible type `T` is
/// added to the shared data under the given name and a reference to it is returned.
template <typename T>
T &get_or_create_shared_data(const std::string &name) {
return *detail::with_internals([&](detail::internals &internals) {
auto it = internals.shared_data.find(name);
T *ptr = (T *) (it != internals.shared_data.end() ? it->second : nullptr);
if (!ptr) {
ptr = new T();
internals.shared_data[name] = ptr;
}
return ptr;
});
}
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)