summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Demel <demel@ant.uni-bremen.de>2020-06-08 11:25:20 +0200
committerMarcus Müller <marcus@hostalia.de>2020-06-22 15:27:17 +0200
commit587303c5d87c07e2efc6ae94ad85e317251e5844 (patch)
tree728945d689ebd596f6a2db77958c049cc04ccfd6
parent75286c00a3ff8175a05a9a6d2a1482b05ff8d95b (diff)
gr-uhd: Fix assumption that pmt pair passes is_dict
Previously, `pmt::is_dict` would return `true` for pairs and vice versa. This assumption was built into gr-uhd command handling. With this commit, a new check `if(pmt::is_pair(...))` is introduced to convert pairs to dicts for further processing.
-rw-r--r--gr-uhd/lib/usrp_block_impl.cc19
1 files changed, 8 insertions, 11 deletions
diff --git a/gr-uhd/lib/usrp_block_impl.cc b/gr-uhd/lib/usrp_block_impl.cc
index 2ce7aa3b39..5eab8fad0f 100644
--- a/gr-uhd/lib/usrp_block_impl.cc
+++ b/gr-uhd/lib/usrp_block_impl.cc
@@ -487,6 +487,14 @@ void usrp_block_impl::msg_handler_command(pmt::pmt_t msg)
}
// End of legacy backward compat code.
+ // Apparently, pmt::is_dict does not return true for pairs anymore. Yeah!
+ if (pmt::is_pair(msg)) {
+ GR_LOG_DEBUG(d_logger,
+ boost::format("Command message is pair, converting to dict: %s") %
+ msg);
+ msg = pmt::dict_add(pmt::make_dict(), pmt::car(msg), pmt::cdr(msg));
+ }
+
// Turn pair into dict
if (!pmt::is_dict(msg)) {
GR_LOG_ERROR(d_logger,
@@ -494,17 +502,6 @@ void usrp_block_impl::msg_handler_command(pmt::pmt_t msg)
return;
}
- // OK, here comes the horrible part. Pairs pass is_dict(), but they're not dicts. Such
- // dicks.
- try {
- // This will fail if msg is a pair:
- pmt::pmt_t keys = pmt::dict_keys(msg);
- } catch (const pmt::wrong_type& e) {
- // So we fix it:
- GR_LOG_DEBUG(d_debug_logger, boost::format("Converting pair to dict: %s") % msg);
- msg = pmt::dict_add(pmt::make_dict(), pmt::car(msg), pmt::cdr(msg));
- }
-
/*** Start the actual message processing *************************/
/// 1) Check if there's a time stamp
if (pmt::dict_has_key(msg, cmd_time_key())) {