3 * Copyright (c) 1998-2004
6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13 * LOCATION: see http://www.boost.org for most recent version.
15 * VERSION: see <boost/version.hpp>
16 * DESCRIPTION: Misc boost::regbase member funnctions.
20 #define BOOST_REGEX_SOURCE
23 #include <boost/regex.hpp>
24 #include <boost/throw_exception.hpp>
26 #if defined(BOOST_REGEX_HAS_MS_STACK_GUARD) && defined(_MSC_VER) && (_MSC_VER >= 1300)
29 #ifdef BOOST_REGEX_HAS_MS_STACK_GUARD
30 #define WIN32_LEAN_AND_MEAN
39 #if defined(BOOST_REGEX_NON_RECURSIVE) && !defined(BOOST_REGEX_V3)
40 #if BOOST_REGEX_MAX_CACHE_BLOCKS == 0
43 #include <boost/regex/v4/mem_block_cache.hpp>
48 #pragma warning(disable:383)
54 // fix: these are declared out of line here to ensure
55 // that dll builds contain the Virtual table for these
56 // types - this ensures that exceptions can be thrown
57 // from the dll and caught in an exe.
58 regex_error::regex_error(const std::string
& s
, regex_constants::error_type err
, std::ptrdiff_t pos
)
59 : std::runtime_error(s
)
65 regex_error::regex_error(regex_constants::error_type err
)
66 : std::runtime_error(::boost::re_detail::get_default_error_string(err
))
72 regex_error::~regex_error() throw()
76 void regex_error::raise()const
78 #ifndef BOOST_NO_EXCEPTIONS
79 ::boost::throw_exception(*this);
87 BOOST_REGEX_DECL
void BOOST_REGEX_CALL
raise_runtime_error(const std::runtime_error
& ex
)
89 ::boost::throw_exception(ex
);
92 // error checking API:
94 BOOST_REGEX_DECL
void BOOST_REGEX_CALL
verify_options(boost::regex::flag_type
/*ef*/, match_flag_type mf
)
96 #ifndef BOOST_REGEX_V3
98 // can't mix match_extra with POSIX matching rules:
100 if((mf
& match_extra
) && (mf
& match_posix
))
102 std::logic_error
msg("Usage Error: Can't mix regular expression captures with POSIX matching rules");
103 throw_exception(msg
);
108 #ifdef BOOST_REGEX_HAS_MS_STACK_GUARD
110 static void execute_eror()
112 // we only get here after a stack overflow,
113 // this has to be a separate proceedure because we
114 // can't mix __try{}__except block with local objects
115 // that have destructors:
116 reset_stack_guard_page();
117 std::runtime_error
err("Out of stack space, while attempting to match a regular expression.");
118 raise_runtime_error(err
);
121 bool BOOST_REGEX_CALL
abstract_protected_call::execute()const
125 }__except(EXCEPTION_STACK_OVERFLOW
== GetExceptionCode())
129 // We never really get here at all:
133 BOOST_REGEX_DECL
void BOOST_REGEX_CALL
reset_stack_guard_page()
135 #if defined(BOOST_REGEX_HAS_MS_STACK_GUARD) && defined(_MSC_VER) && (_MSC_VER >= 1300)
139 // We need to locate the current page being used by the stack,
140 // move to the page below it and then deallocate and protect
141 // that page. Note that ideally we would protect only the lowest
142 // stack page that has been allocated: in practice there
143 // seems to be no easy way to locate this page, in any case as
144 // long as the next page is protected, then Windows will figure
145 // the rest out for us...
149 MEMORY_BASIC_INFORMATION mi
;
150 DWORD previous_protection_status
;
152 // this is an address in our stack space:
154 LPBYTE page
= (LPBYTE
)&page
;
156 // Get the current memory page in use:
158 VirtualQuery(page
, &mi
, sizeof(mi
));
160 // Go to the page one below this:
162 page
= (LPBYTE
)(mi
.BaseAddress
)-si
.dwPageSize
;
164 // Free and protect everything from the start of the
165 // allocation range, to the end of the page below the
168 if (!VirtualFree(mi
.AllocationBase
, (LPBYTE
)page
- (LPBYTE
)mi
.AllocationBase
, MEM_DECOMMIT
)
169 || !VirtualProtect(page
, si
.dwPageSize
, PAGE_GUARD
| PAGE_READWRITE
, &previous_protection_status
))
171 throw std::bad_exception();
177 #if defined(BOOST_REGEX_NON_RECURSIVE) && !defined(BOOST_REGEX_V3)
179 #if BOOST_REGEX_MAX_CACHE_BLOCKS == 0
181 BOOST_REGEX_DECL
void* BOOST_REGEX_CALL
get_mem_block()
183 return ::operator new(BOOST_REGEX_BLOCKSIZE
);
186 BOOST_REGEX_DECL
void BOOST_REGEX_CALL
put_mem_block(void* p
)
188 ::operator delete(p
);
193 #ifdef BOOST_HAS_THREADS
194 mem_block_cache block_cache
= { 0, 0, BOOST_STATIC_MUTEX_INIT
, };
196 mem_block_cache block_cache
= { 0, 0, };
199 BOOST_REGEX_DECL
void* BOOST_REGEX_CALL
get_mem_block()
201 return block_cache
.get();
204 BOOST_REGEX_DECL
void BOOST_REGEX_CALL
put_mem_block(void* p
)
213 } // namespace re_detail
219 #if defined(BOOST_RE_USE_VCL) && defined(BOOST_REGEX_DYN_LINK)
221 int WINAPI
DllEntryPoint(HINSTANCE
, unsigned long , void*)