diff options
author | Jacob Gilbert <jacob.gilbert@protonmail.com> | 2021-06-01 19:23:08 -0600 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-06-07 07:35:30 -0400 |
commit | ab1e21c114465fa03d7fb1b56b3d5f8c9f56671e (patch) | |
tree | 115918cf9dbcc1c7b3be5abff70ebb6d76320aed /gr-blocks/python/blocks/msg_pair_to_var.py | |
parent | d84df80edaf1e8491a1b4fc208b407b7e5c5198c (diff) |
blocks: improvements to var/msg blocks
Fixes an issue where a user was feeding a dictionary into the msg_to_var
block which was then setting the variable to 'None' causing unexpected
behavior. This improves input sanitization for both blocks and adds
some extra info to the docstrings.
Signed-off-by: Jacob Gilbert <jacob.gilbert@protonmail.com>
Diffstat (limited to 'gr-blocks/python/blocks/msg_pair_to_var.py')
-rw-r--r-- | gr-blocks/python/blocks/msg_pair_to_var.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/gr-blocks/python/blocks/msg_pair_to_var.py b/gr-blocks/python/blocks/msg_pair_to_var.py index 17cd7fcc38..97f73f85f8 100644 --- a/gr-blocks/python/blocks/msg_pair_to_var.py +++ b/gr-blocks/python/blocks/msg_pair_to_var.py @@ -13,7 +13,10 @@ import pmt class msg_pair_to_var(gr.sync_block): """ - This block will take an input message pair and allow you to set a gnuradio variable. + This block will take an input message pair and allow you to set a flowgraph variable + via setter callback. If the second element the pair is a compound PMT object or not + of the datatype expected by the flowgraph the behavior of the flowgraph may be + unpredictable. """ def __init__(self, callback): gr.sync_block.__init__(self, name="msg_pair_to_var", in_sig=None, out_sig=None) @@ -24,13 +27,16 @@ class msg_pair_to_var(gr.sync_block): self.set_msg_handler(pmt.intern("inpair"), self.msg_handler) def msg_handler(self, msg): - try: - new_val = pmt.to_python(pmt.cdr(msg)) + if not pmt.is_pair(msg) or pmt.is_dict(msg) or pmt.is_pdu(msg): + gr.log.warn("Input message %s is not a simple pair, dropping" % repr(msg)) + return + new_val = pmt.to_python(pmt.cdr(msg)) + try: self.callback(new_val) - except Exception as e: - gr.log.error("Error with message conversion: %s" % str(e)) + gr.log.error("Error when calling " + repr(self.callback.name()) + " with " + + repr(new_val) + " (reason: %s)" % repr(e)) def stop(self): return True |