diff --git a/include/boost/regex/v4/perl_matcher.hpp b/include/boost/regex/v4/perl_matcher.hpp index 8ccf7446..44751e58 100644 --- a/include/boost/regex/v4/perl_matcher.hpp +++ b/include/boost/regex/v4/perl_matcher.hpp @@ -287,7 +287,13 @@ public: match_flag_type f); bool match(); + bool match_imp(); bool find(); + bool find_imp(); +#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD + typedef bool (perl_matcher::*protected_proc_type)(); + bool protected_call(protected_proc_type); +#endif void setf(match_flag_type f) { m_match_flags |= f; } diff --git a/include/boost/regex/v4/perl_matcher_common.hpp b/include/boost/regex/v4/perl_matcher_common.hpp index 992643f1..a8c485d5 100644 --- a/include/boost/regex/v4/perl_matcher_common.hpp +++ b/include/boost/regex/v4/perl_matcher_common.hpp @@ -91,14 +91,37 @@ void perl_matcher::estimate_max_sta max_state_count = BOOST_REGEX_MAX_STATE_COUNT; } - +#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD +template +bool perl_matcher::protected_call( + protected_proc_type proc) +{ + __try{ + return (this->*proc)(); + }__except(EXCEPTION_STACK_OVERFLOW == GetExceptionCode()) + { + reset_stack_guard_page(); + } + // we only get here after a stack overflow: + raise_error(traits_inst, REG_E_MEMORY); + // and we never really get here at all: + return false; +} +#endif template bool perl_matcher::match() { #ifdef BOOST_REGEX_HAS_MS_STACK_GUARD - __try{ + return protected_call(&perl_matcher::match_imp); +#else + return match_imp(); #endif +} + +template +bool perl_matcher::match_imp() +{ // initialise our stack if we are non-recursive: #ifdef BOOST_REGEX_NON_RECURSIVE save_state_init init(&m_stack_base, &m_backup_state); @@ -133,20 +156,20 @@ bool perl_matcher::match() throw; } #endif -#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD - }__except(EXCEPTION_STACK_OVERFLOW == GetExceptionCode()) - { - reset_stack_guard_page(); - } - // we only get here after a stack overflow: - raise_error(traits_inst, REG_E_MEMORY); - // and we never really get here at all: - return false; -#endif } template bool perl_matcher::find() +{ +#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD + return protected_call(&perl_matcher::find_imp); +#else + return find_imp(); +#endif +} + +template +bool perl_matcher::find_imp() { static matcher_proc_type const s_find_vtable[7] = { @@ -159,10 +182,6 @@ bool perl_matcher::find() &perl_matcher::find_restart_lit, }; -#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD - __try{ -#endif - // initialise our stack if we are non-recursive: #ifdef BOOST_REGEX_NON_RECURSIVE save_state_init init(&m_stack_base, &m_backup_state); @@ -228,16 +247,6 @@ bool perl_matcher::find() throw; } #endif -#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD - }__except(EXCEPTION_STACK_OVERFLOW == GetExceptionCode()) - { - reset_stack_guard_page(); - } - // we only get here after a stack overflow: - raise_error(traits_inst, REG_E_MEMORY); - // and we never really get here at all: - return false; -#endif } template