* fix: PyCapsule_GetDestructor is allowed to return a nullptr destructor
Previously, this code would error out if the destructor happened to be
a nullptr. This is incorrect. nullptrs are allowed for capsule
destructors.
"It is legal for a capsule to have a NULL destructor. This makes a
NULL return code somewhat ambiguous; use PyCapsule_IsValid() or
PyErr_Occurred() to disambiguate."
See:
https://docs.python.org/3/c-api/capsule.html#c.PyCapsule_GetDestructor
I noticed this while working on a type caster related to #3858 DLPack
happens to allow the destructor not to be defined on a capsule, and I
encountered such a case. See:
e2bdd3bee8/include/dlpack/dlpack.h (L219)
* Add test for the fix.
* Update tests/test_pytypes.cpp
I tried this locally and it works!
I never knew that there are cases where `reinterpret_cast` does not work but `static_cast` does. Let's see if all compilers are happy with this.
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
* style: pre-commit fixes
Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rwgkio@gmail.com>
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Disable test triggering ASAN failure (to pin-point where the problem is).
* Fix unsafe "block" implementation in test_eigen.cpp
* Undo changes (i.e. revert back to master).
* Detect "type_caster for Eigen::Ref made a copy."
This is achieved without
* reaching into internals,
* making test_eigen.cpp depend on pybind11/numpy.h.
* Add comment pointing to PR, for easy reference.
* Work-Around: NVCC 11.4.0 - 11.8.0
Adds a targeted NVCC work around for limited number of CUDA
releases. Fixed in NVCC development.
* style: pre-commit fixes
* CI: Bump CTK Version 11.2 -> 11.7
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Call reserve method in set and map casters too
* Refactor template logic into has_reserve_method
* Adjust comment for reviews
* Rearrange reserve_maybe to not be underneath macro
* Add debug fprintf to test_interpreter.cpp
* Update `sys.path` from `PYTHONPATH` in Python >= 3.11 branch of `initialize_interpreter()`
* Use `config.isolated = 0; config.use_environment = 1;`
As suggsted by @vstinner here: https://github.com/pybind/pybind11/pull/4119#issuecomment-1219442853
* Add `TEST_CASE("PYTHONPATH is used to update sys.path")`
* Fix clang-tidy error.
* Use `_putenv_s()` under Windows.
* Fix clang-tidy error: argument name ... in comment does not match parameter name
* Remove slash from PYTHONPATH addition, to work around Windows slash-vs-backslash issue.
* Use `py::str(...)` instead of `.attr("__str__")` as suggested by @skylion007
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
* add installation support for pkg-config dependency detection
pkg-config is a buildsystem-agnostic alternative to
`pybind11Config.cmake` that can be used from build systems other than
cmake.
Fixes#230
* tests: add test for pkg config
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
* Add `-DPYBIND11_WERROR=ON` to mingw cmake commands (and `-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON`).
* Using no-destructor idiom to side-step overzealous MINGW warning.
* Add __MINGW32__ pragma GCC diagnostic ignored in eigen.h
* Add another no-destructor workaround.
* Temporarily add -k (keep-going) flags to hopefully speed up finding all warnings.
* Revert "Temporarily add -k (keep-going) flags to hopefully speed up finding all warnings."
This reverts commit f36b0af8f9.
* Very minor shuffle to avoid MSVC warnings.
* Remove all `:BOOL` as suggested by @henryiii
* For PyPy only, re-enable old behavior (likely to mask bugs), to avoid segfault with unknown root cause.
Change prompted by https://github.com/pybind/pybind11/issues/4075
* Undo the change in tests/test_exceptions.py
I turns out (I forgot) that PyPy segfaults in `test_flaky_exception_failure_point_init` already before the `MISMATCH` code path is reached:
https://github.com/pybind/pybind11/runs/7383663596
```
RPython traceback:
test_exceptions.py .......X.........Error in cpyext, CPython compatibility layer:
File "pypy_module_cpyext.c", line 14052, in wrapper_second_level__star_3_1
File "pypy_module_cpyext_1.c", line 35750, in not_supposed_to_fail
Fatal Python error: Segmentation fault
Stack (most recent call first, approximate line numbers):
File "/home/runner/work/pybind11/pybind11/tests/test_exceptions.py", line 306 in test_flaky_exception_failure_point_init
The function PyErr_NormalizeException was not supposed to fail
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/python.py", line 185 in pytest_pyfunc_call
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_callers.py", line 9 in _multicall
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_manager.py", line 77 in _hookexec
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_hooks.py", line 244 in __call__
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/python.py", line 1716 in runtest
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/runner.py", line 159 in pytest_runtest_call
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_callers.py", line 9 in _multicall
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_manager.py", line 77 in _hookexec
Fatal error in cpyext, CPython compatibility layer, calling PyErr_NormalizeException
Either report a bug or consider not using this particular extension
<SystemError object at 0x7fcc8cea6868>
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_hooks.py", line 244 in __call__
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/runner.py", line 261 in <lambda>
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/runner.py", line 317 in from_call
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/runner.py", line 246 in call_runtest_hook
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/runner.py", line 218 in call_and_report
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/runner.py", line 118 in runtestprotocol
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/runner.py", line 110 in pytest_runtest_protocol
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_callers.py", line 9 in _multicall
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_manager.py", line 77 in _hookexec
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_hooks.py", line 244 in __call__
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/main.py", line 335 in pytest_runtestloop
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_callers.py", line 9 in _multicall
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_manager.py", line 77 in _hookexec
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_hooks.py", line 244 in __call__
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/main.py", line 318 in _main
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/main.py", line 255 in wrap_session
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/main.py", line 314 in pytest_cmdline_main
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_callers.py", line 9 in _multicall
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_manager.py", line 77 in _hookexec
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pluggy/_hooks.py", line 244 in __call__
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/config/__init__.py", line 133 in main
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/_pytest/config/__init__.py", line 181 in console_main
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/site-packages/pytest/__main__.py", line 1 in <module>
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/lib-python/3/runpy.py", line 62 in _run_code
File "/opt/hostedtoolcache/PyPy/3.7.13/x64/lib-python/3/runpy.py", line 170 in _run_module_as_main
File "<builtin>/app_main.py", line 109 in run_toplevel
File "<builtin>/app_main.py", line 652 in run_command_line
File "<builtin>/app_main.py", line 996 in entry_point
Segmentation fault (core dumped)
```
* Add test_pypy_oserror_normalization
* Disable new `PYPY_VERSION` `#if`, to verify that the new test actually fails.
* Restore PYPY_VERSION workaround and update comment to reflect what was learned.
* [ci skip] Fix trivial oversight in comment.
* Use equals default in pyobject macros
* Remove extra semicolon
* Update clang-tidy equals-default rule to not ignore macros
* Fix formatting
* One last formatting change