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 #788, Simplified CFE_EVS_SendEvent macros #867

Merged
merged 2 commits into from
Nov 10, 2020

Conversation

CDKnightNASA
Copy link
Contributor

Closes #788

Describe the contribution
Macros for more compact calls to CFE_EVS_SendEvent, making the type be part of the fn name.

Contributor Info - All information REQUIRED for consideration of pull request
[email protected]

@CDKnightNASA
Copy link
Contributor Author

Should I, as part of this PR, change a bunch of cFE code to use these simplified macro calls?

@astrogeco
Copy link
Contributor

Should I, as part of this PR, change a bunch of cFE code to use these simplified macro calls?

I like keeping things separate. So at the very least do it in separate commits. Another option is to provide a sample implementation or documentation with this PR. And, once the approach is "approved" by the CCB open a PR to update the cFE code.

@CDKnightNASA CDKnightNASA added the CCB:Ready Ready for discussion at the Configuration Control Board (CCB) label Sep 9, 2020
@iamthad
Copy link

iamthad commented Sep 9, 2020

This could be done with an inline function instead of a macro if a version of CFE_EVS_SendEvent that takes va_list (as requested in #249) were implemented.

@ghost
Copy link

ghost commented Sep 9, 2020

Suggestion for less duplicate code:

#define CFE_EVS_SendDbg(E,...) CFE_EVS_SendEvent((E), CFE_EVS_EventType_DEBUG, __VA_ARGS__)
#define CFE_EVS_SendInfo(E,...) CFE_EVS_SendEvent((E), CFE_EVS_EventType_INFORMATION, __VA_ARGS__)
#define CFE_EVS_SendErr(E,...) CFE_EVS_SendEvent((E), CFE_EVS_EventType_ERROR, __VA_ARGS__)
#define CFE_EVS_SendCrit(E,...) CFE_EVS_SendEvent((E), CFE_EVS_EventType_CRITICAL, __VA_ARGS__)

instead:

#define CFE_EVS_Send(E,T,...) CFE_EVS_SendEvent((E), CFE_EVS_EventType_##T, __VA_ARGS__)
#define CFE_EVS_SendInfo(E,...) CFE_EVS_Send(E, INFORMATION, __VA_ARGS__)

... and so on

@skliper
Copy link
Contributor

skliper commented Sep 9, 2020

Suggestion for less...

@klystron78 - copy, a helper macro for the helper macros. I'm fine with either approach.

@ghost
Copy link

ghost commented Sep 9, 2020

Looks like double underscore bolds in the comments. There's probably a way to do a code block or something like that.

@skliper
Copy link
Contributor

skliper commented Sep 9, 2020

@Klystron single back quote (just learned also known as birk, blugle, or grave) inline code or triple

for block of code

@CDKnightNASA
Copy link
Contributor Author

This could be done with an inline function instead of a macro if a version of CFE_EVS_SendEvent that takes va_list (as requested in #249) were implemented.

I'm confused what the benefit is of an inline (which, of course, isn't always inline) over a macro. Can you describe/prototype?

@CDKnightNASA
Copy link
Contributor Author

Suggestion for less duplicate code:

#define CFE_EVS_SendDbg(E,...) CFE_EVS_SendEvent((E), CFE_EVS_EventType_DEBUG, __VA_ARGS__)
#define CFE_EVS_SendInfo(E,...) CFE_EVS_SendEvent((E), CFE_EVS_EventType_INFORMATION, __VA_ARGS__)
#define CFE_EVS_SendErr(E,...) CFE_EVS_SendEvent((E), CFE_EVS_EventType_ERROR, __VA_ARGS__)
#define CFE_EVS_SendCrit(E,...) CFE_EVS_SendEvent((E), CFE_EVS_EventType_CRITICAL, __VA_ARGS__)

instead:

#define CFE_EVS_Send(E,T,...) CFE_EVS_SendEvent((E), CFE_EVS_EventType_##T, __VA_ARGS__)
#define CFE_EVS_SendInfo(E,...) CFE_EVS_Send(E, INFORMATION, __VA_ARGS__)

... and so on

I like, I'll change, thanks!

@iamthad
Copy link

iamthad commented Sep 9, 2020

This could be done with an inline function instead of a macro if a version of CFE_EVS_SendEvent that takes va_list (as requested in #249) were implemented.

I'm confused what the benefit is of an inline (which, of course, isn't always inline) over a macro. Can you describe/prototype?

General advice these days seems to be to prefer inline functions over function-like macros. For example, see SEI CERT Recommendation PRE00-C. I admit, for this sort of trivial wrapper, the benefit is probably small and probably outweighed by the additional lines of code.

It would look something like the following (using a hypothetical CFE_EVS_VSendEvent):

static inline int32 CFE_EVS_SendDbg(uint16 EventID, const char *Spec, ...)
{
    va_list ap;
    va_start(ap, Spec);
    int32 res = CFE_EVS_VSendEvent(EventID, CFE_EVS_EventType_DEBUG, Spec, ap);
    va_end(ap);
    return res;
}

@jphickey
Copy link
Contributor

I'm generally a fan of inline functions rather than macros because they are more type-safe, and they offer more predictable/defined behavior as to when things are evaluated and when side effects occur, such as the classic example of a macro that evaluates its arguments more than once.

Admittedly they aren't quite as useful in C as they are in C++, where you have templates. So in C we need a explicitly-defined inline function for every type variant, whereas a macro or C++ template can be evaluated at compile-time for any type.

It is true they are not always actually inlined - it's a suggestion to the compiler, but depends on compiler capabilities, settings, etc as to whether it accepts that suggestion.

But I'm not sure if any compiler can inline something that uses va_list because AFAIK it depends on having those arguments in a stack frame. If truly inline-d then there is no stack frame for it. For anything that uses variable arguments/va_list then it is probably not worth trying to inline it.

@astrogeco astrogeco added CCB-20200909 and removed CCB:Ready Ready for discussion at the Configuration Control Board (CCB) labels Sep 11, 2020
@astrogeco
Copy link
Contributor

@CDKnightNASA is this ready to merge?

@CDKnightNASA
Copy link
Contributor Author

@CDKnightNASA is this ready to merge?

yes please

@astrogeco astrogeco marked this pull request as ready for review September 11, 2020 15:16
@skliper
Copy link
Contributor

skliper commented Oct 29, 2020

@astrogeco - what's the status on this one?

@astrogeco
Copy link
Contributor

astrogeco commented Oct 29, 2020

@astrogeco - what's the status on this one?

Whoops, looks like this never made it to a CCB since it hasn't been "github reviewed". Tagging it for next week

Edit-1: Unless we did review it and I forgot to comment on it :( I'm looking through the old agendas right now
Edit-2: Looks like we had queued for CCB 2020-09-09 but didn't get approved then

@astrogeco astrogeco added the CCB:Ready Ready for discussion at the Configuration Control Board (CCB) label Oct 29, 2020
@astrogeco
Copy link
Contributor

@skliper or we could fast-track it

@astrogeco astrogeco changed the title simplified CFE_EVS_SendEvent macros Fix #788, Simplified CFE_EVS_SendEvent macros Nov 4, 2020
@astrogeco astrogeco added CCB-20201104 and removed CCB:Ready Ready for discussion at the Configuration Control Board (CCB) labels Nov 4, 2020
@astrogeco
Copy link
Contributor

astrogeco commented Nov 4, 2020

CCB 2020-11-04 APPROVED

@CDKnightNASA can you rebase/squash the commits?

@astrogeco astrogeco changed the base branch from main to integration-candidate November 10, 2020 17:24
@astrogeco astrogeco merged commit 0041085 into nasa:integration-candidate Nov 10, 2020
astrogeco added a commit to nasa/cFS that referenced this pull request Nov 10, 2020
astrogeco added a commit to nasa/cFS that referenced this pull request Nov 16, 2020
* Add nasa/cFE#984

* Add nasa/cFE#980

* Add nasa/cFE#867

* Add nasa/osal#638 and update cfe due to rebase

* Add nasa/cFE#987

* Add nasa/to_lab#64 and nasa/sample_app#104

* Add nasa/osal#643

* Add nasa/cFE#1000

* Add nasa/ci_lab#58

* Add doxygen fixes for nasa/osal#643

* Add nasa/cFE#1013

* Add nasa/cFE#1011

* Add nasa/ci_lab#61

* Add nasa/sample_app#109

* Bump versions and point to submodules main

Co-authored-by: Joseph Hickey <[email protected]>
@skliper skliper added this to the 7.0.0 milestone Sep 24, 2021
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.

CFE_EVS_Send{Crit|Critical|Err|Error|Info|Information|Debug} wrapper for CFE_EVS_SendEvent
5 participants