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

Add type_caster<PyObject> #4601

Merged
merged 21 commits into from
May 7, 2023
Merged

Commits on Apr 1, 2023

  1. Add type_caster<PyObject> (tests are still incomplete).

    Ralf W. Grosse-Kunstleve committed Apr 1, 2023
    Configuration menu
    Copy the full SHA
    ef13f04 View commit details
    Browse the repository at this point in the history
  2. Fix oversight (const PyObject *).

    Ralf W. Grosse-Kunstleve committed Apr 1, 2023
    Configuration menu
    Copy the full SHA
    c7c52b0 View commit details
    Browse the repository at this point in the history
  3. Ensure type_caster<PyObject> only works for PyObject *

    Ralf W. Grosse-Kunstleve committed Apr 1, 2023
    Configuration menu
    Copy the full SHA
    f220f0c View commit details
    Browse the repository at this point in the history
  4. Move is_same_ignoring_cvref into detail namespace.

    Ralf W. Grosse-Kunstleve committed Apr 1, 2023
    Configuration menu
    Copy the full SHA
    467b237 View commit details
    Browse the repository at this point in the history
  5. Add test_cast_nullptr

    Ralf W. Grosse-Kunstleve committed Apr 1, 2023
    Configuration menu
    Copy the full SHA
    79f2b05 View commit details
    Browse the repository at this point in the history
  6. Change is_same_ignoring_cvref from variable template to using.

    ```
    test_type_caster_pyobject_ptr.cpp:8:23: error: variable templates only available with ‘-std=c++14’ or ‘-std=gnu++14’ [-Werror]
        8 | static constexpr bool is_same_ignoring_cvref = std::is_same<detail::remove_cvref_t<T>, U>::value;
          |                       ^~~~~~~~~~~~~~~~~~~~~~
    ```
    Ralf W. Grosse-Kunstleve committed Apr 1, 2023
    Configuration menu
    Copy the full SHA
    45f915b View commit details
    Browse the repository at this point in the history
  7. Remove return_value_policy::reference_internal keep_alive feature…

    … (because of doubts about it actually being useful).
    Ralf W. Grosse-Kunstleve committed Apr 1, 2023
    Configuration menu
    Copy the full SHA
    00cc8b4 View commit details
    Browse the repository at this point in the history
  8. Add missing test, fix bug (missing throw error_already_set();), var…

    …ious cosmetic changes.
    Ralf W. Grosse-Kunstleve committed Apr 1, 2023
    Configuration menu
    Copy the full SHA
    432de63 View commit details
    Browse the repository at this point in the history
  9. Move type_caster<PyObject> from test to new include (pybind11/type_…

    …caster_pyobject_ptr.h)
    Ralf W. Grosse-Kunstleve committed Apr 1, 2023
    Configuration menu
    Copy the full SHA
    db47541 View commit details
    Browse the repository at this point in the history
  10. Add new header file to CMakeLists.txt and tests/extra_python_package/…

    …test_files.py
    Ralf W. Grosse-Kunstleve committed Apr 1, 2023
    Configuration menu
    Copy the full SHA
    b393001 View commit details
    Browse the repository at this point in the history

Commits on Apr 3, 2023

  1. Backport changes from google/pybind11clif#30021 to pybind#4601

    Ralf W. Grosse-Kunstleve committed Apr 3, 2023
    Configuration menu
    Copy the full SHA
    0ba8003 View commit details
    Browse the repository at this point in the history

Commits on Apr 4, 2023

  1. Merge branch 'master' into type_caster_PyObject_master

    Ralf W. Grosse-Kunstleve committed Apr 4, 2023
    Configuration menu
    Copy the full SHA
    d976e66 View commit details
    Browse the repository at this point in the history
  2. Fix oversight in test (to resolve a valgrind leak detection error) an…

    …d add a related comment in cast.h.
    
    No production code changes.
    
    Make tests more sensitive by using `ValueHolder` instead of empty tuples and dicts.
    
    Manual leak checks with `while True:` & top command repeated for all tests.
    Ralf W. Grosse-Kunstleve committed Apr 4, 2023
    Configuration menu
    Copy the full SHA
    af1886a View commit details
    Browse the repository at this point in the history

Commits on Apr 5, 2023

  1. Add tests for interop with stl.h list_caster

    (No production code changes.)
    Ralf W. Grosse-Kunstleve committed Apr 5, 2023
    Configuration menu
    Copy the full SHA
    3391bbd View commit details
    Browse the repository at this point in the history
  2. Bug fix in test. Minor comment enhancements.

    Ralf W. Grosse-Kunstleve committed Apr 5, 2023
    Configuration menu
    Copy the full SHA
    f6c7cee View commit details
    Browse the repository at this point in the history

