-
Notifications
You must be signed in to change notification settings - Fork 206
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
Type safety and improved handling of CFE_SB_MsgId_t values #245
Comments
Imported from trac issue 214. Created by cdknight on 2017-10-24T13:48:15, last modified: 2019-07-03T12:58:32 |
Trac comment by cdknight on 2017-10-24 14:03:11: Note that the struct should read (sorry the double-underscore got interpreted by the trac system): {{{ |
Trac comment by cdknight on 2017-10-24 14:04:04: Curious what the performance impact will be for this, particularly for frequently-used types. One option would be to have a compile-time flag that enables the wrappers so you can do compiler type checking, then disable for performance. A-la: typedef uint16 CFE_SB_MsgId_Atom_t; #else typedef uint16 CFE_SB_MsgId_t; #endif |
Trac comment by glimes on 2017-10-24 14:05:16: I have the power to edit the Description for you (this may |
Trac comment by cdknight on 2017-10-24 14:09:44: Replying to [comment:4 glimes]:
yes, you silly admin. :D |
Trac comment by glimes on 2017-10-24 14:10:46: Before you make the code complicated in the name of making it faster, please prototype and measure. You may find that there is no runtime cost. Generally, I've found that
|
Trac comment by cdknight on 2017-10-24 14:11:47: Note also I filed ticket #241 suggesting creating a type for status/return codes so that it's clear when functions are returning a status. I have a first pass at the ES patch demonstrating the code change impact. |
Trac comment by cdknight on 2017-10-24 15:00:38: whoop, not 6.6 |
Trac comment by cdknight on 2017-10-27 13:24:21: also note we may want to wrap void *'s wherever possible/needed (see ticket #247 for an example where we got bit by a void *.) |
Trac comment by cdknight on 2017-10-27 14:26:57: see also ticket #172 |
Trac comment by jphickey on 2018-05-14 12:36:48: Upvote this ticket to be addressed in the next CFE release. See also #100. We should use the same approach for CFE Pipe IDs as I'm seeing some potential (mis)use of pipe IDs as array indices. In every reasonable compiler out there, passing a struct by value is just as efficient as passing an integer of the same size (provided the structure size is less than or equal to I would advocate using this approach everywhere we have an "id" type that is numeric in nature. It ensures that it cannot be mixed with other integer types haphazardly, and also helps preserve architectural integrity by forcing one to treat it as an opaque value, only going through the correct API to manipulate the values. |
Trac comment by jphickey on 2019-03-27 11:23:51: Branch This was originally implemented in #206 but not included in CFE 6.6 due to the API compatibility concerns at the time of review. I have rebased it to the current development branch and associated it with this ticket instead. |
Trac comment by jhageman on 2019-07-03 12:58:32: Moved unfinished 6.7.0 tickets to next release |
Submitted tickets and pull requests in all app repos to be compatible going forward: |
Treat the CFE_SB_MsgId_t type as an opaque/abstract value and do not assume it is an integer. Enforce using CFE_SB_MsgIdToValue() when displaying the value in via an event or syslog.
Treat the CFE_SB_MsgId_t type as an opaque/abstract value and do not assume it is an integer. This change offers two modes of operation, where CFE_SB_MsgId_t is defined as a simple integer and is backward compatible, or defined as a type safe structure. In type safe mode, passing an integer to an API requiring a CFE_SB_MsgId_t value will result in an error. The macros and conversion functions can be used with either mode, allowing a transition for applications.
Treat the CFE_SB_MsgId_t type as an opaque/abstract value and do not assume it is an integer. This change offers two modes of operation, where CFE_SB_MsgId_t is defined as a simple integer and is backward compatible, or defined as a type safe structure. In type safe mode, passing an integer to an API requiring a CFE_SB_MsgId_t value will result in an error. The macros and conversion functions can be used with either mode, allowing a transition for applications.
@astrogeco - right. Only partially addressed. |
This makes CFE_SB_MsgId_t to be a safe wrapper around CFE_SB_MsgId_Atom_t, such that the values cannot be silently/implicitly interchanged with other integers. This enforces that the MsgId/Value conversion helpers must be used when conversion to/from integers is intended.
This makes CFE_SB_MsgId_t to be a safe wrapper around CFE_SB_MsgId_Atom_t, such that the values cannot be silently/implicitly interchanged with other integers. This enforces that the MsgId/Value conversion helpers must be used when conversion to/from integers is intended.
In 6.6, as we move to supporting MsgId's, MsgKey's, RouteIdx, and other types, we should move away from using native C types and wrapping the types in a struct to prevent accidentally using the wrong type in assignments and function calls.
This will, of course, require re-tooling any existing code that expects the type to be a simple type...
For example, instead of:
Use:
The text was updated successfully, but these errors were encountered: