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

strawman for #888 - return code for cFE #889

Closed
wants to merge 1 commit into from

Conversation

CDKnightNASA
Copy link
Contributor

closes #888 -- not like this strawman will close it, but just creating the linkage

Describe the contribution
This is a strawman for return code typedef for cFE.

Testing performed
code builds

Expected behavior changes
Returns for cFE functions now typedef'd in headers (.h), not in the source (.c).

Contributor Info - All information REQUIRED for consideration of pull request
Christopher.D.Knight@nasa.gov

@CDKnightNASA
Copy link
Contributor Author

note also I did a bit of formatting cleanup (joining multi-line into single line when it fits)

Copy link
Contributor

@jphickey jphickey left a comment

Choose a reason for hiding this comment

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

Just a quick look through, some more comments inline.

But also note that in order to be really type-agnostic, one must offer an inline function (or macro) to test for any value, not just success. That's because conditionals like:

if (Status == CFE_ES_ERR_TASKID)

no longer work if using a type for which a numeric equality test isn't implemented. In C++ it would be easy to simply provide a == operator, but in C we have to provide an explicit IsEqual function.

*/

typedef int32 CFE_Status_t;
typedef CFE_Status_t CFE_RC_t;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why have two typedefs?

* Utility macros.
*/
#define CFE_ISSUCCESS(S) ((S) & CFE_SEVERITY_BITMASK != CFE_SEVERITY_ERROR)
#define CFE_ISINFO(S) ((S) & CFE_SEVERITY_BITMASK == CFE_SEVERITY_INFO)
Copy link
Contributor

Choose a reason for hiding this comment

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

can these be inline functions instead? These are just as fast but more type safe and don't have the same risks/issues as macros.

Copy link

Choose a reason for hiding this comment

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

Just as fast if inlining is enabled. If it's not, and these are "real" functions, there's a decent amount of overhead.

If they are declared inline, they should be static inline at least, to avoid GOT/PLT lookup and such.

@jphickey
Copy link
Contributor

And also, FWIW, I'm still strongly in favor of getting rid of the notion of multiple success variants as indicated in #483.

Functions should have either SUCCESS -- i.e. it worked fully and completely, or it FAILED - nothing in between.

Having multiple different values for failure is fine - as it can indicate why it failed - but all of them should mean the same thing which is that the function did nothing at all (it failed). There shouldn't be any cases of "half-worked" -- that means the API is too complex. Any current API that returns half-worked "sorta success" codes should be split up and simplified into units that can fit the model of all or nothing.

@CDKnightNASA
Copy link
Contributor Author

And also, FWIW, I'm still strongly in favor of getting rid of the notion of multiple success variants as indicated in #483.

Functions should have either SUCCESS -- i.e. it worked fully and completely, or it FAILED - nothing in between.

Having multiple different values for failure is fine - as it can indicate why it failed - but all of them should mean the same thing which is that the function did nothing at all (it failed). There shouldn't be any cases of "half-worked" -- that means the API is too complex. Any current API that returns half-worked "sorta success" codes should be split up and simplified into units that can fit the model of all or nothing.

CFE_TBL is a standout for using non-error returns....Feel free to peruse the .h and consider alternative models? I can file a ticket for a redesign of CFE_TBL to remove the "WARN" and "INFO" return statuses.

@@ -176,7 +177,7 @@ static inline uint32 CFE_ES_ResourceID_FromInteger(unsigned long Value)
* @return Execution status, see @ref CFEReturnCodes
* @retval #CFE_SUCCESS @copybrief CFE_SUCCESS
*/
int32 CFE_ES_AppID_ToIndex(uint32 AppID, uint32 *Idx);
CFE_RC_t CFE_ES_AppID_ToIndex(uint32 AppID, uint32 *Idx);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use CFE_ReturnCode_t ? I like spelling out things as much as possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A lot of typing, and causes more line wrapping...I'm open though if that's the consensus.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I use autocomplete on Atom. I assume this type would be used by app developers so I'd rather be explicit. If it's just internal to cFE then I feel slightly better about abbreviations

@astrogeco
Copy link
Contributor

CCB 2020-09-16 Discussed benefits and problems with multiple types. Also talked about the problems with multiple "success" and "failure" return codes. We should always ask, what is the purpose of the code? How can it be used?

@jphickey
Copy link
Contributor

CFE_TBL is a standout for using non-error returns....Feel free to peruse the .h and consider alternative models? I can file a ticket for a redesign of CFE_TBL to remove the "WARN" and "INFO" return statuses.

FYI - see my synopsis here for the various functions that need attention:
#483 (comment)

Probably could have a whole separate discussion on each function.

@CDKnightNASA
Copy link
Contributor Author

One vote for the naming discussion, note that "RC" is a term/acronym used throughout event messages and documentation in cfe_es_events.h, such as:

/** \brief <tt> 'Failed to start \%s from \%s, RC = \%08X' </tt>

@astrogeco
Copy link
Contributor

astrogeco commented Sep 17, 2020

I'm biased against acronyms and initialisms, especially after reading "Acronyms Seriuosly Suck". Could "RtrnCode" be a good compromise?

@jphickey
Copy link
Contributor

I'm biased against acronyms and initialisms, especially after reading "Acronyms Seriuosly Suck". Could "RtrnCode" be a good compromise?

I am NOT a fan of the vowel-removal approach -- code that does this I find really ugly and hard to read. I also have a slight preference for full words, despite the fact that it makes long lines, I think the result is overall more readable. I also use an editor with autocomplete so the typing isn't a strong concern.

My preference is CFE_Status_t. Because many times it is referred to as a a status code and stored in a variable called "Status".

I'm also OK with: CFE_ReturnCode_t, CFE_Error_t, CFE_RC_t.

But please - lets steer clear of quasi-abbreviations like "RtrnCode" -- this looks more like a letter jumble.

@skliper
Copy link
Contributor

skliper commented Sep 21, 2020

I vote CFE_Status_t for the same reasons @jphickey states.

@CDKnightNASA
Copy link
Contributor Author

consensus is CFE_Status_t, will update PR prior to next CCB.

@CDKnightNASA CDKnightNASA deleted the fix-888-return_code branch September 28, 2020 15:29
@skliper
Copy link
Contributor

skliper commented Sep 30, 2020

Marked as duplicate of #919 (this PR was the strawman for discussion).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

typedef for status return values
6 participants