Commits on Apr 27, 2023

  1. Merge branch 'master' into type_caster_PyObject_master

    Ralf W. Grosse-Kunstleve committed Apr 27, 2023
    Configuration menu
    Copy the full SHA
    9907943 View commit details
    Browse the repository at this point in the history
  2. Change type_caster<PyObject>::name to object, as suggested by @Sk…

    Ralf W. Grosse-Kunstleve committed Apr 27, 2023
    Configuration menu
    Copy the full SHA
    5ccb893 View commit details
    Browse the repository at this point in the history
  3. Merge branch 'master' into type_caster_PyObject_master

    Ralf W. Grosse-Kunstleve committed Apr 27, 2023
    Configuration menu
    Copy the full SHA
    39cb0d8 View commit details
    Browse the repository at this point in the history
  4. Expand comment for the new T cast(const handle &handle) [T = `PyO…

    …bject *`]
    Ralf W. Grosse-Kunstleve committed Apr 27, 2023
    Configuration menu
    Copy the full SHA
    cf4c282 View commit details
    Browse the repository at this point in the history

Commits on May 1, 2023

  1. Merge branch 'master' into type_caster_PyObject_master

    Ralf W. Grosse-Kunstleve committed May 1, 2023
    Configuration menu
    Copy the full SHA
    6afa757 View commit details
    Browse the repository at this point in the history

Commits on May 2, 2023

  1. Add T cast(object &&obj) overload as suggested by @Skylion007

    The original suggestion leads to `error: call to 'cast' is ambiguous` (full error message below), therefore SFINAE guarding is needed.
    
    ```
    clang++ -o pybind11/tests/test_type_caster_pyobject_ptr.os -c -std=c++17 -fPIC -fvisibility=hidden -O0 -g -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -Wundef -Wnon-virtual-dtor -Wunused-result -Werror -isystem /usr/include/python3.10 -isystem /usr/include/eigen3 -DPYBIND11_STRICT_ASSERTS_CLASS_HOLDER_VS_TYPE_CASTER_MIX -DPYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD_IF_AVAILABLE -DPYBIND11_TEST_BOOST -Ipybind11/include -I/usr/local/google/home/rwgk/forked/pybind11/include -I/usr/local/google/home/rwgk/clone/pybind11/include /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp
    In file included from /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:1:
    In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/functional.h:12:
    In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:13:
    In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/class.h:12:
    In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/attr.h:14:
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1165:12: error: call to 'cast' is ambiguous
        return pybind11::cast<T>(std::move(*this));
               ^~~~~~~~~~~~~~~~~
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/functional.h:109:70: note: in instantiation of function template specialization 'pybind11::object::cast<_object *>' requested here
                    return hfunc.f(std::forward<Args>(args)...).template cast<Return>();
                                                                         ^
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/functional.h:103:16: note: in instantiation of member function 'pybind11::detail::type_caster<std::function<_object *(int)>>::load(pybind11::handle, bool)::func_wrapper::operator()' requested here
            struct func_wrapper {
                   ^
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1456:47: note: in instantiation of member function 'pybind11::detail::type_caster<std::function<_object *(int)>>::load' requested here
            if ((... || !std::get<Is>(argcasters).load(call.args[Is], call.args_convert[Is]))) {
                                                  ^
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1434:50: note: in instantiation of function template specialization 'pybind11::detail::argument_loader<const std::function<_object *(int)> &, int>::load_impl_sequence<0UL, 1UL>' requested here
        bool load_args(function_call &call) { return load_impl_sequence(call, indices{}); }
                                                     ^
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:227:33: note: in instantiation of member function 'pybind11::detail::argument_loader<const std::function<_object *(int)> &, int>::load_args' requested here
                if (!args_converter.load_args(call)) {
                                    ^
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:101:9: note: in instantiation of function template specialization 'pybind11::cpp_function::initialize<(lambda at /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:50:9), _object *, const std::function<_object *(int)> &, int, pybind11::name, pybind11::scope, pybind11::sibling, pybind11::return_value_policy>' requested here
            initialize(
            ^
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:1163:22: note: in instantiation of function template specialization 'pybind11::cpp_function::cpp_function<(lambda at /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:50:9), pybind11::name, pybind11::scope, pybind11::sibling, pybind11::return_value_policy, void>' requested here
            cpp_function func(std::forward<Func>(f),
                         ^
    /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:48:7: note: in instantiation of function template specialization 'pybind11::module_::def<(lambda at /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:50:9), pybind11::return_value_policy>' requested here
        m.def(
          ^
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1077:3: note: candidate function [with T = _object *, $1 = 0]
    T cast(object &&obj) {
      ^
    /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1149:1: note: candidate function [with T = _object *]
    cast(object &&object) {
    ^
    1 error generated.
    ```
    Ralf W. Grosse-Kunstleve committed May 2, 2023
    Configuration menu
    Copy the full SHA
    2e5a699 View commit details
    Browse the repository at this point in the history