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

Allow function pointer extraction from overloaded functions #2944

Merged
merged 2 commits into from
Apr 13, 2021

Conversation

otamachan
Copy link
Contributor

Description

When I try to avoid C++ -> Python -> C++ roundtrip for overloaded functions, it only works for the first overloaded function.
This PR allows function pointer extraction from all overloaded functions.

I added a failure test case. Without the fix in this PR, it fails as follows:

>       assert (
            m.test_dummy_function(m.dummy_function_overloaded)
            == "matches dummy_function: eval(1) = 2"
        )
E       assert "can't conver...: eval(1) = 2" == 'matches dumm...: eval(1) = 2'
E         - matches dummy_function: eval(1) = 2
E         + can't convert to function pointer: eval(1) = 2

I applied clang-format to only the related code block so the style was changed a bit.

Suggested changelog entry:

Allow function pointer extraction from overloaded functions

value = ((capture *) &rec->data)->f;
return true;
}
rec = rec->next;
Copy link
Collaborator

@henryiii henryiii Apr 10, 2021

Choose a reason for hiding this comment

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

This line (and the while) is the only actual change, I think. The rest is formatting. Note that if we used clang-format, this would not randomly change. :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, I feel the same.

Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

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

Looks great to me, thanks for the fix Tamaki!
(I'm a bit amazed that this oversight survived for so long.)

I already ran this PR through our Google-internal global testing system: all green.
I'll go ahead with merging this PR.

value = ((capture *) &rec->data)->f;
return true;
}
rec = rec->next;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, I feel the same.

@rwgk rwgk merged commit 6709abb into pybind:master Apr 13, 2021
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Apr 13, 2021
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Jul 13, 2021
kraj referenced this pull request in YoeDistro/meta-openembedded Jul 26, 2021
v2.7.0 (Jul 16, 2021)
---------------------

New features:

* Enable ``py::implicitly_convertible<py::none, ...>`` for
  ``py::class_``-wrapped types.
  `#3059 <https://github.com/pybind/pybind11/pull/3059>`_

* Allow function pointer extraction from overloaded functions.
  `#2944 <https://github.com/pybind/pybind11/pull/2944>`_

* NumPy: added ``.char_()`` to type which gives the NumPy public ``char``
  result, which also distinguishes types by bit length (unlike ``.kind()``).
  `#2864 <https://github.com/pybind/pybind11/pull/2864>`_

* Add ``pybind11::bytearray`` to manipulate ``bytearray`` similar to ``bytes``.
  `#2799 <https://github.com/pybind/pybind11/pull/2799>`_

* ``pybind11/stl/filesystem.h`` registers a type caster that, on C++17/Python
  3.6+, converts ``std::filesystem::path`` to ``pathlib.Path`` and any
  ``os.PathLike`` to ``std::filesystem::path``.
  `#2730 <https://github.com/pybind/pybind11/pull/2730>`_

* A ``PYBIND11_VERSION_HEX`` define was added, similar to ``PY_VERSION_HEX``.
  `#3120 <https://github.com/pybind/pybind11/pull/3120>`_

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
kraj referenced this pull request in YoeDistro/meta-openembedded Jul 26, 2021
v2.7.0 (Jul 16, 2021)
---------------------

New features:

* Enable ``py::implicitly_convertible<py::none, ...>`` for
  ``py::class_``-wrapped types.
  `#3059 <https://github.com/pybind/pybind11/pull/3059>`_

* Allow function pointer extraction from overloaded functions.
  `#2944 <https://github.com/pybind/pybind11/pull/2944>`_

* NumPy: added ``.char_()`` to type which gives the NumPy public ``char``
  result, which also distinguishes types by bit length (unlike ``.kind()``).
  `#2864 <https://github.com/pybind/pybind11/pull/2864>`_

* Add ``pybind11::bytearray`` to manipulate ``bytearray`` similar to ``bytes``.
  `#2799 <https://github.com/pybind/pybind11/pull/2799>`_

* ``pybind11/stl/filesystem.h`` registers a type caster that, on C++17/Python
  3.6+, converts ``std::filesystem::path`` to ``pathlib.Path`` and any
  ``os.PathLike`` to ``std::filesystem::path``.
  `#2730 <https://github.com/pybind/pybind11/pull/2730>`_

