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

Issue #2727: Refactor System Resources OSAL Implmentation #2922

Merged
merged 25 commits into from
Oct 9, 2024

Conversation

LeStarch
Copy link
Collaborator

@LeStarch LeStarch commented Oct 7, 2024

Related Issue(s)
Has Unit Tests (y/n)
Documentation Included (y/n)

Change Description

Fixes issue #2727 by creating Os::Memory and Os::Cpu interfaces to support the non-filesystem aspects of SystemResources.

Fw/Types/StringUtils.cpp Fixed Show fixed Hide fixed
Os/Cpu.cpp Fixed Show fixed Hide fixed
Os/Memory.cpp Fixed Show fixed Hide fixed
Os/Cpu.cpp Dismissed Show dismissed Hide dismissed
Os/Memory.cpp Dismissed Show dismissed Hide dismissed
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@LeStarch
Copy link
Collaborator Author

LeStarch commented Oct 8, 2024

@thomas-bc will you review?

@LeStarch
Copy link
Collaborator Author

LeStarch commented Oct 8, 2024

@bocchino will you review the use of templates here:

// Template for internal implementation only
// \tparam T: input type (U8, I8, U64, I64)
// \tparam Tinternal: function api type
// \tparam F: conversion function to use
template <typename T, typename Tinternal, Tinternal (*F)(const char*, char**, int)>
Fw::StringUtils::StringToNumberStatus string_to_number_as_template(const CHAR* input, FwSizeType max_length, T& output, char** next, U8 base) {
static_assert(std::numeric_limits<T>::is_integer, "Type must be integer");
static_assert(std::numeric_limits<Tinternal>::is_integer, "Type must be integer");
static_assert(std::numeric_limits<T>::is_signed == std::numeric_limits<Tinternal>::is_signed, "Signedness must match");
static_assert(std::numeric_limits<T>::max() <= std::numeric_limits<Tinternal>::max(), "Invalid internal type chosen");
static_assert(std::numeric_limits<T>::min() >= std::numeric_limits<Tinternal>::min(), "Invalid internal type chosen");
char* output_next = nullptr;
Fw::StringUtils::StringToNumberStatus status = string_to_helper_input_check(input, max_length, base);
if (status == Fw::StringUtils::SUCCESSFUL_CONVERSION) {
Tinternal output_api = 0;
output_api = F(input, &output_next, base);
if (output_api > std::numeric_limits<T>::max()) {
status = Fw::StringUtils::StringToNumberStatus::INVALID_RANGE;
output_api = std::numeric_limits<T>::max();
}
if (output_api < std::numeric_limits<T>::min()) {
status = Fw::StringUtils::StringToNumberStatus::INVALID_RANGE;
output_api = std::numeric_limits<T>::min();
}
output = static_cast<T>(output_api);
}
status = string_to_helper_output_check(status, input, output_next, next);
return status;
}

I can make the argument it is a safe use of templates because: the template is not exposed to users, or outside code (it is implemented in the CPP). The template is used as the implementation of a set of non-templated functions needed by the end user.

@LeStarch LeStarch requested a review from bocchino October 8, 2024 01:27
Copy link
Collaborator

@bocchino bocchino left a comment

Choose a reason for hiding this comment

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

I have reviewed the template usage. It looks good!

Fw/Types/StringToNumber.cpp Outdated Show resolved Hide resolved
Fw/Types/StringToNumber.cpp Outdated Show resolved Hide resolved
Fw/Types/StringUtils.cpp Outdated Show resolved Hide resolved
Os/Darwin/Cpu.cpp Outdated Show resolved Hide resolved
Os/File.cpp Outdated Show resolved Hide resolved
Os/Linux/Cpu.cpp Outdated Show resolved Hide resolved
Os/Stub/test/ut/StubFileTests.cpp Outdated Show resolved Hide resolved
cmake/platform/Linux.cmake Outdated Show resolved Hide resolved
CMakePresets.json Outdated Show resolved Hide resolved
CMakePresets.json Outdated Show resolved Hide resolved
@LeStarch LeStarch merged commit 105cd8e into nasa:devel Oct 9, 2024
34 of 35 checks passed
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.

3 participants