Skip to content

Commit 514b5f2

Browse files
authored
Fix cyclic references in shared_ptr (#174)
* Refs #15831: Remove acyclic shared_ptrs Signed-off-by: jparisu <[email protected]> * Refs #15831: Fix fragile ==operator Signed-off-by: jparisu <[email protected]> * Refs #15831: Fix documentation API spelling error Signed-off-by: jparisu <[email protected]> * Refs #15831: Fix memory leaks in some tests Signed-off-by: jparisu <[email protected]> * Refs #15831: Fix CI error when no ASAN failures Signed-off-by: jparisu <[email protected]> * Refs #15831: Add doxygen to fragile_ptr Signed-off-by: jparisu <[email protected]> * Refs #15831: apply suggestions over fragile_ptr Signed-off-by: jparisu <[email protected]> * Refs #15831: apply suggestions and add tests Signed-off-by: jparisu <[email protected]> * Refs #15831: uncrustify Signed-off-by: jparisu <[email protected]> Signed-off-by: jparisu <[email protected]>
1 parent 04e66d5 commit 514b5f2

File tree

20 files changed

+873
-210
lines changed

20 files changed

+873
-210
lines changed

.github/workflows/asan_log_parser.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@
4545
dict({'ID': split_test[0], 'Name': split_test[2]}))
4646

4747
# Convert python dict to markdown table
48-
md_table = Tomark.table(failed_tests)
49-
print(md_table)
50-
51-
# Save table of failed test to GitHub action summary file
52-
with open(SUMMARY_FILE, 'a') as file:
53-
file.write(f'\n{md_table}')
48+
if (failed_tests):
49+
md_table = Tomark.table(failed_tests)
50+
print(md_table)
51+
# Save table of failed test to GitHub action summary file
52+
with open(SUMMARY_FILE, 'a') as file:
53+
file.write(f'\n{md_table}')
54+
else:
55+
print('NO TESTS FAILED!')
56+
with open(SUMMARY_FILE, 'a') as file:
57+
file.write('\nNO TESTS FAILED!')

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ jobs:
232232
if: always()
233233

234234
- name: Report ASAN errors
235+
continue-on-error: true
235236
if: always()
236237
run: |
237238
echo -n "**ASAN Errors**: " >> $GITHUB_STEP_SUMMARY

docs/rst/api-reference/exception/exception_index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ Exception
99
/rst/api-reference/exception/corruptedfile
1010
/rst/api-reference/exception/error
1111
/rst/api-reference/exception/exception
12+
/rst/api-reference/exception/inconsistency
1213
/rst/api-reference/exception/preconditionnotmet
1314
/rst/api-reference/exception/unsupported
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. _api_exception_inconsistency:
2+
3+
.. rst-class:: api-ref
4+
5+
Inconsistency
6+
-------------
7+
8+
.. doxygenclass:: eprosima::statistics_backend::Inconsistency
9+
:project: fastdds_statistics_backend
10+
:members:

