diff --git a/include/boost/regex/config.hpp b/include/boost/regex/config.hpp index 0db63f84..5d58b733 100644 --- a/include/boost/regex/config.hpp +++ b/include/boost/regex/config.hpp @@ -23,6 +23,10 @@ # define BOOST_REGEX_CXX03 #endif +#if defined(BOOST_REGEX_RECURSIVE) && !defined(BOOST_REGEX_CXX03) +# define BOOST_REGEX_CXX03 +#endif + #if defined(__has_include) #if !defined(BOOST_REGEX_STANDALONE) && !__has_include() #define BOOST_REGEX_STANDALONE @@ -374,21 +378,6 @@ BOOST_REGEX_DECL void BOOST_REGEX_CALL reset_stack_guard_page(); #endif -/***************************************************************************** - * - * helper memory allocation functions: - * - ****************************************************************************/ - -#if defined(__cplusplus) && defined(BOOST_REGEX_NON_RECURSIVE) -namespace boost{ namespace BOOST_REGEX_DETAIL_NS{ - -BOOST_REGEX_DECL void* BOOST_REGEX_CALL get_mem_block(); -BOOST_REGEX_DECL void BOOST_REGEX_CALL put_mem_block(void*); - -}} /* namespaces */ -#endif - /***************************************************************************** * * Diagnostics: diff --git a/include/boost/regex/pattern_except.hpp b/include/boost/regex/pattern_except.hpp index c61c9bac..e39553ea 100644 --- a/include/boost/regex/pattern_except.hpp +++ b/include/boost/regex/pattern_except.hpp @@ -27,8 +27,10 @@ #include #ifdef BOOST_REGEX_CXX03 #include +#include #else #include +#include #endif namespace boost{ @@ -51,17 +53,32 @@ namespace boost{ #pragma warning(disable : 26812) #endif #endif -class BOOST_REGEX_DECL regex_error : public std::runtime_error +class regex_error : public std::runtime_error { public: - explicit regex_error(const std::string& s, regex_constants::error_type err = regex_constants::error_unknown, std::ptrdiff_t pos = 0); - explicit regex_error(regex_constants::error_type err); - ~regex_error() BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE; + explicit regex_error(const std::string& s, regex_constants::error_type err = regex_constants::error_unknown, std::ptrdiff_t pos = 0) + : std::runtime_error(s) + , m_error_code(err) + , m_position(pos) + { + } + explicit regex_error(regex_constants::error_type err) + : std::runtime_error(::boost::BOOST_REGEX_DETAIL_NS::get_default_error_string(err)) + , m_error_code(err) + , m_position(0) + { + } + ~regex_error() BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE {} regex_constants::error_type code()const { return m_error_code; } std::ptrdiff_t position()const { return m_position; } - void raise()const; + void raise()const + { +#ifndef BOOST_NO_EXCEPTIONS + ::boost::throw_exception(*this); +#endif + } private: regex_constants::error_type m_error_code; std::ptrdiff_t m_position; @@ -72,7 +89,10 @@ typedef regex_error bad_expression; namespace BOOST_REGEX_DETAIL_NS{ -BOOST_REGEX_DECL void BOOST_REGEX_CALL raise_runtime_error(const std::runtime_error& ex); +inline void BOOST_REGEX_CALL raise_runtime_error(const std::runtime_error& ex) +{ + ::boost::throw_exception(ex); +} template void raise_error(const traits& t, regex_constants::error_type code) diff --git a/include/boost/regex/v4/mem_block_cache.hpp b/include/boost/regex/v4/mem_block_cache.hpp index 50af421e..1996a512 100644 --- a/include/boost/regex/v4/mem_block_cache.hpp +++ b/include/boost/regex/v4/mem_block_cache.hpp @@ -69,6 +69,12 @@ struct mem_block_cache } ::operator delete(ptr); } + + static mem_block_cache& instance() + { + static mem_block_cache block_cache = { { {nullptr} } }; + return block_cache; + } }; @@ -129,11 +135,43 @@ struct mem_block_cache ++cached_blocks; } } + static mem_block_cache& instance() + { +#ifdef BOOST_HAS_THREADS + static mem_block_cache block_cache = { 0, 0, BOOST_STATIC_MUTEX_INIT, }; +#else + static mem_block_cache block_cache = { 0, 0, }; +#endif + return block_cache; + } }; #endif -extern mem_block_cache block_cache; +#if BOOST_REGEX_MAX_CACHE_BLOCKS == 0 +inline void* BOOST_REGEX_CALL get_mem_block() +{ + return ::operator new(BOOST_REGEX_BLOCKSIZE); +} + +inline void BOOST_REGEX_CALL put_mem_block(void* p) +{ + ::operator delete(p); +} + +#else + +inline void* BOOST_REGEX_CALL get_mem_block() +{ + return mem_block_cache::instance().get(); +} + +inline void BOOST_REGEX_CALL put_mem_block(void* p) +{ + mem_block_cache::instance().put(p); +} + +#endif } } // namespace boost diff --git a/include/boost/regex/v4/perl_matcher.hpp b/include/boost/regex/v4/perl_matcher.hpp index 7d04ff26..4bd7d114 100644 --- a/include/boost/regex/v4/perl_matcher.hpp +++ b/include/boost/regex/v4/perl_matcher.hpp @@ -45,7 +45,17 @@ namespace BOOST_REGEX_DETAIL_NS{ // // error checking API: // -BOOST_REGEX_DECL void BOOST_REGEX_CALL verify_options(boost::regex_constants::syntax_option_type ef, match_flag_type mf); +inline void BOOST_REGEX_CALL verify_options(boost::regex_constants::syntax_option_type, match_flag_type mf) +{ + // + // can't mix match_extra with POSIX matching rules: + // + if ((mf & match_extra) && (mf & match_posix)) + { + std::logic_error msg("Usage Error: Can't mix regular expression captures with POSIX matching rules"); + throw_exception(msg); + } +} // // function can_start: // diff --git a/include/boost/regex/v4/perl_matcher_non_recursive.hpp b/include/boost/regex/v4/perl_matcher_non_recursive.hpp index 7e3dce89..1042e794 100644 --- a/include/boost/regex/v4/perl_matcher_non_recursive.hpp +++ b/include/boost/regex/v4/perl_matcher_non_recursive.hpp @@ -20,7 +20,7 @@ #ifndef BOOST_REGEX_V4_PERL_MATCHER_NON_RECURSIVE_HPP #define BOOST_REGEX_V4_PERL_MATCHER_NON_RECURSIVE_HPP -#include +#include #ifdef BOOST_MSVC #pragma warning(push) diff --git a/include/boost/regex/v4/regex_traits_defaults.hpp b/include/boost/regex/v4/regex_traits_defaults.hpp index 38f1d198..2a6c0d12 100644 --- a/include/boost/regex/v4/regex_traits_defaults.hpp +++ b/include/boost/regex/v4/regex_traits_defaults.hpp @@ -31,6 +31,7 @@ #endif #include +#include #ifndef BOOST_REGEX_SYNTAX_TYPE_HPP #include @@ -38,6 +39,7 @@ #ifndef BOOST_REGEX_ERROR_TYPE_HPP #include #endif +#include #include #include diff --git a/include/boost/regex/v5/mem_block_cache.hpp b/include/boost/regex/v5/mem_block_cache.hpp index 50af421e..1996a512 100644 --- a/include/boost/regex/v5/mem_block_cache.hpp +++ b/include/boost/regex/v5/mem_block_cache.hpp @@ -69,6 +69,12 @@ struct mem_block_cache } ::operator delete(ptr); } + + static mem_block_cache& instance() + { + static mem_block_cache block_cache = { { {nullptr} } }; + return block_cache; + } }; @@ -129,11 +135,43 @@ struct mem_block_cache ++cached_blocks; } } + static mem_block_cache& instance() + { +#ifdef BOOST_HAS_THREADS + static mem_block_cache block_cache = { 0, 0, BOOST_STATIC_MUTEX_INIT, }; +#else + static mem_block_cache block_cache = { 0, 0, }; +#endif + return block_cache; + } }; #endif -extern mem_block_cache block_cache; +#if BOOST_REGEX_MAX_CACHE_BLOCKS == 0 +inline void* BOOST_REGEX_CALL get_mem_block() +{ + return ::operator new(BOOST_REGEX_BLOCKSIZE); +} + +inline void BOOST_REGEX_CALL put_mem_block(void* p) +{ + ::operator delete(p); +} + +#else + +inline void* BOOST_REGEX_CALL get_mem_block() +{ + return mem_block_cache::instance().get(); +} + +inline void BOOST_REGEX_CALL put_mem_block(void* p) +{ + mem_block_cache::instance().put(p); +} + +#endif } } // namespace boost diff --git a/include/boost/regex/v5/perl_matcher.hpp b/include/boost/regex/v5/perl_matcher.hpp index e61b3de2..fc0b7b4a 100644 --- a/include/boost/regex/v5/perl_matcher.hpp +++ b/include/boost/regex/v5/perl_matcher.hpp @@ -45,7 +45,17 @@ namespace BOOST_REGEX_DETAIL_NS{ // // error checking API: // -BOOST_REGEX_DECL void BOOST_REGEX_CALL verify_options(boost::regex_constants::syntax_option_type ef, match_flag_type mf); +inline void BOOST_REGEX_CALL verify_options(boost::regex_constants::syntax_option_type, match_flag_type mf) +{ + // + // can't mix match_extra with POSIX matching rules: + // + if ((mf & match_extra) && (mf & match_posix)) + { + std::logic_error msg("Usage Error: Can't mix regular expression captures with POSIX matching rules"); + throw_exception(msg); + } +} // // function can_start: // @@ -407,10 +417,6 @@ private: bool find_imp(); bool match_imp(); -#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD - typedef bool (perl_matcher::*protected_proc_type)(); - bool protected_call(protected_proc_type); -#endif void estimate_max_state_count(std::random_access_iterator_tag*); void estimate_max_state_count(void*); bool match_prefix(); diff --git a/include/boost/regex/v5/perl_matcher_common.hpp b/include/boost/regex/v5/perl_matcher_common.hpp index 06710868..d6c2d028 100644 --- a/include/boost/regex/v5/perl_matcher_common.hpp +++ b/include/boost/regex/v5/perl_matcher_common.hpp @@ -178,27 +178,10 @@ inline void perl_matcher::estimate_max_state_co max_state_count = BOOST_REGEX_MAX_STATE_COUNT; } -#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD -template -inline bool perl_matcher::protected_call( - protected_proc_type proc) -{ - ::boost::BOOST_REGEX_DETAIL_NS::concrete_protected_call - > - obj(this, proc); - return obj.execute(); - -} -#endif - template inline bool perl_matcher::match() { -#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD - return protected_call(&perl_matcher::match_imp); -#else return match_imp(); -#endif } template @@ -242,11 +225,7 @@ bool perl_matcher::match_imp() template inline bool perl_matcher::find() { -#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD - return protected_call(&perl_matcher::find_imp); -#else return find_imp(); -#endif } template diff --git a/include/boost/regex/v5/perl_matcher_non_recursive.hpp b/include/boost/regex/v5/perl_matcher_non_recursive.hpp index 7e3dce89..8f264e46 100644 --- a/include/boost/regex/v5/perl_matcher_non_recursive.hpp +++ b/include/boost/regex/v5/perl_matcher_non_recursive.hpp @@ -20,7 +20,7 @@ #ifndef BOOST_REGEX_V4_PERL_MATCHER_NON_RECURSIVE_HPP #define BOOST_REGEX_V4_PERL_MATCHER_NON_RECURSIVE_HPP -#include +#include #ifdef BOOST_MSVC #pragma warning(push) diff --git a/include/boost/regex/v5/protected_call.hpp b/include/boost/regex/v5/protected_call.hpp deleted file mode 100644 index 451b2e34..00000000 --- a/include/boost/regex/v5/protected_call.hpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * - * Copyright (c) 2004 - * John Maddock - * - * Use, modification and distribution are subject to the - * Boost Software License, Version 1.0. (See accompanying file - * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - * - */ - - /* - * LOCATION: see http://www.boost.org for most recent version. - * FILE basic_regex_creator.cpp - * VERSION see - * DESCRIPTION: Declares template class basic_regex_creator which fills in - * the data members of a regex_data object. - */ - -#ifndef BOOST_REGEX_V4_PROTECTED_CALL_HPP -#define BOOST_REGEX_V4_PROTECTED_CALL_HPP - -#include - -#ifdef BOOST_MSVC -#pragma warning(push) -#pragma warning(disable: 4103) -#endif -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_PREFIX -#endif -#ifdef BOOST_MSVC -#pragma warning(pop) -#endif - -namespace boost{ -namespace BOOST_REGEX_DETAIL_NS{ - -class BOOST_REGEX_DECL abstract_protected_call -{ -public: - bool BOOST_REGEX_CALL execute()const; - // this stops gcc-4 from complaining: - virtual ~abstract_protected_call(){} -private: - virtual bool call()const = 0; -}; - -template -class concrete_protected_call - : public abstract_protected_call -{ -public: - typedef bool (T::*proc_type)(); - concrete_protected_call(T* o, proc_type p) - : obj(o), proc(p) {} -private: - bool call()const BOOST_OVERRIDE; - T* obj; - proc_type proc; -}; - -template -bool concrete_protected_call::call()const -{ - return (obj->*proc)(); -} - -} -} // namespace boost - -#ifdef BOOST_MSVC -#pragma warning(push) -#pragma warning(disable: 4103) -#endif -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_SUFFIX -#endif -#ifdef BOOST_MSVC -#pragma warning(pop) -#endif - -#endif diff --git a/include/boost/regex/v5/regex.hpp b/include/boost/regex/v5/regex.hpp index 9196b04b..7a1ee4bf 100644 --- a/include/boost/regex/v5/regex.hpp +++ b/include/boost/regex/v5/regex.hpp @@ -81,9 +81,6 @@ #ifndef BOOST_REGEX_V4_MATCH_RESULTS_HPP #include #endif -#ifndef BOOST_REGEX_V4_PROTECTED_CALL_HPP -#include -#endif #ifndef BOOST_REGEX_MATCHER_HPP #include #endif diff --git a/include/boost/regex/v5/regex_traits_defaults.hpp b/include/boost/regex/v5/regex_traits_defaults.hpp index 38f1d198..7eaf31f3 100644 --- a/include/boost/regex/v5/regex_traits_defaults.hpp +++ b/include/boost/regex/v5/regex_traits_defaults.hpp @@ -38,8 +38,10 @@ #ifndef BOOST_REGEX_ERROR_TYPE_HPP #include #endif +#include #include #include +#include #ifdef BOOST_NO_STDC_NAMESPACE namespace std{ diff --git a/src/regex.cpp b/src/regex.cpp index ee0204cc..2d923955 100644 --- a/src/regex.cpp +++ b/src/regex.cpp @@ -19,15 +19,12 @@ #define BOOST_REGEX_SOURCE -#include -#include -#include -#include +#include -#if defined(BOOST_REGEX_HAS_MS_STACK_GUARD) && defined(_MSC_VER) && (_MSC_VER >= 1300) -# include -#endif #ifdef BOOST_REGEX_HAS_MS_STACK_GUARD + +#include + #ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN #endif @@ -37,78 +34,12 @@ #define NOGDI #define NOUSER #include -#endif +#include +#include +#include -#if defined(BOOST_REGEX_NON_RECURSIVE) && !defined(BOOST_REGEX_V3) -#if BOOST_REGEX_MAX_CACHE_BLOCKS == 0 -#include -#else -#include -#endif -#endif - -#ifdef BOOST_INTEL -#pragma warning(disable:383) -#endif - -namespace boost{ - -// -// fix: these are declared out of line here to ensure -// that dll builds contain the Virtual table for these -// types - this ensures that exceptions can be thrown -// from the dll and caught in an exe. -regex_error::regex_error(const std::string& s, regex_constants::error_type err, std::ptrdiff_t pos) - : std::runtime_error(s) - , m_error_code(err) - , m_position(pos) -{ -} - -regex_error::regex_error(regex_constants::error_type err) - : std::runtime_error(::boost::BOOST_REGEX_DETAIL_NS::get_default_error_string(err)) - , m_error_code(err) - , m_position(0) -{ -} - -regex_error::~regex_error() BOOST_NOEXCEPT_OR_NOTHROW -{ -} - -void regex_error::raise()const -{ -#ifndef BOOST_NO_EXCEPTIONS - ::boost::throw_exception(*this); -#endif -} - - - -namespace BOOST_REGEX_DETAIL_NS{ - -BOOST_REGEX_DECL void BOOST_REGEX_CALL raise_runtime_error(const std::runtime_error& ex) -{ - ::boost::throw_exception(ex); -} -// -// error checking API: -// -BOOST_REGEX_DECL void BOOST_REGEX_CALL verify_options(boost::regex::flag_type /*ef*/, match_flag_type mf) -{ -#ifndef BOOST_REGEX_V3 - // - // can't mix match_extra with POSIX matching rules: - // - if((mf & match_extra) && (mf & match_posix)) - { - std::logic_error msg("Usage Error: Can't mix regular expression captures with POSIX matching rules"); - throw_exception(msg); - } -#endif -} - -#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD +namespace boost { +namespace BOOST_REGEX_DETAIL_NS { static void execute_eror() { @@ -175,52 +106,10 @@ BOOST_REGEX_DECL void BOOST_REGEX_CALL reset_stack_guard_page() } #endif } -#endif - -#if defined(BOOST_REGEX_NON_RECURSIVE) && !defined(BOOST_REGEX_V3) - -#if BOOST_REGEX_MAX_CACHE_BLOCKS == 0 - -BOOST_REGEX_DECL void* BOOST_REGEX_CALL get_mem_block() -{ - return ::operator new(BOOST_REGEX_BLOCKSIZE); } - -BOOST_REGEX_DECL void BOOST_REGEX_CALL put_mem_block(void* p) -{ - ::operator delete(p); -} - -#else - -#if defined(BOOST_REGEX_MEM_BLOCK_CACHE_LOCK_FREE) -mem_block_cache block_cache = { { {nullptr} } } ; -#elif defined(BOOST_HAS_THREADS) -mem_block_cache block_cache = { 0, 0, BOOST_STATIC_MUTEX_INIT, }; -#else -mem_block_cache block_cache = { 0, 0, }; +} // namspaces #endif -BOOST_REGEX_DECL void* BOOST_REGEX_CALL get_mem_block() -{ - return block_cache.get(); -} - -BOOST_REGEX_DECL void BOOST_REGEX_CALL put_mem_block(void* p) -{ - block_cache.put(p); -} - -#endif - -#endif - -} // namespace BOOST_REGEX_DETAIL_NS - - - -} // namespace boost - #if defined(BOOST_RE_USE_VCL) && defined(BOOST_REGEX_DYN_LINK) int WINAPI DllEntryPoint(HINSTANCE , unsigned long , void*)