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 #663, more consistent use of data types #1003

Merged
merged 7 commits into from
Nov 21, 2020

Conversation

jphickey
Copy link
Contributor

@jphickey jphickey commented Nov 5, 2020

Describe the contribution
Define and Use data types more consistently across CFE.

Replace many uses of generic uint16/uint32 with a more purpose-specific typedef. Replace all sizes with size_t across the API.

Fixes #663

Testing performed
Build and sanity test CFE

Expected behavior changes
None, but does affect API. The API changes should be largely backward compatible, however.

System(s) tested on
Ubuntu 20.04, 64-bit

Contributor Info - All information REQUIRED for consideration of pull request
Joseph Hickey, Vantage Systems, Inc.

EDIT: Also fixed #843

@jphickey
Copy link
Contributor Author

jphickey commented Nov 5, 2020

Pushed a draft/preview commit as discussed in the 2020-11-04 CCB. This has all the API changes but the unit test updates are not complete.

@jphickey
Copy link
Contributor Author

jphickey commented Nov 5, 2020

General summary of what's being proposed:

  • Use size_t for all in-memory object sizes, EXCEPT for:

    • CMD/TLM messages - where CFE_ES_MemOffset_Atom_t is used
    • Interface with PSP, where uint32 must be used until PSP API is updated (could do that too)
  • Use sizeof() more consistently - particularly on strings on the stack in message handlers. It is more type correct (because value is a size_t, not int) and it adheres to the DRY principle - we want the actual size of the string, whatever it really is - don't assume it was declared to a certain size.

  • Use ES-defined typedefs for Task Priority, Stack Pointer, etc.

  • Anywhere a constant is used for these types, wrap it in a macro that converts the type, which makes the type conversion explicit when reading the code.

@jphickey
Copy link
Contributor Author

jphickey commented Nov 5, 2020

Also note that this sweep also caught a bunch of issues in the old SB message API - which if its being deprecated, we can just ignore those. But we should decide whether the new MSG API should use size_t or keep its separate CFE_MSG_Size_t ... my thought is if we are going to use size_t, lets use it everywhere. The same justification for not putting a size typedef in CFE should apply to the module(s) (and vice versa).

@skliper
Copy link
Contributor

skliper commented Nov 5, 2020

...issues in the old SB message API

I also noticed a bunch of type issues (maybe some of the same?), fixed what I saw in #998. Mostly using uint16 for message size all over, which is a bug since it can't represent the full size CCSDS message. Agree that size_t could replace CFE_MSG_Size_t. The less one-off types the better in my mind. Maybe get #998 in first, then fix?

Could we use a more descriptive name than CFE_ES_MemOffset_Atom_t? Really it's a conversion instead of the atomic type, isn't it? I think of it as the native to tlm conversion for size_t...

Is the CDS offset type just for the PSP? If so I say we get that fixed also. It stands out as unique.

@skliper
Copy link
Contributor

skliper commented Nov 5, 2020

This will conflict with #998, but I like your change better (using size_t for the verify command length).

I would prefer separating the concept of the atomic type (which could be native) with the conversion to fit in telemetry. I'd also prefer the default behavior to use 64 bit's for memory addresses... if a user wants to use just 32 bit they can, but I'd rather default to consistent sized messages across 64/32 and valid data in both.

@jphickey
Copy link
Contributor Author

jphickey commented Nov 5, 2020

...issues in the old SB message API

I also noticed a bunch of type issues (maybe some of the same?), fixed what I saw in #998. Mostly using uint16 for message size all over, which is a bug since it can't represent the full size CCSDS message. Agree that size_t could replace CFE_MSG_Size_t. The less one-off types the better in my mind. Maybe get #998 in first, then fix?

Yes, I think the best approach would be to embrace size_t everywhere, for all in-memory objects. There was also some random casting of sizes to uint16 here and there (EVS had one, I think - fixed in this PR). And yes, I concur with finishing up the pending changes first.

Could we use a more descriptive name than CFE_ES_MemOffset_Atom_t? Really it's a conversion instead of the atomic type, isn't it? I think of it as the native to tlm conversion for size_t...