docs/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ add_test(NAME documentation.code_block_check.cpp
6161
# Check docs spelling
6262
add_test(NAME documentation.spell_check
6363
COMMAND
64-
${SPHINX_EXECUTABLE} -Q -W --keep-going
64+
${SPHINX_EXECUTABLE} -W --keep-going
6565
-D breathe_projects.fastdds_statistics_backend=${DOXYGEN_OUTPUT_DIR}/xml
6666
-b spelling
6767
-d "${PROJECT_BINARY_DOCS_DIR}/doctrees"

include/fastdds_statistics_backend/exception/Exception.hpp

Lines changed: 39 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,8 @@ class Error : public Exception
9090

9191
public:
9292

93-
/**
94-
* @brief Construct a new statistics_backend::Error exception
95-
*
96-
* @param message The message to be returned by what()
97-
*/
98-
FASTDDS_STATISTICS_BACKEND_DllAPI Error(
99-
const char* message) noexcept;
100-
101-
/**
102-
* @brief Construct a new statistics_backend::Error exception
103-
*
104-
* @param message The message to be returned by what()
105-
*/
106-
FASTDDS_STATISTICS_BACKEND_DllAPI Error(
107-
const std::string& message);
93+
// Use parent constructors.
94+
using Exception::Exception;
10895

10996
/**
11097
* @brief Copies the statistics_backend::Error exception into a new one
@@ -132,21 +119,8 @@ class Unsupported : public Exception
132119

133120
public:
134121

135-
/**
136-
* @brief Construct a new statistics_backend::Unsupported exception
137-
*
138-
* @param message The message to be returned by what()
139-
*/
140-
FASTDDS_STATISTICS_BACKEND_DllAPI Unsupported(
141-
const char* message) noexcept;
142-
143-
/**
144-
* @brief Construct a new statistics_backend::Unsupported exception
145-
*
146-
* @param message The message to be returned by what()
147-
*/
148-
FASTDDS_STATISTICS_BACKEND_DllAPI Unsupported(
149-
const std::string& message);
122+
// Use parent constructors.
123+
using Exception::Exception;
150124

151125
/**
152126
* @brief Copies the statistics_backend::Unsupported exception into a new one
@@ -174,21 +148,8 @@ class BadParameter : public Exception
174148

175149
public:
176150

177-
/**
178-
* @brief Construct a new statistics_backend::BadParameter exception
179-
*
180-
* @param message The message to be returned by what()
181-
*/
182-
FASTDDS_STATISTICS_BACKEND_DllAPI BadParameter(
183-
const char* message) noexcept;
184-
185-
/**
186-
* @brief Construct a new statistics_backend::BadParameter exception
187-
*
188-
* @param message The message to be returned by what()
189-
*/
190-
FASTDDS_STATISTICS_BACKEND_DllAPI BadParameter(
191-
const std::string& message);
151+
// Use parent constructors.
152+
using Exception::Exception;
192153

193154
/**
194155
* @brief Copies the statistics_backend::BadParameter exception into a new one
@@ -216,21 +177,8 @@ class PreconditionNotMet : public Exception
216177

217178
public:
218179

219-
/**
220-
* @brief Construct a new statistics_backend::PreconditionNotMet exception
221-
*
222-
* @param message The message to be returned by what()
223-
*/
224-
FASTDDS_STATISTICS_BACKEND_DllAPI PreconditionNotMet(
225-
const char* message) noexcept;
226-
227-
/**
228-
* @brief Construct a new statistics_backend::PreconditionNotMet exception
229-
*
230-
* @param message The message to be returned by what()
231-
*/
232-
FASTDDS_STATISTICS_BACKEND_DllAPI PreconditionNotMet(
233-
const std::string& message);
180+
// Use parent constructors.
181+
using Exception::Exception;
234182

235183
/**
236184
* @brief Copies the statistics_backend::PreconditionNotMet exception into a new one
@@ -258,21 +206,8 @@ class CorruptedFile : public Exception
258206

259207
public:
260208

261-
/**
262-
* @brief Construct a new statistics_backend::CorruptedFile exception
263-
*
264-
* @param message The message to be returned by what()
265-
*/
266-
FASTDDS_STATISTICS_BACKEND_DllAPI CorruptedFile(
267-
const char* message) noexcept;
268-
269-
/**
270-
* @brief Construct a new statistics_backend::CorruptedFile exception
271-
*
272-
* @param message The message to be returned by what()
273-
*/
274-
FASTDDS_STATISTICS_BACKEND_DllAPI CorruptedFile(
275-
const std::string& message);
209+
// Use parent constructors.
210+
using Exception::Exception;
276211

277212
/**
278213
* @brief Copies the statistics_backend::CorruptedFile exception into a new one
@@ -292,9 +227,36 @@ class CorruptedFile : public Exception
292227
const CorruptedFile& other) = default;
293228
};
294229

230+
/**
231+
* @brief Exception to signal that an inconsistency inside the database has been found.
232+
*/
233+
class Inconsistency : public Exception
234+
{
235+
236+
public:
237+
238+
// Use parent constructors.
239+
using Exception::Exception;
240+
241+
/**
242+
* @brief Copies the statistics_backend::Inconsistency exception into a new one
243+
*
244+
* @param other The original exception object to copy
245+
*/
246+
FASTDDS_STATISTICS_BACKEND_DllAPI Inconsistency(
247+
const Inconsistency& other) = default;
248+
249+
/**
250+
* @brief Copies the statistics_backend::Inconsistency exception into the current one
251+
*
252+
* @param other The original statistics_backend::Inconsistency exception to copy
253+
* @return the current statistics_backend::Inconsistency exception after the copy
254+
*/
255+
FASTDDS_STATISTICS_BACKEND_DllAPI Inconsistency& operator =(
256+
const Inconsistency& other) = default;
257+
};
258+
295259
} // namespace statistics_backend
296260
} // namespace eprosima
297261

