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

@ -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<collate_name_t>();
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<char>::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<wchar_t>::init()
if(nlsw_count == 0)
{
wlocale_name = new std::string("xxxxxxxxxxxxxxxx");
#ifndef BOOST_NO_EXCEPTIONS
try{
#endif
syntax = new std::list<syntax_map_t>();
BOOST_REGEX_NOEH_ASSERT(syntax)
#ifndef BOOST_NO_EXCEPTIONS
}
catch(...)
{
delete wlocale_name;
throw;
}
#endif
}
++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);
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<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);
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<char>(i);
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())
{
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<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));
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<wchar_t>(i);
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);
}
unsigned int RegEx::error_code()const
{
return pdata->e.error_code();
}
std::string RegEx::Expression()const
{
BOOST_RE_GUARD_STACK

View File

@ -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<const char*>(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);
}

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)
{
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<regex*>(expression->guts)->set_expression(ptr, p2, flags);
expression->re_nsub = static_cast<regex*>(expression->guts)->mark_count() - 1;
result = static_cast<regex*>(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<regex*>(expression->guts), flags);
}
else
return result;
#ifndef BOOST_NO_EXCEPTIONS
} catch(...)
{
return REG_E_UNKNOWN;
}
#endif
if(result)
{

View File

@ -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)

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)
{
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<wregex*>(expression->guts)->set_expression(ptr, p2, flags);
expression->re_nsub = static_cast<wregex*>(expression->guts)->mark_count() - 1;
result = static_cast<wregex*>(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<wregex*>(expression->guts), flags);
}
else
return result;
#ifndef BOOST_NO_EXCEPTIONS
} catch(...)
{
return REG_E_UNKNOWN;
}
#endif
if(result)
{
// extract what matched: