diff --git a/include/boost/cregex.hpp b/include/boost/cregex.hpp index f280a2c6..2cb2b5a4 100644 --- a/include/boost/cregex.hpp +++ b/include/boost/cregex.hpp @@ -242,6 +242,7 @@ public: 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); } std::string Expression()const; + unsigned int error_code()const; // // now matching operators: // diff --git a/include/boost/regex.hpp b/include/boost/regex.hpp index d218873d..e03aafaf 100644 --- a/include/boost/regex.hpp +++ b/include/boost/regex.hpp @@ -794,7 +794,10 @@ int do_toi(iterator i, iterator j, char c, int radix) std::string s(i, j); char* p; int result = std::strtol(s.c_str(), &p, radix); +#ifndef BOOST_NO_EXCEPTIONS if(*p)throw bad_pattern("Bad sub-expression"); +#endif + BOOST_REGEX_NOEH_ASSERT(0 == *p) return result; } @@ -819,7 +822,10 @@ sub_match::operator int()const { iterator i = first; iterator j = second; +#ifndef BOOST_NO_EXCEPTIONS if(i == j)throw bad_pattern("Bad sub-expression"); +#endif + BOOST_REGEX_NOEH_ASSERT(i != j) int neg = 1; if((i != j) && (*i == '-')) { @@ -827,7 +833,10 @@ sub_match::operator int()const ++i; } neg *= re_detail::do_toi(i, j, *i); +#ifndef BOOST_NO_EXCEPTIONS if(i != j)throw bad_pattern("Bad sub-expression"); +#endif + BOOST_REGEX_NOEH_ASSERT(i == j) return neg; } template @@ -835,8 +844,11 @@ sub_match::operator unsigned int()const { iterator i = first; iterator j = second; +#ifndef BOOST_NO_EXCEPTIONS if(i == j) throw bad_pattern("Bad sub-expression"); +#endif + BOOST_REGEX_NOEH_ASSERT(i != j) return re_detail::do_toi(i, j, *first); } #endif @@ -1063,27 +1075,33 @@ template match_results_base::match_results_base(const Allocator& a) { ref = (c_reference*)c_alloc(a).allocate(sizeof(sub_match) + sizeof(c_reference)); +#ifndef BOOST_NO_EXCEPTIONS try { +#endif new (ref) c_reference(a); ref->cmatches = 1; ref->count = 1; // construct the sub_match: +#ifndef BOOST_NO_EXCEPTIONS try { +#endif new ((sub_match*)(ref+1)) sub_match(); +#ifndef BOOST_NO_EXCEPTIONS } catch(...) - { - ::boost::re_detail::pointer_destroy(ref); - throw; + { + ::boost::re_detail::pointer_destroy(ref); + throw; } } catch(...) - { - c_alloc(a).deallocate((char*)(void*)ref, sizeof(sub_match) + sizeof(c_reference)); - throw; + { + c_alloc(a).deallocate((char*)(void*)ref, sizeof(sub_match) + sizeof(c_reference)); + throw; } +#endif } template @@ -1148,25 +1166,30 @@ void BOOST_REGEX_CALL match_results_base::set_size(size_typ if(ref->cmatches != n) { c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match) * n + sizeof(c_reference)); +#ifndef BOOST_NO_EXCEPTIONS try { +#endif new (newref) c_reference(*ref); newref->count = 1; newref->cmatches = n; sub_match* p1, *p2; p1 = (sub_match*)(newref+1); p2 = p1 + newref->cmatches; +#ifndef BOOST_NO_EXCEPTIONS try { +#endif while(p1 != p2) { new (p1) sub_match(); ++p1; } m_free(); +#ifndef BOOST_NO_EXCEPTIONS } catch(...) - { + { p2 = (sub_match*)(newref+1); while(p2 != p1) { @@ -1174,15 +1197,18 @@ void BOOST_REGEX_CALL match_results_base::set_size(size_typ ++p2; } ::boost::re_detail::pointer_destroy(ref); - throw; + throw; } +#endif ref = newref; +#ifndef BOOST_NO_EXCEPTIONS } catch(...) - { - ref->deallocate((char*)(void*)newref, sizeof(sub_match) * n + sizeof(c_reference)); - throw; + { + ref->deallocate((char*)(void*)newref, sizeof(sub_match) * n + sizeof(c_reference)); + throw; } +#endif } } @@ -1192,20 +1218,25 @@ void BOOST_REGEX_CALL match_results_base::set_size(size_typ if(ref->cmatches != n) { c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match) * n + sizeof(c_reference));; +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif new (newref) c_reference(*ref); newref->count = 1; newref->cmatches = n; sub_match* p1 = (sub_match*)(newref+1); sub_match* p2 = p1 + newref->cmatches; +#ifndef BOOST_NO_EXCEPTIONS try { +#endif while(p1 != p2) { new (p1) sub_match(j); ++p1; } m_free(); +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { @@ -1218,13 +1249,16 @@ void BOOST_REGEX_CALL match_results_base::set_size(size_typ ::boost::re_detail::pointer_destroy(ref); throw; } +#endif ref = newref; +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { ref->deallocate((char*)(void*)newref, sizeof(sub_match) * n + sizeof(c_reference)); throw; } +#endif } else { @@ -1298,19 +1332,24 @@ void BOOST_REGEX_CALL match_results_base::cow() if(ref->count > 1) { c_reference* newref = (c_reference*)ref->allocate(sizeof(sub_match) * ref->cmatches + sizeof(c_reference)); +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif new (newref) c_reference(*ref); newref->count = 1; sub_match* p1 = (sub_match*)(newref+1); sub_match* p2 = p1 + newref->cmatches; sub_match* p3 = (sub_match*)(ref+1); +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif while(p1 != p2) { new (p1) sub_match(*p3); ++p1; ++p3; } +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { @@ -1323,14 +1362,17 @@ void BOOST_REGEX_CALL match_results_base::cow() ::boost::re_detail::pointer_destroy(ref); throw; } +#endif --(ref->count); ref = newref; +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { ref->deallocate((char*)(void*)newref, sizeof(sub_match) * ref->cmatches + sizeof(c_reference)); throw; } +#endif } } @@ -1418,19 +1460,24 @@ match_results::match_results(const match_results::c_reference *> (m.ref->allocate(sizeof(sub_match) * m.ref->cmatches + sizeof(typename re_detail::match_results_base::c_reference))); +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif new (this->ref) typename re_detail::match_results_base::c_reference(*m.ref); this->ref->count = 1; sub_match* p1 = (sub_match*)(this->ref+1); sub_match* p2 = p1 + this->ref->cmatches; sub_match* p3 = (sub_match*)(m.ref+1); +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif while(p1 != p2) { new (p1) sub_match(*p3); ++p1; ++p3; } +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { @@ -1449,6 +1496,7 @@ match_results::match_results(const match_resultsdeallocate((char*)(void*)this->ref, sizeof(sub_match) * m.ref->cmatches + sizeof(typename re_detail::match_results_base::c_reference)); throw; } +#endif } template diff --git a/include/boost/regex/config.hpp b/include/boost/regex/config.hpp index e98319b3..28b8d35a 100644 --- a/include/boost/regex/config.hpp +++ b/include/boost/regex/config.hpp @@ -273,6 +273,35 @@ using std::distance; # include #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__ +// seems not to make stderr usable with Borland: +#include +#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: @@ -516,6 +545,10 @@ namespace std{ using ::fopen; using ::fclose; using ::FILE; +#ifdef BOOST_NO_EXCEPTIONS + using ::fprintf; + using ::abort; +#endif } #endif diff --git a/include/boost/regex/detail/regex_compile.hpp b/include/boost/regex/detail/regex_compile.hpp index 18f3eee6..e7bb5bd8 100644 --- a/include/boost/regex/detail/regex_compile.hpp +++ b/include/boost/regex/detail/regex_compile.hpp @@ -1167,8 +1167,10 @@ void BOOST_REGEX_CALL reg_expression::fixup_apply(re_d register re_detail::re_syntax_base* ptr = b; bool* pb = 0; b_alloc a(data.allocator()); +#ifndef BOOST_NO_EXCEPTIONS try { +#endif pb = a.allocate(cbraces); for(unsigned i = 0; i < cbraces; ++i) pb[i] = false; @@ -1232,6 +1234,7 @@ void BOOST_REGEX_CALL reg_expression::fixup_apply(re_d } a.deallocate(pb, cbraces); pb = 0; +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { @@ -1239,6 +1242,7 @@ void BOOST_REGEX_CALL reg_expression::fixup_apply(re_d a.deallocate(pb, cbraces); throw; } +#endif } @@ -2053,10 +2057,12 @@ void BOOST_REGEX_CALL reg_expression::fail(unsigned in if(err) { _flags |= regbase::failbit; +#ifndef BOOST_NO_EXCEPTIONS if(_flags & regbase::use_except) { throw bad_expression(traits_inst.error_string(err)); } +#endif } else _flags &= ~regbase::failbit; diff --git a/src/c_regex_traits.cpp b/src/c_regex_traits.cpp index 8faee829..a0b2e0f7 100644 --- a/src/c_regex_traits.cpp +++ b/src/c_regex_traits.cpp @@ -199,14 +199,19 @@ void BOOST_REGEX_CALL re_init_classes() if(classes_count == 0) { re_cls_name = new std::string("xxxxxxxx"); +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif pclasses = new std::string[re_classes_max]; + BOOST_REGEX_NOEH_ASSERT(pclasses) +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { delete re_cls_name; throw; } +#endif } ++classes_count; } @@ -243,14 +248,19 @@ void BOOST_REGEX_CALL re_init_collate() if(collate_count == 0) { re_coll_name = new std::string("xxxxxxxx"); +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif pcoll_names = new std::list(); + BOOST_REGEX_NOEH_ASSERT(pcoll_names) +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { delete re_coll_name; throw; } +#endif } ++collate_count; } @@ -345,11 +355,15 @@ void BOOST_REGEX_CALL re_message_update() if(*boost::re_detail::c_traits_base::get_catalogue()) { message_cat = catopen(boost::re_detail::c_traits_base::get_catalogue(), 0); +#ifndef BOOST_NO_EXCEPTIONS if(message_cat == (nl_catd)-1) { std::string m("Unable to open message catalog: "); 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 for(int i = 0; i < boost::REG_E_UNKNOWN; ++i) @@ -592,14 +606,19 @@ void BOOST_REGEX_CALL c_regex_traits::init() if(entry_count == 0) { ctype_name = new std::string("xxxxxxxxxxxxxxxx"); +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif collate_name = new std::string("xxxxxxxxxxxxxxxx"); + BOOST_REGEX_NOEH_ASSERT(collate_name) +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { delete ctype_name; throw; } +#endif } re_message_init(); re_init_classes(); @@ -763,14 +782,19 @@ void BOOST_REGEX_CALL c_regex_traits::init() if(nlsw_count == 0) { wlocale_name = new std::string("xxxxxxxxxxxxxxxx"); +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif syntax = new std::list(); + BOOST_REGEX_NOEH_ASSERT(syntax) +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { delete wlocale_name; throw; } +#endif } ++nlsw_count; } diff --git a/src/cpp_regex_traits.cpp b/src/cpp_regex_traits.cpp index de43207a..b42ced8d 100644 --- a/src/cpp_regex_traits.cpp +++ b/src/cpp_regex_traits.cpp @@ -197,11 +197,15 @@ message_data::message_data(const std::locale& l, const std::string& regex_ { pm = &BOOST_USE_FACET(std::messages, l); cat = pm->open(regex_message_catalogue, l); +#ifndef BOOST_NO_EXCEPTIONS if(cat < 0) { std::string m("Unable to open message catalog: "); throw std::runtime_error(m + regex_message_catalogue); } +#else + BOOST_REGEX_NOEH_ASSERT(cat >= 0); +#endif } #endif std::memset(syntax_map, cpp_regex_traits::syntax_char, 256); @@ -296,14 +300,19 @@ cpp_regex_traits::cpp_regex_traits() { pmd = new re_detail::message_data(locale_inst, regex_message_cat); psyntax = pmd->syntax_map; +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif lower_map = new char[char_set_size]; + BOOST_REGEX_NOEH_ASSERT(lower_map) +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { delete pmd; throw; } +#endif for(unsigned int i = 0; i < char_set_size; ++i) lower_map[i] = static_cast(i); pctype = &BOOST_USE_FACET(std::ctype, locale_inst); @@ -565,11 +574,15 @@ message_data::message_data(const std::locale& l, const std::string& reg if(regex_message_catalogue.size()) { cat = msgs.open(regex_message_catalogue, l); +#ifndef BOOST_NO_EXCEPTIONS if(cat < 0) { std::string m("Unable to open message catalog: "); throw std::runtime_error(m + regex_message_catalogue); } +#else + BOOST_REGEX_NOEH_ASSERT(cat >= 0); +#endif } #endif scoped_array a; @@ -770,14 +783,19 @@ cpp_regex_traits::cpp_regex_traits() { pmd = new re_detail::message_data(locale_inst, std::string(regex_message_cat)); psyntax = pmd->syntax_; +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif lower_map = new wchar_t[char_set_size]; + BOOST_REGEX_NOEH_ASSERT(lower_map) +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { delete pmd; throw; } +#endif for(unsigned int i = 0; i < char_set_size; ++i) lower_map[i] = static_cast(i); pctype = &BOOST_USE_FACET(std::ctype, locale_inst); diff --git a/src/cregex.cpp b/src/cregex.cpp index c39b8dc9..d9a54b47 100644 --- a/src/cregex.cpp +++ b/src/cregex.cpp @@ -178,6 +178,12 @@ unsigned int RegEx::SetExpression(const char* p, bool icase) return pdata->e.set_expression(p, f); } +unsigned int RegEx::error_code()const +{ + return pdata->e.error_code(); +} + + std::string RegEx::Expression()const { BOOST_RE_GUARD_STACK diff --git a/src/fileiter.cpp b/src/fileiter.cpp index 3a4b9c86..ebe9a3a8 100644 --- a/src/fileiter.cpp +++ b/src/fileiter.cpp @@ -81,7 +81,11 @@ void mapfile::open(const char* file) CloseHandle(hfile); hmap = 0; hfile = 0; +#ifndef BOOST_NO_EXCEPTIONS throw std::runtime_error("Unable to create file mapping."); +#else + BOOST_REGEX_NOEH_ASSERT(hmap != INVALID_HANDLE_VALUE); +#endif } _first = static_cast(MapViewOfFile(hmap, FILE_MAP_READ, 0, 0, 0)); if(_first == 0) @@ -90,14 +94,22 @@ void mapfile::open(const char* file) CloseHandle(hfile); hmap = 0; hfile = 0; +#ifndef BOOST_NO_EXCEPTIONS throw std::runtime_error("Unable to create file mapping."); +#else + BOOST_REGEX_NOEH_ASSERT(_first != 0); +#endif } _last = _first + GetFileSize(hfile, 0); } else { hfile = 0; +#ifndef BOOST_NO_EXCEPTIONS 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 hfile = std::fopen(file, "rb"); +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif if(hfile != 0) { _size = get_file_length(hfile); @@ -306,10 +320,16 @@ void mapfile::open(const char* file) } else { +#ifndef BOOST_NO_EXCEPTIONS throw std::runtime_error("Unable to open file."); +#else + BOOST_REGEX_NOEH_ASSERT(hfile != 0); +#endif } +#ifndef BOOST_NO_EXCEPTIONS }catch(...) { close(); throw; } +#endif } void mapfile::close() @@ -342,15 +362,21 @@ file_iterator::file_iterator() BOOST_RE_GUARD_STACK _root = _path = 0; ref = 0; +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif _root = new char[MAX_PATH]; + BOOST_REGEX_NOEH_ASSERT(_root) _path = new char[MAX_PATH]; + BOOST_REGEX_NOEH_ASSERT(_path) ptr = _path; *_path = 0; *_root = 0; ref = new file_iterator_ref(); + BOOST_REGEX_NOEH_ASSERT(ref) ref->hf = _fi_invalid_handle; ref->count = 1; +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { @@ -359,6 +385,7 @@ file_iterator::file_iterator() delete ref; throw; } +#endif } file_iterator::file_iterator(const char* wild) @@ -366,9 +393,13 @@ file_iterator::file_iterator(const char* wild) BOOST_RE_GUARD_STACK _root = _path = 0; ref = 0; +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif _root = new char[MAX_PATH]; + BOOST_REGEX_NOEH_ASSERT(_root) _path = new char[MAX_PATH]; + BOOST_REGEX_NOEH_ASSERT(_path) std::strcpy(_root, wild); ptr = _root; while(*ptr)++ptr; @@ -399,6 +430,7 @@ file_iterator::file_iterator(const char* wild) #endif ref = new file_iterator_ref(); + BOOST_REGEX_NOEH_ASSERT(ref) ref->hf = FindFirstFileA(wild, &(ref->_data)); ref->count = 1; @@ -413,6 +445,7 @@ file_iterator::file_iterator(const char* wild) if(ref->_data.dwFileAttributes & _fi_dir) next(); } +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { @@ -421,6 +454,7 @@ file_iterator::file_iterator(const char* wild) delete ref; throw; } +#endif } file_iterator::file_iterator(const file_iterator& other) @@ -428,13 +462,18 @@ file_iterator::file_iterator(const file_iterator& other) BOOST_RE_GUARD_STACK _root = _path = 0; ref = 0; +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif _root = new char[MAX_PATH]; + BOOST_REGEX_NOEH_ASSERT(_root) _path = new char[MAX_PATH]; + BOOST_REGEX_NOEH_ASSERT(_path) std::strcpy(_root, other._root); std::strcpy(_path, other._path); ptr = _path + (other.ptr - other._path); ref = other.ref; +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { @@ -442,6 +481,7 @@ file_iterator::file_iterator(const file_iterator& other) delete[] _path; throw; } +#endif ++(ref->count); } @@ -517,15 +557,21 @@ directory_iterator::directory_iterator() BOOST_RE_GUARD_STACK _root = _path = 0; ref = 0; +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif _root = new char[MAX_PATH]; + BOOST_REGEX_NOEH_ASSERT(_root) _path = new char[MAX_PATH]; + BOOST_REGEX_NOEH_ASSERT(_path) ptr = _path; *_path = 0; *_root = 0; ref = new file_iterator_ref(); + BOOST_REGEX_NOEH_ASSERT(ref) ref->hf = _fi_invalid_handle; ref->count = 1; +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { @@ -534,6 +580,7 @@ directory_iterator::directory_iterator() delete ref; throw; } +#endif } directory_iterator::directory_iterator(const char* wild) @@ -541,9 +588,13 @@ directory_iterator::directory_iterator(const char* wild) BOOST_RE_GUARD_STACK _root = _path = 0; ref = 0; +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif _root = new char[MAX_PATH]; + BOOST_REGEX_NOEH_ASSERT(_root) _path = new char[MAX_PATH]; + BOOST_REGEX_NOEH_ASSERT(_path) std::strcpy(_root, wild); ptr = _root; while(*ptr)++ptr; @@ -573,6 +624,7 @@ directory_iterator::directory_iterator(const char* wild) } #endif ref = new file_iterator_ref(); + BOOST_REGEX_NOEH_ASSERT(ref) ref->count = 1; ref->hf = FindFirstFileA(wild, &(ref->_data)); 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)) next(); } +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { @@ -594,6 +647,7 @@ directory_iterator::directory_iterator(const char* wild) delete ref; throw; } +#endif } directory_iterator::~directory_iterator() @@ -614,13 +668,18 @@ directory_iterator::directory_iterator(const directory_iterator& other) BOOST_RE_GUARD_STACK _root = _path = 0; ref = 0; +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif _root = new char[MAX_PATH]; + BOOST_REGEX_NOEH_ASSERT(_root) _path = new char[MAX_PATH]; + BOOST_REGEX_NOEH_ASSERT(_path) std::strcpy(_root, other._root); std::strcpy(_path, other._path); ptr = _path + (other.ptr - other._path); ref = other.ref; +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { @@ -628,6 +687,7 @@ directory_iterator::directory_iterator(const directory_iterator& other) delete[] _path; throw; } +#endif ++(ref->count); } diff --git a/src/posix_api.cpp b/src/posix_api.cpp index f64755a0..cd3dc0a2 100644 --- a/src/posix_api.cpp +++ b/src/posix_api.cpp @@ -43,12 +43,19 @@ BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompA(regex_tA* expression, const char if(expression->re_magic != magic_value) { expression->guts = 0; +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif expression->guts = new regex(); +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { return REG_ESPACE; } +#else + if(0 == expression->guts) + return REG_E_MEMORY; +#endif } // set default flags: 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; +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif expression->re_magic = magic_value; static_cast(expression->guts)->set_expression(ptr, p2, flags); expression->re_nsub = static_cast(expression->guts)->mark_count() - 1; result = static_cast(expression->guts)->error_code(); +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { result = REG_E_UNKNOWN; } +#endif if(result) regfreeA(expression); return result; @@ -174,17 +185,21 @@ BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecA(const regex_tA* expression, cons end = buf + std::strlen(buf); } +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif if(expression->re_magic == magic_value) { result = regex_search(start, end, m, *static_cast(expression->guts), flags); } else return result; +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { return REG_E_UNKNOWN; } +#endif if(result) { diff --git a/src/w32_regex_traits.cpp b/src/w32_regex_traits.cpp index d43b1aa6..d1a5aa0d 100644 --- a/src/w32_regex_traits.cpp +++ b/src/w32_regex_traits.cpp @@ -236,11 +236,15 @@ void BOOST_REGEX_CALL w32_traits_base::do_init() if(*regex_message_catalogue) { hresmod = LoadLibraryA(regex_message_catalogue); +#ifndef BOOST_NO_EXCEPTIONS if(hresmod == NULL) { std::string s("Unable to open dll: "); throw std::runtime_error(s + regex_message_catalogue); } +#else + BOOST_REGEX_NOEH_ASSERT(hresmod != NULL); +#endif } unsigned int i; for(i = 0; i < REG_E_UNKNOWN; ++i) diff --git a/src/wide_posix_api.cpp b/src/wide_posix_api.cpp index 7db03d6a..83dd7a03 100644 --- a/src/wide_posix_api.cpp +++ b/src/wide_posix_api.cpp @@ -51,12 +51,19 @@ BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompW(regex_tW* expression, const wcha if(expression->re_magic != wmagic_value) { expression->guts = 0; +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif expression->guts = new wregex(); +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { return REG_ESPACE; } +#else + if(0 == expression->guts) + return REG_E_MEMORY; +#endif } // set default flags: 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; +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif expression->re_magic = wmagic_value; static_cast(expression->guts)->set_expression(ptr, p2, flags); expression->re_nsub = static_cast(expression->guts)->mark_count() - 1; result = static_cast(expression->guts)->error_code(); +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { result = REG_E_UNKNOWN; } +#endif if(result) regfreeW(expression); return result; @@ -182,18 +193,21 @@ BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecW(const regex_tW* expression, cons end = buf + std::wcslen(buf); } +#ifndef BOOST_NO_EXCEPTIONS try{ +#endif if(expression->re_magic == wmagic_value) { result = regex_search(start, end, m, *static_cast(expression->guts), flags); } else return result; +#ifndef BOOST_NO_EXCEPTIONS } catch(...) { return REG_E_UNKNOWN; } - +#endif if(result) { // extract what matched: diff --git a/test/regress/tests.cpp b/test/regress/tests.cpp index 559a2cc2..eebe543d 100644 --- a/test/regress/tests.cpp +++ b/test/regress/tests.cpp @@ -58,11 +58,14 @@ void cpp_eh_tests(const reg_expression& ) #ifndef __GNUC__ bool thrown = false; // try set_expression form first: +#ifndef BOOST_NO_EXCEPTIONS try { +#endif A a; reg_expression e(a); e.set_expression(expression.c_str(), flags[2] | regbase::use_except); +#ifndef BOOST_NO_EXCEPTIONS } catch(const boost::bad_expression&) { @@ -74,14 +77,18 @@ void cpp_eh_tests(const reg_expression& ) begin_error(); cout << "Error: expected exception not thrown" << endl; } +#endif // now try constructor form: thrown = false; +#ifndef BOOST_NO_EXCEPTIONS try +#endif { A a; reg_expression e(expression.c_str(), flags[2] | regbase::use_except, a); } +#ifndef BOOST_NO_EXCEPTIONS catch(const boost::bad_expression&) { thrown = true; @@ -93,6 +100,7 @@ void cpp_eh_tests(const reg_expression& ) cout << "Error: expected exception not thrown" << endl; } #endif +#endif } template @@ -515,6 +523,16 @@ void cpp_hl_tests(RegEx& e, bool recurse = true) if(flags[4] & REG_MERGE) 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) { // copy and assign test: @@ -611,13 +629,16 @@ void run_tests() return; #endif #ifndef NO_CPP_TEST +#ifndef BOOST_NO_EXCEPTIONS try { +#endif unsigned int f = flags[2] & ~regbase::use_except; if(flags[0] & REG_ICASE) f |= regbase::icase; re_type e(expression.c_str(), f); cpp_tests(e, true); +#ifndef BOOST_NO_EXCEPTIONS } catch(const std::exception& e) { @@ -634,17 +655,21 @@ void run_tests() begin_error(); cout << "Unexpected exception thrown from C++ library" << endl; } +#endif // BOOST_NO_EXCEPTIONS #endif #if !defined(TEST_UNICODE) +#ifndef BOOST_NO_EXCEPTIONS try { +#endif if(((flags[3] & match_partial) == 0) && (flags[2] == regbase::normal) && (has_nulls(search_text.begin(), search_text.end()) == false)) { RegEx e; e.SetExpression(expression.c_str(), flags[0] & REG_ICASE); cpp_hl_tests(e, true); } +#ifndef BOOST_NO_EXCEPTIONS } catch(const std::exception& ) { @@ -659,6 +684,7 @@ void run_tests() begin_error(); cout << "Unexpected exception thrown from RegEx::SetExpression" << endl; } +#endif // BOOST_NO_EXCEPTIONS #endif if(flags[4] & (REG_NO_POSIX_TEST | REG_GREP | REG_MERGE | REG_MERGE_COPY))