Skip to content

Conversation

@felixendres
Copy link
Contributor

Fix issue #285:
Remove the temporary variable in a macro, because the name of the variable may shadow a variable of the macro user.
As suggested by @clalancette, also wrapped it into a do-while wrapping.

Signed-off-by: Felix Endres

} \
} \
}
} while (0);
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks pretty good to me. One thing that I'd prefer to do here is to remove the semicolon from the end of this line, and make the callers of this macro have the semicolon. That will play more nicely with text editors, and also look more like statements inline.

To do this, we'd have to update all of the callers of RCUTILS_LOGGING_AUTOINIT to have a semicolon on the end. Most of the callers are in this repository, but there is also a caller in rcl and rclpy. We'd need to have separate PRs for that.

@felixendres Are you willing to make those updates? If so, please go ahead and fix up rcutils as suggested, and open PRs to rcl and rclpy as well. If not, that's OK, but please open an issue so we can do this follow-up in the future.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I totally agree on @clalancette suggestion, in addition to

  • No need to prevent uncrustify from making unnecessary indents.
  • It is unlikely that user application calls RCUTILS_LOGGING_AUTOINIT directly.

} \
} \
}
} while (0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I totally agree on @clalancette suggestion, in addition to

  • No need to prevent uncrustify from making unnecessary indents.
  • It is unlikely that user application calls RCUTILS_LOGGING_AUTOINIT directly.

@felixendres
Copy link
Contributor Author

I'd prefer to not make the semicolon changes. This issue is actually an extremely minor issue, so let's not sink too much time into it.

Apart from the uncrustify comment (which I don't understand, so you be the judge) the current change improves the status quo. The semicolon issue is the same as before (putting one after the macro is superfluous before and after).

So I suggest to merge it as is, unless that uncrustify thing is a problem.

felixendres and others added 3 commits October 1, 2020 01:04
Fix issue ros2#285:
Remove the temporary variable in a macro, because the name of the variable may shadow a variable of the macro user.
As suggested by @clalancette, also wrapped it into a do-while wrapping.

Signed-off-by: Felix Endres <[email protected]>
Signed-off-by: Chris Lalancette <[email protected]>
@clalancette
Copy link
Contributor

clalancette commented Oct 1, 2020

I've gone ahead and rebased this, and also changed to remove the semicolon. Besides the changes in this PR, this required two other PRs, one in rclpy and one in rcl. Here's CI for the whole lot:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@clalancette
Copy link
Contributor

All right. The Windows failures are happening on nightlies as well, so this is ready to go. Since I made changes here, I'm going to wait for another review from @ros2/team .

@dirk-thomas
Copy link
Member

@felixendres it would good to update the ticket title to express the content of the patch since it will become the squashed commit message.

@clalancette clalancette merged commit 61b0264 into ros2:master Oct 5, 2020
@clalancette clalancette changed the title Update logging.h Remove the temporary variable in RCUTILS_LOGGING_AUTOINIT Oct 5, 2020
@felixendres felixendres changed the title Remove the temporary variable in RCUTILS_LOGGING_AUTOINIT Code quality improvements for logging macro Oct 6, 2020
@felixendres felixendres changed the title Code quality improvements for logging macro Remove the temporary variable in RCUTILS_LOGGING_AUTOINIT Oct 6, 2020
@felixendres
Copy link
Contributor Author

Sorry, for the title-change back and forth. I could swear I still saw the old title "Update logging.h", when I changed it...

@felixendres felixendres deleted the patch-1 branch October 6, 2020 09:22
@clalancette
Copy link
Contributor

Sorry, for the title-change back and forth. I could swear I still saw the old title "Update logging.h", when I changed it...

No worries, it was probably just cached in your browser.

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.

5 participants