Skip to content

Commit

Permalink
Update Boost regex to 1.85 develop branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed May 12, 2024
1 parent 4631e00 commit c864296
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 151 deletions.
4 changes: 0 additions & 4 deletions scintilla/include/boost/regex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
#include <boost/regex/config.hpp>
#endif

#ifdef BOOST_REGEX_CXX03
#include <boost/regex/v4/regex.hpp>
#else
#include <boost/regex/v5/regex.hpp>
#endif

#endif // include

Expand Down
115 changes: 7 additions & 108 deletions scintilla/include/boost/regex/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@
#ifndef BOOST_REGEX_CONFIG_HPP
#define BOOST_REGEX_CONFIG_HPP

#if !((__cplusplus >= 201103L) || (defined(_MSC_VER) && (_MSC_VER >= 1600)) || defined(BOOST_REGEX_CXX03))
# define BOOST_REGEX_CXX03
#endif

#if defined(BOOST_REGEX_RECURSIVE) && !defined(BOOST_REGEX_CXX03)
# define BOOST_REGEX_CXX03
#if defined(BOOST_REGEX_RECURSIVE)
#error "All support for the C++03 recursive engine has been removed, this define has no effect anymore."
#endif

#if defined(__has_include)
Expand All @@ -33,13 +29,6 @@
#endif
#endif

/*
* Borland C++ Fix/error check
* this has to go *before* we include any std lib headers:
*/
#if defined(__BORLANDC__) && !defined(__clang__)
# include <boost/regex/config/borland.hpp>
#endif
#ifndef BOOST_REGEX_STANDALONE
#include <boost/version.hpp>
#endif
Expand Down Expand Up @@ -90,20 +79,7 @@
# endif
#endif


/****************************************************************************
*
* Legacy support:
*
*******************************************************************************/

#if defined(BOOST_NO_STD_LOCALE) || defined(BOOST_NO_CXX11_HDR_MUTEX) || defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) \
|| defined(BOOST_NO_CXX11_HDR_ATOMIC) || defined(BOOST_NO_CXX11_ALLOCATOR) || defined(BOOST_NO_CXX11_SMART_PTR) \
|| defined(BOOST_NO_CXX11_STATIC_ASSERT) || defined(BOOST_NO_NOEXCEPT)
#ifndef BOOST_REGEX_CXX03
# define BOOST_REGEX_CXX03
#endif
#endif
#define BOOST_REGEX_MAX_RECURSION_DEPTH 100

/*****************************************************************************
*
Expand All @@ -112,7 +88,7 @@
****************************************************************************/

/* Obsolete macro, use BOOST_VERSION instead: */
#define BOOST_RE_VERSION 500
#define BOOST_RE_VERSION 600

/* fix: */
#if defined(_UNICODE) && !defined(UNICODE)
Expand Down Expand Up @@ -157,40 +133,6 @@
*/
#define BOOST_REGEX_DETAIL_NS BOOST_REGEX_JOIN(re_detail_, BOOST_RE_VERSION)

/*
* Fix for gcc prior to 3.4: std::ctype<wchar_t> doesn't allow
* masks to be combined, for example:
* std::use_facet<std::ctype<wchar_t> >.is(std::ctype_base::lower|std::ctype_base::upper, L'a');
* returns *false*.
*/
#if defined(__GLIBCPP__) && defined(BOOST_REGEX_CXX03)
# define BOOST_REGEX_BUGGY_CTYPE_FACET
#endif

/*
* If there isn't good enough wide character support then there will
* be no wide character regular expressions:
*/
#if (defined(BOOST_NO_CWCHAR) || defined(BOOST_NO_CWCTYPE) || defined(BOOST_NO_STD_WSTRING))
# if !defined(BOOST_NO_WREGEX)
# define BOOST_NO_WREGEX
# endif
#else
# if defined(__sgi) && (defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION))
/* STLPort on IRIX is misconfigured: <cwctype> does not compile
* as a temporary fix include <wctype.h> instead and prevent inclusion
* of STLPort version of <cwctype> */
# include <wctype.h>
# define __STLPORT_CWCTYPE
# define _STLP_CWCTYPE
# endif

#if defined(__cplusplus) && defined(BOOST_REGEX_CXX03)
# include <boost/regex/config/cwchar.hpp>
#endif

#endif

/*
* If Win32 support has been disabled for boost in general, then
* it is for regex in particular:
Expand Down Expand Up @@ -251,19 +193,6 @@
# define BOOST_REGEX_DECL
#endif

#ifdef BOOST_REGEX_CXX03
#if !defined(BOOST_REGEX_NO_LIB) && !defined(BOOST_REGEX_SOURCE) && !defined(BOOST_ALL_NO_LIB) && defined(__cplusplus)
# define BOOST_LIB_NAME boost_regex
# if defined(BOOST_REGEX_DYN_LINK) || defined(BOOST_ALL_DYN_LINK)
# define BOOST_DYN_LINK
# endif
# ifdef BOOST_REGEX_DIAG
# define BOOST_LIB_DIAGNOSTIC
# endif
# include <boost/config/auto_link.hpp>
#endif
#endif

/*****************************************************************************
*
* Set up function call type:
Expand Down Expand Up @@ -355,18 +284,9 @@
* If there are no exceptions then we must report critical-errors
* the only way we know how; by terminating.
*/
#include <stdexcept>
#include <string>
#include <boost/throw_exception.hpp>

