Commit Graph

3154 Commits

Author SHA1 Message Date
Ralf W. Grosse-Kunstleve
0161da9d6d [skip ci] .gitignore: exclude __pycache__ directories (#5838)
Python may leave behind temporary `.pyc.*` files inside `__pycache__`
on some filesystems (e.g. WSL2 mounts). Adding `__pycache__/` ensures
these directories and any leftover files are consistently ignored.

Background: Python writes bytecode to a temp file with an extra suffix
before renaming it to `.pyc`. If the process is interrupted or the
filesystem rename isn’t fully atomic, those temp files may remain.

See: https://docs.python.org/3/library/py_compile.html#py_compile.compile
2025-09-27 13:12:56 -07:00
gentlegiantJGC
81ffb1d5cc Add 90 minute limit for tests (#5851)
Occasionally a test will get stuck and run for 6 hours until Github cancels the workflow.
This reduces the timeout to 90 minutes to not waste resources.
Pybind11's tests seem to run in 30 minutes so this should be plenty of time.
2025-09-27 12:53:47 -07:00
gentlegiantJGC
8ed0dab67f Add float type caster and revert type hint changes to int_ and float_ (#5839)
* Revert type hint changes to int_ and float_

These two types do not support casting from int-like and float-like types.

* Fix tests

* Add a custom py::float_ caster

The default py::object caster only works if the object is an instance of the type.
py::float_ should accept python int objects as well as float.
This caster will pass through float as usual and cast int to float.
The caster handles the type name so the custom one is not required.

* style: pre-commit fixes

* Fix name

* Fix variable

* Try satisfying the formatter

* Rename test function

* Simplify type caster

* Fix reference counting issue

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-09-27 09:13:21 -07:00
Scott Wolchok
30748f863f Avoid heap allocation for function calls with a small number of args (#5824)
* Avoid heap allocation for function calls with a small number of arguments

We don't have access to llvm::SmallVector or similar, but given the
limited subset of the `std::vector` API that
`function_call::args{,_convert}` need and the "reserve-then-fill"
usage pattern, it is relatively straightforward to implement custom
containers that get the job done.

Seems to improves time to call the collatz function in
pybind/pybind11_benchmark significantly; numbers are a little noisy
but there's a clear improvement from "about 60 ns per call" to "about
45 ns per call" on my machine (M4 Max Mac), as measured with
`timeit.repeat('collatz(4)', 'from pybind11_benchmark import
collatz')`.

* clang-tidy

* more clang-tidy

* clang-tidy NOLINTBEGIN/END instead of NOLINTNEXTLINE

* forgot to increase inline size after removing std::variant

* constexpr arg_vector_small_size, use move instead of swap to hopefully clarify second_pass_convert

* rename test_embed to test_low_level

* rename test_low_level to test_with_catch

* Be careful to NOINLINE slow paths

* rename array/vector members to iarray/hvector. Move comment per request. Add static_asserts for our untagged union implementation per request.

* drop is_standard_layout assertions; see https://github.com/pybind/pybind11/pull/5824#issuecomment-3308616072
2025-09-19 13:44:40 -07:00
b-pass
326b10637a Use thread_local instead of thread_specific_storage for internals (#5834)
* Use thread_local instead of thread_specific_storage for internals mangement

thread_local is faster.

* Make the pp manager a singleton.

Strictly speaking, since the members are static, the instances must also be singletons or this wouldn't work.  They already are, but we can make the class enforce it to be more 'self-documenting'.
2025-09-14 09:07:08 -07:00
Ralf W. Grosse-Kunstleve
d4d555d9e0 Restore runs-on: windows-latest (#5835)
* Revert "s/windows-2022/windows-latest/ in .github/workflows/{ci,pip}.yml (#5826)"

This reverts commit 852a4b5010.

* Add module-level skip for Windows build >= 26100 in test_iostream.py

* Changes suggested by at-henryiii
2025-09-12 21:52:44 -07:00
Scott Wolchok
937552f0ad Use thread_local for loader_life_support to improve performance (#5830)
* Use thread_local for loader_life_support to improve performance

As explained in a new code comment, `loader_life_support` needs to be
`thread_local` but does not need to be isolated to a particular
interpreter because any given function call is already going to only
happen on a single interpreter by definiton.

Performance before:
- on M4 Max using pybind/pybind11_benchmark unmodified repo:
```
> python -m timeit --setup 'from pybind11_benchmark import collatz' 'collatz(4)'
5000000 loops, best of 5: 63.8 nsec per loop
```

- Linux server:
```
python -m timeit --setup 'from pybind11_benchmark import collatz' 'collatz(4)'                                                                                                                                        (pytorch)
2000000 loops, best of 5: 120 nsec per loop
```

After:
- M4 Max:
```
python -m timeit --setup 'from pybind11_benchmark import collatz' 'collatz(4)'
5000000 loops, best of 5: 53.1 nsec per loop
```

- Linux server:
```
> python -m timeit --setup 'from pybind11_benchmark import collatz' 'collatz(4)'                                                                                                                                        (pytorch)
2000000 loops, best of 5: 101 nsec per loop
```

A quick profile with perf shows that pthread_setspecific and pthread_getspecific are gone.

Open questions:

- How do we determine whether we can safely use `thread_local`? I see
  concerns about old iOS versions on
  https://github.com/pybind/pybind11/pull/5705#issuecomment-2922858880
  and https://github.com/pybind/pybind11/pull/5709; is there anything
  else?
- Do we have a test that covers "function called in one interpreter
  calls a C++ function that causes a function call in another
  interpreter"? I think it's fine, but can it happen?
- Are we happy with what we think will happen in the case where
  multiple extensions compiled with and without this PR interoperate?
  I think it's fine -- each dispatch pushes and cleans up its own
  state -- but a second opinion is certainly welcome.

* Remove PYBIND11_CAN_USE_THREAD_LOCAL

* clarify comment

* Simplify loader_life_support TLS storage

Replace the `fake_thread_specific_storage` struct with a direct
thread-local pointer managed via a function-local static:

    static loader_life_support *& tls_current_frame()

This retains the "stack of frames" behavior via the `parent` link. It also
reduces indirection and clarifies intent.

Note: this form is C++11-compatible; once pybind11 requires C++17, the
helper can be simplified to:

    inline static thread_local loader_life_support *tls_current_frame = nullptr;

* loader_life_support: avoid duplicate tls_current_frame() calls

Replace repeated calls with a single local reference:

    auto &frame = tls_current_frame();

This ensures the thread_local initialization guard is checked only once
per constructor/destructor call site, avoids potential clang-tidy
complaints, and makes the code more readable. Functional behavior is
unchanged.

* Add REMINDER for next version bump in internals.h

---------

Co-authored-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
2025-09-12 14:37:01 -07:00
Joshua Oreman
68cbae6641 tests: add or delete copy/move ctors where needed to make type traits match reality (#5833) 2025-09-08 15:47:24 -07:00
Thomas Köppe
a6581eee89 pytypes.h: constrain accessor::operator= templates so that they do not obscure special members (#5832)
* pytypes.h: constrain accessor::operator= templates so that they do not match calls that should use the special member functions.

Found by an experimental, new clang-tidy check. While we may not know the exact design decisions now, it seems unlikely that the special members were deliberately meant to not be selected (for otherwise they could have been defined differently to make this clear). Rather, it seems like an oversight that the operator templates win in overload resolution, and we should restore the intended resolution.

* Use C++11-compatible facilities

* Use C++11-compatible facilities

* style: pre-commit fixes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-09-08 11:52:41 -07:00
dependabot[bot]
7fb54e3065 chore(deps): bump the actions group with 3 updates (#5831)
* chore(deps): bump the actions group with 3 updates

Bumps the actions group with 3 updates: [actions/checkout](https://github.com/actions/checkout), [actions/setup-python](https://github.com/actions/setup-python) and [actions/labeler](https://github.com/actions/labeler).


Updates `actions/checkout` from 1 to 5
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v1...v5)

Updates `actions/setup-python` from 5 to 6
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v5...v6)

Updates `actions/labeler` from 5 to 6
- [Release notes](https://github.com/actions/labeler/releases)
- [Commits](https://github.com/actions/labeler/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: actions/setup-python
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: actions/labeler
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>

* Manually reset "🐍 3.9 • Debian • x86 •  Install" back to `actions/checkout@v1`

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
2025-09-07 20:22:29 -07:00
Scott Wolchok
852a4b5010 s/windows-2022/windows-latest/ in .github/workflows/{ci,pip}.yml (#5826)
Per request from @rwgk: https://github.com/pybind/pybind11/pull/5825#issuecomment-3256438901
2025-09-04 23:39:33 -04:00
dependabot[bot]
ef0f1ff5f1 chore(deps): bump the actions group across 1 directory with 2 updates (#5818)
* chore(deps): bump the actions group across 1 directory with 2 updates

Bumps the actions group with 2 updates in the / directory: [actions/checkout](https://github.com/actions/checkout) and [actions/attest-build-provenance](https://github.com/actions/attest-build-provenance).


Updates `actions/checkout` from 1 to 5
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v1...v5)

Updates `actions/attest-build-provenance` from 2 to 3
- [Release notes](https://github.com/actions/attest-build-provenance/releases)
- [Changelog](https://github.com/actions/attest-build-provenance/blob/main/RELEASE.md)
- [Commits](https://github.com/actions/attest-build-provenance/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: actions/attest-build-provenance
  dependency-version: '3'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update .github/workflows/ci.yml

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2025-09-03 18:25:27 -07:00
Plamen Totev
bf2d56e8ac Fix the first example in the first steps guide not compiling (#5823)
The alias of the pybind11 namespace is missing
2025-09-03 09:07:22 -07:00
Ralf W. Grosse-Kunstleve
cd56888c89 Bring CI back to all-working condition (#5822)
* Fix "🐍 3 • windows-latest • mingw64" job (apparently msys2/setup-msys2@v2 cannot be run twice anymore):

https://github.com/pybind/pybind11/actions/runs/17394902023/job/49417376616?pr=5796

```
Run msys2/setup-msys2@v2
  with:
    msystem: mingw64
    install: mingw-w64-x86_64-python-numpy mingw-w64-x86_64-python-scipy mingw-w64-x86_64-eigen3
    path-type: minimal
    update: false
    pacboy: false
    release: true
    location: RUNNER_TEMP
    platform-check-severity: fatal
    cache: true
  env:
    PYTHONDEVMODE: 1
    PIP_BREAK_SYSTEM_PACKAGES: 1
    PIP_ONLY_BINARY: numpy
    FORCE_COLOR: 3
    PYTEST_TIMEOUT: 300
    VERBOSE: 1
    CMAKE_COLOR_DIAGNOSTICS: 1
    MSYSTEM: MINGW64
Error: Trying to install MSYS2 to D:\a\_temp\msys64 but that already exists, cannot continue.
```

* Add `pytest.xfail("[TEST-GIL-SCOPED] macOS free-threading...)`

* Change env.SYS_IS_GIL_ENABLED constant to env.sys_is_gil_enabled function

* Change install_mingw64_only → extra_install

* Also xfail if macOS and PY_GIL_DISABLED, show SOABI

* build-ios: brew upgrade|install cmake

* Revert "build-ios: brew upgrade|install cmake"

This reverts commit bd3900ee79.

See also:

https://github.com/pybind/pybind11/pull/5822#issuecomment-3247827317

* Disable build-ios job in tests-cibw.yml

* Remove macos_brew_install_llvm job because it started failing, to reduce our maintenance overhead:

Failures tracked here: https://github.com/pybind/pybind11/pull/5822#issuecomment-3247998220

* Fix iOS build step for cmake installation

Replaced brew upgrade with brew install for cmake.

* Update cmake installation steps in CI workflow

Uninstall cmake before installing the latest version due to GitHub's local tap changes.

* Update .github/workflows/tests-cibw.yml

---------

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2025-09-03 09:06:41 -07:00
MoonE
3878c23f8d Fix typo in error message (#5817) 2025-08-30 23:07:03 -07:00
Tobias Leibner
3c0ee89716 Fix compiler detection with clang-cl (#5816)
* Fix compiler detection with clang-cl

* Follow review suggestion
2025-08-27 11:06:29 -07:00
Henry Schreiner
6e0d1c2400 chore: back to work
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2025-08-22 16:08:51 -04:00
Henry Schreiner
f5fbe867d2 chore: bump to 3.0.1 (#5810)
* docs: prepare for 3.0.1

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

* chore: bump for 3.0.1

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

* Update docs/changelog.md

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
v3.0.1
2025-08-22 15:57:09 -04:00
Henry Schreiner
cddec2bb1d fix: limit warning issue (#5807)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2025-08-21 16:07:26 -04:00
Henry Schreiner
e71489c314 tests: avoid false DOWNLOAD_CATCH manually-specified variables warning (#5803)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2025-08-21 15:52:09 -04:00
gentlegiantJGC
8bbc3091c8 Improve buffer_info type checking in numpy docs (#5805)
When comparing buffer types there are some edge cases on some platforms that are equivalent but the format string is not identical.
item_type_is_equivalent_to is more forgiving than direct string comparison.
2025-08-21 15:14:57 -04:00
Dima Pasechnik
03607757fc correct homebrew package URL in installing.rst (#5808)
the URL missed a part
2025-08-21 15:14:40 -04:00
Henry Schreiner
adb5603f60 chore: rename generic slots variable (#5793)
* fix: better compatibility with Qt

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

style: pre-commit fixes

* refactor: use mod_def_slots as a name instead

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

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2025-08-21 11:06:30 -04:00
Dustin Spicuzza
7aa3780dd4 Replace robotpy-build with semiwrap (#5804)
- robotpy-build is no longer being updated
2025-08-20 12:21:32 -04:00
Henry Schreiner
ce7122857a ci: avoid macOS 15 image change for iOS (#5798) 2025-08-16 09:12:00 -04:00
Justen Di Ruscio
c1bf55a211 Fix subinterpreter exception handling SEGFAULT (#5795)
* check for current exception, not uncaught_exceptions

* remove all in-flight exception handling from ~subinterpreter_scoped_activate
2025-08-15 00:03:03 -07:00
dependabot[bot]
90bc05c7ae chore(deps): bump actions/download-artifact (#5792)
Bumps the actions group with 1 update in the / directory: [actions/download-artifact](https://github.com/actions/download-artifact).


Updates `actions/download-artifact` from 4 to 5
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-12 09:01:01 -04:00
Robert Haschke
580494c7b4 fix: LTO warning of gcc >= 11.4 (#5791)
lto-wrapper: warning: using serial compilation of n LTRANS jobs
https://stackoverflow.com/questions/72218980/gcc-v12-1-warning-about-serial-compilation
2025-08-12 09:00:33 -04:00
Robert Haschke
6292b704f6 Explain linting suppressions (#5790)
* Reduce NOLINT

* Revert "Reduce NOLINT"

This reverts commit 96593d3142.

* Explain NOLINT

We explicitly want to test copying the argument.
2025-08-11 19:34:37 -07:00
Justen Di Ruscio
94c8250818 inline get_interpreter_state_uncheccked inline function (#5789) 2025-08-11 19:25:09 -07:00
Henry Schreiner
23c59b6e3d ci: add android test (#5714)
* ci: add android test

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

* Fix Android tests (#23)

* Android tests working

* Clarifications

* ci: only use fork on Android

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

* ci: add wheel (missing)

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

* ci: no patchelf?

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

* ci: forgot pyproject android mention

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

* Fix GHA configuration

* Update to cibuildwheel 3.1

* Restore installation of "wheel"

* Revert iOS to cibuildwheel 3.0

* Actually revert iOS back to cibuildwheel 3.0

* Restore iOS to cibuildwheel 3.1, and skip Python 3.14 instead

* Update .github/workflows/tests-cibw.yml

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Malcolm Smith <smith@chaquo.com>
2025-08-06 22:32:45 -04:00
Ralf W. Grosse-Kunstleve
a5665e3aca fix: type_caster_enum_type for pointer types (#5694) (#5776)
Add pointer overload to type_caster_enum_type::cast method to handle
enum pointer casting. Fixes compilation error when returning pointers
to enum types from bound functions.

Experiment for validation:

Temporarily undo the changes in include/pybind11/cast.h:

```
g++ -o pybind11/tests/test_native_enum.os -c -std=c++20 -fPIC -fvisibility=hidden -O0 -g -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -Wundef -Wnon-virtual-dtor -Wunused-result -Werror -funsigned-char -Wpedantic -isystem /usr/include/python3.12 -isystem /usr/include/eigen3 -DPYBIND11_SMART_HOLDER_PADDING_ON -DPYBIND11_STRICT_ASSERTS_CLASS_HOLDER_VS_TYPE_CASTER_MIX -DPYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD_IF_AVAILABLE -DPYBIND11_TEST_BOOST -Ipybind11/include -I/home/rgrossekunst/forked/pybind11/include -I/home/rgrossekunst/clone/pybind11/include /home/rgrossekunst/forked/pybind11/tests/test_native_enum.cpp
In file included from /home/rgrossekunst/forked/pybind11/include/pybind11/native_enum.h:10,
                 from /home/rgrossekunst/forked/pybind11/tests/test_native_enum.cpp:1:
/home/rgrossekunst/forked/pybind11/include/pybind11/cast.h: In instantiation of ‘static pybind11::handle pybind11::detail::type_caster_enum_type<EnumType>::cast(SrcType&&, pybind11::return_value_policy, pybind11::handle) [with SrcType = const test_native_enum::color*; EnumType = test_native_enum::color]’:
/home/rgrossekunst/forked/pybind11/include/pybind11/pybind11.h:429:40:   required from ‘void pybind11::cpp_function::initialize(Func&&, Return (*)(Args ...), const Extra& ...) [with Func = test_submodule_native_enum(pybind11::module_&)::<lambda()>; Return = const test_native_enum::color*; Args = {}; Extra = {pybind11::name, pybind11::scope, pybind11::sibling}]’
/home/rgrossekunst/forked/pybind11/include/pybind11/pybind11.h:274:19:   required from ‘pybind11::cpp_function::cpp_function(Func&&, const Extra& ...) [with Func = test_submodule_native_enum(pybind11::module_&)::<lambda()>; Extra = {pybind11::name, pybind11::scope, pybind11::sibling}; <template-parameter-1-3> = void]’
/home/rgrossekunst/forked/pybind11/include/pybind11/pybind11.h:1384:22:   required from ‘pybind11::module_& pybind11::module_::def(const char*, Func&&, const Extra& ...) [with Func = test_submodule_native_enum(pybind11::module_&)::<lambda()>; Extra = {}]’
/home/rgrossekunst/forked/pybind11/tests/test_native_enum.cpp:139:10:   required from here
/home/rgrossekunst/forked/pybind11/include/pybind11/cast.h:70:32: error: invalid ‘static_cast’ from type ‘const test_native_enum::color*’ to type ‘pybind11::detail::type_caster_enum_type<test_native_enum::color>::Underlying’ {aka ‘unsigned int’}
   70 |             return native_enum(static_cast<Underlying>(src)).release();
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/rgrossekunst/forked/pybind11/include/pybind11/cast.h: In instantiation of ‘static pybind11::handle pybind11::detail::type_caster_enum_type<EnumType>::cast(SrcType&&, pybind11::return_value_policy, pybind11::handle) [with SrcType = test_native_enum::color*; EnumType = test_native_enum::color]’:
/home/rgrossekunst/forked/pybind11/include/pybind11/pybind11.h:429:40:   required from ‘void pybind11::cpp_function::initialize(Func&&, Return (*)(Args ...), const Extra& ...) [with Func = test_submodule_native_enum(pybind11::module_&)::<lambda()>; Return = test_native_enum::color*; Args = {}; Extra = {pybind11::name, pybind11::scope, pybind11::sibling}]’
/home/rgrossekunst/forked/pybind11/include/pybind11/pybind11.h:274:19:   required from ‘pybind11::cpp_function::cpp_function(Func&&, const Extra& ...) [with Func = test_submodule_native_enum(pybind11::module_&)::<lambda()>; Extra = {pybind11::name, pybind11::scope, pybind11::sibling}; <template-parameter-1-3> = void]’
/home/rgrossekunst/forked/pybind11/include/pybind11/pybind11.h:1384:22:   required from ‘pybind11::module_& pybind11::module_::def(const char*, Func&&, const Extra& ...) [with Func = test_submodule_native_enum(pybind11::module_&)::<lambda()>; Extra = {}]’
/home/rgrossekunst/forked/pybind11/tests/test_native_enum.cpp:143:10:   required from here
/home/rgrossekunst/forked/pybind11/include/pybind11/cast.h:70:32: error: invalid ‘static_cast’ from type ‘test_native_enum::color*’ to type ‘pybind11::detail::type_caster_enum_type<test_native_enum::color>::Underlying’ {aka ‘unsigned int’}
```
2025-08-06 17:11:45 -04:00
pre-commit-ci[bot]
9360553f87 chore(deps): update pre-commit hooks (#5785)
updates:
- [github.com/pre-commit/mirrors-clang-format: v20.1.7 → v20.1.8](https://github.com/pre-commit/mirrors-clang-format/compare/v20.1.7...v20.1.8)
- [github.com/astral-sh/ruff-pre-commit: v0.12.2 → v0.12.7](https://github.com/astral-sh/ruff-pre-commit/compare/v0.12.2...v0.12.7)
- [github.com/pre-commit/mirrors-mypy: v1.16.1 → v1.17.1](https://github.com/pre-commit/mirrors-mypy/compare/v1.16.1...v1.17.1)
- [github.com/sirosen/texthooks: 0.6.8 → 0.7.1](https://github.com/sirosen/texthooks/compare/0.6.8...0.7.1)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-08-06 17:11:28 -04:00
b-pass
c5e8fec920 Make function record subinterpreter safe (#5771)
* Make function_record type subinterpreter safe

* Get rid of static state in implicit conversion

* style: pre-commit fixes

* Fix lambda

* Bump ABI because we added an internals member

* Set __module__ on the type instance to get rid of DepricationWarning

* Work around internal compiler error in CUDA by not using typedef

hopefully

* Make clang-tidy happy

* Use the same __module__ as pybind11_static_property

* style: pre-commit fixes

* Oops, find-replace error

* style: pre-commit fixes

* Move the once initialization to happen more behind the scenes

* Oops, need those casts...

* Undo implicit conversion change, will do a separate PR

* Use local_internals for function_record pointer to avoid ABI bump

* style: pre-commit fixes

* Get rid of this auto for readability

* Change back to using unqualified tp_name, set __module__ attribute, explicitly add Py_TPFLAGS_HEAPTYPE → does not resolve DeprecationWarning :-(

* Revert "Change back to using unqualified tp_name, set __module__ attribute, explicitly add Py_TPFLAGS_HEAPTYPE → does not resolve DeprecationWarning :-("

This reverts commit 9ccd6de9b7.

* Add Py_TPFLAGS_HEAPTYPE to be explicit (more readable).

* Remove obsolete PYBIND11_WARNING_DISABLE_...

* Make tp_plainname_impl, tp_qualname_impl more DRY

* Change PYBIND11_INTERNAL_MODULE_NAME → PYBIND11_DUMMY_MODULE_NAME

* Add a long comment to explain the tp_qualname_impl workaround.

* Rename local_internals::function_record → function_record_py_type

---------

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>
Co-authored-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
2025-08-04 05:00:33 -07:00
b-pass
0db3d59fdf Allow multiphase modules to be re-imported (#5782)
* Failing unit test

* Potential fix for the issue of re-importing a multi-phase module

- When a module is successfully imported and exec'd, save its handle in a dict in the interpreter state
- Use a special Py_mod_create slot to look in the cache and return the cached handle if it is in the cache
- Don't re-run the user exec function if the module is in the interpreter's cache (implying it was already successfully imported)

* Oops, need to inline these.

* Clang-Tidy fixes

* Oops, debug code

* Add xfail for this GraalPy bug

* Remove static from these function defs, it was a cut-and-paste error in the first place.

* Fix test comment

* Proper error handling

* Oops

* Split up this line, but still just ignore failure .. if the module doesn't have the right properties to check the cache then just allow exec to run.

* Clean up - already looked up the name, just use that.

* Some compilers complain if the pointer isn't taken here, weird.

* Allow attribute errors to be thrown here, will be converted to import errors by the exception handler.

* Remove bogus incref, unconditionally expect a __spec__.name on the module

* Add PR to test comment

* style: pre-commit fixes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-08-02 19:48:38 -07:00
b-pass
780ec11360 Make implicitly_convertable sub-interpreter and free-threading safe (#5777)
* Replace static bool with thread-specific-storage to make this code sub-interpreter and free-threading safe.

* Make sure there is only one tss value in existence for this.

The previous code had multiple (one for every type pair, as this is a template function), which may have posed a problem for some platforms.

* Make set_flag in implicitly_convertible() non-copyable/movable

set_flag is an RAII guard for a thread-specific reentrancy flag.
Copying or moving it would risk double-resetting or rearming the flag,
breaking the protection. Disable copy/move constructors and assignment
operators to make this explicit.

* Minor cleanup to avoid venturing into UB territory.

* Experiment: Disable `~thread_specific_storage()` body when using GraalPy.

* Try the suggestion to only call TSS_free if the python interpreter is still active.

* Add IsFinalizing check

* Put this back to having a per-template-instance static

---------

Co-authored-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rwgkio@gmail.com>
2025-08-01 20:04:44 -07:00
b-pass
9af8adb712 Subinterpreter creation concurrency issues in 3.12 (#5779)
* Seems like 3.12 has concurrency issues when creating a subinterpreter, easiest workaround is just to lock during it.

* Only need this for PER_INTERPRETER_GIL
2025-07-30 21:31:54 -07:00
Henry Schreiner
6972597c9b docs: show nogil in most examples (#5770)
Created using [mini-swe-agent](https://mini-swe-agent.com) and the propmt:

I'd like to find usages of PYBIND11_MODULE in the docs folder and add py::mod_gil_not_used() as a third argument if there ar
e only two arguments. These are examples, and it's really a good idea to always include that now.

I removed a few of the changes.

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2025-07-27 23:08:11 -06:00
b-pass
33533ff3f8 Fix IsolatedConfig test (#5768)
* Fix IsolatedConfig test

The test was throwing import errors past the lifetime of the owning scoped_interpreter

* Clang format

* Clang tidy
2025-07-26 22:17:37 -07:00
Paul Fultz II
7f5eea432e Check for __cpp_lib_remove_cvref as well (#5761)
C++20 can be enabled while the C++ runtime is still much older so use the feature macro to check for it. 

For example, we are using the latest clang with c++23 on SLES, while the gcc version is 7.
2025-07-24 10:01:18 -07:00
Mike Jarvis
49d19fef68 Implement binary version of make_index_sequence (#5751)
* Implement binary version of make_index_sequence

* style: pre-commit fixes

* typo

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-07-24 09:56:32 -07:00
gentlegiantJGC
6aeae9c311 Fix py::trampoline_self_life_support visibility in docs (#5766)
C++ classes default inheritance rule is private.
I believe py::trampoline_self_life_support must be public to work correctly.
2025-07-24 08:33:23 -07:00
moi15moi
316273efc8 fix: don't force -fvisibility=hidden on Windows (#5757)
Fix https://github.com/pybind/pybind11/discussions/5750
2025-07-18 09:51:33 -07:00
Thomas Braun
c4ee83c498 fix:: initialize_generic compiler warning about nullptr dereference (#5756)
When compiling an application using pybind11 3.0.0, GCC 13.3.0 and
python 3.11.13 the following warning is emitted [1]:

  In function 'PyObject* PyCFunction_GET_SELF(PyObject*)',
      inlined from 'void pybind11::cpp_function::initialize_generic(unique_function_record&&, const char*, const std::type_info* const*, pybind11::size_t)' at /opt/conda/lib/python3.11/site-packages/pybind11/include/pybind11/pybind11.h:605:30:
  /opt/conda/include/python3.11/cpython/methodobject.h:50:16: error: potential null pointer dereference [-Werror=null-dereference]
     50 |         return _Py_NULL;
        |                ^~~~~~~~

It stems form the fact that PyCFunction_GET_SELF can return a nullptr.
Let's fail in this case.

[1]: https://gitlab.com/tango-controls/pytango/-/jobs/10671972312#L570
2025-07-18 09:50:33 -07:00
pre-commit-ci[bot]
cc69a3789c chore(deps): update pre-commit hooks (#5745)
* chore(deps): update pre-commit hooks

updates:
- [github.com/pre-commit/mirrors-clang-format: v20.1.5 → v20.1.7](https://github.com/pre-commit/mirrors-clang-format/compare/v20.1.5...v20.1.7)
- [github.com/astral-sh/ruff-pre-commit: v0.11.12 → v0.12.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.11.12...v0.12.2)
- [github.com/pre-commit/mirrors-mypy: v1.16.0 → v1.16.1](https://github.com/pre-commit/mirrors-mypy/compare/v1.16.0...v1.16.1)
- [github.com/python-jsonschema/check-jsonschema: 0.33.0 → 0.33.2](https://github.com/python-jsonschema/check-jsonschema/compare/0.33.0...0.33.2)

* chore: fix new ruff check warnings

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

* style: pre-commit fixes

---------

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>
2025-07-11 15:36:38 -07:00
Henry Schreiner
66d394f259 docs: standardize header a bit (#5749) 2025-07-11 13:51:17 -07:00
Ralf W. Grosse-Kunstleve
fa72aff53d [skip ci] Small docs/release.rst update, mainly to remove git push --tags. (#5748)
* [skip ci] Small docs/release.rst update, mainly to warn about `git push --tags`.

* Remove mention of `git push --tags`

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>

---------

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2025-07-11 13:49:30 -07:00
Ralf W. Grosse-Kunstleve
422990f842 chore: get back to work (after v3.0.0 release) (#5747)
* Change version on master to v3.0.1a0

* Fix up PYBIND11_VERSION_PATCH
2025-07-11 13:25:25 -07:00
Ralf W. Grosse-Kunstleve
ed5057ded6 chore: prepare for 3.0.0 (final) (#5746)
* Update docs/changelog.md and change version to v3.0.0 (final)

* [skip ci] Add `|SPEC 4 — Using and Creating Nightly Wheels|` badge in main README.rst
v3.0.0
2025-07-10 09:16:14 -07:00
Ralf W. Grosse-Kunstleve
4dc4aca2e1 [skip ci] Explain: conduit feature only covers from-Python-to-C++ conversions (#5740) 2025-06-20 13:23:26 -07:00