Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/regex/src/regex.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 5.3 KB
Line 
1/*
2 *
3 * Copyright (c) 1998-2004
4 * John Maddock
5 *
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)
9 *
10 */
11
12 /*
13  *   LOCATION:    see http://www.boost.org for most recent version.
14  *   FILE:        regex.cpp
15  *   VERSION:     see <boost/version.hpp>
16  *   DESCRIPTION: Misc boost::regbase member funnctions.
17  */
18
19
20#define BOOST_REGEX_SOURCE
21
22#include <new>
23#include <boost/regex.hpp>
24#include <boost/throw_exception.hpp>
25
26#if defined(BOOST_REGEX_HAS_MS_STACK_GUARD) && defined(_MSC_VER) && (_MSC_VER >= 1300)
27#  include <malloc.h>
28#endif
29#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD
30#define WIN32_LEAN_AND_MEAN
31#ifndef NOMINMAX
32#  define NOMINMAX
33#endif
34#define NOGDI
35#define NOUSER
36#include <windows.h>
37#endif
38
39#if defined(BOOST_REGEX_NON_RECURSIVE) && !defined(BOOST_REGEX_V3)
40#if BOOST_REGEX_MAX_CACHE_BLOCKS == 0
41#include <new>
42#else
43#include <boost/regex/v4/mem_block_cache.hpp>
44#endif
45#endif
46
47
48namespace boost{
49
50//
51// fix: these are declared out of line here to ensure
52// that dll builds contain the Virtual table for these
53// types - this ensures that exceptions can be thrown
54// from the dll and caught in an exe.
55regex_error::regex_error(const std::string& s, regex_constants::error_type err, std::ptrdiff_t pos) 
56   : std::runtime_error(s)
57   , m_error_code(err)
58   , m_position(pos) 
59{
60}
61
62regex_error::regex_error(regex_constants::error_type err) 
63   : std::runtime_error(::boost::re_detail::get_default_error_string(err))
64   , m_error_code(err)
65   , m_position(0) 
66{
67}
68
69regex_error::~regex_error() throw() 
70{
71}
72
73void regex_error::raise()const
74{
75#ifndef BOOST_NO_EXCEPTIONS
76   ::boost::throw_exception(*this);
77#endif
78}
79
80
81
82namespace re_detail{
83
84BOOST_REGEX_DECL void BOOST_REGEX_CALL raise_runtime_error(const std::runtime_error& ex)
85{
86   ::boost::throw_exception(ex);
87}
88//
89// error checking API:
90//
91BOOST_REGEX_DECL void BOOST_REGEX_CALL verify_options(boost::regex::flag_type /*ef*/, match_flag_type mf)
92{
93#ifndef BOOST_REGEX_V3
94   //
95   // can't mix match_extra with POSIX matching rules:
96   //
97   if((mf & match_extra) && (mf & match_posix))
98   {
99      std::logic_error msg("Usage Error: Can't mix regular expression captures with POSIX matching rules");
100      throw_exception(msg);
101   }
102#endif
103}
104
105#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD
106
107static void execute_eror()
108{
109   // we only get here after a stack overflow,
110   // this has to be a separate proceedure because we
111   // can't mix __try{}__except block with local objects 
112   // that have destructors:
113   reset_stack_guard_page();
114   std::runtime_error err("Out of stack space, while attempting to match a regular expression.");
115   raise_runtime_error(err);
116}
117
118bool BOOST_REGEX_CALL abstract_protected_call::execute()const
119{
120   __try{
121      return this->call();
122   }__except(EXCEPTION_STACK_OVERFLOW == GetExceptionCode())
123   {
124      execute_eror();
125   }
126   // We never really get here at all:
127   return false;
128}
129
130BOOST_REGEX_DECL void BOOST_REGEX_CALL reset_stack_guard_page()
131{
132#if defined(BOOST_REGEX_HAS_MS_STACK_GUARD) && defined(_MSC_VER) && (_MSC_VER >= 1300)
133   _resetstkoflw();
134#else
135   //
136   // We need to locate the current page being used by the stack,
137   // move to the page below it and then deallocate and protect
138   // that page.  Note that ideally we would protect only the lowest
139   // stack page that has been allocated: in practice there
140   // seems to be no easy way to locate this page, in any case as
141   // long as the next page is protected, then Windows will figure
142   // the rest out for us...
143   //
144   SYSTEM_INFO si;
145   GetSystemInfo(&si);
146   MEMORY_BASIC_INFORMATION mi;
147   DWORD previous_protection_status;
148   //
149   // this is an address in our stack space:
150   //
151   LPBYTE page = (LPBYTE)&page;
152   //
153   // Get the current memory page in use:
154   //
155   VirtualQuery(page, &mi, sizeof(mi));
156   //
157   // Go to the page one below this:
158   //
159   page = (LPBYTE)(mi.BaseAddress)-si.dwPageSize;
160   //
161   // Free and protect everything from the start of the
162   // allocation range, to the end of the page below the
163   // one in use:
164   //
165   if (!VirtualFree(mi.AllocationBase, (LPBYTE)page - (LPBYTE)mi.AllocationBase, MEM_DECOMMIT)
166      || !VirtualProtect(page, si.dwPageSize, PAGE_GUARD | PAGE_READWRITE, &previous_protection_status))
167   {
168      throw std::bad_exception();
169   }
170#endif
171}
172#endif
173
174#if defined(BOOST_REGEX_NON_RECURSIVE) && !defined(BOOST_REGEX_V3)
175
176#if BOOST_REGEX_MAX_CACHE_BLOCKS == 0
177
178BOOST_REGEX_DECL void* BOOST_REGEX_CALL get_mem_block()
179{
180   return ::operator new(BOOST_REGEX_BLOCKSIZE);
181}
182
183BOOST_REGEX_DECL void BOOST_REGEX_CALL put_mem_block(void* p)
184{
185   ::operator delete(p);
186}
187
188#else
189
190#ifdef BOOST_HAS_THREADS
191mem_block_cache block_cache = { 0, 0, BOOST_STATIC_MUTEX_INIT, };
192#else
193mem_block_cache block_cache = { 0, 0, };
194#endif
195
196BOOST_REGEX_DECL void* BOOST_REGEX_CALL get_mem_block()
197{
198   return block_cache.get();
199}
200
201BOOST_REGEX_DECL void BOOST_REGEX_CALL put_mem_block(void* p)
202{
203   block_cache.put(p);
204}
205
206#endif
207
208#endif
209
210} // namespace re_detail
211
212
213
214} // namespace boost
215
216#if defined(BOOST_RE_USE_VCL) && defined(BOOST_REGEX_DYN_LINK)
217
218int WINAPI DllEntryPoint(HINSTANCE , unsigned long , void*)
219{
220   return 1;
221}
222#endif
223
224#if defined(__IBMCPP__) && defined(BOOST_REGEX_DYN_LINK)
225//
226// Is this correct - linker complains without it ?
227//
228int main()
229{ 
230   return 0; 
231}
232
233#endif
234
235
236
237
238
239
Note: See TracBrowser for help on using the repository browser.