From 0038a5e7552b1d5a5f1f02f739793d24a3c79884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Thu, 29 Mar 2018 13:59:48 +0200 Subject: [PATCH] uorb: fix constness for _uorb_topics_list _uorb_topics_list was marked as 'const char *' array, which means the data of the array was not actually const and thus landed in the data section (so in RAM instead of FLASH). The size of the array is 436 bytes. --- msg/templates/uorb/uORBTopics.cpp.template | 4 ++-- src/modules/logger/logger.cpp | 6 +++--- src/modules/replay/replay_main.cpp | 2 +- src/modules/uORB/uORBTopics.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/msg/templates/uorb/uORBTopics.cpp.template b/msg/templates/uorb/uORBTopics.cpp.template index c8e29cd18972..0d884d48f0dc 100644 --- a/msg/templates/uorb/uORBTopics.cpp.template +++ b/msg/templates/uorb/uORBTopics.cpp.template @@ -56,7 +56,7 @@ msgs_count_all = len(msg_names_all) @[end for] const size_t _uorb_topics_count = @(msgs_count_all); -const struct orb_metadata* _uorb_topics_list[_uorb_topics_count] = { +const constexpr struct orb_metadata* const _uorb_topics_list[_uorb_topics_count] = { @[for idx, msg_name in enumerate(msg_names_all, 1)]@ ORB_ID(@(msg_name))@[if idx != msgs_count_all],@[end if] @[end for] @@ -67,7 +67,7 @@ size_t orb_topics_count() return _uorb_topics_count; } -const struct orb_metadata **orb_get_topics() +const struct orb_metadata *const*orb_get_topics() { return _uorb_topics_list; } diff --git a/src/modules/logger/logger.cpp b/src/modules/logger/logger.cpp index cb98b347f019..30943a28b0a9 100644 --- a/src/modules/logger/logger.cpp +++ b/src/modules/logger/logger.cpp @@ -402,7 +402,7 @@ Logger::Logger(LogWriter::Backend backend, size_t buffer_size, uint32_t log_inte _sdlog_profile_handle = param_find("SDLOG_PROFILE"); if (poll_topic_name) { - const orb_metadata **topics = orb_get_topics(); + const orb_metadata *const*topics = orb_get_topics(); for (size_t i = 0; i < orb_topics_count(); i++) { if (strcmp(poll_topic_name, topics[i]->o_name) == 0) { @@ -478,7 +478,7 @@ LoggerSubscription* Logger::add_topic(const orb_metadata *topic) bool Logger::add_topic(const char *name, unsigned interval) { - const orb_metadata **topics = orb_get_topics(); + const orb_metadata *const*topics = orb_get_topics(); LoggerSubscription *subscription = nullptr; for (size_t i = 0; i < orb_topics_count(); i++) { @@ -1625,7 +1625,7 @@ void Logger::write_formats() { _writer.lock(); ulog_message_format_s msg = {}; - const orb_metadata **topics = orb_get_topics(); + const orb_metadata *const*topics = orb_get_topics(); //write all known formats for (size_t i = 0; i < orb_topics_count(); i++) { diff --git a/src/modules/replay/replay_main.cpp b/src/modules/replay/replay_main.cpp index 418e04040cb7..8b7bac555bb1 100644 --- a/src/modules/replay/replay_main.cpp +++ b/src/modules/replay/replay_main.cpp @@ -631,7 +631,7 @@ bool Replay::nextDataMessage(std::ifstream &file, Subscription &subscription, in const orb_metadata *Replay::findTopic(const std::string &name) { - const orb_metadata **topics = orb_get_topics(); + const orb_metadata *const *topics = orb_get_topics(); for (size_t i = 0; i < orb_topics_count(); i++) { if (name == topics[i]->o_name) { diff --git a/src/modules/uORB/uORBTopics.h b/src/modules/uORB/uORBTopics.h index f7c3a3c8653b..be82aaaa7fcc 100644 --- a/src/modules/uORB/uORBTopics.h +++ b/src/modules/uORB/uORBTopics.h @@ -45,6 +45,6 @@ extern size_t orb_topics_count() __EXPORT; /* * Returns array of topics metadata */ -extern const struct orb_metadata **orb_get_topics() __EXPORT; +extern const struct orb_metadata *const *orb_get_topics() __EXPORT; #endif /* MODULES_UORB_UORBTOPICS_H_ */