# define BOOST_REGEX_NOEH_ASSERT(x)\
if(0 == (x))\
{\
std::string s("Error: critical regex++ failure in: ");\
s.append(#x);\
std::runtime_error e(s);\
boost::throw_exception(e);\
}
#include <cassert>

# define BOOST_REGEX_NOEH_ASSERT(x) assert(x);
#else
/*
* With exceptions then error handling is taken care of and
Expand Down Expand Up @@ -405,26 +325,6 @@ BOOST_REGEX_DECL void BOOST_REGEX_CALL reset_stack_guard_page();

#endif


/*****************************************************************************
*
* Algorithm selection and configuration.
* These options are now obsolete for C++11 and later (regex v5).
*
****************************************************************************/

#if !defined(BOOST_REGEX_RECURSIVE) && !defined(BOOST_REGEX_NON_RECURSIVE)
# if defined(BOOST_REGEX_HAS_MS_STACK_GUARD) && !defined(_STLP_DEBUG) && !defined(__STL_DEBUG) && !(defined(_MSC_VER) && (_MSC_VER >= 1400)) && defined(BOOST_REGEX_CXX03)
# define BOOST_REGEX_RECURSIVE
# else
# define BOOST_REGEX_NON_RECURSIVE
# endif
#endif

#ifdef BOOST_REGEX_NON_RECURSIVE
# ifdef BOOST_REGEX_RECURSIVE
# error "Can't set both BOOST_REGEX_RECURSIVE and BOOST_REGEX_NON_RECURSIVE"
# endif
# ifndef BOOST_REGEX_BLOCKSIZE
# define BOOST_REGEX_BLOCKSIZE 4096
# endif
Expand All @@ -440,7 +340,6 @@ BOOST_REGEX_DECL void BOOST_REGEX_CALL reset_stack_guard_page();
# ifndef BOOST_REGEX_MAX_CACHE_BLOCKS
# define BOOST_REGEX_MAX_CACHE_BLOCKS 16
# endif
#endif


/*****************************************************************************
Expand Down
4 changes: 0 additions & 4 deletions scintilla/include/boost/regex/pattern_except.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
#include <boost/regex/config.hpp>
#endif

#ifdef BOOST_REGEX_CXX03
#include <boost/regex/v4/pattern_except.hpp>
#else
#include <boost/regex/v5/pattern_except.hpp>
#endif

#endif
4 changes: 0 additions & 4 deletions scintilla/include/boost/regex/regex_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
#endif

# ifndef BOOST_REGEX_TRAITS_HPP_INCLUDED
#ifdef BOOST_REGEX_CXX03
# include <boost/regex/v4/regex_traits.hpp>
#else
# include <boost/regex/v5/regex_traits.hpp>
#endif
# endif

#endif // include
Expand Down
14 changes: 4 additions & 10 deletions scintilla/include/boost/regex/user.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@
// exception handling.
// #define BOOST_REGEX_HAS_MS_STACK_GUARD

// define this if you want to use the recursive algorithm
// even if BOOST_REGEX_HAS_MS_STACK_GUARD is not defined.
// NOTE: OBSOLETE!!
// #define BOOST_REGEX_RECURSIVE

// define this if you want to use the non-recursive
// algorithm, even if the recursive version would be the default.
// NOTE: OBSOLETE!!
// #define BOOST_REGEX_NON_RECURSIVE

// define this if you want to set the size of the memory blocks
// used by the non-recursive algorithm.
// #define BOOST_REGEX_BLOCKSIZE 4096
Expand All @@ -93,3 +83,7 @@

// define this if you want regex to use __cdecl calling convensions, even when __fastcall is available:
// #define BOOST_REGEX_NO_FASTCALL

// define this to control how deep non-avoidable recursive function calls can go, typical expressions
// and format strings should only recurse a handful of times, this is mainly to prevent DOS type attacks.
// #define BOOST_REGEX_MAX_RECURSION_DEPTH 100
18 changes: 16 additions & 2 deletions scintilla/include/boost/regex/v5/basic_regex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ class basic_regex : public regbase
}
//
// swap:
void swap(basic_regex& that)throw()
void swap(basic_regex& that)noexcept
{
m_pimpl.swap(that.m_pimpl);
}
Expand Down Expand Up @@ -533,7 +533,21 @@ class basic_regex : public regbase
return status() - that.status();
if(flags() != that.flags())
return flags() - that.flags();
return str().compare(that.str());

const char_type* i = m_pimpl->begin();
const char_type* j = that.m_pimpl->begin();
while ((i != m_pimpl->end()) && (j != that.m_pimpl->end()))
{
if (*i != *j)
return *i < *j ? -1 : 1;
++i;
++j;
}
if (i != m_pimpl->end())
return *i > static_cast<char_type>(0) ? 1 : -1;
if (j != that.m_pimpl->end())
return *j > static_cast<char_type>(0) ? -1 : 1;
return 0;
}
bool operator==(const basic_regex& e)const
{
Expand Down
38 changes: 30 additions & 8 deletions scintilla/include/boost/regex/v5/basic_regex_creator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class basic_regex_creator
void fixup_recursions(re_syntax_base* state);
void create_startmaps(re_syntax_base* state);
int calculate_backstep(re_syntax_base* state);
void create_startmap(re_syntax_base* state, unsigned char* l_map, unsigned int* pnull, unsigned char mask);
void create_startmap(re_syntax_base* state, unsigned char* l_map, unsigned int* pnull, unsigned char mask, unsigned recursion_count = 0);
unsigned get_restart_type(re_syntax_base* state);
void set_all_masks(unsigned char* bits, unsigned char);
bool is_bad_repeat(re_syntax_base* pt);
Expand Down Expand Up @@ -1074,7 +1074,7 @@ struct recursion_saver
};

template <class charT, class traits>
void basic_regex_creator<charT, traits>::create_startmap(re_syntax_base* state, unsigned char* l_map, unsigned int* pnull, unsigned char mask)
void basic_regex_creator<charT, traits>::create_startmap(re_syntax_base* state, unsigned char* l_map, unsigned int* pnull, unsigned char mask, unsigned recursion_count)
{
recursion_saver saved_recursions(&m_recursion_checks);
int not_last_jump = 1;
Expand All @@ -1085,6 +1085,28 @@ void basic_regex_creator<charT, traits>::create_startmap(re_syntax_base* state,
// track case sensitivity:
bool l_icase = m_icase;

if (recursion_count > BOOST_REGEX_MAX_RECURSION_DEPTH)
{
// Oops error:
if (0 == this->m_pdata->m_status) // update the error code if not already set
this->m_pdata->m_status = boost::regex_constants::error_complexity;
//
// clear the expression, we should be empty:
//
this->m_pdata->m_expression = 0;
this->m_pdata->m_expression_len = 0;
//
// and throw if required:
//
if (0 == (this->flags() & regex_constants::no_except))
{
std::string message = "Expression complexity exceeded.";
boost::regex_error e(message, boost::regex_constants::error_complexity, 0);
e.raise();
}
return;
}

while(state)
{
switch(state->type)
Expand Down Expand Up @@ -1122,7 +1144,7 @@ void basic_regex_creator<charT, traits>::create_startmap(re_syntax_base* state,
}
// now figure out if we can match a NULL string at this point:
if(pnull)
create_startmap(state->next.p, 0, pnull, mask);
create_startmap(state->next.p, 0, pnull, mask, ++recursion_count);
return;
}
case syntax_element_recurse:
Expand Down Expand Up @@ -1184,7 +1206,7 @@ void basic_regex_creator<charT, traits>::create_startmap(re_syntax_base* state,
case syntax_element_word_start:
{
// recurse, then AND with all the word characters:
create_startmap(state->next.p, l_map, pnull, mask);
create_startmap(state->next.p, l_map, pnull, mask, ++recursion_count);
if(l_map)
{
l_map[0] |= mask_init;
Expand All @@ -1199,7 +1221,7 @@ void basic_regex_creator<charT, traits>::create_startmap(re_syntax_base* state,
case syntax_element_word_end:
{
// recurse, then AND with all the word characters:
create_startmap(state->next.p, l_map, pnull, mask);
create_startmap(state->next.p, l_map, pnull, mask, ++recursion_count);
if(l_map)
{
l_map[0] |= mask_init;
Expand Down Expand Up @@ -1291,11 +1313,11 @@ void basic_regex_creator<charT, traits>::create_startmap(re_syntax_base* state,
return;
}
set_bad_repeat(state);
create_startmap(state->next.p, l_map, pnull, mask);
create_startmap(state->next.p, l_map, pnull, mask, ++recursion_count);
if((state->type == syntax_element_alt)
|| (static_cast<re_repeat*>(state)->min == 0)
|| (not_last_jump == 0))
create_startmap(rep->alt.p, l_map, pnull, mask);
create_startmap(rep->alt.p, l_map, pnull, mask, ++recursion_count);
}
}
return;
Expand Down Expand Up @@ -1354,7 +1376,7 @@ void basic_regex_creator<charT, traits>::create_startmap(re_syntax_base* state,
if(ok && ((m_recursion_checks[static_cast<re_brace*>(state)->index] & 2u) == 0))
{
m_recursion_checks[static_cast<re_brace*>(state)->index] |= 2u;
create_startmap(p->next.p, l_map, pnull, mask);
create_startmap(p->next.p, l_map, pnull, mask, ++recursion_count);
}
}
state = state->next.p;
Expand Down

0 comments on commit c864296

Please sign in to comment.