Skip to content

Commit 2681ad4

Browse files
committed
Merge remote-tracking branch 'origin/master' into interop
2 parents a21e7bc + e6984c8 commit 2681ad4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1549
-318
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ jobs:
179179

180180
name: "🐍 ${{ matrix.python-version }} • ${{ matrix.runs-on }} • x64 inplace C++14"
181181
runs-on: ${{ matrix.runs-on }}
182+
timeout-minutes: 90
182183

183184
steps:
184185
- uses: actions/checkout@v5
@@ -202,7 +203,8 @@ jobs:
202203
if: runner.os != 'Windows'
203204
run: echo "CMAKE_GENERATOR=Ninja" >> "$GITHUB_ENV"
204205

205-
# More-or-less randomly adding a few extra flags here
206+
# More-or-less randomly adding a few extra flags here.
207+
# In particular, use this one to test the next ABI bump (internals version).
206208
- name: Configure
207209
run: >
208210
cmake -S. -B.
@@ -212,6 +214,7 @@ jobs:
212214
-DDOWNLOAD_CATCH=ON
213215
-DDOWNLOAD_EIGEN=ON
214216
-DCMAKE_CXX_STANDARD=14
217+
-DPYBIND11_INTERNALS_VERSION=10000000
215218
216219
# Checks to makes sure defining `_` is allowed
217220
# Triggers EHsc missing error on Windows
@@ -277,6 +280,7 @@ jobs:
277280

278281
name: "🐍 ${{ matrix.python-version }}${{ matrix.python-debug && '-dbg' || '' }} (deadsnakes)${{ matrix.valgrind && ' • Valgrind' || '' }} • x64"
279282
runs-on: ubuntu-latest
283+
timeout-minutes: 90
280284

281285
steps:
282286
- uses: actions/checkout@v5
@@ -364,6 +368,7 @@ jobs:
364368

365369
name: "🐍 3 • Clang ${{ matrix.clang }} • C++${{ matrix.std }} • x64${{ matrix.cxx_flags && ' • cxx_flags' || '' }}"
366370
container: "silkeh/clang:${{ matrix.clang }}${{ matrix.container_suffix }}"
371+
timeout-minutes: 90
367372

368373
steps:
369374
- uses: actions/checkout@v5
@@ -401,6 +406,7 @@ jobs:
401406
runs-on: ubuntu-latest
402407
name: "🐍 3.10 • CUDA 12.2 • Ubuntu 22.04"
403408
container: nvidia/cuda:12.2.0-devel-ubuntu22.04
409+
timeout-minutes: 90
404410

405411
steps:
406412
- uses: actions/checkout@v5
@@ -468,6 +474,7 @@ jobs:
468474
if: github.event.pull_request.draft == false
469475
runs-on: ubuntu-22.04
470476
name: "🐍 3 • NVHPC 23.5 • C++17 • x64"
477+
timeout-minutes: 90
471478

472479
env:
473480
# tzdata will try to ask for the timezone, so set the DEBIAN_FRONTEND
@@ -532,6 +539,7 @@ jobs:
532539

533540
name: "🐍 3 • GCC ${{ matrix.gcc }} • C++${{ matrix.std }} • x64${{ matrix.cxx_flags && ' • cxx_flags' || '' }}"
534541
container: "gcc:${{ matrix.gcc }}"
542+
timeout-minutes: 90
535543

536544
steps:
537545
- uses: actions/checkout@v5
@@ -593,6 +601,7 @@ jobs:
593601
icc:
594602
if: github.event.pull_request.draft == false
595603
runs-on: ubuntu-22.04
604+
timeout-minutes: 90
596605

597606
name: "🐍 3 • ICC latest • x64"
598607

@@ -707,6 +716,7 @@ jobs:
707716

708717
name: "🐍 3 • ${{ matrix.container }} • x64"
709718
container: "${{ matrix.container }}"
719+
timeout-minutes: 90
710720

711721
steps:
712722
- name: Latest actions/checkout
@@ -765,6 +775,7 @@ jobs:
765775
name: "🐍 3.9 • Debian • x86 • Install"
766776
runs-on: ubuntu-latest
767777
container: i386/debian:bullseye
778+
timeout-minutes: 90
768779

769780
steps:
770781
- uses: actions/checkout@v1 # v1 is required to run inside docker
@@ -809,6 +820,7 @@ jobs:
809820
if: github.event.pull_request.draft == false
810821
name: "Documentation build test"
811822
runs-on: ubuntu-latest
823+
timeout-minutes: 90
812824

813825
steps:
814826
- uses: actions/checkout@v5
@@ -855,6 +867,7 @@ jobs:
855867

856868
name: "🐍 ${{ matrix.python }} • MSVC 2022 • x86 ${{ matrix.args }}"
857869
runs-on: windows-2022
870+
timeout-minutes: 90
858871

859872
steps:
860873
- uses: actions/checkout@v5
@@ -907,6 +920,7 @@ jobs:
907920

908921
name: "🐍 ${{ matrix.python }} • MSVC 2022 (Debug) • x86 ${{ matrix.args }}"
909922
runs-on: windows-2022
923+
timeout-minutes: 90
910924

911925
steps:
912926
- uses: actions/checkout@v5
@@ -955,6 +969,7 @@ jobs:
955969

956970
name: "🐍 ${{ matrix.python }} • MSVC 2022 C++20 • x64"
957971
runs-on: windows-2022
972+
timeout-minutes: 90
958973

959974
steps:
960975
- uses: actions/checkout@v5
@@ -1012,6 +1027,7 @@ jobs:
10121027
if: github.event.pull_request.draft == false
10131028
name: "🐍 3 • windows-latest • ${{ matrix.sys }}"
10141029
runs-on: windows-latest
1030+
timeout-minutes: 90
10151031
defaults:
10161032
run:
10171033
shell: msys2 {0}
@@ -1125,6 +1141,7 @@ jobs:
11251141
python: ['3.10']
11261142

11271143
runs-on: "${{ matrix.os }}"
1144+
timeout-minutes: 90
11281145

11291146
name: "🐍 ${{ matrix.python }} • ${{ matrix.os }} • clang-latest"
11301147

.github/workflows/reusable-standard.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
standard:
2929
name: 🧪
3030
runs-on: ${{ inputs.runs-on }}
31+
timeout-minutes: 90
3132

3233
steps:
3334
- uses: actions/checkout@v5

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ MANIFEST
2626
/.ninja_*
2727
/*.ninja
2828
/docs/.build
29+
__pycache__/
2930
*.py[co]
3031
*.egg-info
3132
*~

.pre-commit-config.yaml

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

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

3333
# Ruff, the Python auto-correcting linter/formatter written in Rust
3434
- repo: https://github.com/astral-sh/ruff-pre-commit
35-
rev: v0.12.7
35+
rev: v0.13.3
3636
hooks:
3737
- id: ruff-check
3838
args: ["--fix", "--show-fixes"]
3939
- id: ruff-format
4040

4141
# Check static types with mypy
4242
- repo: https://github.com/pre-commit/mirrors-mypy
43-
rev: "v1.17.1"
43+
rev: "v1.18.2"
4444
hooks:
4545
- id: mypy
4646
args: []
@@ -62,7 +62,7 @@ repos:
6262

6363
# Standard hooks
6464
- repo: https://github.com/pre-commit/pre-commit-hooks
65-
rev: "v5.0.0"
65+
rev: "v6.0.0"
6666
hooks:
6767
- id: check-added-large-files
6868
- id: check-case-conflict
@@ -80,7 +80,7 @@ repos:
8080

8181
# Also code format the docs
8282
- repo: https://github.com/adamchainz/blacken-docs
83-
rev: "1.19.1"
83+
rev: "1.20.0"
8484
hooks:
8585
- id: blacken-docs
8686
additional_dependencies:
@@ -120,7 +120,7 @@ repos:
120120

121121
# Check for common shell mistakes
122122
- repo: https://github.com/shellcheck-py/shellcheck-py
123-
rev: "v0.10.0.1"
123+
rev: "v0.11.0.1"
124124
hooks:
125125
- id: shellcheck
126126

@@ -135,14 +135,14 @@ repos:
135135

136136
# PyLint has native support - not always usable, but works for us
137137
- repo: https://github.com/PyCQA/pylint
138-
rev: "v3.3.7"
138+
rev: "v3.3.9"
139139
hooks:
140140
- id: pylint
141141
files: ^pybind11
142142

143143
# Check schemas on some of our YAML files
144144
- repo: https://github.com/python-jsonschema/check-jsonschema
145-
rev: 0.33.2
145+
rev: 0.34.0
146146
hooks:
147147
- id: check-readthedocs
148148
- id: check-github-workflows

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ endif()
181181

182182
set(PYBIND11_HEADERS
183183
include/pybind11/contrib/pymetabind.h
184+
include/pybind11/detail/argument_vector.h
184185
include/pybind11/detail/class.h
185186
include/pybind11/detail/common.h
186187
include/pybind11/detail/cpp_conduit.h
@@ -189,6 +190,7 @@ set(PYBIND11_HEADERS
189190
include/pybind11/detail/exception_translation.h
190191
include/pybind11/detail/foreign.h
191192
include/pybind11/detail/function_record_pyobject.h
193+
include/pybind11/detail/holder_caster_foreign_helpers.h
192194
include/pybind11/detail/init.h
193195
include/pybind11/detail/internals.h
194196
include/pybind11/detail/native_enum_data.h

include/pybind11/cast.h

Lines changed: 27 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
#pragma once
1212

13+
#include "detail/argument_vector.h"
1314
#include "detail/common.h"
1415
#include "detail/descr.h"
16+
#include "detail/holder_caster_foreign_helpers.h"
1517
#include "detail/native_enum_data.h"
1618
#include "detail/type_caster_base.h"
1719
#include "detail/typeid.h"
@@ -859,71 +861,6 @@ struct holder_helper {
859861
static auto get(const T &p) -> decltype(p.get()) { return p.get(); }
860862
};
861863

862-
struct holder_caster_foreign_helpers {
863-
struct py_deleter {
864-
void operator()(const void *) const noexcept {
865-
// Don't run the deleter if the interpreter has been shut down
866-
if (Py_IsInitialized() == 0) {
867-
return;
868-
}
869-
gil_scoped_acquire guard;
870-
Py_DECREF(o);
871-
}
872-
873-
PyObject *o;
874-
};
875-
876-
template <typename type>
877-
static auto try_shared_from_this(type *value, std::shared_ptr<type> *holder_out)
878-
-> decltype(value->shared_from_this(), bool()) {
879-
// object derives from enable_shared_from_this;
880-
// try to reuse an existing shared_ptr if one is known
881-
if (auto existing = try_get_shared_from_this(value)) {
882-
*holder_out = std::static_pointer_cast<type>(existing);
883-
return true;
884-
}
885-
return false;
886-
}
887-
888-
template <typename type>
889-
static bool try_shared_from_this(void *, std::shared_ptr<type> *) {
890-
return false;
891-
}
892-
893-
template <typename type>
894-
static bool set_foreign_holder(handle src, type *value, std::shared_ptr<type> *holder_out) {
895-
// We only support using std::shared_ptr<T> for foreign T, and
896-
// it's done by creating a new shared_ptr control block that
897-
// owns a reference to the original Python object.
898-
if (value == nullptr) {
899-
*holder_out = {};
900-
return true;
901-
}
902-
if (try_shared_from_this(value, holder_out)) {
903-
return true;
904-
}
905-
*holder_out = std::shared_ptr<type>(value, py_deleter{src.inc_ref().ptr()});
906-
return true;
907-
}
908-
909-
template <typename type>
910-
static bool
911-
set_foreign_holder(handle src, const type *value, std::shared_ptr<const type> *holder_out) {
912-
std::shared_ptr<type> holder_mut;
913-
if (set_foreign_holder(src, const_cast<type *>(value), &holder_mut)) {
914-
*holder_out = holder_mut;
915-
return true;
916-
}
917-
return false;
918-
}
919-
920-
template <typename type>
921-
static bool set_foreign_holder(handle, type *, ...) {
922-
throw cast_error("Unable to cast foreign type to held instance -- "
923-
"only std::shared_ptr<T> is supported in this case");
924-
}
925-
};
926-
927864
// SMART_HOLDER_BAKEIN_FOLLOW_ON: Rewrite comment, with reference to shared_ptr specialization.
928865
/// Type caster for holder types like std::shared_ptr, etc.
929866
/// The SFINAE hook is provided to help work around the current lack of support
@@ -1284,8 +1221,8 @@ struct move_only_holder_caster<
12841221
}
12851222

12861223
bool set_foreign_holder(handle) {
1287-
throw cast_error("Foreign types cannot be converted to std::unique_ptr "
1288-
"because we don't know how to make them relinquish "
1224+
throw cast_error("Foreign instance cannot be converted to std::unique_ptr "
1225+
"because we don't know how to make it relinquish "
12891226
"ownership");
12901227
}
12911228

@@ -1467,7 +1404,7 @@ struct handle_type_name<buffer> {
14671404
};
14681405
template <>
14691406
struct handle_type_name<int_> {
1470-
static constexpr auto name = io_name("typing.SupportsInt", "int");
1407+
static constexpr auto name = const_name("int");
14711408
};
14721409
template <>
14731410
struct handle_type_name<iterable> {
@@ -1479,7 +1416,7 @@ struct handle_type_name<iterator> {
14791416
};
14801417
template <>
14811418
struct handle_type_name<float_> {
1482-
static constexpr auto name = io_name("typing.SupportsFloat", "float");
1419+
static constexpr auto name = const_name("float");
14831420
};
14841421
template <>
14851422
struct handle_type_name<function> {
@@ -1600,6 +1537,21 @@ struct pyobject_caster {
16001537
template <typename T>
16011538
class type_caster<T, enable_if_t<is_pyobject<T>::value>> : public pyobject_caster<T> {};
16021539

1540+
template <>
1541+
class type_caster<float_> : public pyobject_caster<float_> {
1542+
public:
1543+
bool load(handle src, bool /* convert */) {
1544+
if (isinstance<float_>(src)) {
1545+
value = reinterpret_borrow<float_>(src);
1546+
} else if (isinstance<int_>(src)) {
1547+
value = float_(reinterpret_borrow<int_>(src));
1548+
} else {
1549+
return false;
1550+
}
1551+
return true;
1552+
}
1553+
};
1554+
16031555
// Our conditions for enabling moving are quite restrictive:
16041556
// At compile time:
16051557
// - T needs to be a non-const, non-pointer, non-reference type
@@ -2104,6 +2056,10 @@ using is_pos_only = std::is_same<intrinsic_t<T>, pos_only>;
21042056
// forward declaration (definition in attr.h)
21052057
struct function_record;
21062058

2059+
/// (Inline size chosen mostly arbitrarily; 6 should pad function_call out to two cache lines
2060+
/// (16 pointers) in size.)
2061+
constexpr std::size_t arg_vector_small_size = 6;
2062+
21072063
/// Internal data associated with a single function call
21082064
struct function_call {
21092065
function_call(const function_record &f, handle p); // Implementation in attr.h
@@ -2112,10 +2068,10 @@ struct function_call {
21122068
const function_record &func;
21132069

21142070
/// Arguments passed to the function:
2115-
std::vector<handle> args;
2071+
argument_vector<arg_vector_small_size> args;
21162072

21172073
/// The `convert` value the arguments should be loaded with
2118-
std::vector<bool> args_convert;
2074+
args_convert_vector<arg_vector_small_size> args_convert;
21192075

21202076
/// Extra references for the optional `py::args` and/or `py::kwargs` arguments (which, if
21212077
/// present, are also in `args` but without a reference).

0 commit comments

Comments
 (0)