Skip to content

Working with a homebrewed shared pointer type that does not implement .get() #585

@jbarlow83

Description

@jbarlow83

First off, I really appreciate pybind11, after having played with bindings in Cython, SWIG, and some automatic generators that mostly create broken bindings, this is the clear winner.

I am trying to bind a class that is returned via a library's homebrewed shared pointer called PointerHolder that is basically a std::shared_ptr with a slightly different API.

The main difference is that it does not have a .get() method, the equivalent being named .getPointer(). It has the expected operator* and operator->.

Changing the existing library and header is not an option.

Is there any way to deal with this? Is it safe to change this occurrence of src.get() in pybind11 to *src since most custom holder types will have operator*? Or should should I wrap or extend PointerHolder to work around this?

In file included from src/main.cpp:15:
In file included from pybind11/pybind11.h:36:
In file included from pybind11/attr.h:13:
pybind11/cast.h:942:17: error: 
      no member named 'get' in 'PointerHolder<Actor>'
            src.get(), return_value_policy::take_ownership, handle(),
            ~~~ ^
pybind11/pybind11.h:140:39: note: 
      in instantiation of member function
      'pybind11::detail::type_caster_holder<Actor, PointerHolder<Actor>
      >::cast' requested here
            handle result = cast_out::cast(args_converter.template call<...
                                      ^
[... some details omitted... ]
1 error generated.
error: command 'clang' failed with exit status 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions