Skip to content

Commit 4dbe657

Browse files
committed
Merge branch 'smart_holder' into unique_ptr_deleter_sh
2 parents d815d7d + e955753 commit 4dbe657

38 files changed

+412
-143
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ The valid options are:
135135
* Use `-G` and the name of a generator to use something different. `cmake
136136
--help` lists the generators available.
137137
- On Unix, setting `CMAKE_GENERATER=Ninja` in your environment will give
138-
you automatic mulithreading on all your CMake projects!
138+
you automatic multithreading on all your CMake projects!
139139
* Open the `CMakeLists.txt` with QtCreator to generate for that IDE.
140140
* You can use `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON` to generate the `.json` file
141141
that some tools expect.

.github/workflows/ci.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,10 @@ jobs:
196196
matrix:
197197
include:
198198
# TODO: Fails on 3.10, investigate
199-
- python-version: "3.9"
200-
python-debug: true
201-
valgrind: true
199+
# JOB DISABLED (NEEDS WORK): https://github.com/pybind/pybind11/issues/4889
200+
# - python-version: "3.9"
201+
# python-debug: true
202+
# valgrind: true
202203
- python-version: "3.11"
203204
python-debug: false
204205

@@ -1053,7 +1054,7 @@ jobs:
10531054
uses: jwlawson/[email protected]
10541055

10551056
- name: Install ninja-build tool
1056-
uses: seanmiddleditch/gha-setup-ninja@v3
1057+
uses: seanmiddleditch/gha-setup-ninja@v4
10571058

10581059
- name: Run pip installs
10591060
run: |

.github/workflows/ci_sh_def.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,10 @@ jobs:
211211
matrix:
212212
include:
213213
# TODO: Fails on 3.10, investigate
214-
- python-version: "3.9"
215-
python-debug: true
216-
valgrind: true
214+
# JOB DISABLED (NEEDS WORK): https://github.com/pybind/pybind11/issues/4889
215+
# - python-version: "3.9"
216+
# python-debug: true
217+
# valgrind: true
217218
- python-version: "3.11"
218219
python-debug: false
219220

@@ -1080,7 +1081,7 @@ jobs:
10801081
uses: jwlawson/[email protected]
10811082

10821083
- name: Install ninja-build tool
1083-
uses: seanmiddleditch/gha-setup-ninja@v3
1084+
uses: seanmiddleditch/gha-setup-ninja@v4
10841085

10851086
- name: Run pip installs
10861087
run: |

.github/workflows/ci_sh_def.yml.patch

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
--- ci.yml 2023-09-10 10:49:38.655616237 -0700
2-
+++ ci_sh_def.yml 2023-09-10 10:50:17.855597833 -0700
1+
--- ci.yml 2023-10-20 00:00:26.619833296 -0700
2+
+++ ci_sh_def.yml 2023-10-20 00:00:43.927801556 -0700
33
@@ -1,4 +1,16 @@
44
-name: CI
55
+# PLEASE KEEP THIS GROUP OF FILES IN SYNC AT ALL TIMES:
@@ -51,23 +51,23 @@
5151
-DPYBIND11_INTERNALS_VERSION=10000000
5252
${{ matrix.args }}
5353

54-
@@ -255,6 +270,7 @@
54+
@@ -256,6 +271,7 @@
5555
-DDOWNLOAD_CATCH=ON
5656
-DDOWNLOAD_EIGEN=ON
5757
-DCMAKE_CXX_STANDARD=17
5858
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
5959

6060
- name: Build
6161
run: cmake --build build -j 2
62-
@@ -323,6 +339,7 @@
62+
@@ -324,6 +340,7 @@
6363
-DPYBIND11_WERROR=ON
6464
-DDOWNLOAD_CATCH=ON
6565
-DCMAKE_CXX_STANDARD=${{ matrix.std }}
6666
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
6767
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
6868

6969
- name: Build
70-
@@ -352,7 +369,7 @@
70+
@@ -353,7 +370,7 @@
7171
run: apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y cmake git python3-dev python3-pytest python3-numpy
7272

7373
- name: Configure
@@ -76,7 +76,7 @@
7676

7777
- name: Build
7878
run: cmake --build build -j2 --verbose
79-
@@ -440,7 +457,7 @@
79+
@@ -441,7 +458,7 @@
8080
cmake -S . -B build -DDOWNLOAD_CATCH=ON \
8181
-DCMAKE_CXX_STANDARD=17 \
8282
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") \
@@ -85,87 +85,87 @@
8585
-DPYBIND11_TEST_FILTER="test_smart_ptr.cpp"
8686

8787
- name: Build
88-
@@ -494,6 +511,7 @@
88+
@@ -495,6 +512,7 @@
8989
-DPYBIND11_WERROR=ON
9090
-DDOWNLOAD_CATCH=ON
9191
-DCMAKE_CXX_STANDARD=${{ matrix.std }}
9292
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
9393
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
9494

9595
- name: Build
96-
@@ -516,6 +534,7 @@
96+
@@ -517,6 +535,7 @@
9797
-DPYBIND11_WERROR=ON
9898
-DDOWNLOAD_CATCH=ON
9999
-DCMAKE_CXX_STANDARD=${{ matrix.std }}
100100
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
101101
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
102102
"-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp"
103103

104-
@@ -567,6 +586,7 @@
104+
@@ -568,6 +587,7 @@
105105
-DDOWNLOAD_CATCH=ON \
106106
-DDOWNLOAD_EIGEN=OFF \
107107
-DCMAKE_CXX_STANDARD=11 \
108108
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT" \
109109
-DCMAKE_CXX_COMPILER=$(which icpc) \
110110
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
111111

112-
@@ -599,6 +619,7 @@
112+
@@ -600,6 +620,7 @@
113113
-DDOWNLOAD_CATCH=ON \
114114
-DDOWNLOAD_EIGEN=OFF \
115115
-DCMAKE_CXX_STANDARD=17 \
116116
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT" \
117117
-DCMAKE_CXX_COMPILER=$(which icpc) \
118118
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
119119

120-
@@ -672,6 +693,7 @@
120+
@@ -673,6 +694,7 @@
121121
-DDOWNLOAD_CATCH=ON
122122
-DDOWNLOAD_EIGEN=ON
123123
-DCMAKE_CXX_STANDARD=11
124124
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
125125
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
126126

127127
- name: Build
128-
@@ -722,6 +744,7 @@
128+
@@ -723,6 +745,7 @@
129129
cmake ../pybind11-tests
130130
-DDOWNLOAD_CATCH=ON
131131
-DPYBIND11_WERROR=ON
132132
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
133133
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
134134
working-directory: /build-tests
135135

136-
@@ -817,6 +840,7 @@
136+
@@ -818,6 +841,7 @@
137137
-DPYBIND11_WERROR=ON
138138
-DDOWNLOAD_CATCH=ON
139139
-DDOWNLOAD_EIGEN=ON
140140
+ -DCMAKE_CXX_FLAGS="/GR /EHsc /DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
141141
${{ matrix.args }}
142142
- name: Build C++11
143143
run: cmake --build build -j 2
144-
@@ -871,6 +895,7 @@
144+
@@ -872,6 +896,7 @@
145145
-DPYBIND11_WERROR=ON
146146
-DDOWNLOAD_CATCH=ON
147147
-DDOWNLOAD_EIGEN=ON
148148
+ -DCMAKE_CXX_FLAGS="/GR /EHsc /DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
149149
${{ matrix.args }}
150150
- name: Build C++11
151151
run: cmake --build build --config Debug -j 2
152-
@@ -911,6 +936,7 @@
152+
@@ -912,6 +937,7 @@
153153
-DDOWNLOAD_CATCH=ON
154154
-DDOWNLOAD_EIGEN=ON
155155
-DCMAKE_CXX_STANDARD=20
156156
+ -DCMAKE_CXX_FLAGS="/GR /EHsc /DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
157157

