Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2008-02-21 19:42:13


Author: eric_niebler
Date: 2008-02-21 19:42:12 EST (Thu, 21 Feb 2008)
New Revision: 43363
URL: http://svn.boost.org/trac/boost/changeset/43363

Log:
fix crash when actions are in keep() expressions
Text files modified:
   trunk/boost/xpressive/detail/core/matcher/end_matcher.hpp | 19 +++++++++++++++++++
   trunk/boost/xpressive/detail/core/matcher/keeper_matcher.hpp | 4 +++-
   trunk/boost/xpressive/detail/core/matcher/lookahead_matcher.hpp | 6 +++++-
   trunk/boost/xpressive/detail/core/matcher/lookbehind_matcher.hpp | 4 ++++
   trunk/boost/xpressive/detail/core/state.hpp | 19 +++++++++++++++----
   trunk/boost/xpressive/detail/detail_fwd.hpp | 4 ++++
   trunk/boost/xpressive/detail/static/transforms/as_independent.hpp | 12 ++++++------
   trunk/boost/xpressive/regex_compiler.hpp | 6 +++---
   trunk/boost/xpressive/xpressive_typeof.hpp | 1 +
   9 files changed, 60 insertions(+), 15 deletions(-)

Modified: trunk/boost/xpressive/detail/core/matcher/end_matcher.hpp
==============================================================================
--- trunk/boost/xpressive/detail/core/matcher/end_matcher.hpp (original)
+++ trunk/boost/xpressive/detail/core/matcher/end_matcher.hpp 2008-02-21 19:42:12 EST (Thu, 21 Feb 2008)
@@ -74,6 +74,25 @@
         }
     };
 
+ ///////////////////////////////////////////////////////////////////////////////
+ // independent_end_matcher
+ //
+ struct independent_end_matcher
+ : quant_style_assertion
+ {
+ template<typename BidiIter, typename Next>
+ static bool match(match_state<BidiIter> &state, Next const &)
+ {
+ // Now execute any actions that have been queued
+ for(actionable const *actor = state.action_list_.next; 0 != actor; actor = actor->next)
+ {
+ actor->execute(state.action_args_);
+ }
+
+ return true;
+ }
+ };
+
 }}}
 
 #endif

Modified: trunk/boost/xpressive/detail/core/matcher/keeper_matcher.hpp
==============================================================================
--- trunk/boost/xpressive/detail/core/matcher/keeper_matcher.hpp (original)
+++ trunk/boost/xpressive/detail/core/matcher/keeper_matcher.hpp 2008-02-21 19:42:12 EST (Thu, 21 Feb 2008)
@@ -71,10 +71,12 @@
 
             if(!this->xpr_.match(state))
             {
+ restore_action_queue(mem, state);
                 reclaim_sub_matches(mem, state, false);
                 return false;
             }
- else if(next.match(state))
+ restore_action_queue(mem, state);
+ if(next.match(state))
             {
                 reclaim_sub_matches(mem, state, true);
                 return true;

Modified: trunk/boost/xpressive/detail/core/matcher/lookahead_matcher.hpp
==============================================================================
--- trunk/boost/xpressive/detail/core/matcher/lookahead_matcher.hpp (original)
+++ trunk/boost/xpressive/detail/core/matcher/lookahead_matcher.hpp 2008-02-21 19:42:12 EST (Thu, 21 Feb 2008)
@@ -106,11 +106,13 @@
 
                 if(this->xpr_.match(state))
                 {
+ restore_action_queue(mem, state);
                     restore_sub_matches(mem, state);
                     state.cur_ = tmp;
                     return false;
                 }
- else if(next.match(state))
+ restore_action_queue(mem, state);
+ if(next.match(state))
                 {
                     reclaim_sub_matches(mem, state, true);
                     return true;
@@ -121,10 +123,12 @@
             {
                 if(!this->xpr_.match(state))
                 {
+ restore_action_queue(mem, state);
                     reclaim_sub_matches(mem, state, false);
                     return false;
                 }
                 state.cur_ = tmp;
+ restore_action_queue(mem, state);
                 if(next.match(state))
                 {
                     reclaim_sub_matches(mem, state, true);

Modified: trunk/boost/xpressive/detail/core/matcher/lookbehind_matcher.hpp
==============================================================================
--- trunk/boost/xpressive/detail/core/matcher/lookbehind_matcher.hpp (original)
+++ trunk/boost/xpressive/detail/core/matcher/lookbehind_matcher.hpp 2008-02-21 19:42:12 EST (Thu, 21 Feb 2008)
@@ -120,11 +120,13 @@
 
                 if(this->xpr_.match(state))
                 {
+ restore_action_queue(mem, state);
                     restore_sub_matches(mem, state);
                     BOOST_ASSERT(state.cur_ == tmp);
                     return false;
                 }
                 state.cur_ = tmp;
+ restore_action_queue(mem, state);
                 if(next.match(state))
                 {
                     reclaim_sub_matches(mem, state, true);
@@ -137,10 +139,12 @@
                 if(!this->xpr_.match(state))
                 {
                     state.cur_ = tmp;
+ restore_action_queue(mem, state);
                     reclaim_sub_matches(mem, state, false);
                     return false;
                 }
                 BOOST_ASSERT(state.cur_ == tmp);
+ restore_action_queue(mem, state);
                 if(next.match(state))
                 {
                     reclaim_sub_matches(mem, state, true);

Modified: trunk/boost/xpressive/detail/core/state.hpp
==============================================================================
--- trunk/boost/xpressive/detail/core/state.hpp (original)
+++ trunk/boost/xpressive/detail/core/state.hpp 2008-02-21 19:42:12 EST (Thu, 21 Feb 2008)
@@ -316,6 +316,7 @@
 {
     sub_match_impl<BidiIter> *old_sub_matches_;
     std::size_t nested_results_count_;
+ actionable const *action_list_head_;
     actionable const **action_list_tail_;
     attr_context attr_context_;
 };
@@ -330,14 +331,28 @@
     {
         state.extras_->sub_match_stack_.push_sequence(state.mark_count_, no_fill)
       , state.context_.results_ptr_->nested_results().size()
+ , state.action_list_.next
       , state.action_list_tail_
       , state.attr_context_
     };
+ state.action_list_.next = 0;
+ state.action_list_tail_ = &state.action_list_.next;
     std::copy(state.sub_matches_, state.sub_matches_ + state.mark_count_, mem.old_sub_matches_);
     return mem;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
+// restore_action_queue
+//
+template<typename BidiIter>
+inline void restore_action_queue(memento<BidiIter> const &mem, match_state<BidiIter> &state)
+{
+ state.action_list_.next = mem.action_list_head_;
+ state.action_list_tail_ = mem.action_list_tail_;
+ *state.action_list_tail_ = 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
 // restore_sub_matches
 //
 template<typename BidiIter>
@@ -350,8 +365,6 @@
     std::copy(mem.old_sub_matches_, mem.old_sub_matches_ + state.mark_count_, state.sub_matches_);
     state.extras_->sub_match_stack_.unwind_to(mem.old_sub_matches_);
     state.attr_context_ = mem.attr_context_;
- state.action_list_tail_ = mem.action_list_tail_;
- *state.action_list_tail_ = 0;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -371,8 +384,6 @@
     if(!success)
     {
         state.attr_context_ = mem.attr_context_;
- state.action_list_tail_ = mem.action_list_tail_;
- *state.action_list_tail_ = 0;
     }
 }
 

Modified: trunk/boost/xpressive/detail/detail_fwd.hpp
==============================================================================
--- trunk/boost/xpressive/detail/detail_fwd.hpp (original)
+++ trunk/boost/xpressive/detail/detail_fwd.hpp 2008-02-21 19:42:12 EST (Thu, 21 Feb 2008)
@@ -69,6 +69,8 @@
     //
     struct end_matcher;
 
+ struct independent_end_matcher;
+
     struct assert_bos_matcher;
 
     struct assert_eos_matcher;
@@ -264,6 +266,8 @@
 
     typedef static_xpression<alternate_end_matcher, no_next> alternate_end_xpression;
 
+ typedef static_xpression<independent_end_matcher, no_next> independent_end_xpression;
+
     typedef static_xpression<true_matcher, no_next> true_xpression;
 
     template<typename Matcher, typename Next = end_xpression>

Modified: trunk/boost/xpressive/detail/static/transforms/as_independent.hpp
==============================================================================
--- trunk/boost/xpressive/detail/static/transforms/as_independent.hpp (original)
+++ trunk/boost/xpressive/detail/static/transforms/as_independent.hpp 2008-02-21 19:42:12 EST (Thu, 21 Feb 2008)
@@ -44,7 +44,7 @@
         {
             typedef typename proto::result_of::arg<Expr>::type arg_type;
             typedef detail::lookahead_matcher<
- typename Grammar::template result<void(arg_type, detail::true_xpression, Visitor)>::type
+ typename Grammar::template result<void(arg_type, detail::independent_end_xpression, Visitor)>::type
> type;
         };
 
@@ -53,7 +53,7 @@
         operator ()(Expr const &expr, State const &, Visitor &visitor) const
         {
             return typename result<void(Expr, State, Visitor)>::type(
- Grammar()(proto::arg(expr), detail::true_xpression(), visitor)
+ Grammar()(proto::arg(expr), detail::independent_end_xpression(), visitor)
               , false
             );
         }
@@ -68,7 +68,7 @@
         struct result<This(Expr, State, Visitor)>
         {
             typedef typename proto::result_of::arg<Expr>::type arg_type;
- typedef typename Grammar::template result<void(arg_type, detail::true_xpression, Visitor)>::type xpr_type;
+ typedef typename Grammar::template result<void(arg_type, detail::independent_end_xpression, Visitor)>::type xpr_type;
             typedef detail::lookbehind_matcher<xpr_type> type;
         };
 
@@ -77,7 +77,7 @@
         operator ()(Expr const &expr, State const &, Visitor &visitor) const
         {
             typedef typename result<void(Expr, State, Visitor)>::xpr_type xpr_type;
- xpr_type const &expr2 = Grammar()(proto::arg(expr), detail::true_xpression(), visitor);
+ xpr_type const &expr2 = Grammar()(proto::arg(expr), detail::independent_end_xpression(), visitor);
             std::size_t width = expr2.get_width().value();
             return detail::lookbehind_matcher<xpr_type>(expr2, width, false);
         }
@@ -93,7 +93,7 @@
         {
             typedef typename proto::result_of::arg<Expr>::type arg_type;
             typedef detail::keeper_matcher<
- typename Grammar::template result<void(arg_type, detail::true_xpression, Visitor)>::type
+ typename Grammar::template result<void(arg_type, detail::independent_end_xpression, Visitor)>::type
> type;
         };
 
@@ -102,7 +102,7 @@
         operator ()(Expr const &expr, State const &, Visitor &visitor) const
         {
             return typename result<void(Expr, State, Visitor)>::type(
- Grammar()(proto::arg(expr), detail::true_xpression(), visitor)
+ Grammar()(proto::arg(expr), detail::independent_end_xpression(), visitor)
             );
         }
     };

Modified: trunk/boost/xpressive/regex_compiler.hpp
==============================================================================
--- trunk/boost/xpressive/regex_compiler.hpp (original)
+++ trunk/boost/xpressive/regex_compiler.hpp 2008-02-21 19:42:12 EST (Thu, 21 Feb 2008)
@@ -320,19 +320,19 @@
             negative = true; // fall-through
         case token_positive_lookahead:
             lookahead = true;
- seq_end = detail::make_dynamic<BidiIter>(detail::true_matcher());
+ seq_end = detail::make_dynamic<BidiIter>(detail::independent_end_matcher());
             break;
 
         case token_negative_lookbehind:
             negative = true; // fall-through
         case token_positive_lookbehind:
             lookbehind = true;
- seq_end = detail::make_dynamic<BidiIter>(detail::true_matcher());
+ seq_end = detail::make_dynamic<BidiIter>(detail::independent_end_matcher());
             break;
 
         case token_independent_sub_expression:
             keeper = true;
- seq_end = detail::make_dynamic<BidiIter>(detail::true_matcher());
+ seq_end = detail::make_dynamic<BidiIter>(detail::independent_end_matcher());
             break;
 
         case token_comment:

Modified: trunk/boost/xpressive/xpressive_typeof.hpp
==============================================================================
--- trunk/boost/xpressive/xpressive_typeof.hpp (original)
+++ trunk/boost/xpressive/xpressive_typeof.hpp 2008-02-21 19:42:12 EST (Thu, 21 Feb 2008)
@@ -72,6 +72,7 @@
 BOOST_TYPEOF_REGISTER_TYPE(boost::xpressive::detail::epsilon_matcher)
 BOOST_TYPEOF_REGISTER_TYPE(boost::xpressive::detail::true_matcher)
 BOOST_TYPEOF_REGISTER_TYPE(boost::xpressive::detail::end_matcher)
+BOOST_TYPEOF_REGISTER_TYPE(boost::xpressive::detail::independent_end_matcher)
 BOOST_TYPEOF_REGISTER_TYPE(boost::xpressive::detail::any_matcher)
 BOOST_TYPEOF_REGISTER_TYPE(boost::xpressive::detail::assert_bos_matcher)
 BOOST_TYPEOF_REGISTER_TYPE(boost::xpressive::detail::assert_eos_matcher)


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk