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

Fixes for new warnings/behaviours in GCC7+/cppcheck. #480

Closed
wants to merge 9 commits into from

Conversation

mikepurvis
Copy link
Member

A bunch of stuff that came up when testing with the GCC9-based toolchain that will ship in Ubuntu Focal:

  • Add missing member initializations.
  • Add missing override specifiers.
  • Hacky cast for the 16 bit AVR float logic.

There are a few more member initializations to add in NodeHandle. Will get to those before merging.

Also, I believe this will break Bionic, and it's a pretty breaking change regardless, so this probably merits cutting a noetic-devel branch for it.

@mikepurvis mikepurvis changed the title Fixes for new warnings/behaviours in GCC 7+. Fixes for new warnings/behaviours in GCC7+/cppcheck. Apr 14, 2020
@romainreignier
Copy link
Contributor

About improving code quality, it would be nice to make the time related functions const like I did in our qt version.

Also, we could align the current toNsec with the ROS toNSec (capital S).
This is breaking the API but if a new noetic-devel branch is created, maybe it's the moment.

Regarding time functions, maybe we could try to use 64 bit variables even if I know that the major use case is on small microcontrollers so the time is not always an epoch time.
What do you think about that?

@mikepurvis mikepurvis changed the base branch from melodic-devel to noetic-devel April 14, 2020 21:27
@mikepurvis
Copy link
Member Author

mikepurvis commented Apr 14, 2020

PR is up for noetic-devel branch PR testing here: ros/rosdistro#24473

The tests will continue to fail until the Python 3 situation in rosserial_python is resolved. I might simply disable those tests in this PR so that it can merge and then open a separate one to get rosserial_python functional again.

Note also that the travis build will also have to be updated; there's no base VM for focal, so it should probably be switched to use the docker service, see: https://docs.travis-ci.com/user/docker/ (though that would be blocked on having the official ROS Noetic docker image— osrf/docker_images#395)

Copy link
Contributor

@stertingen stertingen left a comment

Choose a reason for hiding this comment

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

Although I approve Python 3 support in general; I wonder why is it included in this PR (targeting C++warnings).

@@ -545,7 +538,7 @@ def run(self):
else:
rospy.loginfo("wrong checksum for topic id and msg")

except IOError as exc:
except ImportError as exc:
Copy link
Contributor

Choose a reason for hiding this comment

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

What could possibly raise an ImportError that is caught here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, this makes no sense. Reverting.

rosserial_python/src/rosserial_python/SerialClient.py Outdated Show resolved Hide resolved
uint8_t message_in[INPUT_SIZE];
uint8_t message_out[OUTPUT_SIZE];
uint8_t message_in[INPUT_SIZE] = {0};
uint8_t message_out[OUTPUT_SIZE] = {0};

Publisher * publishers[MAX_PUBLISHERS];
Subscriber_ * subscribers[MAX_SUBSCRIBERS];
Copy link
Contributor

Choose a reason for hiding this comment

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

For the sake of consistency, publishers and subscribers should be initialized with = {nullptr}.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed. I wonder why cppcheck complained about all the other ones and not these.

try:
sent = self.socket.send(data[totalsent:])
except BrokenPipeError:
sent = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not raise RuntimeError(...) here?

The message "RosSerialServer.write() socket connection broken" below seems inappopriate for the case in which a BrokenPipeError was not caught, but zero bytes were sent anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, yeah I wasn't sure what to do here. From https://stackoverflow.com/a/34920917/109517, it seems like socket.send can legitimately return zero in at least some non-error scenarios. I suppose the risk is that it would hard loop on this, especially if you had a non-blocking socket, but that's not the case here with a dedicated writer thread. Have updated it to ignore the 0 scenario and instead throw from inside the except.

@mikepurvis
Copy link
Member Author

@stertingen Without proper Python 3 support landing for Noetic, the tests using rosserial_python don't pass. However, given the scope of the changes, perhaps it would make more sense to just disable those, merge the smaller original change here, and make a separate PR for fixing rosserial_python.

Publisher * publishers[MAX_PUBLISHERS];
Subscriber_ * subscribers[MAX_SUBSCRIBERS];
Publisher * publishers[MAX_PUBLISHERS] = {nullptr};
Subscriber_ * subscribers[MAX_SUBSCRIBERS] {nullptr};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Subscriber_ * subscribers[MAX_SUBSCRIBERS] {nullptr};
Subscriber_ * subscribers[MAX_SUBSCRIBERS] = {nullptr};

@mikepurvis
Copy link
Member Author

Closed in favour of #508.

@mikepurvis mikepurvis closed this Aug 21, 2020
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.

3 participants