158158
- name: Build C++20
159159
run: cmake --build build -j 2
160-
@@ -931,6 +957,7 @@
160+
@@ -932,6 +958,7 @@
161161
-DDOWNLOAD_CATCH=ON
162162
-DDOWNLOAD_EIGEN=ON
163163
-DCMAKE_CXX_STANDARD=20
164164
+ -DCMAKE_CXX_FLAGS="/GR /EHsc /DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
165165
"-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp"
166166

167167
- name: Build C++20 - Exercise cmake -DPYBIND11_TEST_OVERRIDE
168-
@@ -973,7 +1000,7 @@
168+
@@ -974,7 +1001,7 @@
169169
- name: Configure C++11
170170
# LTO leads to many undefined reference like
171171
# `pybind11::detail::function_call::function_call(pybind11::detail::function_call&&)
@@ -174,7 +174,7 @@
174174

175175
- name: Build C++11
176176
run: cmake --build build -j 2
177-
@@ -991,7 +1018,7 @@
177+
@@ -992,7 +1019,7 @@
178178
run: git clean -fdx
179179

180180
- name: Configure C++14
@@ -183,7 +183,7 @@
183183

184184
- name: Build C++14
185185
run: cmake --build build2 -j 2
186-
@@ -1009,7 +1036,7 @@
186+
@@ -1010,7 +1037,7 @@
187187
run: git clean -fdx
188188

189189
- name: Configure C++17
@@ -192,23 +192,23 @@
192192

193193
- name: Build C++17
194194
run: cmake --build build3 -j 2
195-
@@ -1076,6 +1103,7 @@
195+
@@ -1077,6 +1104,7 @@
196196
-DDOWNLOAD_EIGEN=ON
197197
-DCMAKE_CXX_COMPILER=clang++
198198
-DCMAKE_CXX_STANDARD=17
199199
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
200200

201201
- name: Build
202202
run: cmake --build . -j 2
203-
@@ -1141,6 +1169,7 @@
203+
@@ -1142,6 +1170,7 @@
204204
-DDOWNLOAD_EIGEN=ON
205205
-DCMAKE_CXX_COMPILER=clang++
206206
-DCMAKE_CXX_STANDARD=17
207207
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
208208
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
209209

210210
- name: Build
211-
@@ -1164,6 +1193,7 @@
211+
@@ -1165,6 +1194,7 @@
212212
-DDOWNLOAD_EIGEN=ON
213213
-DCMAKE_CXX_COMPILER=clang++
214214
-DCMAKE_CXX_STANDARD=17

.pre-commit-config.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,27 @@ repos:
2525

2626
# Clang format the codebase automatically
2727
- repo: https://github.com/pre-commit/mirrors-clang-format
28-
rev: "v16.0.6"
28+
rev: "v17.0.3"
2929
hooks:
3030
- id: clang-format
3131
types_or: [c++, c, cuda]
3232

3333
# Black, the code formatter, natively supports pre-commit
3434
- repo: https://github.com/psf/black-pre-commit-mirror
35-
rev: "23.7.0" # Keep in sync with blacken-docs
35+
rev: "23.10.1" # Keep in sync with blacken-docs
3636
hooks:
3737
- id: black
3838

3939
# Ruff, the Python auto-correcting linter written in Rust
4040
- repo: https://github.com/astral-sh/ruff-pre-commit
41-
rev: v0.0.287
41+
rev: v0.1.2
4242
hooks:
4343
- id: ruff
4444
args: ["--fix", "--show-fixes"]
4545

4646
# Check static types with mypy
4747
- repo: https://github.com/pre-commit/mirrors-mypy
48-
rev: "v1.5.1"
48+
rev: "v1.6.1"
4949
hooks:
5050
- id: mypy
5151
args: []
@@ -67,7 +67,7 @@ repos:
6767

6868
# Standard hooks
6969
- repo: https://github.com/pre-commit/pre-commit-hooks
70-
rev: "v4.4.0"
70+
rev: "v4.5.0"
7171
hooks:
7272
- id: check-added-large-files
7373
- id: check-case-conflict
@@ -100,7 +100,7 @@ repos:
100100

