Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

squash-merge smart_holder branch into master #5542

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
cd1c9d4
Pure `git merge --squash smart_holder` (no manual interventions).
rwgk Feb 22, 2025
f01bc09
Remove ubench/ directory.
rwgk Feb 22, 2025
4d8973e
Remove include/pybind11/smart_holder.h
rwgk Feb 22, 2025
c807ec3
[ci skip] smart_ptrs.rst updates [WIP/unfinished]
rwgk Feb 23, 2025
76f4da3
[ci skip] smart_ptrs.rst updates continued; also updating classes.rst…
rwgk Feb 23, 2025
eb550d0
Remove README_smart_holder.rst
rwgk Feb 23, 2025
860d58e
Restore original README.rst from master
rwgk Feb 23, 2025
6bf9e88
[ci skip] Minimal change to README.rst, to leave a hint that this is …
rwgk Feb 23, 2025
f4ad02b
[ci skip] Work in ChatGPT suggestions.
rwgk Feb 23, 2025
7cae21f
Change macro name to PYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAUL…
rwgk Feb 24, 2025
388fa99
Add a note pointing to the holder reinterpret_cast.
rwgk Feb 24, 2025
449cceb
Incorporate suggestion by @virtuald: /~https://github.com/pybind/pybind…
rwgk Feb 24, 2025
ac9d31e
Systematically change most py::class_ to py::classh under docs/
rwgk Feb 24, 2025
a4cfd38
Remove references to README_smart_holder.rst
rwgk Feb 24, 2025
046883c
[ci skip] Fix minor oversight (``class_`` -> ``py::class_``) noticed …
rwgk Feb 25, 2025
4cc528d
[ci skip] Resolve suggestion by @virtuald
rwgk Feb 26, 2025
5f1d646
[ci skip] Apply suggestions by @timohl (thanks!)
rwgk Feb 26, 2025
ff7c087
Replace `classh : class_` inhertance with `using`, as suggested by @h…
rwgk Feb 27, 2025
1e646c9
Revert "Systematically change most py::class_ to py::classh under docs/"
henryiii Feb 28, 2025
7dc507e
docs: focus on py::smart_holder instead of py::classh
henryiii Feb 28, 2025
8409b19
Restore minor general fixes that got lost when ac9d31e13fd15f2a8e3dee…
rwgk Mar 1, 2025
85cc92d
Remove `- smart_holder` from list of branches in all .github/workflows
rwgk Mar 1, 2025
b73f430
Extend classh note to explain whitespace noise motivation.
rwgk Mar 1, 2025
d3f9f93
Suggest `py::smart_holder` for "most situations for safety"
rwgk Mar 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .codespell-ignore-lines
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ template <op_id id, op_type ot, typename L, typename R>
template <detail::op_id id, detail::op_type ot, typename L, typename R, typename... Extra>
class_ &def(const detail::op_<id, ot, L, R> &op, const Extra &...extra) {
class_ &def_cast(const detail::op_<id, ot, L, R> &op, const Extra &...extra) {
int valu;
explicit movable_int(int v) : valu{v} {}
movable_int(movable_int &&other) noexcept : valu(other.valu) { other.valu = 91; }
explicit indestructible_int(int v) : valu{v} {}
REQUIRE(hld.as_raw_ptr_unowned<zombie>()->valu == 19);
REQUIRE(othr.valu == 19);
REQUIRE(orig.valu == 91);
(m.pass_valu, "Valu", "pass_valu:Valu(_MvCtor)*_CpCtor"),
atyp_valu rtrn_valu() { atyp_valu obj{"Valu"}; return obj; }
assert m.atyp_valu().get_mtxt() == "Valu"
// valu(e), ref(erence), ptr or p (pointer), r = rvalue, m = mutable, c = const,
@pytest.mark.parametrize("access", ["ro", "rw", "static_ro", "static_rw"])
struct IntStruct {
explicit IntStruct(int v) : value(v){};
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
branches:
- master
- stable
- smart_holder
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left over? (also on other CI files)

- v*

permissions: read-all
Expand Down Expand Up @@ -87,6 +88,20 @@ jobs:
# Extra ubuntu latest job
- runs-on: ubuntu-latest
python: '3.11'
# Exercise PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
# with recent (or ideally latest) released Python version.
- runs-on: ubuntu-latest
python: '3.12'
args: >
-DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
- runs-on: macos-13
python: '3.12'
args: >
-DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
- runs-on: windows-2022
python: '3.12'
args: >
-DCMAKE_CXX_FLAGS="/DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT /GR /EHsc"
exclude:
# The setup-python action currently doesn't have graalpy for windows
- python: 'graalpy-24.1'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
branches:
- master
- stable
- smart_holder
- v*

permissions:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/emscripten.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
branches:
- master
- stable
- smart_holder
- v*

concurrency:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
branches:
- master
- stable
- smart_holder
- "v*"

permissions:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
branches:
- master
- stable
- smart_holder
- v*
release:
types:
Expand Down
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ repos:
- id: mixed-line-ending
- id: requirements-txt-fixer
- id: trailing-whitespace
exclude: \.patch?$

# Also code format the docs
- repo: /~https://github.com/adamchainz/blacken-docs
Expand All @@ -90,6 +91,7 @@ repos:
rev: "v1.5.5"
hooks:
- id: remove-tabs
exclude: (^docs/.*|\.patch)?$

# Avoid directional quotes
- repo: /~https://github.com/sirosen/texthooks
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,13 @@ set(PYBIND11_HEADERS
include/pybind11/detail/common.h
include/pybind11/detail/cpp_conduit.h
include/pybind11/detail/descr.h
include/pybind11/detail/dynamic_raw_ptr_cast_if_possible.h
include/pybind11/detail/init.h
include/pybind11/detail/internals.h
include/pybind11/detail/struct_smart_holder.h
include/pybind11/detail/type_caster_base.h
include/pybind11/detail/typeid.h
include/pybind11/detail/using_smart_holder.h
include/pybind11/detail/value_and_holder.h
include/pybind11/detail/exception_translation.h
include/pybind11/attr.h
Expand Down Expand Up @@ -164,6 +167,7 @@ set(PYBIND11_HEADERS
include/pybind11/stl.h
include/pybind11/stl_bind.h
include/pybind11/stl/filesystem.h
include/pybind11/trampoline_self_life_support.h
include/pybind11/type_caster_pyobject_ptr.h
include/pybind11/typing.h
include/pybind11/warnings.h)
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
prune tests
include README_smart_holder.rst
recursive-include pybind11/include/pybind11 *.h
recursive-include pybind11 *.py
recursive-include pybind11 py.typed
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. figure:: /~https://github.com/pybind/pybind11/raw/master/docs/pybind11-logo.png
:alt: pybind11 logo

**pybind11 — Seamless operability between C++11 and Python**
**pybind11 (v3) — Seamless interoperability between C++ and Python**

|Latest Documentation Status| |Stable Documentation Status| |Gitter chat| |GitHub Discussions| |CI| |Build status|

Expand Down
26 changes: 26 additions & 0 deletions docs/advanced/classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,32 @@ extend ``Animal``, but not ``Dog``: see :ref:`virtual_and_inheritance` for the
necessary steps required to providing proper overriding support for inherited
classes.

To enable safely passing a ``std::unique_ptr`` to a trampoline object between
Python and C++,

1. the C++ type (``Animal`` above) must be wrapped with ``py::classh``
(see :ref:`smart_holder`), and

2. the trampoline helper class must inherit from
``py::trampoline_self_life_support``.

I.e. the example above needs these two changes:

.. code-block:: cpp

class PyAnimal : public Animal, public py::trampoline_self_life_support {
...
};

.. code-block:: cpp

py::classh<Animal, PyAnimal>(m, "Animal");

.. seealso::

A fairly minimal but complete example is in
:file:`tests/test_class_sh_trampoline_unique_ptr.cpp`.

The Python session below shows how to override ``Animal::go`` and invoke it via
a virtual method call.

Expand Down
Loading