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

[core][apps] Some refactoring per clang-reported warnings #3019

Merged
merged 2 commits into from
Sep 9, 2024

Conversation

ethouris
Copy link
Collaborator

@ethouris ethouris commented Sep 3, 2024

Changes are added for various reasons.

Inline comments have been added to explain the reason of particular changes.

@@ -17,8 +17,8 @@ jobs:
- name: configure
run: |
md _build && cd _build
cmake ../ -DENABLE_STDCXX_SYNC=ON -DENABLE_ENCRYPTION=OFF -DENABLE_UNITTESTS=ON -DENABLE_BONDING=ON
cmake ../ -DENABLE_STDCXX_SYNC=ON -DENABLE_ENCRYPTION=OFF -DENABLE_UNITTESTS=ON -DENABLE_BONDING=ON -DUSE_CXX_STD=c++11
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is to prevent the compiler from compiling in any other version than exactly C++11.

- name: build
run: cd _build && cmake --build ./ --config Release
run: cd _build && cmake --build ./ --config Release --verbose
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

CI builds need to be verbose, otherwise any error will be unclear.

@@ -595,7 +595,7 @@ class FileCC : public SrtCongestionControlBase
{
m_dPktSndPeriod = m_dCWndSize / (m_parent->SRTT() + m_iRCInterval);
HLOGC(cclog.Debug, log << "FileCC: CHKTIMER, SLOWSTART:OFF, sndperiod=" << m_dPktSndPeriod << "us AS wndsize/(RTT+RCIV) (wndsize="
<< setprecision(6) << m_dCWndSize << " RTT=" << m_parent->SRTT() << " RCIV=" << m_iRCInterval << ")");
<< m_dCWndSize << " RTT=" << m_parent->SRTT() << " RCIV=" << m_iRCInterval << ")");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Precision is 6 by default.

@@ -300,7 +300,7 @@ std::string srt::SrtFlagString(int32_t flags)
#define LEN(arr) (sizeof (arr)/(sizeof ((arr)[0])))

std::string output;
static std::string namera[] = { "TSBPD-snd", "TSBPD-rcv", "haicrypt", "TLPktDrop", "NAKReport", "ReXmitFlag", "StreamAPI" };
static std::string namera[] = { "TSBPD-snd", "TSBPD-rcv", "haicrypt", "TLPktDrop", "NAKReport", "ReXmitFlag", "StreamAPI", "FilterCapable" };
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This field wasn't added properly after adding a corresponding flag.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe something for 1.5.4. 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was considering it. All other changes don't disturb anyway.

This one of course isn't a crash, at worst it will report this flag as "unknown".

@@ -54,7 +54,7 @@ written by
{ \
srt_logging::LogDispatcher::Proxy log(logdes); \
log.setloc(__FILE__, __LINE__, __FUNCTION__); \
const srt_logging::LogDispatcher::Proxy& log_prox SRT_ATR_UNUSED = args; \
{ (void)(const srt_logging::LogDispatcher::Proxy&)(args); } \
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Despite the unused attribute, this may generate a warning in some situations, depending on what is in args. This is safer.

// If the size of the FA name together with severity exceeds the size,
// just skip the former.
if (logger_pfx && strlen(prefix) + strlen(logger_pfx) + 1 < MAX_PREFIX_SIZE)
size_t your_pfx_len = your_pfx ? strlen(your_pfx) : 0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This avoids using snprintf and playing with alternatives. The length of the strings is taken once and then all copying is done on memcpy with known size. The snprintf function was prone to various warnings either through clang or MSVC.

@@ -381,7 +382,7 @@ struct LogDispatcher::Proxy
buf[len-1] = '\0';
}

os << buf;
os.write(buf, len);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is done to bypass any formatting features of ostringstream (idem the next one).

, m_iPort(0)
, m_iIPversion(0)
, m_iRefCount(1)
, m_iID(-1)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Somehow these values have never been initialized. Since UDT.

using namespace std;

ostringstream os;
os << setfill('0') << setw(2) << hex << uppercase;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That old version with so much of messing around was unncessary. Even if the state clearing after a single value was in plans before C++98, it was finally decided that the flags are changed permanently by manipultors.

@@ -76,7 +76,7 @@ struct MediumPair
bytevector initial_portion;
string name;

MediumPair(unique_ptr<Source> s, unique_ptr<Target> t): src(move(s)), tar(move(t)) {}
MediumPair(unique_ptr<Source> s, unique_ptr<Target> t): src(std::move(s)), tar(std::move(t)) {}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This and below: by some reason clang strictly requires that move be always used as std::move explicitly. Probably because this is a library support for a language feature and could be easily confused if the possibly local move name is in use.

@@ -120,4 +120,20 @@ void TargetMedium::Runner()
}
}

bool TargetMedium::Schedule(const MediaPacket& data)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This function was moved here in order to not pollute the header file.

@@ -29,7 +28,7 @@ struct Medium
std::mutex buffer_lock;
std::thread thr;
std::condition_variable ready;
std::atomic<bool> running = {false};
srt::sync::atomic<bool> running {false};
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For consistency, in all SRT applications, which also use internal SRT facilities, the std::atomic should not be used and srt::sync::atomic is used instead.

srtcore/logging.h Outdated Show resolved Hide resolved
srtcore/logging.h Outdated Show resolved Hide resolved
Added suggestions from code review.

Co-authored-by: Maxim Sharabayko <maxlovic@gmail.com>
@ethouris ethouris added this to the v1.5.4 milestone Sep 4, 2024
@ethouris ethouris added Type: Maintenance Work required to maintain or clean up the code [apps] Area: Test applications related improvements [core] Area: Changes in SRT library core [build] Area: Changes in build files labels Sep 9, 2024
@maxsharabayko maxsharabayko merged commit ff96e17 into Haivision:master Sep 9, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[apps] Area: Test applications related improvements [build] Area: Changes in build files [core] Area: Changes in SRT library core Type: Maintenance Work required to maintain or clean up the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants