diff --git a/src/c4/yml/event_handler_tree.hpp b/src/c4/yml/event_handler_tree.hpp index 6ed9d249..d526125d 100644 --- a/src/c4/yml/event_handler_tree.hpp +++ b/src/c4/yml/event_handler_tree.hpp @@ -135,6 +135,18 @@ struct EventHandlerTree void finish_parse() { + /** This pointer is temporary. Remember that: + * + * - this handler object may be held by the user + * - it may be used with a temporary tree inside the parse function + * - when the parse function returns the temporary tree, its address + * will change + * + * As a result, the user could try to read the tree from m_tree, and + * end up reading the stale temporary object. + * + * So it is better to clear it here; then the user will get an obvious + * segfault to read from m_tree. */ m_tree = nullptr; } @@ -298,13 +310,9 @@ struct EventHandlerTree /** @name YAML stream functions */ /** @{ */ - void begin_stream() - { - } + C4_ALWAYS_INLINE void begin_stream() {} - void end_stream() - { - } + C4_ALWAYS_INLINE void end_stream() {} /** @} */ @@ -797,16 +805,6 @@ struct EventHandlerTree } } - C4_ALWAYS_INLINE bool has_key_tag() const - { - return _has_any_(KEYTAG); - } - - C4_ALWAYS_INLINE bool has_val_tag() const - { - return _has_any_(VALTAG); - } - /** @} */ public: diff --git a/test/test_suite/test_suite_event_handler.hpp b/test/test_suite/test_suite_event_handler.hpp index 41a0794f..e7342719 100644 --- a/test/test_suite/test_suite_event_handler.hpp +++ b/test/test_suite/test_suite_event_handler.hpp @@ -339,6 +339,20 @@ struct EventHandlerYamlStd return result; } + bool _should_push_on_begin_doc() const + { + const bool is_root = (m_stack.size() == 1u); + { + return is_root && (_has_any_(DOC) || m_curr->ev_has_children); + } + } + + bool _should_pop_on_end_doc() const + { + const bool is_root = (m_stack.size() == 1u); + return !is_root && _has_any_(DOC); + } + /** @} */ public: @@ -368,20 +382,6 @@ struct EventHandlerYamlStd /** @name YAML document functions */ /** @{ */ - bool _should_push_on_begin_doc() const - { - const bool is_root = (m_stack.size() == 1u); - { - return is_root && (_has_any_(DOC) || m_curr->ev_has_children); - } - } - - bool _should_pop_on_end_doc() const - { - const bool is_root = (m_stack.size() == 1u); - return !is_root && _has_any_(DOC); - } - /** called at the beginning of parsing a non-empty stream */ void begin_doc() { @@ -834,16 +834,6 @@ struct EventHandlerYamlStd } } - C4_ALWAYS_INLINE bool has_key_tag() const - { - return _has_any_(KEYTAG); - } - - C4_ALWAYS_INLINE bool has_val_tag() const - { - return _has_any_(VALTAG); - } - /** @} */ public: