This is an archive of the discontinued LLVM Phabricator instance.

[NativeProcessLinux] Reduce the number of casts
ClosedPublic

Authored by labath on Aug 20 2015, 3:05 AM.

Details

Summary

NPL used to be peppered with casts of the NativeThreadProtocol objects into NativeThreadLinux. I
move these closer to the source where we obtain these objects. This way, the rest of the code can
assume we are working with the correct type of objects.

Diff Detail

Event Timeline

labath updated this revision to Diff 32673.Aug 20 2015, 3:05 AM
labath retitled this revision from to [NativeProcessLinux] Reduce the number of casts.
labath updated this object.
labath added reviewers: ovyalov, tberghammer.
labath added a subscriber: lldb-commits.
tberghammer accepted this revision.Aug 20 2015, 4:05 AM
tberghammer edited edge metadata.

Looks good.

One inconsistency what might worth a change is that you usually pass NPL as a shared_ptr (or a reference to a shared_ptr) but you created a few function where it isn't true (e.g. ThreadWasCreated). I would prefer to always pass it by shared_ptr (possibly as a reference) for consistency.

This revision is now accepted and ready to land.Aug 20 2015, 4:05 AM
ovyalov accepted this revision.Aug 20 2015, 9:28 AM
ovyalov edited edge metadata.

LGTM

source/Plugins/Process/Linux/NativeProcessLinux.cpp
2834

You may use std::make_shared

labath marked an inline comment as done.Aug 21 2015, 2:12 AM

Passing around pointers (shared or otherwise) encourages people to litter the code with null pointer checks. For the next cleanup, I would like to move these checks to a single place and then convert more of these functions to take references.

This revision was automatically updated to reflect the committed changes.

Thanks for the info about the plans. If you plan to move to this direction then it make sense to leave these functions with reference arguments.

Side note: Why we use a shared_ptr for NTL? I would expect a unique_ptr would be sufficient in NPL (or possibly a store by value with move constructors).