Skip to content

Stop double-defining structs.#333

Merged
clalancette merged 1 commit intomasterfrom
clalancette/rename-structs
Aug 8, 2021
Merged

Stop double-defining structs.#333
clalancette merged 1 commit intomasterfrom
clalancette/rename-structs

Conversation

@clalancette
Copy link
Copy Markdown
Contributor

@clalancette clalancette commented Mar 12, 2021

Currently we use something like:

typedef struct foo_t
{
} foo_t;

But that actually double-defines the foo_t symbol
(at least, according to Doxygen). Instead, use the
more traditional:

typedef struct foo
{
} foo_t;

This is slightly controversial in that it is an API break;
any code that was using struct foo_t before will now fail
to compile (anything that was just using foo_t will be fine).

However, this should mostly affect low-level libraries
like client libraries and the such, so the scale of breakage
here should be low.

Signed-off-by: Chris Lalancette clalancette@openrobotics.org

@clalancette
Copy link
Copy Markdown
Contributor Author

CI (everything, just to ensure there is no higher-level breakage):

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

Copy link
Copy Markdown
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

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

lgtm

@clalancette clalancette self-assigned this Apr 1, 2021
Copy link
Copy Markdown
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

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

I would actually prefer to see this pattern:

typedef struct rcutils_foo_s {
  // ...
} rcutils_foo_t;

My reasons for this:

  • we already have code like rcutils_foo_t rcutils_foo = ...;
  • other users (outside our code base) could be using rcutils_foo (without the _t) causing a collision, but I think it is much less likely anyone is using rcutils_foo_s
  • having some suffix helps denote that it may be a complex type
  • though it is discouraged to use _t in your projects, the reasoning is that POSIX may arbitrarily add new <type>_t types, but since we namespace 100% of our C symbols with <package_name>_, that's not a problem
  • when using auto-complete seeing foo_t and foo_s indicates to me (without knowing the code base) which is the struct and which is the typedef, i.e. with foo and foo_t it could just as easily be struct foo_t as struct foo in my opinion

Thoughts?


If others agree, then I can update this pull request and add some documentation to our contributing/style guides.

@wjwwood
Copy link
Copy Markdown
Member

wjwwood commented Aug 5, 2021

we already have code like rcutils_foo_t rcutils_foo = ...;

I should clarify I think this is the case if we expand this pattern to other packages like rmw and rcl, though I don't think we have any instances of it for rcutils.

Currently we use something like:

typedef struct foo_t
{
} foo_t;

But that actually double-defines the `foo_t` symbol
(at least, according to Doxygen).  Instead, use the
more traditional:

typedef struct foo_s
{
} foo_t;

This is slightly controversial in that it is an API break;
any code that was using `struct foo_t` before will now fail
to compile (anything that was just using `foo_t` will be fine).

However, this should mostly affect low-level libraries
like client libraries and the such, so the scale of breakage
here should be low.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@clalancette
Copy link
Copy Markdown
Contributor Author

Thoughts?

I honestly don't have a strong opinion either way, so I'll go ahead and rebase this and change it to _s everywhere.

@clalancette clalancette force-pushed the clalancette/rename-structs branch from a30f1b9 to 415ebda Compare August 5, 2021 13:54
@clalancette
Copy link
Copy Markdown
Contributor Author

CI:

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

@wjwwood
Copy link
Copy Markdown
Member

wjwwood commented Aug 6, 2021

Rerunning CI since ros2/system_tests#481 and ros2/rcl_interfaces#125 were merged:

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

@clalancette
Copy link
Copy Markdown
Contributor Author

The failures in Windows were also in the nightlies. I'm going to go ahead and merge this, thanks for the reviews!

@clalancette clalancette merged commit 9d46b79 into master Aug 8, 2021
@clalancette clalancette deleted the clalancette/rename-structs branch August 8, 2021 12:59
@ros-discourse
Copy link
Copy Markdown

This pull request has been mentioned on ROS Discourse. There might be relevant details there:

https://discourse.ros.org/t/ros-2-tsc-meeting-minutes-2021-9-16/22372/1

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