298-
299262
#endif // _EPROSIMA_FASTDDS_STATISTICS_BACKEND_EXCEPTION_EXCEPTION_HPP_
300-

src/cpp/StatisticsBackendData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ void StatisticsBackendData::stop_monitor(
399399

400400
// The monitor is inactive
401401
// NOTE: for test sake, this is not always set
402-
if (database_->is_entity_present(monitor_id))
402+
if (database_ && database_->is_entity_present(monitor_id))
403403
{
404404
database_->change_entity_status(monitor_id, false);
405405
}

src/cpp/database/database.hpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ class Database
7979
{
8080
public:
8181

82+
/**
83+
* @brief Destructor of Database.
84+
*
85+
* @note It requires a virtual dtor for test sake.
86+
*/
87+
virtual ~Database() = default;
88+
8289
/**
8390
* @brief Insert a new entity into the database.
8491
* @param entity The entity object to be inserted.
@@ -465,7 +472,7 @@ class Database
465472
throw BadParameter("Endpoint locators cannot be empty");
466473
}
467474

468-
/* Check that participant exits */
475+
/* Check that participant exists */
469476
bool participant_exists = false;
470477
auto domain_participants = participants_.find(endpoint->participant->domain->id);
471478
if (domain_participants != participants_.end())
@@ -585,11 +592,11 @@ class Database
585592
}
586593
}
587594

588-
// Change the curent locators map for the new updated one
589-
endpoint->locators = actual_locators_map;
595+
// Remove the current locator map as it will be filled in the following loop
596+
endpoint->locators.clear();
590597

591598
/* Add to x_by_y_ collections and to locators_ */
592-
for (auto& locator_it : endpoint->locators)
599+
for (auto& locator_it : actual_locators_map)
593600
{
594601
/* Check that locator exists */
595602
if (locators_.find(locator_it.first) == locators_.end())
@@ -599,6 +606,9 @@ class Database
599606

600607
// Add endpoint to locator's collection
601608
insert_ddsendpoint_to_locator(endpoint, locator_it.second);
609+
610+
// Add this locator to the locators map
611+
endpoint->locators[locator_it.first] = locator_it.second;
602612
}
603613

604614
/* Add endpoint to topics's collection */

src/cpp/database/entities.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ DDSEndpoint::DDSEndpoint(
5858
std::string endpoint_name, /* "INVALID" */
5959
Qos endpoint_qos, /* {} */
6060
std::string endpoint_guid, /* "|GUID UNKNOWN|" */
61-
std::shared_ptr<DomainParticipant> endpoint_participant, /* nullptr */
62-
std::shared_ptr<Topic> endpoint_topic /* nullptr */) noexcept
61+
details::fragile_ptr<DomainParticipant> endpoint_participant, /* nullptr */
62+
details::fragile_ptr<Topic> endpoint_topic /* nullptr */) noexcept
6363
: DDSEntity(entity_kind, endpoint_name, endpoint_qos, endpoint_guid)
6464
, participant(endpoint_participant)
6565
, topic(endpoint_topic)
@@ -121,25 +121,25 @@ void Locator::clear()
121121
}
122122

123123
template<>
124-
std::map<EntityId, std::shared_ptr<DataReader>>& DomainParticipant::ddsendpoints<DataReader>()
124+
std::map<EntityId, details::fragile_ptr<DataReader>>& DomainParticipant::ddsendpoints<DataReader>()
125125
{
126126
return data_readers;
127127
}
128128

129129
template<>
130-
std::map<EntityId, std::shared_ptr<DataWriter>>& DomainParticipant::ddsendpoints<DataWriter>()
130+
std::map<EntityId, details::fragile_ptr<DataWriter>>& DomainParticipant::ddsendpoints<DataWriter>()
131131
{
132132
return data_writers;
133133
}
134134

135135
template<>
136-
std::map<EntityId, std::shared_ptr<DataReader>>& Topic::ddsendpoints<DataReader>()
136+
std::map<EntityId, details::fragile_ptr<DataReader>>& Topic::ddsendpoints<DataReader>()
137137
{
138138
return data_readers;
139139
}
140140

141141
template<>
142-
std::map<EntityId, std::shared_ptr<DataWriter>>& Topic::ddsendpoints<DataWriter>()
142+
std::map<EntityId, details::fragile_ptr<DataWriter>>& Topic::ddsendpoints<DataWriter>()
143143
{
144144
return data_writers;
145145
}

0 commit comments

Comments
 (0)