Skip to content

Conversation

@wjakob
Copy link
Member

@wjakob wjakob commented Jul 15, 2018

Return value policies for containers like those handled in in 'stl.h'
are currently broken.

The problem is that detail::return_value_policy_override::policy()
always returns 'move' when given a non-pointer/reference type, e.g.
'std::vector<...>'.

This is sensible behavior for custom types that are exposed via
'py::class_<>', but it does not make sense for types that are handled by
other type casters (STL containers, Eigen matrices, etc.).

This commit changes the behavior so that
detail::return_value_policy_override only becomes active when the type
caster derives from type_caster_generic.

Furthermore, the override logic is called recursively in STL type
casters to enable key/value-specific behavior.

Return value policies for containers like those handled in in 'stl.h'
are currently broken.

The problem is that detail::return_value_policy_override<C>::policy()
always returns 'move' when given a non-pointer/reference type, e.g.
'std::vector<...>'.

This is sensible behavior for custom types that are exposed via
'py::class_<>', but it does not make sense for types that are handled by
other type casters (STL containers, Eigen matrices, etc.).

This commit changes the behavior so that
detail::return_value_policy_override only becomes active when the type
caster derives from type_caster_generic.

Furthermore, the override logic is called recursively in STL type
casters to enable key/value-specific behavior.
Copy link
Member

@jagerman jagerman left a comment

Choose a reason for hiding this comment

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

This looks good to me; the logic inversion on the override seems pretty sensible.

class Placeholder {
public:
Placeholder() { print_created(this); }
Placeholder(const Placeholder &) = delete;//{ print_created(this); }
Copy link
Member

Choose a reason for hiding this comment

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

Debugging?

@wjakob wjakob merged commit cbd16a8 into pybind:master Jul 17, 2018
@wjakob
Copy link
Member Author

wjakob commented Jul 17, 2018

Thanks -- merged now.

EricCousineau-TRI added a commit to EricCousineau-TRI/pybind11 that referenced this pull request Sep 3, 2018
EricCousineau-TRI added a commit to EricCousineau-TRI/pybind11 that referenced this pull request Sep 3, 2018
wjakob added a commit that referenced this pull request Sep 11, 2018
* stl.h: propagate return value policies to type-specific casters

Return value policies for containers like those handled in in 'stl.h'
are currently broken.

The problem is that detail::return_value_policy_override<C>::policy()
always returns 'move' when given a non-pointer/reference type, e.g.
'std::vector<...>'.

This is sensible behavior for custom types that are exposed via
'py::class_<>', but it does not make sense for types that are handled by
other type casters (STL containers, Eigen matrices, etc.).

This commit changes the behavior so that
detail::return_value_policy_override only becomes active when the type
caster derives from type_caster_generic.

Furthermore, the override logic is called recursively in STL type
casters to enable key/value-specific behavior.
wojdyr added a commit to project-gemmi/gemmi that referenced this pull request Sep 12, 2018
fix compatibility with pybind11 2.2.4

return type of SubCells.find_atoms() is now "opaque" vector of pointers
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.

2 participants