1. 16 Nov, 2023 4 commits
    • pybind11.pc: use pcfiledir for relative destinations (#4830) · dc9b3959
      * pybind11.pc: use pcfiledir for relative destinations
      
      If the datarootdir is absolute, just use the absolute path directly.
      However, if it is relative, we can compute the prefix from the location
      of the `.pc` file itself. This allows the install to be relocatable.
      
      * chore: use 3.20's cmake_path if available
      
      * style: pre-commit fixes
      
      * Update CMakeLists.txt
      
      ---------
      
      Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
      Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
      Ben Boeckel committed
    • fix(cmake): findpython issues and 3.12 support for pybind11_find_import (#4941) · 9591cfb0
      * fix(cmake): findpython issues and 3.12 support for pybind11_find_import
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      
      * Update pybind11NewTools.cmake
      
      ---------
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      Henry Schreiner committed
    • ci: add more versions of numpy/scipy/pypy (#4714) · 6831666f
      * ci: add more versions of numpy/scipy/pypy
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      
      * Apply suggestions from code review
      
      * style: pre-commit fixes
      
      * Update requirements.txt
      
      * Update requirements.txt
      
      * Apply suggestions from code review
      
      ---------
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
      Henry Schreiner committed
    • fix(cmake): avoid really slow compile on emscripten (#4642) · 6cf90e72
      * fix: avoid really slow compile on emscripten
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      
      * Update tools/pybind11Common.cmake
      
      ---------
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      Henry Schreiner committed
  2. 15 Nov, 2023 1 commit
  3. 08 Nov, 2023 4 commits
    • Fix a long-standing bug in the handling of Python multiple inheritance (#4762) · e250155a
      * Equivalent of https://github.com/google/clif/commit/5718e4d0807fd3b6a8187dde140069120b81ecef
      
      * Resolve clang-tidy errors.
      
      * Moving test_PPCCInit() first changes the behavior!
      
      * Resolve new Clang dev C++11 errors:
      
      ```
      The CXX compiler identification is Clang 17.0.0
      ```
      
      ```
      pytypes.h:1615:23: error: identifier '_s' preceded by whitespace in a literal operator declaration is deprecated [-Werror,-Wdeprecated-literal-operator]
      ```
      
      ```
      cast.h:1380:26: error: identifier '_a' preceded by whitespace in a literal operator declaration is deprecated [-Werror,-Wdeprecated-literal-operator]
      ```
      
      * Resolve gcc 4.8.5 error:
      
      ```
      pytypes.h:1615:12: error: missing space between '""' and suffix identifier
      ```
      
      * Specifically exclude `__clang__`
      
      * Snapshot of debugging code (does NOT pass pre-commit checks).
      
      * Revert "Snapshot of debugging code (does NOT pass pre-commit checks)."
      
      This reverts commit 1d4f9ff2632b32ddcb0dc7ecd0ab7a4ce4c15a4e.
      
      * [ci skip] Order Dependence Demo
      
      * Revert "[ci skip] Order Dependence Demo"
      
      This reverts commit d37b5409d4e5b835620ccbb321a4e1ba89af315c.
      
      * One way to deal with the order dependency issue. This is not the best way, more like a proof of concept.
      
      * Move test_PC() first again.
      
      * Add `all_type_info_add_base_most_derived_first()`, use in `all_type_info_populate()`
      
      * Revert "One way to deal with the order dependency issue. This is not the best way, more like a proof of concept."
      
      This reverts commit eb09c6c1b978208ceee40f05bbe75491b6ff8ad6.
      
      * clang-tidy fixes (automatic)
      
      * Add `is_redundant_value_and_holder()` and use to avoid forcing `__init__` overrides when they are not needed.
      
      * Streamline implementation and avoid unsafe `reinterpret_cast<instance *>()` introduced with PR #2152
      
      The `reinterpret_cast<instance *>(self)` is unsafe if `__new__` is mocked,
      which was actually found in the wild: the mock returned `None` for `self`.
      This was inconsequential because `inst` is currently cast straight back to
      `PyObject *` to compute `all_type_info()`, which is empty if `self` is not
      a pybind11 `instance`, and then `inst` is never dereferenced. However, the
      unsafe detour through `instance *` is easily avoided and the updated
      implementation is less prone to accidents while debugging or refactoring.
      
      * Fix actual undefined behavior exposed by previous changes.
      
      It turns out the previous commit message is incorrect, the `inst` pointer is actually dereferenced, in the `value_and_holder` ctor here:
      
      https://github.com/pybind/pybind11/blob/f3e0602802c7840992c97f4960515777cad6a5c7/include/pybind11/detail/type_caster_base.h#L262-L263
      
      ```
      259     // Main constructor for a found value/holder:
      260     value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index)
      261         : inst{i}, index{index}, type{type},
      262           vh{inst->simple_layout ? inst->simple_value_holder
      263                                  : &inst->nonsimple.values_and_holders[vpos]} {}
      ```
      
      * Add test_mock_new()
      
      * Experiment: specify indirect bases
      
      * Revert "Experiment: specify indirect bases"
      
      This reverts commit 4f90d85f9fc15290d6be54d5ae9417bd131b84d9.
      
      * Add `all_type_info_check_for_divergence()` and some tests.
      
      * Call `all_type_info_check_for_divergence()` also from `type_caster_generic::load_impl<>`
      
      * Resolve clang-tidy error:
      
      ```
      include/pybind11/detail/type_caster_base.h:795:21: error: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty,-warnings-as-errors]
                      if (matching_bases.size() != 0) {
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~
                          !matching_bases.empty()
      ```
      
      * Revert "Resolve clang-tidy error:"
      
      This reverts commit df27188dc6d6cf333145755543f56b2f6657aa5e.
      
      * Revert "Call `all_type_info_check_for_divergence()` also from `type_caster_generic::load_impl<>`"
      
      This reverts commit 5f5fd6a68e3cff1726628f6dea8e1c0754636a23.
      
      * Revert "Add `all_type_info_check_for_divergence()` and some tests."
      
      This reverts commit 0a9599f775bfd3ca196c5e23a3fcf2890cbf6e82.
      Ralf W. Grosse-Kunstleve committed
    • chore: move to ruff-format (#4912) · c758b81f
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
      Henry Schreiner committed
    • chore(deps): update pre-commit hooks (#4923) · 0a974fed
      updates:
      - [github.com/pre-commit/mirrors-clang-format: v17.0.3 → v17.0.4](https://github.com/pre-commit/mirrors-clang-format/compare/v17.0.3...v17.0.4)
      - [github.com/astral-sh/ruff-pre-commit: v0.1.2 → v0.1.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.2...v0.1.4)
      
      Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
      pre-commit-ci[bot] committed
  4. 05 Nov, 2023 1 commit
  5. 04 Nov, 2023 1 commit
  6. 01 Nov, 2023 1 commit
  7. 27 Oct, 2023 3 commits
  8. 24 Oct, 2023 1 commit
  9. 23 Oct, 2023 1 commit
  10. 21 Oct, 2023 1 commit
    • Workaround NVCC parse failure in `cast_op` (#4893) · 3414c56b
      * Workaround NVCC parse failure in `cast_op`
      
      There is a bug in some CUDA versions (observed in CUDA 12.1 and 11.7 w/ GCC 12.2),
      that makes `cast_op` fail to compile:
        `cast.h:45:120: error: expected template-name before ‘<’ token`
      
      Defining the nested type as an alias and using it allows this to work
      without any change in semantics.
      
      Fixes #4606
      
      * style: pre-commit fixes
      
      * Add comments to result_t referencing PR
      
      ---------
      
      Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
      Alexander Grund committed
  11. 20 Oct, 2023 1 commit
  12. 17 Oct, 2023 1 commit
  13. 16 Oct, 2023 1 commit
    • Update pytest to version 7.2.0 (which removes their dependency on py) (#4880) · 0cbd92ba
      * Update pytest (which removes their dependency on py)
      
      The py library through 1.11.0 for Python allows remote attackers to conduct a ReDoS (Regular expression Denial of Service) attack via a Subversion repository with crafted info data, because the InfoSvnCommand argument is mishandled.
      
      The particular codepath in question is the regular expression at py._path.svnurl.InfoSvnCommand.lspattern and is only relevant when dealing with subversion (svn) projects. Notably the codepath is not used in the popular pytest project. The developers of the pytest package have released version 7.2.0 which removes their dependency on py. Users of pytest seeing alerts relating to this advisory may update to version 7.2.0 of pytest to resolve this issue. See https://github.com/pytest-dev/py/issues/287#issuecomment-1290407715 for additional context.
      
      * Added conditions so that we keep using 7.0.0 on python 3.6
      Pablo Speciale committed
  14. 12 Oct, 2023 1 commit
    • Add pybind11/gil_safe_call_once.h (to fix deadlocks in pybind11/numpy.h) (#4877) · 0e2c3e5d
      * LazyInitializeAtLeastOnceDestroyNever v1
      
      * Go back to using `union` as originally suggested by jbms@. The trick (also suggested by jbms@) is to add empty ctor + dtor.
      
      * Revert "Go back to using `union` as originally suggested by jbms@. The trick (also suggested by jbms@) is to add empty ctor + dtor."
      
      This reverts commit e7b8c4f0fcd72191e88d1c17abf5da08fe3a9c6f.
      
      * Remove `#include <stdalign.h>`
      
      * `include\pybind11/numpy.h(24,10): fatal error C1083: Cannot open include file: 'stdalign.h': No such file or directory`
      
      * @tkoeppe wrote: this is a C interop header (and we're not writing C)
      
      * Suppress gcc 4.8.5 (CentOS 7) warning.
      
      ```
      include/pybind11/eigen/../numpy.h:63:53: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
               return *reinterpret_cast<T *>(value_storage_);
                                                           ^
      ```
      
      * Replace comments:
      
      Document PRECONDITION.
      
      Adopt comment suggested by @tkoeppe: https://github.com/pybind/pybind11/pull/4877#discussion_r1350356093
      
      * Adopt suggestion by @tkoeppe:
      
      * https://github.com/pybind/pybind11/pull/4877#issuecomment-1752969127
      
      * https://godbolt.org/z/Wa79nKz6e
      
      * Add `PYBIND11_CONSTINIT`, but it does not work for the current use cases:
      
      ```
      g++ -o pybind11/tests/test_numpy_array.os -c -std=c++20 -fPIC -fvisibility=hidden -O0 -g -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -Wundef -Wnon-virtual-dtor -Wunused-result -Werror -isystem /usr/include/python3.11 -isystem /usr/include/eigen3 -DPYBIND11_STRICT_ASSERTS_CLASS_HOLDER_VS_TYPE_CASTER_MIX -DPYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD_IF_AVAILABLE -DPYBIND11_TEST_BOOST -Ipybind11/include -I/usr/local/google/home/rwgk/forked/pybind11/include -I/usr/local/google/home/rwgk/clone/pybind11/include /usr/local/google/home/rwgk/forked/pybind11/tests/test_numpy_array.cpp
      ```
      
      ```
      In file included from /usr/local/google/home/rwgk/forked/pybind11/tests/test_numpy_array.cpp:10:
      /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/numpy.h: In static member function ‘static pybind11::detail::npy_api& pybind11::detail::npy_api::get()’:
      /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/numpy.h:258:82: error: ‘constinit’ variable ‘api_init’ does not have a constant initializer
        258 |         PYBIND11_CONSTINIT static LazyInitializeAtLeastOnceDestroyNever<npy_api> api_init;
            |                                                                                  ^~~~~~~~
      ```
      
      ```
      In file included from /usr/local/google/home/rwgk/forked/pybind11/tests/test_numpy_array.cpp:10:
      /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/numpy.h: In static member function ‘static pybind11::object& pybind11::dtype::_dtype_from_pep3118()’:
      /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/numpy.h:697:13: error: ‘constinit’ variable ‘imported_obj’ does not have a constant initializer
        697 |             imported_obj;
            |             ^~~~~~~~~~~~
      ```
      
      * Revert "Add `PYBIND11_CONSTINIT`, but it does not work for the current use cases:"
      
      This reverts commit f07b28bda9f91fb723aa898a21c81b6dd6857072.
      
      * Reapply "Add `PYBIND11_CONSTINIT`, but it does not work for the current use cases:"
      
      This reverts commit 36be645758aa82b576d24003808386bec6e55bf9.
      
      * Add Default Member Initializer on `value_storage_` as suggested by @tkoeppe:
      
      https://github.com/pybind/pybind11/pull/4877#issuecomment-1753201342
      
      This fixes the errors reported under commit f07b28bda9f91fb723aa898a21c81b6dd6857072.
      
      * Fix copy-paste-missed-a-change mishap in commit 88cec1152ab5576db19bab95c484672f06f5989a.
      
      * Semi-paranoid placement new (based on https://github.com/pybind/pybind11/pull/4877#discussion_r1350573114).
      
      * Move PYBIND11_CONSTINIT to detail/common.h
      
      * Move code to the right places, rename new class and some variables.
      
      * Fix oversight: update tests/extra_python_package/test_files.py
      
      * Get the name right first.
      
      * Use `std::call_once`, `std::atomic`, following a pattern developed by @tkoeppe
      
      * Make the API more self-documenting (and possibly more easily reusable).
      
      * google-clang-tidy IWYU fixes
      
      * Rewrite comment as suggested by @tkoeppe
      
      * Update test_exceptions.cpp and exceptions.rst
      
      * Fix oversight in previous commit: add `PYBIND11_CONSTINIT`
      
      * Make `get_stored()` non-const for simplicity.
      
      As suggested by @tkoeppe: not seeing any reasonable use in which `get_stored` has to be const.
      
      * Add comment regarding `KeyboardInterrupt` behavior, based heavily on information provided by @jbms.
      
      * Add `assert(PyGILState_Check())` in `gil_scoped_release` ctor (simple & non-simple implementation) as suggested by @EthanSteinberg.
      
      * Fix oversight in previous commit (missing include cassert).
      
      * Remove use of std::atomic, leaving comments with rationale, why it is not needed.
      
      * Rewrite comment re `std:optional` based on deeper reflection (aka 2nd thoughts).
      
      * Additional comment with the conclusion of a discussion under PR #4877.
      
      * https://github.com/pybind/pybind11/pull/4877#issuecomment-1757363179
      
      * Small comment changes suggested by @tkoeppe.
      Ralf W. Grosse-Kunstleve committed
  15. 06 Oct, 2023 1 commit
  16. 03 Oct, 2023 2 commits
  17. 27 Sep, 2023 2 commits
  18. 25 Sep, 2023 1 commit
  19. 15 Sep, 2023 2 commits
  20. 14 Sep, 2023 1 commit
  21. 12 Sep, 2023 3 commits
  22. 07 Sep, 2023 1 commit
  23. 06 Sep, 2023 2 commits
  24. 01 Sep, 2023 1 commit
  25. 31 Aug, 2023 1 commit
  26. 30 Aug, 2023 1 commit