Convert API to use std::shared_ptr#215
Conversation
a2a8c00 to
d71592e
Compare
| MOVEIT_CLASS_FORWARD(Shape); | ||
| class Shape; | ||
| typedef boost::shared_ptr<Shape> ShapePtr; | ||
| typedef boost::shared_ptr<const Shape> ShapeConstPtr; |
There was a problem hiding this comment.
Just to make sure I understand the logic here - we don't want to use std::shared_ptr for Shape because its part of geometric_shapes, which is part of desktop-full, which is not suppose to have std in its public headers yet, correct?
We did already break this rule for that package because it was required for FCL/octomap, but I guess in this case we don't have a good reason to continue to break that rule. But another (cleaner) possibility would be to make the C++11 switch there, as well, correct?
There was a problem hiding this comment.
I agree, it would be nice to have std::shared_ptr there. The previous deviation from REP-003 was out of necessity though. On the other hand, urdfdom also switched. And while it may not be a real ROS package that is more or less a technicality.
But yeah, as long as the geometric_shape API uses boost::shared_ptr we can't switch them here.
/edit: Apparently urdfdom is packaged as ROS package too. It's been a while since I've used the official Ubuntu distribution ^^
There was a problem hiding this comment.
How about a comment for ROS-L saying we'll switch to C++11 then?
There was a problem hiding this comment.
I agree, please add a comment here that explains why this code still uses boost::shared_ptr and that it should be changed for lunar.
|
+1 but other maintainers should get a chance to review and discuss this big change |
|
I would like to merge this asap so we have momentum for the kinetic release |
|
|
||
| /* used to unregister the notifier */ | ||
| boost::weak_ptr<World> world_; | ||
| std::weak_ptr<World> world_; |
There was a problem hiding this comment.
What about a WeakPtr definition in MOVEIT_CLASS_FORWARD?
There was a problem hiding this comment.
We had a short discussion at #206. Nobody seemed very interested (including me), but if you think that is the right approach you can reopen the PR.
| changes_ = other.changes_; | ||
|
|
||
| boost::weak_ptr<World>(world).swap(world_); | ||
| std::weak_ptr<World>(world).swap(world_); |
There was a problem hiding this comment.
see above (WeakPtr forward declaration)
| #include <moveit_msgs/PlanningSceneComponents.h> | ||
| #include <boost/enable_shared_from_this.hpp> | ||
| #include <boost/noncopyable.hpp> | ||
| #include <boost/shared_ptr.hpp> |
There was a problem hiding this comment.
Yeah, line 96 and 887 still use it for non-moveit types.
There was a problem hiding this comment.
yes, but now thant you use the Ptr typedef they don't mention the symbol anymore. So this can be removed imo
The same is probably true for a number of other files..
There was a problem hiding this comment.
Good point, will check.
v4hn
left a comment
There was a problem hiding this comment.
some minor refinements requested.
but overall this looks good to me.
| MOVEIT_CLASS_FORWARD(Shape); | ||
| class Shape; | ||
| typedef boost::shared_ptr<Shape> ShapePtr; | ||
| typedef boost::shared_ptr<const Shape> ShapeConstPtr; |
|
|
||
| #include <moveit/collision_detection/world.h> | ||
| #include <moveit/macros/class_forward.h> | ||
| #include <boost/weak_ptr.hpp> |
There was a problem hiding this comment.
this is missing a <memory> include, isn't it?
There was a problem hiding this comment.
Well, you can't make weak_ptrs without shared_ptrs. Since we have std::shared_ptr typedefs available from a macro in #include <moveit/macros/declare_ptr.h>, that will have pulled in #include <memory>.
But I am a fan of the rule "if you use a symbol from a header, include it", so I'll add it.
There was a problem hiding this comment.
#include <memory> added
| MOVEIT_CLASS_FORWARD(Shape); | ||
| class Shape; | ||
| typedef boost::shared_ptr<Shape> ShapePtr; | ||
| typedef boost::shared_ptr<const Shape> ShapeConstPtr; |
There was a problem hiding this comment.
gosh, how many of these cases are there? Why is this not centralized?
There was a problem hiding this comment.
I was a bit hesitant to add a macro for declaring boost::shared_ptr if they're going to turn in to std::shared_ptrs in the not-too-far future. Having macros like that lying around could be seen as an invitation to use them.
How about adding these typedefs in geometric_shapes (and possibly a new header geometric_shapes/forward.h to avoid including complex header), and until those are available keeping them explicit like this?
There was a problem hiding this comment.
+1, though I think you could make the switch now since kinetic is not released yet and Travis builds geometric_shapes from source for this PR
There was a problem hiding this comment.
Ah, these forward delarations where added by @rhaschke in 13d2e62 to reduce includes of geometric_shapes.
I don't like the idea to introduce a header there that only forward declares all the types.
@rhaschke is this change really worth the overhead to maintain the boost-shared_ptrs here?
On the other hand I agree with @davetcoleman. I don't think it's any good to have boost- and std- shared_ptr around in geometric_shapes in kinetic. So I would actually propose to fully move to std::shared_ptr there. This would also simplify the forward declarations here.
There was a problem hiding this comment.
I like the idea of that. I think I'll have some questions but I'll open a PR there for those (or an issue if the questions are blocking).
There was a problem hiding this comment.
I didn't think of it as a "solution to this problem". More as "this problem arises because the previous change that made geometric_shapes use c++11 shared_ptr was inconsistent."
And if we want to switch MoveIt! to std::shared_ptr (which is what this request is about), this should imho include geometric_shapes. Incidentally, I assumed all shared_ptr references where switched to c++11 when we discussed the issue with FCL and octomap.
There was a problem hiding this comment.
Nevertheless, moveit/geometric_shapes#57 and using MOVEIT_CLASS_FORWARD here again will also solve the practical issue.
That would basically mean dropping one commit from this PR:
- Don't use MOVEIT_CLASS_FORWARD for non-moveit classes.
There was a problem hiding this comment.
I didn't seem your last comment when replying. But fair enough, it does make sense to switch geometric_shapes and moveit at the same time. It could get very confusing otherwise.
And in that light it may be acceptable to use MOVEIT_CLASS_FORWARD for geometric_shapes types. It feels a bit weird to define typedefs using a moveit convention in the namespace of another library, but I suppose geometric_shapes and moveit are related enough.
Shall I just drop the relevant commit then, and revert to using MOVEIT_CLASS_FORWARD?
There was a problem hiding this comment.
let's see what comes out of your new request for geometric_shapes.
There was a problem hiding this comment.
I was assuming we were not switching these because it would violate the ROS policy of no std::shared_ptrs in the public headers of packages in ros-desktop-full. But then again, we already had to break that rule for FCL and Octomap, so it doesn't make a difference going all the way now.
| #include <moveit/collision_distance_field/collision_world_distance_field.h> | ||
| #include <moveit/collision_distance_field/collision_common_distance_field.h> | ||
| #include <moveit/distance_field/propagation_distance_field.h> | ||
| #include <boost/make_shared.hpp> |
There was a problem hiding this comment.
Same as previous, so will also add.
There was a problem hiding this comment.
#include <memory> added
| const std::vector<std::string> &resources) | ||
| { | ||
| return boost::make_shared<moveit_simple_controller_manager::FollowJointTrajectoryControllerHandle>( | ||
| return std::make_shared<moveit_simple_controller_manager::FollowJointTrajectoryControllerHandle>( |
There was a problem hiding this comment.
<memory> is not included here, but <boost/shared_ptr.hpp> still is. Is the latter still required here?
There was a problem hiding this comment.
Good catch. Indeed, boost header removed, #include <memory> added
| #include <moveit_msgs/PickupAction.h> | ||
| #include <moveit_msgs/PlaceAction.h> | ||
| #include <boost/noncopyable.hpp> | ||
| #include <boost/enable_shared_from_this.hpp> |
There was a problem hiding this comment.
<memory> should be included for std::enable_shared_from_this
There was a problem hiding this comment.
#include <memory> added
| MOVEIT_CLASS_FORWARD(Shape); | ||
| class Shape; | ||
| typedef boost::shared_ptr<Shape> ShapePtr; | ||
| typedef boost::shared_ptr<const Shape> ShapeConstPtr; |
There was a problem hiding this comment.
and yet another case that should have a comment saying this should be changed in lunar.
d71592e to
432e1ed
Compare
|
hmm, seems something went wrong during a rebase |
432e1ed to
9cdfbd4
Compare
|
Ah, the new |
|
correct, |
|
Looks like the Bit off-topic: apparently the |
|
@de-vri-es wrote:
This is documented in REP-140, but you're right that Bloom translates those into the appropriate key:value pairs in Debian control and RPM spec files. |
|
I'm looking into why the shadow-fixed CI is not building on Dockerhub |
|
Docker error is described here: ros/ros_comm#904 |
a81a7ae to
6404ac3
Compare
|
@gavanderhoorn: Thanks for the information. Not sure how I missed that. Update regarding this PR:
I think this addresses all the remaining review points, but correct me if I'm wrong. Only the first change affects the MoveIt API. The other two are implementation changes. The last point wasn't technically needed, but I think it makes sense to remove all boost smart pointers in one go. Locally this builds (with moveit/geometric_shapes#57), including the tests. I've never been able to run all tests successfully on my system though (probably due to python3 issues which I intend to investigate later). I don't expect any problems though, considering the interface and semantics of |
|
Actually, there are still There are a number of cases in |
|
For tf I would stick with I'm unsure about the others. But yes, I would welcome changing these cases (and also the non-API cases) too. |
c949c87 to
e7b28c1
Compare
|
The last commit converts a number of internal Ignoring |
|
Rebased on latest kinetic-devel again, now with collision_distance_field and chomp. |
|
Need #250 to be merged before test build https://github.com/davetcoleman/moveit_kinetic_cpp11 passes, indicating this PR is good |
|
@de-vri-es can you rebase this PR with the head of kinetic-devel? The build is failing because of the now fixed fcl dependency |
174af0e to
a2b9c2d
Compare
|
Rebased. Note that there are two commits that we probably want to cherry-pick to I/J (using commit messages in case of future rebases):
|
|
The travis test passes \o/ |
|
darn there is a merge conflict now, and i just merged moveit/geometric_shapes#57 can you fix asap? |
|
On it, rebase worked automatically, but I'd like to compile before pushing to be sure (I find automatic merges scary). Should be about 5 to 10 minutes. |
a2b9c2d to
fa5a9a8
Compare
|
Compiled fine locally, pushed. |
|
👏 C++11! |
|
\o/ |
|
I fully agree with this change, but want to point this out: This change entails that all packages that compile with a |
This PR updates the API to use
std::shared_ptrfor moveit types instead ofboost::shared_ptr.I'm not sure what the opinions are on this topic, but this PR at the least provides a place to discuss this specific API change. But do note that other libraries are doing the same thing right about now (like
fclandurdfdom).Technically, switching from
boost::enable_shared_from_thistostd::enable_shared_from_thisis not 100% API compatible, sinceweak_from_thisis only added in C++17. This is very unlikely to cause problems though.One more point:
pluginlibstill returnsboost::shared_ptrand usingcreateUnmanagedInstanceis discouraged. Instead I opted to convert the pointers tostd::instead. That method is not 100% safe whenweak_ptrare involved in the general case, but it is in this case because nobody else has a copy to the originalboost::shared_ptr.Because the conversion isn't safe in general I didn't want to put it in a header (the header would have to be exported or duplicated across 5 packages). Instead I opted now to duplicate the function in an anonymous namespace in 5 source files. I've also got a PR open with
class_loaderto add support forstd::smart pointers (unique and shared), so when that lands it makes sense to adapt to that interface. In the mean time I didn't know a nicer solution than the current in this PR.