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

Fix MISRA rule 8-3(1/2) 'declarations of a function same name and type' #1742

Merged
merged 6 commits into from
Jul 3, 2023

Conversation

Splinter1984
Copy link
Contributor

This PR addresses rule 8.3.

The identifiers used in the declaration and definition of a function shall be identical.

src/core/ddsc/src/dds_publisher.c Fixed Show fixed Hide fixed
src/core/ddsc/src/dds_reader.c Fixed Show fixed Hide fixed
Copy link
Contributor

@eboasson eboasson left a comment

Choose a reason for hiding this comment

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

Thanks @Splinter1984. In some of the cases I think you picked the wrong name to use consistently. The vast majority is fine, though.

@@ -63,13 +63,13 @@ DDS_INLINE_EXPORT inline dds_return_t dds_rhc_associate (struct dds_rhc *rhc, st
}

/** @component rhc */
DDS_INLINE_EXPORT inline bool dds_rhc_store (struct dds_rhc * __restrict rhc, const struct ddsi_writer_info * __restrict wrinfo, struct ddsi_serdata * __restrict sample, struct ddsi_tkmap_instance * __restrict tk) {
return rhc->common.ops->rhc_ops.store (&rhc->common.rhc, wrinfo, sample, tk);
DDS_INLINE_EXPORT inline bool dds_rhc_store (struct dds_rhc * __restrict rhc, const struct ddsi_writer_info * __restrict pwr_info, struct ddsi_serdata * __restrict sample, struct ddsi_tkmap_instance * __restrict tk) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to consistently use wrinfo (or wr_info) here: the code base consistently uses wr for a writer and pwr for a proxy writer (and similarly, rd/prd for readers and proxy readers). So to have a type named struct ddsi_writer_info and then call the parameter pwr_info is inconsistent.1

As a historical aside: in its very first incarnation (about a decade ago) this only dealt with remote data and hence it was always "proxy writer info" and apparently some parameter names stuck to that when local writers got added, even if the type names got fixed.

Footnotes

  1. One immediately sees the futility of MISRA!

@@ -1735,11 +1735,11 @@ static void pushdown_write_flush (dds_entity *e)
ddsrt_mutex_unlock (&e->m_mutex);
}

dds_return_t dds_write_flush (dds_entity_t entity)
dds_return_t dds_write_flush (dds_entity_t writer)
Copy link
Contributor

Choose a reason for hiding this comment

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

Here entity really is better: it can be a writer, publisher, participant or domain. I suppose that means the declaration in dds.h needs to be updated instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what happens when you blindly follow the MISRA rules!

@@ -31,7 +31,7 @@ const struct dds_entity_deriver dds_entity_deriver_guardcondition = {
.refresh_statistics = dds_entity_deriver_dummy_refresh_statistics
};

dds_entity_t dds_create_guardcondition (dds_entity_t owner)
dds_entity_t dds_create_guardcondition (dds_entity_t participant)
Copy link
Contributor

Choose a reason for hiding this comment

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

Here it is similar, the "owner" of the guard condition can be a participant, domain or even the root of the entity hierarchy. That makes participant a somewhat confusing name.

(As a historical aside: originally I thought it would be possible to limit it to participants. That turned out to be a wrong a call ... but like in some other cases, the declaration in dds.h wasn't updated along with the implementation.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

owner got back.

@@ -372,9 +372,9 @@ STATUS_CB_IMPL (reader, sample_lost, SAMPLE_LOST,
STATUS_CB_IMPL (reader, requested_deadline_missed, REQUESTED_DEADLINE_MISSED, total_count_change)
STATUS_CB_IMPL (reader, requested_incompatible_qos, REQUESTED_INCOMPATIBLE_QOS, total_count_change)

void dds_reader_status_cb (void *ventity, const ddsi_status_cb_data_t *data)
Copy link
Contributor

Choose a reason for hiding this comment

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

I use this v prefix quite often for these void * generic arguments ... in this case it gets cast to a dds_reader *rd, so it doesn't matter so much, but I'd like to keep it. Does that mean all those function type definitions need to be changed? I guess so ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why I decided to change it here 😐.

@@ -758,11 +758,11 @@ dds_entity_t dds_create_reader_rhc (dds_entity_t participant_or_subscriber, dds_
return dds_create_reader_int (participant_or_subscriber, topic, qos, listener, rhc);
}

uint32_t dds_reader_lock_samples (dds_entity_t reader)
uint32_t dds_reader_lock_samples (dds_entity_t entity)
Copy link
Contributor

Choose a reason for hiding this comment

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

So the function type uses entity because it is an entity in general, but these are specialised for a specific entity type ... so now MISRA is forcing my poor brain to track that where it says entity it really means reader ... I thought MISRA was all about reducing the risk of confusion!

(But then they have the "single exit" rule, which every programmer has learnt only increases the state to be tracked when reading the code and hence increases the likelihood of mistakes. I should try to find out who came up with that rule, because I think it is actually older than MISRA, probably some study of common coding mistakes ...)

@@ -306,7 +306,7 @@ dds_get_liveliness_lost_status (
*/
DDS_EXPORT dds_return_t
dds_get_offered_deadline_missed_status(
dds_entity_t writer,
Copy link
Contributor

Choose a reason for hiding this comment

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

This really only takes a writer, so I think "writer" is the better choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied and fixed.

@@ -277,7 +277,7 @@ dds_get_publication_matched_status (
*/
DDS_EXPORT dds_return_t
dds_get_liveliness_lost_status (
dds_entity_t writer,
Copy link
Contributor

Choose a reason for hiding this comment

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

This really only takes a writer, so I think "writer" is the better choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied and fixed.

@@ -248,7 +248,7 @@ dds_get_inconsistent_topic_status (
*/
DDS_EXPORT dds_return_t
dds_get_publication_matched_status (
dds_entity_t writer,
Copy link
Contributor

Choose a reason for hiding this comment

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

This really only takes a writer, so I think "writer" is the better choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied and fixed.

@@ -219,7 +219,7 @@ dds_inconsistent_topic_status_t;
*/
DDS_EXPORT dds_return_t
dds_get_inconsistent_topic_status (
dds_entity_t topic,
Copy link
Contributor

Choose a reason for hiding this comment

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

This really only takes a topic, so I think "topic" is the better choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MISRA want the same argument names for all dds__get_status functions.

#define DDS_GET_STATUS_COMMON(ent_type_, status_) \
dds_return_t dds_get_##status_##_status (dds_entity_t entity, dds_##status_##_status_t *status) \
{ \
dds_##ent_type_ *ent; \
dds_return_t ret; \
if ((ret = dds_##ent_type_##_lock (entity, &ent)) != DDS_RETCODE_OK) \
return ret; \
ddsrt_mutex_lock (&ent->m_entity.m_observers_lock); \
dds_get_##status_##_status_locked (ent, status); \
ddsrt_mutex_unlock (&ent->m_entity.m_observers_lock); \
dds_##ent_type_##_unlock (ent); \
return DDS_RETCODE_OK; \
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, of course ...

Maybe we can solve it by using ent_type_ for the parameter name, though. Like:

dds_return_t dds_get_##status_##_status (dds_entity_t ent_type_, dds_##status_##_status_t *status)

I haven't tried it, but I think it should work, because that's the bit in the type name after the dds_ prefix, so reader, writer, topic, &c.

This whole macro violates MISRA rules 20.10, but that's only advisory so it doesn't matter 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, thank you it works 😎.

*
* @returns the number of samples in the reader cache.
*/
DDS_EXPORT uint32_t
dds_reader_lock_samples (dds_entity_t reader);
Copy link
Contributor

Choose a reason for hiding this comment

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

This really only takes a reader, so I think "reader" is the better choice. But see #1744. It is finally on its way out, so I don't care about this one! 🥳

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I care! (That's why fixed)

Copy link
Contributor

@eboasson eboasson left a comment

Choose a reason for hiding this comment

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

Thanks @Splinter1984 !

@eboasson eboasson merged commit dd43d2f into eclipse-cyclonedds:master Jul 3, 2023
@Splinter1984 Splinter1984 deleted the fix-misra-rule-8-3 branch April 29, 2024 10:35
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.

2 participants