101101
# Avoid directional quotes
102102
- repo: https://github.com/sirosen/texthooks
103-
rev: "0.5.0"
103+
rev: "0.6.2"
104104
hooks:
105105
- id: fix-ligatures
106106
- id: fix-smartquotes
@@ -126,15 +126,15 @@ repos:
126126
# Use tools/codespell_ignore_lines_from_errors.py
127127
# to rebuild .codespell-ignore-lines
128128
- repo: https://github.com/codespell-project/codespell
129-
rev: "v2.2.5"
129+
rev: "v2.2.6"
130130
hooks:
131131
- id: codespell
132132
exclude: ".supp$"
133133
args: ["-x.codespell-ignore-lines", "-Lccompiler"]
134134

135135
# Check for common shell mistakes
136136
- repo: https://github.com/shellcheck-py/shellcheck-py
137-
rev: "v0.9.0.5"
137+
rev: "v0.9.0.6"
138138
hooks:
139139
- id: shellcheck
140140

@@ -144,12 +144,12 @@ repos:
144144
- id: disallow-caps
145145
name: Disallow improper capitalization
146146
language: pygrep
147-
entry: PyBind|Numpy|Cmake|CCache|PyTest
147+
entry: PyBind|\bNumpy\b|Cmake|CCache|PyTest
148148
exclude: ^\.pre-commit-config.yaml$
149149

150150
# PyLint has native support - not always usable, but works for us
151151
- repo: https://github.com/PyCQA/pylint
152-
rev: "v3.0.0a7"
152+
rev: "v3.0.1"
153153
hooks:
154154
- id: pylint
155155
files: ^pybind11

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
# All rights reserved. Use of this source code is governed by a
66
# BSD-style license that can be found in the LICENSE file.
77

8+
# Propagate this policy (FindPythonInterp removal) so it can be detected later
9+
if(NOT CMAKE_VERSION VERSION_LESS "3.27")
10+
cmake_policy(GET CMP0148 _pybind11_cmp0148)
11+
endif()
12+
813
cmake_minimum_required(VERSION 3.5)
914

1015
# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with
@@ -16,6 +21,11 @@ else()
1621
cmake_policy(VERSION 3.26)
1722
endif()
1823

24+
if(_pybind11_cmp0148)
25+
cmake_policy(SET CMP0148 ${_pybind11_cmp0148})
26+
unset(_pybind11_cmp0148)
27+
endif()
28+
1929
# Avoid infinite recursion if tests include this as a subdirectory
2030
if(DEFINED PYBIND11_MASTER_PROJECT)
2131
return()
@@ -137,6 +147,7 @@ set(PYBIND11_HEADERS
137147
include/pybind11/embed.h
138148
include/pybind11/eval.h
139149
include/pybind11/gil.h
150+
include/pybind11/gil_safe_call_once.h
140151
include/pybind11/iostream.h
141152
include/pybind11/functional.h
142153
include/pybind11/numpy.h

docs/advanced/exceptions.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,14 @@ standard python RuntimeError:
141141

142142
.. code-block:: cpp
143143
144-
// This is a static object, so we must leak the Python reference:
145-
// It is undefined when the destructor will run, possibly only after the
146-
// Python interpreter is finalized already.
147-
static py::handle exc = py::exception<MyCustomException>(m, "MyCustomError").release();
144+
PYBIND11_CONSTINIT static py::gil_safe_call_once_and_store<py::object> exc_storage;
145+
exc_storage.call_once_and_store_result(
146+
[&]() { return py::exception<MyCustomException>(m, "MyCustomError"); });
148147
py::register_exception_translator([](std::exception_ptr p) {
149148
try {
150149
if (p) std::rethrow_exception(p);
151150
} catch (const MyCustomException &e) {
152-
py::set_error(exc, e.what());
151+
py::set_error(exc_storage.get_stored(), e.what());
153152
} catch (const OtherException &e) {
154153
py::set_error(PyExc_RuntimeError, e.what());
155154
}

0 commit comments

Comments
 (0)