* A ``PYBIND11_VERSION_HEX`` define was added, similar to ``PY_VERSION_HEX``.
  `#3120 <https://github.com/pybind/pybind11/pull/3120>`_

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
kraj referenced this pull request in YoeDistro/meta-openembedded Jul 27, 2021
v2.7.0 (Jul 16, 2021)
---------------------

New features:

* Enable ``py::implicitly_convertible<py::none, ...>`` for
  ``py::class_``-wrapped types.
  `#3059 <https://github.com/pybind/pybind11/pull/3059>`_

* Allow function pointer extraction from overloaded functions.
  `#2944 <https://github.com/pybind/pybind11/pull/2944>`_

* NumPy: added ``.char_()`` to type which gives the NumPy public ``char``
  result, which also distinguishes types by bit length (unlike ``.kind()``).
  `#2864 <https://github.com/pybind/pybind11/pull/2864>`_

* Add ``pybind11::bytearray`` to manipulate ``bytearray`` similar to ``bytes``.
  `#2799 <https://github.com/pybind/pybind11/pull/2799>`_

* ``pybind11/stl/filesystem.h`` registers a type caster that, on C++17/Python
  3.6+, converts ``std::filesystem::path`` to ``pathlib.Path`` and any
  ``os.PathLike`` to ``std::filesystem::path``.
  `#2730 <https://github.com/pybind/pybind11/pull/2730>`_

* A ``PYBIND11_VERSION_HEX`` define was added, similar to ``PY_VERSION_HEX``.
  `#3120 <https://github.com/pybind/pybind11/pull/3120>`_

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
kraj referenced this pull request in YoeDistro/meta-openembedded Jul 27, 2021
v2.7.0 (Jul 16, 2021)
---------------------

New features:

* Enable ``py::implicitly_convertible<py::none, ...>`` for
  ``py::class_``-wrapped types.
  `#3059 <https://github.com/pybind/pybind11/pull/3059>`_

* Allow function pointer extraction from overloaded functions.
  `#2944 <https://github.com/pybind/pybind11/pull/2944>`_

* NumPy: added ``.char_()`` to type which gives the NumPy public ``char``
  result, which also distinguishes types by bit length (unlike ``.kind()``).
  `#2864 <https://github.com/pybind/pybind11/pull/2864>`_

* Add ``pybind11::bytearray`` to manipulate ``bytearray`` similar to ``bytes``.
  `#2799 <https://github.com/pybind/pybind11/pull/2799>`_

* ``pybind11/stl/filesystem.h`` registers a type caster that, on C++17/Python
  3.6+, converts ``std::filesystem::path`` to ``pathlib.Path`` and any
  ``os.PathLike`` to ``std::filesystem::path``.
  `#2730 <https://github.com/pybind/pybind11/pull/2730>`_

* A ``PYBIND11_VERSION_HEX`` define was added, similar to ``PY_VERSION_HEX``.
  `#3120 <https://github.com/pybind/pybind11/pull/3120>`_

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
kraj referenced this pull request in YoeDistro/meta-openembedded Jul 28, 2021
v2.7.0 (Jul 16, 2021)
---------------------

New features:

* Enable ``py::implicitly_convertible<py::none, ...>`` for
  ``py::class_``-wrapped types.
  `#3059 <https://github.com/pybind/pybind11/pull/3059>`_

* Allow function pointer extraction from overloaded functions.
  `#2944 <https://github.com/pybind/pybind11/pull/2944>`_

* NumPy: added ``.char_()`` to type which gives the NumPy public ``char``
  result, which also distinguishes types by bit length (unlike ``.kind()``).
  `#2864 <https://github.com/pybind/pybind11/pull/2864>`_

* Add ``pybind11::bytearray`` to manipulate ``bytearray`` similar to ``bytes``.
  `#2799 <https://github.com/pybind/pybind11/pull/2799>`_

* ``pybind11/stl/filesystem.h`` registers a type caster that, on C++17/Python
  3.6+, converts ``std::filesystem::path`` to ``pathlib.Path`` and any
  ``os.PathLike`` to ``std::filesystem::path``.
  `#2730 <https://github.com/pybind/pybind11/pull/2730>`_

* A ``PYBIND11_VERSION_HEX`` define was added, similar to ``PY_VERSION_HEX``.
  `#3120 <https://github.com/pybind/pybind11/pull/3120>`_

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
kraj referenced this pull request in YoeDistro/meta-openembedded Jul 28, 2021
v2.7.0 (Jul 16, 2021)
---------------------

