Added support for compilers with no exception handling support.

[SVN r12758]
This commit is contained in:
John Maddock
2002-02-08 12:44:43 +00:00
parent a5d1526fbb
commit c8e9df8fa2
12 changed files with 267 additions and 12 deletions

View File

@ -242,6 +242,7 @@ public:
unsigned int SetExpression(const char* p, bool icase = false); unsigned int SetExpression(const char* p, bool icase = false);
unsigned int SetExpression(const std::string& s, bool icase = false){ return SetExpression(s.c_str(), icase); } unsigned int SetExpression(const std::string& s, bool icase = false){ return SetExpression(s.c_str(), icase); }
std::string Expression()const; std::string Expression()const;
unsigned int error_code()const;
// //
// now matching operators: // now matching operators:
// //

View File

@ -794,7 +794,10 @@ int do_toi(iterator i, iterator j, char c, int radix)
std::string s(i, j); std::string s(i, j);
char* p; char* p;
int result = std::strtol(s.c_str(), &p, radix); int result = std::strtol(s.c_str(), &p, radix);
#ifndef BOOST_NO_EXCEPTIONS
if(*p)throw bad_pattern("Bad sub-expression"); if(*p)throw bad_pattern("Bad sub-expression");
#endif
BOOST_REGEX_NOEH_ASSERT(0 == *p)
return result; return result;
} }
@ -819,7 +822,10 @@ sub_match<iterator>::operator int()const
{ {
iterator i = first; iterator i = first;
iterator j = second; iterator j = second;
#ifndef BOOST_NO_EXCEPTIONS
if(i == j)throw bad_pattern("Bad sub-expression"); if(i == j)throw bad_pattern("Bad sub-expression");
#endif
BOOST_REGEX_NOEH_ASSERT(i != j)
int neg = 1; int neg = 1;
if((i != j) && (*i == '-')) if((i != j) && (*i == '-'))
{ {
@ -827,7 +833,10 @@ sub_match<iterator>::operator int()const
++i; ++i;
} }
neg *= re_detail::do_toi(i, j, *i); neg *= re_detail::do_toi(i, j, *i);
#ifndef BOOST_NO_EXCEPTIONS
if(i != j)throw bad_pattern("Bad sub-expression"); if(i != j)throw bad_pattern("Bad sub-expression");
#endif
BOOST_REGEX_NOEH_ASSERT(i == j)
return neg; return neg;
} }
template <class iterator> template <class iterator>
@ -835,8 +844,11 @@ sub_match<iterator>::operator unsigned int()const
{ {
iterator i = first; iterator i = first;
iterator j = second; iterator j = second;
#ifndef BOOST_NO_EXCEPTIONS
if(i == j) if(i == j)
throw bad_pattern("Bad sub-expression"); throw bad_pattern("Bad sub-expression");
#endif
BOOST_REGEX_NOEH_ASSERT(i != j)
return re_detail::do_toi(i, j, *first); return re_detail::do_toi(i, j, *first);
} }
#endif #endif
@ -1063,27 +1075,33 @@ template <class iterator, class Allocator>
match_results_base<iterator, Allocator>::match_results_base(const Allocator& a) match_results_base<iterator, Allocator>::match_results_base(const Allocator& a)
{ {
ref = (c_reference*)c_alloc(a).allocate(sizeof(sub_match<iterator>) + sizeof(c_reference)); ref = (c_reference*)c_alloc(a).allocate(sizeof(sub_match<iterator>) + sizeof(c_reference));
#ifndef BOOST_NO_EXCEPTIONS
try try
{ {
#endif
new (ref) c_reference(a); new (ref) c_reference(a);
ref->cmatches = 1; ref->cmatches = 1;
ref->count = 1; ref->count = 1;
// construct the sub_match<iterator>: // construct the sub_match<iterator>:
#ifndef BOOST_NO_EXCEPTIONS
try try
{ {
#endif
new ((sub_match<iterator>*)(ref+1)) sub_match<iterator>(); new ((sub_match<iterator>*)(ref+1)) sub_match<iterator>();
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
::boost::re_detail::pointer_destroy(ref); ::boost::re_detail::pointer_destroy(ref);
throw; throw;
} }
} }
catch(...) catch(...)
{ {
c_alloc(a).deallocate((char*)(void*)ref, sizeof(sub_match<iterator>) + sizeof(c_reference)); c_alloc(a).deallocate((char*)(void*)ref, sizeof(sub_match<iterator>) + sizeof(c_reference));
throw; throw;
} }
#endif
} }
template <class iterator, class Allocator> template <class iterator, class Allocator>
@ -1148,25 +1166,30 @@ void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::set_size(size_typ
if(ref->cmatches != n) if(ref->cmatches != n)
{ {
c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match<iterator>) * n + sizeof(c_reference)); c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match<iterator>) * n + sizeof(c_reference));
#ifndef BOOST_NO_EXCEPTIONS
try try
{ {
#endif
new (newref) c_reference(*ref); new (newref) c_reference(*ref);
newref->count = 1; newref->count = 1;
newref->cmatches = n; newref->cmatches = n;
sub_match<iterator>* p1, *p2; sub_match<iterator>* p1, *p2;
p1 = (sub_match<iterator>*)(newref+1); p1 = (sub_match<iterator>*)(newref+1);
p2 = p1 + newref->cmatches; p2 = p1 + newref->cmatches;
#ifndef BOOST_NO_EXCEPTIONS
try try
{ {
#endif
while(p1 != p2) while(p1 != p2)
{ {
new (p1) sub_match<iterator>(); new (p1) sub_match<iterator>();
++p1; ++p1;
} }
m_free(); m_free();
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
p2 = (sub_match<iterator>*)(newref+1); p2 = (sub_match<iterator>*)(newref+1);
while(p2 != p1) while(p2 != p1)
{ {
@ -1174,15 +1197,18 @@ void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::set_size(size_typ
++p2; ++p2;
} }
::boost::re_detail::pointer_destroy(ref); ::boost::re_detail::pointer_destroy(ref);
throw; throw;
} }
#endif
ref = newref; ref = newref;
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
ref->deallocate((char*)(void*)newref, sizeof(sub_match<iterator>) * n + sizeof(c_reference)); ref->deallocate((char*)(void*)newref, sizeof(sub_match<iterator>) * n + sizeof(c_reference));
throw; throw;
} }
#endif
} }
} }
@ -1192,20 +1218,25 @@ void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::set_size(size_typ
if(ref->cmatches != n) if(ref->cmatches != n)
{ {
c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match<iterator>) * n + sizeof(c_reference));; c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match<iterator>) * n + sizeof(c_reference));;
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
new (newref) c_reference(*ref); new (newref) c_reference(*ref);
newref->count = 1; newref->count = 1;
newref->cmatches = n; newref->cmatches = n;
sub_match<iterator>* p1 = (sub_match<iterator>*)(newref+1); sub_match<iterator>* p1 = (sub_match<iterator>*)(newref+1);
sub_match<iterator>* p2 = p1 + newref->cmatches; sub_match<iterator>* p2 = p1 + newref->cmatches;
#ifndef BOOST_NO_EXCEPTIONS
try try
{ {
#endif
while(p1 != p2) while(p1 != p2)
{ {
new (p1) sub_match<iterator>(j); new (p1) sub_match<iterator>(j);
++p1; ++p1;
} }
m_free(); m_free();
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
@ -1218,13 +1249,16 @@ void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::set_size(size_typ
::boost::re_detail::pointer_destroy(ref); ::boost::re_detail::pointer_destroy(ref);
throw; throw;
} }
#endif
ref = newref; ref = newref;
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
ref->deallocate((char*)(void*)newref, sizeof(sub_match<iterator>) * n + sizeof(c_reference)); ref->deallocate((char*)(void*)newref, sizeof(sub_match<iterator>) * n + sizeof(c_reference));
throw; throw;
} }
#endif
} }
else else
{ {
@ -1298,19 +1332,24 @@ void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::cow()
if(ref->count > 1) if(ref->count > 1)
{ {
c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match<iterator>) * ref->cmatches + sizeof(c_reference)); c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match<iterator>) * ref->cmatches + sizeof(c_reference));
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
new (newref) c_reference(*ref); new (newref) c_reference(*ref);
newref->count = 1; newref->count = 1;
sub_match<iterator>* p1 = (sub_match<iterator>*)(newref+1); sub_match<iterator>* p1 = (sub_match<iterator>*)(newref+1);
sub_match<iterator>* p2 = p1 + newref->cmatches; sub_match<iterator>* p2 = p1 + newref->cmatches;
sub_match<iterator>* p3 = (sub_match<iterator>*)(ref+1); sub_match<iterator>* p3 = (sub_match<iterator>*)(ref+1);
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
while(p1 != p2) while(p1 != p2)
{ {
new (p1) sub_match<iterator>(*p3); new (p1) sub_match<iterator>(*p3);
++p1; ++p1;
++p3; ++p3;
} }
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
@ -1323,14 +1362,17 @@ void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::cow()
::boost::re_detail::pointer_destroy(ref); ::boost::re_detail::pointer_destroy(ref);
throw; throw;
} }
#endif
--(ref->count); --(ref->count);
ref = newref; ref = newref;
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
ref->deallocate((char*)(void*)newref, sizeof(sub_match<iterator>) * ref->cmatches + sizeof(c_reference)); ref->deallocate((char*)(void*)newref, sizeof(sub_match<iterator>) * ref->cmatches + sizeof(c_reference));
throw; throw;
} }
#endif
} }
} }
@ -1418,19 +1460,24 @@ match_results<iterator, Allocator>::match_results(const match_results<iterator,
reinterpret_cast<typename re_detail::match_results_base<iterator, Allocator>::c_reference *> reinterpret_cast<typename re_detail::match_results_base<iterator, Allocator>::c_reference *>
(m.ref->allocate(sizeof(sub_match<iterator>) * m.ref->cmatches + (m.ref->allocate(sizeof(sub_match<iterator>) * m.ref->cmatches +
sizeof(typename re_detail::match_results_base<iterator, Allocator>::c_reference))); sizeof(typename re_detail::match_results_base<iterator, Allocator>::c_reference)));
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
new (this->ref) typename re_detail::match_results_base<iterator, Allocator>::c_reference(*m.ref); new (this->ref) typename re_detail::match_results_base<iterator, Allocator>::c_reference(*m.ref);
this->ref->count = 1; this->ref->count = 1;
sub_match<iterator>* p1 = (sub_match<iterator>*)(this->ref+1); sub_match<iterator>* p1 = (sub_match<iterator>*)(this->ref+1);
sub_match<iterator>* p2 = p1 + this->ref->cmatches; sub_match<iterator>* p2 = p1 + this->ref->cmatches;
sub_match<iterator>* p3 = (sub_match<iterator>*)(m.ref+1); sub_match<iterator>* p3 = (sub_match<iterator>*)(m.ref+1);
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
while(p1 != p2) while(p1 != p2)
{ {
new (p1) sub_match<iterator>(*p3); new (p1) sub_match<iterator>(*p3);
++p1; ++p1;
++p3; ++p3;
} }
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
@ -1449,6 +1496,7 @@ match_results<iterator, Allocator>::match_results(const match_results<iterator,
m.ref->deallocate((char*)(void*)this->ref, sizeof(sub_match<iterator>) * m.ref->cmatches + sizeof(typename re_detail::match_results_base<iterator, Allocator>::c_reference)); m.ref->deallocate((char*)(void*)this->ref, sizeof(sub_match<iterator>) * m.ref->cmatches + sizeof(typename re_detail::match_results_base<iterator, Allocator>::c_reference));
throw; throw;
} }
#endif
} }
template <class iterator, class Allocator> template <class iterator, class Allocator>

View File

@ -273,6 +273,35 @@ using std::distance;
# include <windows.h> # include <windows.h>
#endif #endif
/*****************************************************************************
*
* Error Handling for exception free compilers:
*
****************************************************************************/
#ifdef BOOST_NO_EXCEPTIONS
//
// If there are no exceptions then we must report critical-errors
// the only way we know how; by terminating.
//
#ifdef __BORLANDC__
// <cstdio> seems not to make stderr usable with Borland:
#include <stdio.h>
#endif
# define BOOST_REGEX_NOEH_ASSERT(x)\
if(0 == (x))\
{\
std::fprintf(stderr, "Error: critical regex++ failure in \"%s\"", #x);\
std::abort();\
}
#else
//
// With exceptions then error handling is taken care of and
// there is no need for these checks:
//
# define BOOST_REGEX_NOEH_ASSERT(x)
#endif
/***************************************************************************** /*****************************************************************************
* *
* Debugging / tracing support: * Debugging / tracing support:
@ -516,6 +545,10 @@ namespace std{
using ::fopen; using ::fopen;
using ::fclose; using ::fclose;
using ::FILE; using ::FILE;
#ifdef BOOST_NO_EXCEPTIONS
using ::fprintf;
using ::abort;
#endif
} }
#endif #endif

View File

@ -1167,8 +1167,10 @@ void BOOST_REGEX_CALL reg_expression<charT, traits, Allocator>::fixup_apply(re_d
register re_detail::re_syntax_base* ptr = b; register re_detail::re_syntax_base* ptr = b;
bool* pb = 0; bool* pb = 0;
b_alloc a(data.allocator()); b_alloc a(data.allocator());
#ifndef BOOST_NO_EXCEPTIONS
try try
{ {
#endif
pb = a.allocate(cbraces); pb = a.allocate(cbraces);
for(unsigned i = 0; i < cbraces; ++i) for(unsigned i = 0; i < cbraces; ++i)
pb[i] = false; pb[i] = false;
@ -1232,6 +1234,7 @@ void BOOST_REGEX_CALL reg_expression<charT, traits, Allocator>::fixup_apply(re_d
} }
a.deallocate(pb, cbraces); a.deallocate(pb, cbraces);
pb = 0; pb = 0;
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
@ -1239,6 +1242,7 @@ void BOOST_REGEX_CALL reg_expression<charT, traits, Allocator>::fixup_apply(re_d
a.deallocate(pb, cbraces); a.deallocate(pb, cbraces);
throw; throw;
} }
#endif
} }
@ -2053,10 +2057,12 @@ void BOOST_REGEX_CALL reg_expression<charT, traits, Allocator>::fail(unsigned in
if(err) if(err)
{ {
_flags |= regbase::failbit; _flags |= regbase::failbit;
#ifndef BOOST_NO_EXCEPTIONS
if(_flags & regbase::use_except) if(_flags & regbase::use_except)
{ {
throw bad_expression(traits_inst.error_string(err)); throw bad_expression(traits_inst.error_string(err));
} }
#endif
} }
else else
_flags &= ~regbase::failbit; _flags &= ~regbase::failbit;

View File

@ -199,14 +199,19 @@ void BOOST_REGEX_CALL re_init_classes()
if(classes_count == 0) if(classes_count == 0)
{ {
re_cls_name = new std::string("xxxxxxxx"); re_cls_name = new std::string("xxxxxxxx");
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
pclasses = new std::string[re_classes_max]; pclasses = new std::string[re_classes_max];
BOOST_REGEX_NOEH_ASSERT(pclasses)
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
delete re_cls_name; delete re_cls_name;
throw; throw;
} }
#endif
} }
++classes_count; ++classes_count;
} }
@ -243,14 +248,19 @@ void BOOST_REGEX_CALL re_init_collate()
if(collate_count == 0) if(collate_count == 0)
{ {
re_coll_name = new std::string("xxxxxxxx"); re_coll_name = new std::string("xxxxxxxx");
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
pcoll_names = new std::list<collate_name_t>(); pcoll_names = new std::list<collate_name_t>();
BOOST_REGEX_NOEH_ASSERT(pcoll_names)
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
delete re_coll_name; delete re_coll_name;
throw; throw;
} }
#endif
} }
++collate_count; ++collate_count;
} }
@ -345,11 +355,15 @@ void BOOST_REGEX_CALL re_message_update()
if(*boost::re_detail::c_traits_base::get_catalogue()) if(*boost::re_detail::c_traits_base::get_catalogue())
{ {
message_cat = catopen(boost::re_detail::c_traits_base::get_catalogue(), 0); message_cat = catopen(boost::re_detail::c_traits_base::get_catalogue(), 0);
#ifndef BOOST_NO_EXCEPTIONS
if(message_cat == (nl_catd)-1) if(message_cat == (nl_catd)-1)
{ {
std::string m("Unable to open message catalog: "); std::string m("Unable to open message catalog: ");
throw std::runtime_error(m + boost::re_detail::c_traits_base::get_catalogue()); throw std::runtime_error(m + boost::re_detail::c_traits_base::get_catalogue());
} }
#else
BOOST_REGEX_NOEH_ASSERT(message_cat != (nl_catd)-1);
#endif
} }
#endif #endif
for(int i = 0; i < boost::REG_E_UNKNOWN; ++i) for(int i = 0; i < boost::REG_E_UNKNOWN; ++i)
@ -592,14 +606,19 @@ void BOOST_REGEX_CALL c_regex_traits<char>::init()
if(entry_count == 0) if(entry_count == 0)
{ {
ctype_name = new std::string("xxxxxxxxxxxxxxxx"); ctype_name = new std::string("xxxxxxxxxxxxxxxx");
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
collate_name = new std::string("xxxxxxxxxxxxxxxx"); collate_name = new std::string("xxxxxxxxxxxxxxxx");
BOOST_REGEX_NOEH_ASSERT(collate_name)
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
delete ctype_name; delete ctype_name;
throw; throw;
} }
#endif
} }
re_message_init(); re_message_init();
re_init_classes(); re_init_classes();
@ -763,14 +782,19 @@ void BOOST_REGEX_CALL c_regex_traits<wchar_t>::init()
if(nlsw_count == 0) if(nlsw_count == 0)
{ {
wlocale_name = new std::string("xxxxxxxxxxxxxxxx"); wlocale_name = new std::string("xxxxxxxxxxxxxxxx");
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
syntax = new std::list<syntax_map_t>(); syntax = new std::list<syntax_map_t>();
BOOST_REGEX_NOEH_ASSERT(syntax)
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
delete wlocale_name; delete wlocale_name;
throw; throw;
} }
#endif
} }
++nlsw_count; ++nlsw_count;
} }

View File

@ -197,11 +197,15 @@ message_data<char>::message_data(const std::locale& l, const std::string& regex_
{ {
pm = &BOOST_USE_FACET(std::messages<char>, l); pm = &BOOST_USE_FACET(std::messages<char>, l);
cat = pm->open(regex_message_catalogue, l); cat = pm->open(regex_message_catalogue, l);
#ifndef BOOST_NO_EXCEPTIONS
if(cat < 0) if(cat < 0)
{ {
std::string m("Unable to open message catalog: "); std::string m("Unable to open message catalog: ");
throw std::runtime_error(m + regex_message_catalogue); throw std::runtime_error(m + regex_message_catalogue);
} }
#else
BOOST_REGEX_NOEH_ASSERT(cat >= 0);
#endif
} }
#endif #endif
std::memset(syntax_map, cpp_regex_traits<char>::syntax_char, 256); std::memset(syntax_map, cpp_regex_traits<char>::syntax_char, 256);
@ -296,14 +300,19 @@ cpp_regex_traits<char>::cpp_regex_traits()
{ {
pmd = new re_detail::message_data<char>(locale_inst, regex_message_cat); pmd = new re_detail::message_data<char>(locale_inst, regex_message_cat);
psyntax = pmd->syntax_map; psyntax = pmd->syntax_map;
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
lower_map = new char[char_set_size]; lower_map = new char[char_set_size];
BOOST_REGEX_NOEH_ASSERT(lower_map)
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
delete pmd; delete pmd;
throw; throw;
} }
#endif
for(unsigned int i = 0; i < char_set_size; ++i) for(unsigned int i = 0; i < char_set_size; ++i)
lower_map[i] = static_cast<char>(i); lower_map[i] = static_cast<char>(i);
pctype = &BOOST_USE_FACET(std::ctype<char>, locale_inst); pctype = &BOOST_USE_FACET(std::ctype<char>, locale_inst);
@ -565,11 +574,15 @@ message_data<wchar_t>::message_data(const std::locale& l, const std::string& reg
if(regex_message_catalogue.size()) if(regex_message_catalogue.size())
{ {
cat = msgs.open(regex_message_catalogue, l); cat = msgs.open(regex_message_catalogue, l);
#ifndef BOOST_NO_EXCEPTIONS
if(cat < 0) if(cat < 0)
{ {
std::string m("Unable to open message catalog: "); std::string m("Unable to open message catalog: ");
throw std::runtime_error(m + regex_message_catalogue); throw std::runtime_error(m + regex_message_catalogue);
} }
#else
BOOST_REGEX_NOEH_ASSERT(cat >= 0);
#endif
} }
#endif #endif
scoped_array<char> a; scoped_array<char> a;
@ -770,14 +783,19 @@ cpp_regex_traits<wchar_t>::cpp_regex_traits()
{ {
pmd = new re_detail::message_data<wchar_t>(locale_inst, std::string(regex_message_cat)); pmd = new re_detail::message_data<wchar_t>(locale_inst, std::string(regex_message_cat));
psyntax = pmd->syntax_; psyntax = pmd->syntax_;
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
lower_map = new wchar_t[char_set_size]; lower_map = new wchar_t[char_set_size];
BOOST_REGEX_NOEH_ASSERT(lower_map)
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
delete pmd; delete pmd;
throw; throw;
} }
#endif
for(unsigned int i = 0; i < char_set_size; ++i) for(unsigned int i = 0; i < char_set_size; ++i)
lower_map[i] = static_cast<wchar_t>(i); lower_map[i] = static_cast<wchar_t>(i);
pctype = &BOOST_USE_FACET(std::ctype<wchar_t>, locale_inst); pctype = &BOOST_USE_FACET(std::ctype<wchar_t>, locale_inst);

View File

@ -178,6 +178,12 @@ unsigned int RegEx::SetExpression(const char* p, bool icase)
return pdata->e.set_expression(p, f); return pdata->e.set_expression(p, f);
} }
unsigned int RegEx::error_code()const
{
return pdata->e.error_code();
}
std::string RegEx::Expression()const std::string RegEx::Expression()const
{ {
BOOST_RE_GUARD_STACK BOOST_RE_GUARD_STACK

View File

@ -81,7 +81,11 @@ void mapfile::open(const char* file)
CloseHandle(hfile); CloseHandle(hfile);
hmap = 0; hmap = 0;
hfile = 0; hfile = 0;
#ifndef BOOST_NO_EXCEPTIONS
throw std::runtime_error("Unable to create file mapping."); throw std::runtime_error("Unable to create file mapping.");
#else
BOOST_REGEX_NOEH_ASSERT(hmap != INVALID_HANDLE_VALUE);
#endif
} }
_first = static_cast<const char*>(MapViewOfFile(hmap, FILE_MAP_READ, 0, 0, 0)); _first = static_cast<const char*>(MapViewOfFile(hmap, FILE_MAP_READ, 0, 0, 0));
if(_first == 0) if(_first == 0)
@ -90,14 +94,22 @@ void mapfile::open(const char* file)
CloseHandle(hfile); CloseHandle(hfile);
hmap = 0; hmap = 0;
hfile = 0; hfile = 0;
#ifndef BOOST_NO_EXCEPTIONS
throw std::runtime_error("Unable to create file mapping."); throw std::runtime_error("Unable to create file mapping.");
#else
BOOST_REGEX_NOEH_ASSERT(_first != 0);
#endif
} }
_last = _first + GetFileSize(hfile, 0); _last = _first + GetFileSize(hfile, 0);
} }
else else
{ {
hfile = 0; hfile = 0;
#ifndef BOOST_NO_EXCEPTIONS
throw std::runtime_error("Unable to open file."); throw std::runtime_error("Unable to open file.");
#else
BOOST_REGEX_NOEH_ASSERT(hfile != INVALID_HANDLE_VALUE);
#endif
} }
} }
@ -285,7 +297,9 @@ void mapfile::open(const char* file)
{ {
BOOST_RE_GUARD_STACK BOOST_RE_GUARD_STACK
hfile = std::fopen(file, "rb"); hfile = std::fopen(file, "rb");
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
if(hfile != 0) if(hfile != 0)
{ {
_size = get_file_length(hfile); _size = get_file_length(hfile);
@ -306,10 +320,16 @@ void mapfile::open(const char* file)
} }
else else
{ {
#ifndef BOOST_NO_EXCEPTIONS
throw std::runtime_error("Unable to open file."); throw std::runtime_error("Unable to open file.");
#else
BOOST_REGEX_NOEH_ASSERT(hfile != 0);
#endif
} }
#ifndef BOOST_NO_EXCEPTIONS
}catch(...) }catch(...)
{ close(); throw; } { close(); throw; }
#endif
} }
void mapfile::close() void mapfile::close()
@ -342,15 +362,21 @@ file_iterator::file_iterator()
BOOST_RE_GUARD_STACK BOOST_RE_GUARD_STACK
_root = _path = 0; _root = _path = 0;
ref = 0; ref = 0;
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
_root = new char[MAX_PATH]; _root = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_root)
_path = new char[MAX_PATH]; _path = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_path)
ptr = _path; ptr = _path;
*_path = 0; *_path = 0;
*_root = 0; *_root = 0;
ref = new file_iterator_ref(); ref = new file_iterator_ref();
BOOST_REGEX_NOEH_ASSERT(ref)
ref->hf = _fi_invalid_handle; ref->hf = _fi_invalid_handle;
ref->count = 1; ref->count = 1;
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
@ -359,6 +385,7 @@ file_iterator::file_iterator()
delete ref; delete ref;
throw; throw;
} }
#endif
} }
file_iterator::file_iterator(const char* wild) file_iterator::file_iterator(const char* wild)
@ -366,9 +393,13 @@ file_iterator::file_iterator(const char* wild)
BOOST_RE_GUARD_STACK BOOST_RE_GUARD_STACK
_root = _path = 0; _root = _path = 0;
ref = 0; ref = 0;
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
_root = new char[MAX_PATH]; _root = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_root)
_path = new char[MAX_PATH]; _path = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_path)
std::strcpy(_root, wild); std::strcpy(_root, wild);
ptr = _root; ptr = _root;
while(*ptr)++ptr; while(*ptr)++ptr;
@ -399,6 +430,7 @@ file_iterator::file_iterator(const char* wild)
#endif #endif
ref = new file_iterator_ref(); ref = new file_iterator_ref();
BOOST_REGEX_NOEH_ASSERT(ref)
ref->hf = FindFirstFileA(wild, &(ref->_data)); ref->hf = FindFirstFileA(wild, &(ref->_data));
ref->count = 1; ref->count = 1;
@ -413,6 +445,7 @@ file_iterator::file_iterator(const char* wild)
if(ref->_data.dwFileAttributes & _fi_dir) if(ref->_data.dwFileAttributes & _fi_dir)
next(); next();
} }
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
@ -421,6 +454,7 @@ file_iterator::file_iterator(const char* wild)
delete ref; delete ref;
throw; throw;
} }
#endif
} }
file_iterator::file_iterator(const file_iterator& other) file_iterator::file_iterator(const file_iterator& other)
@ -428,13 +462,18 @@ file_iterator::file_iterator(const file_iterator& other)
BOOST_RE_GUARD_STACK BOOST_RE_GUARD_STACK
_root = _path = 0; _root = _path = 0;
ref = 0; ref = 0;
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
_root = new char[MAX_PATH]; _root = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_root)
_path = new char[MAX_PATH]; _path = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_path)
std::strcpy(_root, other._root); std::strcpy(_root, other._root);
std::strcpy(_path, other._path); std::strcpy(_path, other._path);
ptr = _path + (other.ptr - other._path); ptr = _path + (other.ptr - other._path);
ref = other.ref; ref = other.ref;
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
@ -442,6 +481,7 @@ file_iterator::file_iterator(const file_iterator& other)
delete[] _path; delete[] _path;
throw; throw;
} }
#endif
++(ref->count); ++(ref->count);
} }
@ -517,15 +557,21 @@ directory_iterator::directory_iterator()
BOOST_RE_GUARD_STACK BOOST_RE_GUARD_STACK
_root = _path = 0; _root = _path = 0;
ref = 0; ref = 0;
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
_root = new char[MAX_PATH]; _root = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_root)
_path = new char[MAX_PATH]; _path = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_path)
ptr = _path; ptr = _path;
*_path = 0; *_path = 0;
*_root = 0; *_root = 0;
ref = new file_iterator_ref(); ref = new file_iterator_ref();
BOOST_REGEX_NOEH_ASSERT(ref)
ref->hf = _fi_invalid_handle; ref->hf = _fi_invalid_handle;
ref->count = 1; ref->count = 1;
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
@ -534,6 +580,7 @@ directory_iterator::directory_iterator()
delete ref; delete ref;
throw; throw;
} }
#endif
} }
directory_iterator::directory_iterator(const char* wild) directory_iterator::directory_iterator(const char* wild)
@ -541,9 +588,13 @@ directory_iterator::directory_iterator(const char* wild)
BOOST_RE_GUARD_STACK BOOST_RE_GUARD_STACK
_root = _path = 0; _root = _path = 0;
ref = 0; ref = 0;
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
_root = new char[MAX_PATH]; _root = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_root)
_path = new char[MAX_PATH]; _path = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_path)
std::strcpy(_root, wild); std::strcpy(_root, wild);
ptr = _root; ptr = _root;
while(*ptr)++ptr; while(*ptr)++ptr;
@ -573,6 +624,7 @@ directory_iterator::directory_iterator(const char* wild)
} }
#endif #endif
ref = new file_iterator_ref(); ref = new file_iterator_ref();
BOOST_REGEX_NOEH_ASSERT(ref)
ref->count = 1; ref->count = 1;
ref->hf = FindFirstFileA(wild, &(ref->_data)); ref->hf = FindFirstFileA(wild, &(ref->_data));
if(ref->hf == _fi_invalid_handle) if(ref->hf == _fi_invalid_handle)
@ -586,6 +638,7 @@ directory_iterator::directory_iterator(const char* wild)
if(((ref->_data.dwFileAttributes & _fi_dir) == 0) || (std::strcmp(ref->_data.cFileName, ".") == 0) || (std::strcmp(ref->_data.cFileName, "..") == 0)) if(((ref->_data.dwFileAttributes & _fi_dir) == 0) || (std::strcmp(ref->_data.cFileName, ".") == 0) || (std::strcmp(ref->_data.cFileName, "..") == 0))
next(); next();
} }
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
@ -594,6 +647,7 @@ directory_iterator::directory_iterator(const char* wild)
delete ref; delete ref;
throw; throw;
} }
#endif
} }
directory_iterator::~directory_iterator() directory_iterator::~directory_iterator()
@ -614,13 +668,18 @@ directory_iterator::directory_iterator(const directory_iterator& other)
BOOST_RE_GUARD_STACK BOOST_RE_GUARD_STACK
_root = _path = 0; _root = _path = 0;
ref = 0; ref = 0;
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
_root = new char[MAX_PATH]; _root = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_root)
_path = new char[MAX_PATH]; _path = new char[MAX_PATH];
BOOST_REGEX_NOEH_ASSERT(_path)
std::strcpy(_root, other._root); std::strcpy(_root, other._root);
std::strcpy(_path, other._path); std::strcpy(_path, other._path);
ptr = _path + (other.ptr - other._path); ptr = _path + (other.ptr - other._path);
ref = other.ref; ref = other.ref;
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(...) catch(...)
{ {
@ -628,6 +687,7 @@ directory_iterator::directory_iterator(const directory_iterator& other)
delete[] _path; delete[] _path;
throw; throw;
} }
#endif
++(ref->count); ++(ref->count);
} }

View File

@ -43,12 +43,19 @@ BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompA(regex_tA* expression, const char
if(expression->re_magic != magic_value) if(expression->re_magic != magic_value)
{ {
expression->guts = 0; expression->guts = 0;
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
expression->guts = new regex(); expression->guts = new regex();
#ifndef BOOST_NO_EXCEPTIONS
} catch(...) } catch(...)
{ {
return REG_ESPACE; return REG_ESPACE;
} }
#else
if(0 == expression->guts)
return REG_E_MEMORY;
#endif
} }
// set default flags: // set default flags:
boost::uint_fast32_t flags = (f & REG_EXTENDED) ? regbase::extended : regbase::basic; boost::uint_fast32_t flags = (f & REG_EXTENDED) ? regbase::extended : regbase::basic;
@ -77,15 +84,19 @@ BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompA(regex_tA* expression, const char
int result; int result;
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
expression->re_magic = magic_value; expression->re_magic = magic_value;
static_cast<regex*>(expression->guts)->set_expression(ptr, p2, flags); static_cast<regex*>(expression->guts)->set_expression(ptr, p2, flags);
expression->re_nsub = static_cast<regex*>(expression->guts)->mark_count() - 1; expression->re_nsub = static_cast<regex*>(expression->guts)->mark_count() - 1;
result = static_cast<regex*>(expression->guts)->error_code(); result = static_cast<regex*>(expression->guts)->error_code();
#ifndef BOOST_NO_EXCEPTIONS
} catch(...) } catch(...)
{ {
result = REG_E_UNKNOWN; result = REG_E_UNKNOWN;
} }
#endif
if(result) if(result)
regfreeA(expression); regfreeA(expression);
return result; return result;
@ -174,17 +185,21 @@ BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecA(const regex_tA* expression, cons
end = buf + std::strlen(buf); end = buf + std::strlen(buf);
} }
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
if(expression->re_magic == magic_value) if(expression->re_magic == magic_value)
{ {
result = regex_search(start, end, m, *static_cast<regex*>(expression->guts), flags); result = regex_search(start, end, m, *static_cast<regex*>(expression->guts), flags);
} }
else else
return result; return result;
#ifndef BOOST_NO_EXCEPTIONS
} catch(...) } catch(...)
{ {
return REG_E_UNKNOWN; return REG_E_UNKNOWN;
} }
#endif
if(result) if(result)
{ {

View File

@ -236,11 +236,15 @@ void BOOST_REGEX_CALL w32_traits_base::do_init()
if(*regex_message_catalogue) if(*regex_message_catalogue)
{ {
hresmod = LoadLibraryA(regex_message_catalogue); hresmod = LoadLibraryA(regex_message_catalogue);
#ifndef BOOST_NO_EXCEPTIONS
if(hresmod == NULL) if(hresmod == NULL)
{ {
std::string s("Unable to open dll: "); std::string s("Unable to open dll: ");
throw std::runtime_error(s + regex_message_catalogue); throw std::runtime_error(s + regex_message_catalogue);
} }
#else
BOOST_REGEX_NOEH_ASSERT(hresmod != NULL);
#endif
} }
unsigned int i; unsigned int i;
for(i = 0; i < REG_E_UNKNOWN; ++i) for(i = 0; i < REG_E_UNKNOWN; ++i)

View File

@ -51,12 +51,19 @@ BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompW(regex_tW* expression, const wcha
if(expression->re_magic != wmagic_value) if(expression->re_magic != wmagic_value)
{ {
expression->guts = 0; expression->guts = 0;
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
expression->guts = new wregex(); expression->guts = new wregex();
#ifndef BOOST_NO_EXCEPTIONS
} catch(...) } catch(...)
{ {
return REG_ESPACE; return REG_ESPACE;
} }
#else
if(0 == expression->guts)
return REG_E_MEMORY;
#endif
} }
// set default flags: // set default flags:
boost::uint_fast32_t flags = (f & REG_EXTENDED) ? regbase::extended : regbase::basic; boost::uint_fast32_t flags = (f & REG_EXTENDED) ? regbase::extended : regbase::basic;
@ -85,15 +92,19 @@ BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompW(regex_tW* expression, const wcha
int result; int result;
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
expression->re_magic = wmagic_value; expression->re_magic = wmagic_value;
static_cast<wregex*>(expression->guts)->set_expression(ptr, p2, flags); static_cast<wregex*>(expression->guts)->set_expression(ptr, p2, flags);
expression->re_nsub = static_cast<wregex*>(expression->guts)->mark_count() - 1; expression->re_nsub = static_cast<wregex*>(expression->guts)->mark_count() - 1;
result = static_cast<wregex*>(expression->guts)->error_code(); result = static_cast<wregex*>(expression->guts)->error_code();
#ifndef BOOST_NO_EXCEPTIONS
} catch(...) } catch(...)
{ {
result = REG_E_UNKNOWN; result = REG_E_UNKNOWN;
} }
#endif
if(result) if(result)
regfreeW(expression); regfreeW(expression);
return result; return result;
@ -182,18 +193,21 @@ BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecW(const regex_tW* expression, cons
end = buf + std::wcslen(buf); end = buf + std::wcslen(buf);
} }
#ifndef BOOST_NO_EXCEPTIONS
try{ try{
#endif
if(expression->re_magic == wmagic_value) if(expression->re_magic == wmagic_value)
{ {
result = regex_search(start, end, m, *static_cast<wregex*>(expression->guts), flags); result = regex_search(start, end, m, *static_cast<wregex*>(expression->guts), flags);
} }
else else
return result; return result;
#ifndef BOOST_NO_EXCEPTIONS
} catch(...) } catch(...)
{ {
return REG_E_UNKNOWN; return REG_E_UNKNOWN;
} }
#endif
if(result) if(result)
{ {
// extract what matched: // extract what matched:

View File

@ -58,11 +58,14 @@ void cpp_eh_tests(const reg_expression<C, T, A>& )
#ifndef __GNUC__ #ifndef __GNUC__
bool thrown = false; bool thrown = false;
// try set_expression form first: // try set_expression form first:
#ifndef BOOST_NO_EXCEPTIONS
try try
{ {
#endif
A a; A a;
reg_expression<C, T, A> e(a); reg_expression<C, T, A> e(a);
e.set_expression(expression.c_str(), flags[2] | regbase::use_except); e.set_expression(expression.c_str(), flags[2] | regbase::use_except);
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(const boost::bad_expression&) catch(const boost::bad_expression&)
{ {
@ -74,14 +77,18 @@ void cpp_eh_tests(const reg_expression<C, T, A>& )
begin_error(); begin_error();
cout << "Error: expected exception not thrown" << endl; cout << "Error: expected exception not thrown" << endl;
} }
#endif
// now try constructor form: // now try constructor form:
thrown = false; thrown = false;
#ifndef BOOST_NO_EXCEPTIONS
try try
#endif
{ {
A a; A a;
reg_expression<C, T, A> e(expression.c_str(), flags[2] | regbase::use_except, a); reg_expression<C, T, A> e(expression.c_str(), flags[2] | regbase::use_except, a);
} }
#ifndef BOOST_NO_EXCEPTIONS
catch(const boost::bad_expression&) catch(const boost::bad_expression&)
{ {
thrown = true; thrown = true;
@ -93,6 +100,7 @@ void cpp_eh_tests(const reg_expression<C, T, A>& )
cout << "Error: expected exception not thrown" << endl; cout << "Error: expected exception not thrown" << endl;
} }
#endif #endif
#endif
} }
template <class iterator> template <class iterator>
@ -515,6 +523,16 @@ void cpp_hl_tests(RegEx& e, bool recurse = true)
if(flags[4] & REG_MERGE) if(flags[4] & REG_MERGE)
return; return;
if(e.error_code())
{
if(search_text != BOOST_RE_STR("!"))
{
begin_error();
cout << "Expression did not compile with class RegEx" << endl;
}
return;
}
if(recurse) if(recurse)
{ {
// copy and assign test: // copy and assign test:
@ -611,13 +629,16 @@ void run_tests()
return; return;
#endif #endif
#ifndef NO_CPP_TEST #ifndef NO_CPP_TEST
#ifndef BOOST_NO_EXCEPTIONS
try try
{ {
#endif
unsigned int f = flags[2] & ~regbase::use_except; unsigned int f = flags[2] & ~regbase::use_except;
if(flags[0] & REG_ICASE) if(flags[0] & REG_ICASE)
f |= regbase::icase; f |= regbase::icase;
re_type e(expression.c_str(), f); re_type e(expression.c_str(), f);
cpp_tests(e, true); cpp_tests(e, true);
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(const std::exception& e) catch(const std::exception& e)
{ {
@ -634,17 +655,21 @@ void run_tests()
begin_error(); begin_error();
cout << "Unexpected exception thrown from C++ library" << endl; cout << "Unexpected exception thrown from C++ library" << endl;
} }
#endif // BOOST_NO_EXCEPTIONS
#endif #endif
#if !defined(TEST_UNICODE) #if !defined(TEST_UNICODE)
#ifndef BOOST_NO_EXCEPTIONS
try try
{ {
#endif
if(((flags[3] & match_partial) == 0) && (flags[2] == regbase::normal) && (has_nulls(search_text.begin(), search_text.end()) == false)) if(((flags[3] & match_partial) == 0) && (flags[2] == regbase::normal) && (has_nulls(search_text.begin(), search_text.end()) == false))
{ {
RegEx e; RegEx e;
e.SetExpression(expression.c_str(), flags[0] & REG_ICASE); e.SetExpression(expression.c_str(), flags[0] & REG_ICASE);
cpp_hl_tests(e, true); cpp_hl_tests(e, true);
} }
#ifndef BOOST_NO_EXCEPTIONS
} }
catch(const std::exception& ) catch(const std::exception& )
{ {
@ -659,6 +684,7 @@ void run_tests()
begin_error(); begin_error();
cout << "Unexpected exception thrown from RegEx::SetExpression" << endl; cout << "Unexpected exception thrown from RegEx::SetExpression" << endl;
} }
#endif // BOOST_NO_EXCEPTIONS
#endif #endif
if(flags[4] & (REG_NO_POSIX_TEST | REG_GREP | REG_MERGE | REG_MERGE_COPY)) if(flags[4] & (REG_NO_POSIX_TEST | REG_GREP | REG_MERGE | REG_MERGE_COPY))