From c32c644a38f70bbce4d2ffd98c6a44645caa2d86 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Mon, 7 Jul 2003 11:44:00 +0000 Subject: [PATCH] Added fixes for: Compilers that pretend to be Visual C++ export of memory management code [SVN r18955] --- include/boost/regex/config.hpp | 18 ++++++++-- include/boost/regex/v4/perl_matcher.hpp | 1 - .../regex/v4/perl_matcher_non_recursive.hpp | 8 ++--- src/regex.cpp | 35 +++++++++++++++++++ 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/include/boost/regex/config.hpp b/include/boost/regex/config.hpp index 41446058..a0024b9e 100644 --- a/include/boost/regex/config.hpp +++ b/include/boost/regex/config.hpp @@ -232,13 +232,13 @@ using std::distance; * ****************************************************************************/ -#if defined(BOOST_MSVC) || defined(__ICL) +#if defined(_MSC_VER) && (_MSC_VER >= 1200) && defined(_MSC_EXTENSIONS) # if defined(_DEBUG) # define BOOST_REGEX_CALL __cdecl # else # define BOOST_REGEX_CALL __fastcall # endif -# define BOOST_REGEX_CCALL __stdcall +# define BOOST_REGEX_CCALL __cdecl #endif #if defined(__BORLANDC__) @@ -556,5 +556,19 @@ inline void pointer_construct(T* p, const T& t) }} // namespaces #endif +/***************************************************************************** + * + * helper memory allocation functions: + * + ****************************************************************************/ + +#if defined(__cplusplus) && defined(BOOST_REGEX_NON_RECURSIVE) +namespace boost{ namespace re_detail{ + +BOOST_REGEX_DECL void* BOOST_REGEX_CALL get_mem_block(); +BOOST_REGEX_DECL void BOOST_REGEX_CALL put_mem_block(void*); + +}} // namespaces +#endif #endif diff --git a/include/boost/regex/v4/perl_matcher.hpp b/include/boost/regex/v4/perl_matcher.hpp index 2f906458..68a72fd4 100644 --- a/include/boost/regex/v4/perl_matcher.hpp +++ b/include/boost/regex/v4/perl_matcher.hpp @@ -442,7 +442,6 @@ private: #ifdef BOOST_REGEX_RECURSIVE #include #else -#include #include #endif // this one has to be last: diff --git a/include/boost/regex/v4/perl_matcher_non_recursive.hpp b/include/boost/regex/v4/perl_matcher_non_recursive.hpp index d34e173a..438eb48a 100644 --- a/include/boost/regex/v4/perl_matcher_non_recursive.hpp +++ b/include/boost/regex/v4/perl_matcher_non_recursive.hpp @@ -91,7 +91,7 @@ struct save_state_init save_state_init(saved_state** base, saved_state** end) : stack(base) { - *base = static_cast(block_cache.get()); + *base = static_cast(get_mem_block()); *end = reinterpret_cast(reinterpret_cast(*base)+BOOST_REGEX_BLOCKSIZE); --(*end); new (*end)saved_state(0); @@ -99,7 +99,7 @@ struct save_state_init } ~save_state_init() { - block_cache.put(*stack); + put_mem_block(*stack); *stack = 0; } }; @@ -145,7 +145,7 @@ void perl_matcher::extend_stack() --used_block_count; saved_state* stack_base; saved_state* backup_state; - stack_base = static_cast(block_cache.get()); + stack_base = static_cast(get_mem_block()); backup_state = reinterpret_cast(reinterpret_cast(stack_base)+BOOST_REGEX_BLOCKSIZE); saved_extra_block* block = static_cast(backup_state); --block; @@ -799,7 +799,7 @@ bool perl_matcher::unwind_extra_blo m_stack_base = pmp->base; m_backup_state = pmp->end; boost::re_detail::inplace_destroy(pmp); - block_cache.put(condemmed); + put_mem_block(condemmed); return true; // keep looking } diff --git a/src/regex.cpp b/src/regex.cpp index 34d45b8a..c2463880 100644 --- a/src/regex.cpp +++ b/src/regex.cpp @@ -31,6 +31,15 @@ # include #endif +#if defined(BOOST_REGEX_NON_RECURSIVE) && !defined(BOOST_REGEX_V3) +#if BOOST_REGEX_MAX_CACHE_BLOCKS == 0 +#include +#else +#include +#endif +#endif + + namespace boost{ // @@ -104,8 +113,34 @@ BOOST_REGEX_DECL void BOOST_REGEX_CALL raise_regex_exception(const std::string& #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 + mem_block_cache block_cache = { 0, }; +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 re_detail