New features:

* Enable ``py::implicitly_convertible<py::none, ...>`` for
  ``py::class_``-wrapped types.
  `#3059 <https://github.com/pybind/pybind11/pull/3059>`_

* Allow function pointer extraction from overloaded functions.
  `#2944 <https://github.com/pybind/pybind11/pull/2944>`_

* NumPy: added ``.char_()`` to type which gives the NumPy public ``char``
  result, which also distinguishes types by bit length (unlike ``.kind()``).
  `#2864 <https://github.com/pybind/pybind11/pull/2864>`_

* Add ``pybind11::bytearray`` to manipulate ``bytearray`` similar to ``bytes``.
  `#2799 <https://github.com/pybind/pybind11/pull/2799>`_

* ``pybind11/stl/filesystem.h`` registers a type caster that, on C++17/Python
  3.6+, converts ``std::filesystem::path`` to ``pathlib.Path`` and any
  ``os.PathLike`` to ``std::filesystem::path``.
  `#2730 <https://github.com/pybind/pybind11/pull/2730>`_

* A ``PYBIND11_VERSION_HEX`` define was added, similar to ``PY_VERSION_HEX``.
  `#3120 <https://github.com/pybind/pybind11/pull/3120>`_

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
kraj referenced this pull request in YoeDistro/meta-openembedded Jul 28, 2021
v2.7.0 (Jul 16, 2021)
---------------------

New features:

* Enable ``py::implicitly_convertible<py::none, ...>`` for
  ``py::class_``-wrapped types.
  `#3059 <https://github.com/pybind/pybind11/pull/3059>`_

* Allow function pointer extraction from overloaded functions.
  `#2944 <https://github.com/pybind/pybind11/pull/2944>`_

* NumPy: added ``.char_()`` to type which gives the NumPy public ``char``
  result, which also distinguishes types by bit length (unlike ``.kind()``).
  `#2864 <https://github.com/pybind/pybind11/pull/2864>`_

* Add ``pybind11::bytearray`` to manipulate ``bytearray`` similar to ``bytes``.
  `#2799 <https://github.com/pybind/pybind11/pull/2799>`_

* ``pybind11/stl/filesystem.h`` registers a type caster that, on C++17/Python
  3.6+, converts ``std::filesystem::path`` to ``pathlib.Path`` and any
  ``os.PathLike`` to ``std::filesystem::path``.
  `#2730 <https://github.com/pybind/pybind11/pull/2730>`_

* A ``PYBIND11_VERSION_HEX`` define was added, similar to ``PY_VERSION_HEX``.
  `#3120 <https://github.com/pybind/pybind11/pull/3120>`_

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
kraj referenced this pull request in YoeDistro/meta-openembedded Jul 29, 2021
v2.7.0 (Jul 16, 2021)
---------------------

New features:

* Enable ``py::implicitly_convertible<py::none, ...>`` for
  ``py::class_``-wrapped types.
  `#3059 <https://github.com/pybind/pybind11/pull/3059>`_

* Allow function pointer extraction from overloaded functions.
  `#2944 <https://github.com/pybind/pybind11/pull/2944>`_

* NumPy: added ``.char_()`` to type which gives the NumPy public ``char``
  result, which also distinguishes types by bit length (unlike ``.kind()``).
  `#2864 <https://github.com/pybind/pybind11/pull/2864>`_

* Add ``pybind11::bytearray`` to manipulate ``bytearray`` similar to ``bytes``.
  `#2799 <https://github.com/pybind/pybind11/pull/2799>`_

* ``pybind11/stl/filesystem.h`` registers a type caster that, on C++17/Python
  3.6+, converts ``std::filesystem::path`` to ``pathlib.Path`` and any
  ``os.PathLike`` to ``std::filesystem::path``.
  `#2730 <https://github.com/pybind/pybind11/pull/2730>`_

* A ``PYBIND11_VERSION_HEX`` define was added, similar to ``PY_VERSION_HEX``.
  `#3120 <https://github.com/pybind/pybind11/pull/3120>`_

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
kraj referenced this pull request in YoeDistro/meta-openembedded Jul 29, 2021
v2.7.0 (Jul 16, 2021)
---------------------