Yes, perhaps we should bring up/revisit the whole "_Atom_t" suffix thing in general.... the genesis of the type suffixes was to facilitate automation/tool-chaining of these types - and use a different suffix for enums, strings, structures, etc.

It is currently documented in https://github.com/nasa/cFE/blob/main/docs/cFS_IdentifierNamingConvention.md#typedefs (unfortunately just noticed that github doesn't render the table data in this MD file correctly either -- another issue?).

At any rate, this is the pattern that I still try to follow for CMD/TLM types. I still think its a useful thing to have a different suffix, maybe "Atom" is confusing and we could do something else. It is intended to convey that it is a scalar, as opposed a compound type (struct/string/array) etc. Maybe "Scalar"?

Is the CDS offset type just for the PSP? If so I say we get that fixed also. It stands out as unique.

Not just CDS - all the memory blocks incl. reserved area and RAM disk are done with uint32 sizes - and these are especially problematic because they pass by pointer - not by value - so any change would NOT be backward compatible.

Because any change to this API would not be backward compatible - my recommendation is to rethink/redesign this API and make it more future proof, such as:

void * CFE_PSP_GetBlockPointer(CFE_PSP_BlockId_t BlockId);
size_t CFE_PSP_GetBlockSize(CFE_PSP_BlockId_t BlockId);

Then the PSP can also provide separate constants for BlockId corresponding to the ramdisk, reserved area, cds, etc. The important thing is we can add/extend these constants without breaking or changing the general API. The current calls have a separate dedicated call for each memory section. So making it more extensible we can more easily have separate sections for ES/EVS/TIME (I think there is another issue related to this)

Rather than directly referencing a constant, prefer to use
the sizeof() operator on the instance or type whenever possible.
Update use of uint32 to size_t in UT support code
Fix all use of uint32 for sizes, replace with size_t
Scrub all other types to make sure use is consistent,
using proper typedef whenever available.
Fix all use of uint32 for sizes, replace with size_t
Scrub all other types to make sure use is consistent,
using proper typedef whenever available.
Fix all use of uint32 for sizes, replace with size_t
Scrub all other types to make sure use is consistent,
using proper typedef whenever available.
Fix all use of uint32 for sizes, replace with size_t
Scrub all other types to make sure use is consistent,
using proper typedef whenever available.
Fix all use of uint32 for sizes, replace with size_t
Scrub all other types to make sure use is consistent,
using proper typedef whenever available.
@jphickey jphickey changed the title Fix #663, more consistent use of data types (WIP) Fix #663, more consistent use of data types Nov 18, 2020
@jphickey jphickey marked this pull request as ready for review November 18, 2020 04:49
@jphickey jphickey added the CCB:Ready Ready for discussion at the Configuration Control Board (CCB) label Nov 18, 2020
Copy link
Contributor

@astrogeco astrogeco left a comment

Choose a reason for hiding this comment

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

Can we change the word "proposed" here? Feels like its incomplete...

@astrogeco
Copy link
Contributor

astrogeco commented Nov 18, 2020

CCB 2020-11-18 APPROVED

@skliper
Copy link
Contributor

skliper commented Nov 18, 2020

Are all _Atom_t types fixed size (appropriate for cmd/tlm messages)? If so and we continue with this pattern, then I'm fine with it. In my mind it was just the "scalar" type, but without the fixed size restriction.

@astrogeco astrogeco changed the base branch from main to integration-candidate November 21, 2020 17:21
@astrogeco astrogeco added IC-20201124 and removed CCB:Ready Ready for discussion at the Configuration Control Board (CCB) labels Nov 21, 2020
@astrogeco astrogeco merged commit 5ae7613 into nasa:integration-candidate Nov 21, 2020
astrogeco added a commit to astrogeco/cFS that referenced this pull request Nov 21, 2020
astrogeco added a commit to astrogeco/cFS that referenced this pull request Nov 23, 2020
@jphickey jphickey deleted the fix-663-datatypes branch December 3, 2020 17:53
@skliper skliper linked an issue Jan 11, 2021 that may be closed by this pull request
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove/replace/deprecate questionable macros in SB Mismatched Variable Types in Data Structures
3 participants