sclang: ServerShmInterface - avoid object duplication in deepCopy
[supercollider.git] / external_libraries / boost / libs / regex / src / regex.cpp
blob27ac43cc09801fc7838a67caf4889ee7a914bd91
1 /*
3 * Copyright (c) 1998-2004
4 * John Maddock
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.
14 * FILE: regex.cpp
15 * VERSION: see <boost/version.hpp>
16 * DESCRIPTION: Misc boost::regbase member funnctions.
20 #define BOOST_REGEX_SOURCE
22 #include <new>
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)
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
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
47 #ifdef BOOST_INTEL
48 #pragma warning(disable:383)
49 #endif
51 namespace boost{
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)
60 , m_error_code(err)
61 , m_position(pos)
65 regex_error::regex_error(regex_constants::error_type err)
66 : std::runtime_error(::boost::re_detail::get_default_error_string(err))
67 , m_error_code(err)
68 , m_position(0)
72 regex_error::~regex_error() throw()
76 void regex_error::raise()const
78 #ifndef BOOST_NO_EXCEPTIONS
79 ::boost::throw_exception(*this);
80 #endif
85 namespace re_detail{
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);
105 #endif
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
123 __try{
124 return this->call();
125 }__except(EXCEPTION_STACK_OVERFLOW == GetExceptionCode())
127 execute_eror();
129 // We never really get here at all:
130 return false;
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)
136 _resetstkoflw();
137 #else
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...
147 SYSTEM_INFO si;
148 GetSystemInfo(&si);
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
166 // one in use:
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();
173 #endif
175 #endif
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);
191 #else
193 #ifdef BOOST_HAS_THREADS
194 mem_block_cache block_cache = { 0, 0, BOOST_STATIC_MUTEX_INIT, };
195 #else
196 mem_block_cache block_cache = { 0, 0, };
197 #endif
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)
206 block_cache.put(p);
209 #endif
211 #endif
213 } // namespace re_detail
217 } // namespace boost
219 #if defined(BOOST_RE_USE_VCL) && defined(BOOST_REGEX_DYN_LINK)
221 int WINAPI DllEntryPoint(HINSTANCE , unsigned long , void*)
223 return 1;
225 #endif