New features:

* Enable ``py::implicitly_convertible<py::none, ...>`` for
  ``py::class_``-wrapped types.
  `#3059 <https://github.com/pybind/pybind11/pull/3059>`_

* Allow function pointer extraction from overloaded functions.
  `#2944 <https://github.com/pybind/pybind11/pull/2944>`_

* NumPy: added ``.char_()`` to type which gives the NumPy public ``char``
  result, which also distinguishes types by bit length (unlike ``.kind()``).
  `#2864 <https://github.com/pybind/pybind11/pull/2864>`_

* Add ``pybind11::bytearray`` to manipulate ``bytearray`` similar to ``bytes``.
  `#2799 <https://github.com/pybind/pybind11/pull/2799>`_

* ``pybind11/stl/filesystem.h`` registers a type caster that, on C++17/Python
  3.6+, converts ``std::filesystem::path`` to ``pathlib.Path`` and any
  ``os.PathLike`` to ``std::filesystem::path``.
  `#2730 <https://github.com/pybind/pybind11/pull/2730>`_

* A ``PYBIND11_VERSION_HEX`` define was added, similar to ``PY_VERSION_HEX``.
  `#3120 <https://github.com/pybind/pybind11/pull/3120>`_

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
Signed-off-by: Trevor Gamblin <[email protected]>
daregit referenced this pull request in daregit/yocto-combined May 22, 2024
v2.7.0 (Jul 16, 2021)
---------------------

New features:

* Enable ``py::implicitly_convertible<py::none, ...>`` for
  ``py::class_``-wrapped types.
  `#3059 <https://github.com/pybind/pybind11/pull/3059>`_

* Allow function pointer extraction from overloaded functions.
  `#2944 <https://github.com/pybind/pybind11/pull/2944>`_

* NumPy: added ``.char_()`` to type which gives the NumPy public ``char``
  result, which also distinguishes types by bit length (unlike ``.kind()``).
  `#2864 <https://github.com/pybind/pybind11/pull/2864>`_

* Add ``pybind11::bytearray`` to manipulate ``bytearray`` similar to ``bytes``.
  `#2799 <https://github.com/pybind/pybind11/pull/2799>`_

* ``pybind11/stl/filesystem.h`` registers a type caster that, on C++17/Python
  3.6+, converts ``std::filesystem::path`` to ``pathlib.Path`` and any
  ``os.PathLike`` to ``std::filesystem::path``.
  `#2730 <https://github.com/pybind/pybind11/pull/2730>`_

* A ``PYBIND11_VERSION_HEX`` define was added, similar to ``PY_VERSION_HEX``.
  `#3120 <https://github.com/pybind/pybind11/pull/3120>`_

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
Signed-off-by: Trevor Gamblin <[email protected]>
daregit referenced this pull request in daregit/yocto-combined May 22, 2024
v2.7.0 (Jul 16, 2021)
---------------------

New features:

* Enable ``py::implicitly_convertible<py::none, ...>`` for
  ``py::class_``-wrapped types.
  `#3059 <https://github.com/pybind/pybind11/pull/3059>`_

* Allow function pointer extraction from overloaded functions.
  `#2944 <https://github.com/pybind/pybind11/pull/2944>`_

* NumPy: added ``.char_()`` to type which gives the NumPy public ``char``
  result, which also distinguishes types by bit length (unlike ``.kind()``).
  `#2864 <https://github.com/pybind/pybind11/pull/2864>`_

* Add ``pybind11::bytearray`` to manipulate ``bytearray`` similar to ``bytes``.
  `#2799 <https://github.com/pybind/pybind11/pull/2799>`_

* ``pybind11/stl/filesystem.h`` registers a type caster that, on C++17/Python
  3.6+, converts ``std::filesystem::path`` to ``pathlib.Path`` and any
  ``os.PathLike`` to ``std::filesystem::path``.
  `#2730 <https://github.com/pybind/pybind11/pull/2730>`_

* A ``PYBIND11_VERSION_HEX`` define was added, similar to ``PY_VERSION_HEX``.
  `#3120 <https://github.com/pybind/pybind11/pull/3120>`_

Signed-off-by: Zheng Ruoqin <[email protected]>
Signed-off-by: Khem Raj <[email protected]>
Signed-off-by: Trevor Gamblin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants