Commit Graph

3258 Commits

Author SHA1 Message Date
Ralf W. Grosse-Kunstleve
686783b3da Merge branch 'master' into sh_merge_master 2023-12-01 21:59:50 -08:00
Antoine Prouvost
a67d786571
fix(stl_bind): Enable bind_map with using declarations. (#4952)
* Enable `bind_map` with `using` declarations.

* style: pre-commit fixes

* Enable directives in bind_vector

* Add tests for bind_ and using directives

* style: pre-commit fixes

* Remove C++17 functions

* Fix test comment

* Add minimal user like map py test

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-11-29 12:56:25 -08:00
dependabot[bot]
4bb6163b4f
chore(deps): bump deadsnakes/action from 3.0.1 to 3.1.0 (#4951)
Bumps [deadsnakes/action](https://github.com/deadsnakes/action) from 3.0.1 to 3.1.0.
- [Release notes](https://github.com/deadsnakes/action/releases)
- [Commits](https://github.com/deadsnakes/action/compare/v3.0.1...v3.1.0)

---
updated-dependencies:
- dependency-name: deadsnakes/action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-27 15:37:43 -08:00
Ben Boeckel
dc9b39596d
pybind11.pc: use pcfiledir for relative destinations (#4830)
* 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>
2023-11-16 00:55:14 -05:00
Henry Schreiner
9591cfb0b8
fix(cmake): findpython issues and 3.12 support for pybind11_find_import (#4941)
* 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>
2023-11-16 00:54:47 -05:00
Henry Schreiner
6831666f5c
ci: add more versions of numpy/scipy/pypy (#4714)
* 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>
2023-11-16 00:52:05 -05:00
Henry Schreiner
6cf90e7286
fix(cmake): avoid really slow compile on emscripten (#4642)
* 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>
2023-11-16 00:50:15 -05:00
Henry Schreiner
b389ae77cb
chore: update changelog script for categories (#4942) 2023-11-15 18:59:07 -05:00
Ralf W. Grosse-Kunstleve
c6e71cf71c Merge branch 'master' into smart_holder 2023-11-08 13:04:09 -08:00
Ralf W. Grosse-Kunstleve
e250155afa
Fix a long-standing bug in the handling of Python multiple inheritance (#4762)
* Equivalent of 5718e4d080

* 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 1d4f9ff263.

* [ci skip] Order Dependence Demo

* Revert "[ci skip] Order Dependence Demo"

This reverts commit d37b5409d4.

* 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 eb09c6c1b9.

* 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:

f3e0602802/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 4f90d85f9f.

* 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 df27188dc6.

* Revert "Call `all_type_info_check_for_divergence()` also from `type_caster_generic::load_impl<>`"

This reverts commit 5f5fd6a68e.

* Revert "Add `all_type_info_check_for_divergence()` and some tests."

This reverts commit 0a9599f775.
2023-11-08 12:44:04 -08:00
Ralf W. Grosse-Kunstleve
b9c17cfcd9 Merge branch 'master' into smart_holder 2023-11-08 11:18:21 -08:00
Ralf W. Grosse-Kunstleve
2c35fde389
Fix refcount bug introduced with PR #4916. (#4927)
https://github.com/pybind/pybind11/pull/4916/files#r1387035547
2023-11-08 11:16:10 -08:00
Ralf W. Grosse-Kunstleve
124b62a087 Merge branch 'master' into sh_merge_master 2023-11-07 23:44:24 -08:00
Henry Schreiner
c758b81f3b
chore: move to ruff-format (#4912)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
2023-11-07 23:42:54 -08:00
pre-commit-ci[bot]
0a974fed54
chore(deps): update pre-commit hooks (#4923)
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>
2023-11-07 22:59:52 -08:00
Ivor Wanders
e5ce9631b1
[smart_holder] Unique ptr deleter roundtrip tests and fix (#4921)
* Roundtrip through unique pointer with custom deleter.

Currently failing.

* Ensure the custom deleter is copied back to the unique pointer.

Feels like there's still a gap around the raw pointer flavour, but this at least
makes the unit test of the previous commit succeed.

* Add deleter roundtrip for const atyp.

Currently failing, custom deleter is lost.

* Fix storing deleter for const unique ptr.

Unit test from the previous commit passes.

* Remove SFINEA deleter assignment.

At the construction of the smart holder, it is either a del_fun, or a default constructed deleter, so this complexity is unnecessary.

* Clang format.

* Fixes for ci.

Clang 3.6 requires the extra constructors in the custom_deleter.

* fix(smart_holder): Loosen requirement on deleter to be default constructible.

And some other PR feedback.

* fix(smart_holder): Custom deleter in unit tests traces constructions.

* fix(smart_holder): Use pybind11_fail instead of assert.

* fix(smart_holder): Add unit tests for the default constructible deleter.

* fix(smart_holder): Use regex matching for deleter constructors in unit tests.
2023-11-07 22:58:24 -08:00
Ivor Wanders
e02fe001cd
fix(smart_holder): Use std::default_delete. (#4924)
Ensures `std::default_delete<T>` is used to look up the deleter for a type instead of `delete` directly.
2023-11-06 15:56:21 -08:00
cyyever
f2606930bf
Use newer PyCode API and other fixes (#4916)
* Use PyCode API

* style: pre-commit fixes

* Free locals

* Fix PY_VERSION_HEX check

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-11-05 14:08:32 -08:00
Social_Mean
31b0a5d94f fix doc typo 2023-11-03 23:51:16 -04:00
Ralf W. Grosse-Kunstleve
edfaaed87e
[smart_holder] type_caster_odr_guard MSVC 193732825 C++17 windows-2022 is failing for unknown reasons. (#4918)
* MSVC 193732825 C++17 windows-2022 is failing for unknown reasons.

* Bug fix: Need to test `_MSC_FULL_VER` (not `_MSC_VER`).
2023-11-02 23:03:53 -07:00
Ralf W. Grosse-Kunstleve
fb79bc8c14 Merge branch 'master' into sh_merge_master 2023-11-02 09:50:53 -07:00
Ralf W. Grosse-Kunstleve
55105fbeaf
[smart_holder] Bug fix: std::unique_ptr deleter needs to be copied. (#4850)
* Store `std::function<void (void *)>` del_fun; in `guarded_delete`

* Specialize the simple common case.

Using a `union` is complicated: https://en.cppreference.com/w/cpp/language/union

> If members of a union are classes with user-defined constructors and destructors, to switch the active member, explicit destructor and placement new are generally needed:

Using `std::variant` increases compile-time overhead.

It is currently unclear how much these effects matter in practice: optimization left for later.

* Add one test case (more later).

* Add `const` to resolve clang-tidy error.

```
-- The CXX compiler identification is Clang 15.0.7

/usr/bin/cmake -E __run_co_compile --tidy="/usr/bin/clang-tidy;--use-color;--warnings-as-errors=*;--extra-arg-before=--driver-mode=g++" --source=/__w/pybind11/pybind11/tests/test_class_sh_inheritance.cpp -- /usr/bin/c++ -DPYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD_IF_AVAILABLE -DPYBIND11_TEST_EIGEN -Dpybind11_tests_EXPORTS -I/__w/pybind11/pybind11/include -isystem /usr/include/python3.9 -isystem /__w/pybind11/pybind11/build/_deps/eigen-src -Os -DNDEBUG -fPIC -fvisibility=hidden -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -Wundef -Wnon-virtual-dtor -flto=thin -std=c++17 -o CMakeFiles/pybind11_tests.dir/test_class_sh_inheritance.cpp.o -c /__w/pybind11/pybind11/tests/test_class_sh_inheritance.cpp
/__w/pybind11/pybind11/tests/pure_cpp/smart_holder_poc_test.cpp:264:30: error: pointer parameter 'raw_ptr' can be pointer to const [readability-non-const-parameter,-warnings-as-errors]
        new int(19), [](int *raw_ptr) { delete raw_ptr; });
                             ^
                        const
```

* Introduce `struct custom_deleter` to ensure the deleter is moved as desired (the lambda function only captures a reference, which can become dangling).

* Resolve helpful clang-tidy errors.

```
/usr/bin/cmake -E __run_co_compile --tidy="/usr/bin/clang-tidy;--use-color;--warnings-as-errors=*;--extra-arg-before=--driver-mode=g++" --source=/__w/pybind11/pybind11/tests/test_class.cpp -- /usr/bin/c++ -DPYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD_IF_AVAILABLE -DPYBIND11_TEST_EIGEN -Dpybind11_tests_EXPORTS -I/__w/pybind11/pybind11/include -isystem /usr/include/python3.9 -isystem /__w/pybind11/pybind11/build/_deps/eigen-src -Os -DNDEBUG -fPIC -fvisibility=hidden -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -Wundef -Wnon-virtual-dtor -flto=thin -std=c++17 -o CMakeFiles/pybind11_tests.dir/test_class.cpp.o -c /__w/pybind11/pybind11/tests/test_class.cpp
/__w/pybind11/pybind11/include/pybind11/detail/smart_holder_poc.h:114:5: error: single-argument constructors must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor,-warnings-as-errors]
    custom_deleter(D &&deleter) : deleter{std::move(deleter)} {}
    ^
    explicit
/__w/pybind11/pybind11/include/pybind11/detail/smart_holder_poc.h:120:76: error: forwarding reference passed to std::move(), which may unexpectedly cause lvalues to be moved; use std::forward() instead [bugprone-move-forwarding-reference,-warnings-as-errors]
    return guarded_delete(std::function<void(void *)>(custom_deleter<T, D>(std::move(uqp_del))),
                                                                           ^~~~~~~~~
                                                                           std::forward<D>
```

* Workaround for gcc 4.8.5, clang 3.6

* Transfer reduced test here.

Reduced from a PyCLIF use case in the wild by @wangxf123456 (internal change cl/565476030).

* Add missing include (clangd Include Cleaner)

* Change `std::move` to `std::forward` as suggested by @iwanders.

* Add missing includes (clangd Include Cleaner)

* Use new `PYBIND11_TESTS_PURE_CPP_SMART_HOLDER_POC_TEST_CPP` to exclude `smart_holder::as_unique_ptr` method from production code.

* Systematically add `PYBIND11_TESTS_PURE_CPP_SMART_HOLDER_POC_TEST_CPP` to mark code that is not used from production code. Add comment to explain.

* Very simple experiment related to https://github.com/pybind/pybind11/pull/4850#issuecomment-1789780676

Does the `PYBIND11_TESTS_PURE_CPP_SMART_HOLDER_POC_TEST_CPP` define have anything to do with it?

* Revert "Very simple experiment related to https://github.com/pybind/pybind11/pull/4850#issuecomment-1789780676"

This reverts commit fe59369f40.
2023-11-02 08:21:13 -07:00
Axel Huebl
76b7f53649
Python_ADDITIONAL_VERSIONS: 3.12 (#4909)
Add 3.12 to the default `Python_ADDITIONAL_VERSIONS`.
2023-10-31 22:56:16 -04:00
Henry Schreiner
a18c10f690
fix(cmake): make library component optional (#4805)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2023-10-27 11:02:05 -04:00
Ralf W. Grosse-Kunstleve
e955753c1b Fix pre-commit mypy error:
```
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

ubench/holder_comparison.py:12: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
```
2023-10-26 22:48:43 -07:00
Ralf W. Grosse-Kunstleve
f8ea68f242 Merge branch 'master' into sh_merge_master 2023-10-26 22:38:47 -07:00
Henry Schreiner
3aece819fd
chore: update hooks and Ruff config (#4904)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2023-10-27 01:26:28 -04:00
Chun Yang
1e28599e41
fix: Add missing spaces to error string (#4906)
* [minor] Add a missing space

Add a missing space to error message

* Add space after period, always add newline.
2023-10-26 20:40:19 -07:00
Mattias Ellert
fa27d2fd43
Adapt to changed function name in Python 3.13 (#4902)
According to https://docs.python.org/3.13/whatsnew/3.13.html:

Add PyThreadState_GetUnchecked() function: similar to
PyThreadState_Get(), but don't kill the process with a fatal error if
it is NULL. The caller is responsible to check if the result is
NULL. Previously, the function was private and known as
_PyThreadState_UncheckedGet().
2023-10-24 09:46:26 -07:00
Ralf W. Grosse-Kunstleve
28ec485553 Merge branch 'master' into sh_merge_master 2023-10-23 16:26:40 -07:00
Ralf W. Grosse-Kunstleve
bf88e29c95
Bug fix: Replace bare static exception<T> with gil_safe_call_once_and_store. (#4897)
This is to ensure that `Py_DECREF()` is not called after the Python interpreter was finalized already:

3414c56b6c/include/pybind11/gil_safe_call_once.h (L19)
2023-10-23 12:51:04 -07:00
Alexander Grund
3414c56b6c
Workaround NVCC parse failure in cast_op (#4893)
* 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>
2023-10-21 10:50:14 -07:00
Ralf W. Grosse-Kunstleve
4c5b88a557 Tracking ci.yml changes from master. 2023-10-20 00:00:54 -07:00
Ralf W. Grosse-Kunstleve
b272af80a5 Merge branch 'master' into sh_merge_master 2023-10-20 00:00:26 -07:00
Ralf W. Grosse-Kunstleve
7969049de4
Comment out failing job, with link to #4889 (#4890) 2023-10-19 23:12:37 -07:00
Ralf W. Grosse-Kunstleve
ae02940be9 Merge branch 'master' into sh_merge_master 2023-10-17 12:08:51 -07:00
Sergei Izmailov
74439a64a2
feature: Use typed iterators in make_*iterator (#4876) 2023-10-17 12:04:46 -07:00
Pablo Speciale
0cbd92bab8
Update pytest to version 7.2.0 (which removes their dependency on py) (#4880)
* 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
2023-10-16 07:42:30 -07:00
Ralf W. Grosse-Kunstleve
901586943f Tracking ci.yml changes from master. 2023-10-11 21:10:22 -07:00
Ralf W. Grosse-Kunstleve
2c88356284 Merge branch 'master' into sh_merge_master 2023-10-11 21:07:36 -07:00
Ralf W. Grosse-Kunstleve
0e2c3e5db4
Add pybind11/gil_safe_call_once.h (to fix deadlocks in pybind11/numpy.h) (#4877)
* 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 e7b8c4f0fc.

* 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 f07b28bda9.

* Reapply "Add `PYBIND11_CONSTINIT`, but it does not work for the current use cases:"

This reverts commit 36be645758.

* 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 f07b28bda9.

* Fix copy-paste-missed-a-change mishap in commit 88cec1152a.

* 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.
2023-10-11 21:05:31 -07:00
dependabot[bot]
6c77208561
chore(deps): bump seanmiddleditch/gha-setup-ninja from 3 to 4 (#4875)
Bumps [seanmiddleditch/gha-setup-ninja](https://github.com/seanmiddleditch/gha-setup-ninja) from 3 to 4.
- [Release notes](https://github.com/seanmiddleditch/gha-setup-ninja/releases)
- [Commits](https://github.com/seanmiddleditch/gha-setup-ninja/compare/v3...v4)

---
updated-dependencies:
- dependency-name: seanmiddleditch/gha-setup-ninja
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-05 21:21:22 -07:00
Ralf W. Grosse-Kunstleve
7953d19a7c Merge branch 'master' into sh_merge_master 2023-10-03 22:45:09 -07:00
pre-commit-ci[bot]
2b2e4ca4a3
chore(deps): update pre-commit hooks (#4868)
* chore(deps): update pre-commit hooks

updates:
- [github.com/psf/black-pre-commit-mirror: 23.7.0 → 23.9.1](https://github.com/psf/black-pre-commit-mirror/compare/23.7.0...23.9.1)
- [github.com/astral-sh/ruff-pre-commit: v0.0.287 → v0.0.292](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.287...v0.0.292)
- [github.com/codespell-project/codespell: v2.2.5 → v2.2.6](https://github.com/codespell-project/codespell/compare/v2.2.5...v2.2.6)
- [github.com/shellcheck-py/shellcheck-py: v0.9.0.5 → v0.9.0.6](https://github.com/shellcheck-py/shellcheck-py/compare/v0.9.0.5...v0.9.0.6)
- [github.com/PyCQA/pylint: v3.0.0a7 → v3.0.0](https://github.com/PyCQA/pylint/compare/v3.0.0a7...v3.0.0)

* Update .pre-commit-config.yaml

* style: pre-commit fixes

* Update .pre-commit-config.yaml

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2023-10-03 13:13:44 -04:00
Mateusz Sokół
dd64df73c3
MAINT: Remove np.int_ (#4867) 2023-10-03 09:12:58 -07:00
Mateusz Sokół
0a756c0bb2
MAINT: Include numpy._core imports (#4857)
* MAINT: Include numpy._core imports

* style: pre-commit fixes

* Apply review comments

* style: pre-commit fixes

* Add no-inline attribute

* Select submodule name based on numpy version

* style: pre-commit fixes

* Update pre-commit check

* Add error_already_set and simplify if statement

* Update .pre-commit-config.yaml

Co-authored-by: Ralf W. Grosse-Kunstleve <rwgkio@gmail.com>

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rwgkio@gmail.com>
2023-09-27 10:22:04 -07:00
Ralf W. Grosse-Kunstleve
f468b0707e
Add 2 missing throw error_already_set(); (#4863)
Fixes oversights in PR #4570.
2023-09-27 09:55:49 -07:00
Oleksandr Pavlyk
7e5edbc947
Avoid copy in iteration by using const auto & (#4861)
This change is fixing a Coverity AUTO_CAUSES_COPY issues.
2023-09-25 08:38:21 -07:00
László Papp
5891867ee4
fix(cmake): support DEBUG_POSTFIX correctly (#4761)
* cmake: split extension

Into suffix and debug postfix. Pybind11 is currently treating both as
suffix, which is problematic when something else defines the
DEBUG_POSTFIX because they will be concatenated.

pybind11_extension sets SUFFIX to _d.something and if DEBUG_POSTFIX is
set to _d.

    _d + _d.something = _d_d.something

The issue has been reported at:

https://github.com/pybind/pybind11/issues/4699

* style: pre-commit fixes

* fix(cmake): support postfix for old FindPythonInterp mode too

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
2023-09-15 18:05:43 -04:00
Henry Schreiner
4fb111bd78
fix(cmake): correctly detect FindPython policy and better warning (#4806) 2023-09-15 17:59:30 -04:00