Skip to content

Commit bc160a5

Browse files
committed
Merge branch 'develop' into git_issue_80
Fixed Conflicts: include/boost/regex/v4/basic_regex_creator.hpp include/boost/regex/v4/basic_regex_parser.hpp
2 parents f64c228 + 70c3ffa commit bc160a5

File tree

9 files changed

+102
-104
lines changed

9 files changed

+102
-104
lines changed

.travis.yml

Lines changed: 17 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@
44

55
language: cpp
66

7-
sudo: false
8-
9-
python: "2.7"
10-
11-
os:
12-
- linux
13-
- osx
14-
157
branches:
168
only:
179
- master
1810
- develop
11+
- /feature\/.*/
1912

2013
env:
2114
matrix:
@@ -30,25 +23,15 @@ matrix:
3023
- os: linux
3124
env: TEST_CMAKE=true # variables unused - just for identification in travis ci gui
3225
script:
33-
- git submodule update --init tools/cmake
34-
- git submodule update --init libs/conversion
35-
- git submodule update --init libs/function_types
36-
- git submodule update --init libs/fusion
37-
- git submodule update --init libs/typeof
3826
- mkdir __build__ && cd __build__
39-
- cmake .. -DBOOST_ENABLE_CMAKE=ON -DBOOST_REGEX_INCLUDE_EXAMPLES=ON
27+
- cmake .. -DBOOST_ENABLE_CMAKE=ON -DBOOST_INCLUDE_LIBRARIES=regex -DBOOST_REGEX_INCLUDE_EXAMPLES=ON
4028
- cmake --build .
4129

4230
- os: linux
4331
env: TEST_CMAKE=true BUILD_SHARED_LIBS=On # variables unused - just for identification in travis ci gui
4432
script:
45-
- git submodule update --init tools/cmake
46-
- git submodule update --init libs/conversion
47-
- git submodule update --init libs/function_types
48-
- git submodule update --init libs/fusion
49-
- git submodule update --init libs/typeof
5033
- mkdir __build__ && cd __build__
51-
- cmake .. -DBUILD_SHARED_LIBS=ON -DBOOST_ENABLE_CMAKE=ON -DBOOST_REGEX_INCLUDE_EXAMPLES=ON
34+
- cmake .. -DBUILD_SHARED_LIBS=ON -DBOOST_ENABLE_CMAKE=ON -DBOOST_INCLUDE_LIBRARIES=regex -DBOOST_REGEX_INCLUDE_EXAMPLES=ON
5235
- cmake --build .
5336

5437
- os: linux
@@ -265,63 +248,27 @@ matrix:
265248
- os: osx
266249
env: TOOLSET=clang COMPILER=clang++ CXXSTD=11
267250
osx_image: xcode6.4
268-
251+
# On this image, git doesn't support --jobs 3
252+
install:
253+
- BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
254+
- cd ..
255+
- git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
256+
- cd boost-root
257+
- git submodule update --init tools/boostdep
258+
- cp -r $TRAVIS_BUILD_DIR/* libs/regex
259+
- python tools/boostdep/depinst/depinst.py -I example regex
260+
- ./bootstrap.sh
261+
- ./b2 headers
269262

270263

271264
install:
272265
- BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
273266
- cd ..
274-
- git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost-root
267+
- git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
275268
- cd boost-root
276-
- git submodule update --init tools/build
277-
- git submodule update --init tools/boost_install
278-
- git submodule update --init libs/headers
279-
- git submodule update --init libs/config
280-
- git submodule update --init libs/core
281-
- git submodule update --init libs/container_hash
282-
- git submodule update --init libs/detail
283-
- git submodule update --init libs/smart_ptr
284-
- git submodule update --init libs/predef
285-
- git submodule update --init libs/assert
286-
- git submodule update --init libs/throw_exception
287-
- git submodule update --init libs/mpl
288-
- git submodule update --init libs/type_traits
289-
- git submodule update --init libs/static_assert
290-
- git submodule update --init libs/integer
291-
- git submodule update --init libs/preprocessor
292-
- git submodule update --init libs/functional
293-
- git submodule update --init libs/program_options
294-
- git submodule update --init libs/chrono
295-
- git submodule update --init libs/system
296-
- git submodule update --init libs/thread
297-
- git submodule update --init libs/winapi
298-
- git submodule update --init libs/move
299-
- git submodule update --init libs/date_time
300-
- git submodule update --init libs/ratio
301-
- git submodule update --init libs/iterator
302-
- git submodule update --init libs/range
303-
- git submodule update --init libs/any
304-
- git submodule update --init libs/concept_check
305-
- git submodule update --init libs/array
306-
- git submodule update --init libs/timer
307-
- git submodule update --init libs/bind
308-
- git submodule update --init libs/utility
309-
- git submodule update --init libs/io
310-
- git submodule update --init libs/intrusive
311-
- git submodule update --init libs/container
312-
- git submodule update --init libs/tuple
313-
- git submodule update --init libs/exception
314-
- git submodule update --init libs/function
315-
- git submodule update --init libs/type_index
316-
- git submodule update --init libs/lexical_cast
317-
- git submodule update --init libs/numeric
318-
- git submodule update --init libs/math
319-
- git submodule update --init libs/tokenizer
320-
- git submodule update --init libs/optional
321-
- git submodule update --init libs/atomic
322-
- git submodule update --init libs/rational
323-
- git submodule update --init libs/algorithm
269+
- git submodule update --init tools/boostdep
324270
- cp -r $TRAVIS_BUILD_DIR/* libs/regex
271+
- python tools/boostdep/depinst/depinst.py -I example -g "--jobs 3" regex
325272
- ./bootstrap.sh
326273
- ./b2 headers
327274

CMakeLists.txt

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@
4141
##### Current Limitations:
4242
#
4343
# - Doesn't compile or run tests
44-
# - Doesn't support installation
4544
#
4645

47-
cmake_minimum_required( VERSION 3.5 )
48-
project( BoostRegex LANGUAGES CXX )
46+
cmake_minimum_required( VERSION 3.5...3.16 )
47+
project( boost_regex VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX )
4948

5049
option( BOOST_REGEX_INCLUDE_EXAMPLES "Also build (some) boost regex examples" OFF )
5150
option( BOOST_REGEX_USE_ICU "Enable ICU support in boost regex" OFF )
@@ -55,20 +54,11 @@ file( GLOB BOOST_REGEX_SRC ./src/*.cpp )
5554
add_library( boost_regex ${BOOST_REGEX_SRC} )
5655
add_library( Boost::regex ALIAS boost_regex )
5756

58-
# Currently, installation isn't supported directly,
59-
# but someone else might install this target from the parent
60-
# CMake script, so lets proactively differentiate between
61-
# the include directory during regular use (BUILD_INTERFACE)
62-
# and after installation
63-
target_include_directories( boost_regex
64-
PUBLIC
65-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
66-
$<INSTALL_INTERFACE:include>
67-
)
57+
target_include_directories( boost_regex PUBLIC include )
6858

6959
target_compile_definitions( boost_regex
7060
PUBLIC
71-
# No need for autolink and we don't mangle library name anyway
61+
# No need for autolink
7262
BOOST_REGEX_NO_LIB
7363
$<$<STREQUAL:$<TARGET_PROPERTY:boost_regex,TYPE>,SHARED_LIBRARY>:BOOST_REGEX_DYN_LINK=1>
7464
$<$<STREQUAL:$<TARGET_PROPERTY:boost_regex,TYPE>,STATIC_LIBRARY>:BOOST_REGEX_STATIC_LINK=1>

include/boost/regex/v4/basic_regex.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ void bubble_down_one(I first, I last)
7070
}
7171
}
7272

73+
static const int hash_value_mask = 1 << (std::numeric_limits<int>::digits - 1);
74+
7375
template <class Iterator>
7476
inline int hash_value_from_capture_name(Iterator i, Iterator j)
7577
{
7678
std::size_t r = boost::hash_range(i, j);
77-
r %= ((std::numeric_limits<int>::max)() - 10001);
78-
r += 10000;
79-
return static_cast<int>(r);
79+
r %= ((std::numeric_limits<int>::max)());
80+
return static_cast<int>(r) | hash_value_mask;
8081
}
8182

8283
class named_subexpressions

include/boost/regex/v4/basic_regex_creator.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#ifndef BOOST_REGEX_V4_BASIC_REGEX_CREATOR_HPP
2121
#define BOOST_REGEX_V4_BASIC_REGEX_CREATOR_HPP
2222

23+
#include <boost/regex/v4/indexed_bit_flag.hpp>
24+
2325
#ifdef BOOST_MSVC
2426
#pragma warning(push)
2527
#pragma warning(disable: 4103)
@@ -239,7 +241,7 @@ class basic_regex_creator
239241
bool m_icase; // true for case insensitive matches
240242
unsigned m_repeater_id; // the state_id of the next repeater
241243
bool m_has_backrefs; // true if there are actually any backrefs
242-
unsigned m_backrefs; // bitmask of permitted backrefs
244+
indexed_bit_flag m_backrefs; // bitmask of permitted backrefs
243245
boost::uintmax_t m_bad_repeats; // bitmask of repeats we can't deduce a startmap for;
244246
bool m_has_recursions; // set when we have recursive expresisons to fixup
245247
std::vector<unsigned char> m_recursion_checks; // notes which recursions we've followed while analysing this expression
@@ -268,7 +270,7 @@ class basic_regex_creator
268270
template <class charT, class traits>
269271
basic_regex_creator<charT, traits>::basic_regex_creator(regex_data<charT, traits>* data)
270272
: m_pdata(data), m_traits(*(data->m_ptraits)), m_last_state(0), m_icase(false), m_repeater_id(0),
271-
m_has_backrefs(false), m_backrefs(0), m_bad_repeats(0), m_has_recursions(false), m_word_mask(0), m_mask_space(0), m_lower_mask(0), m_upper_mask(0), m_alpha_mask(0)
273+
m_has_backrefs(false), m_bad_repeats(0), m_has_recursions(false), m_word_mask(0), m_mask_space(0), m_lower_mask(0), m_upper_mask(0), m_alpha_mask(0)
272274
{
273275
m_pdata->m_data.clear();
274276
m_pdata->m_status = ::boost::regex_constants::error_ok;
@@ -764,7 +766,7 @@ void basic_regex_creator<charT, traits>::fixup_recursions(re_syntax_base* state)
764766
if(idx < 0)
765767
{
766768
idx = -idx-1;
767-
if(idx >= 10000)
769+
if(idx >= hash_value_mask)
768770
{
769771
idx = m_pdata->get_id(idx);
770772
if(idx <= 0)
@@ -796,7 +798,7 @@ void basic_regex_creator<charT, traits>::fixup_recursions(re_syntax_base* state)
796798
bool ok = false;
797799
re_syntax_base* p = base;
798800
std::ptrdiff_t idx = static_cast<re_jump*>(state)->alt.i;
799-
if(idx > 10000)
801+
if(idx >= hash_value_mask)
800802
{
801803
//
802804
// There may be more than one capture group with this hash, just do what Perl

include/boost/regex/v4/basic_regex_parser.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,8 @@ bool basic_regex_parser<charT, traits>::parse_open_paren()
558558
//
559559
// allow backrefs to this mark:
560560
//
561-
if((markid > 0) && (markid < sizeof(unsigned) * CHAR_BIT))
562-
this->m_backrefs |= 1u << (markid - 1);
561+
if(markid > 0)
562+
this->m_backrefs.set(markid);
563563

564564
return true;
565565
}
@@ -925,7 +925,7 @@ bool basic_regex_parser<charT, traits>::parse_extended_escape()
925925
}
926926
if(negative)
927927
i = 1 + (static_cast<boost::intmax_t>(m_mark_count) - i);
928-
if(((i > 0) && (i < std::numeric_limits<unsigned>::digits) && (i - 1 < static_cast<boost::intmax_t>(sizeof(unsigned) * CHAR_BIT)) && (this->m_backrefs & (1u << (i-1)))) || ((i > 10000) && (this->m_pdata->get_id(i) > 0) && (static_cast<boost::intmax_t>(this->m_pdata->get_id(i))-1 < static_cast<boost::intmax_t>(sizeof(unsigned) * CHAR_BIT)) && (this->m_backrefs & (1u << (this->m_pdata->get_id(i)-1)))))
928+
if(((i < hash_value_mask) && (i > 0) && (this->m_backrefs.test(i))) || ((i >= hash_value_mask) && (this->m_pdata->get_id(i) > 0) && (this->m_backrefs.test(this->m_pdata->get_id(i)))))
929929
{
930930
m_position = pc;
931931
re_brace* pb = static_cast<re_brace*>(this->append_state(syntax_element_backref, sizeof(re_brace)));
@@ -1957,7 +1957,7 @@ bool basic_regex_parser<charT, traits>::parse_backref()
19571957
charT c = unescape_character();
19581958
this->append_literal(c);
19591959
}
1960-
else if((i > 0) && (this->m_backrefs & (1u << (i-1))))
1960+
else if((i > 0) && (this->m_backrefs.test(i)))
19611961
{
19621962
m_position = pc;
19631963
re_brace* pb = static_cast<re_brace*>(this->append_state(syntax_element_backref, sizeof(re_brace)));
@@ -2731,8 +2731,7 @@ bool basic_regex_parser<charT, traits>::parse_perl_extension()
27312731
//
27322732
// allow backrefs to this mark:
27332733
//
2734-
if(markid < (int)(sizeof(unsigned) * CHAR_BIT))
2735-
this->m_backrefs |= 1u << (markid - 1);
2734+
this->m_backrefs.set(markid);
27362735
}
27372736
return true;
27382737
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
*
3+
* Copyright (c) 2020
4+
* John Maddock
5+
*
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)
9+
*
10+
*/
11+
12+
/*
13+
* LOCATION: see http://www.boost.org for most recent version.
14+
* FILE basic_regex_parser.cpp
15+
* VERSION see <boost/version.hpp>
16+
* DESCRIPTION: Declares template class basic_regex_parser.
17+
*/
18+
19+
#include <boost/regex/config.hpp>
20+
#include <set>
21+
22+
#ifndef BOOST_REGEX_V4_INDEXED_BIT_FLAG_HPP
23+
#define BOOST_REGEX_V4_INDEXED_BIT_FLAG_HPP
24+
25+
namespace boost{
26+
namespace BOOST_REGEX_DETAIL_NS{
27+
28+
class indexed_bit_flag
29+
{
30+
boost::uint64_t low_mask;
31+
std::set<std::size_t> mask_set;
32+
public:
33+
indexed_bit_flag() : low_mask(0) {}
34+
void set(std::size_t i)
35+
{
36+
if (i < std::numeric_limits<boost::uint64_t>::digits - 1)
37+
low_mask |= static_cast<boost::uint64_t>(1u) << i;
38+
else
39+
mask_set.insert(i);
40+
}
41+
bool test(std::size_t i)
42+
{
43+
if (i < std::numeric_limits<boost::uint64_t>::digits - 1)
44+
return low_mask & static_cast<boost::uint64_t>(1u) << i ? true : false;
45+
else
46+
return mask_set.find(i) != mask_set.end();
47+
}
48+
};
49+
50+
} // namespace BOOST_REGEX_DETAIL_NS
51+
} // namespace boost
52+
53+
54+
#endif

include/boost/regex/v4/perl_matcher_common.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_backref()
619619
// or PCRE.
620620
//
621621
int index = static_cast<const re_brace*>(pstate)->index;
622-
if(index >= 10000)
622+
if(index >= hash_value_mask)
623623
{
624624
named_subexpressions::range_type r = re.get_data().equal_range(index);
625625
BOOST_ASSERT(r.first != r.second);
@@ -768,7 +768,7 @@ inline bool perl_matcher<BidiIterator, Allocator, traits>::match_assert_backref(
768768
{
769769
// Have we matched subexpression "index"?
770770
// Check if index is a hash value:
771-
if(index >= 10000)
771+
if(index >= hash_value_mask)
772772
{
773773
named_subexpressions::range_type r = re.get_data().equal_range(index);
774774
while(r.first != r.second)
@@ -792,7 +792,7 @@ inline bool perl_matcher<BidiIterator, Allocator, traits>::match_assert_backref(
792792
// Have we recursed into subexpression "index"?
793793
// If index == 0 then check for any recursion at all, otherwise for recursion to -index-1.
794794
int idx = -(index+1);
795-
if(idx >= 10000)
795+
if(idx >= hash_value_mask)
796796
{
797797
named_subexpressions::range_type r = re.get_data().equal_range(idx);
798798
int stack_index = recursion_stack.empty() ? -1 : recursion_stack.back().idx;

test/regress/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ int cpp_main(int /*argc*/, char * /*argv*/[])
139139

140140
int* get_array_data()
141141
{
142-
static boost::thread_specific_ptr<boost::array<int, 200> > tp;
142+
static boost::thread_specific_ptr<boost::array<int, 800> > tp;
143143

144144
if(tp.get() == 0)
145-
tp.reset(new boost::array<int, 200>);
145+
tp.reset(new boost::array<int, 800>);
146146

147147
return tp.get()->data();
148148
}
@@ -160,9 +160,9 @@ const int* make_array(int first, ...)
160160
#ifdef TEST_THREADS
161161
int* data = get_array_data();
162162
#else
163-
static int data[200];
163+
static int data[800];
164164
#endif
165-
std::fill_n(data, 200, -2);
165+
std::fill_n(data, 800, -2);
166166
va_list ap;
167167
va_start(ap, first);
168168
//

test/regress/test_backrefs.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,10 @@ void test_backrefs()
103103
TEST_REGEX_SEARCH("a(?'foo'(?'bar'(?'bb'(?'aa'b*))))c\\g{foo}d", perl, "abbcbbbd", match_default, make_array(-2, -2));
104104
TEST_REGEX_SEARCH("^(?'foo'.)\\g{foo}", perl, "abc", match_default, make_array(-2, -2));
105105
TEST_REGEX_SEARCH("a(?'foo'[bc])\\g{foo}d", perl, "abcdabbd", match_default, make_array(4, 8, 5, 6, -2, -2));
106+
107+
// Bug cases from https://github.com/boostorg/regex/issues/75
108+
TEST_REGEX_SEARCH("(?:(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)\\g{-1}|WORKING)", perl, "WORKING", match_default, make_array(0, 7, -2, -2));
109+
TEST_REGEX_SEARCH("(?:(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)(z)\\g{-1}|WORKING)", perl, "WORKING", match_default, make_array(0, 7, -2, -2));
110+
106111
}
107112

0 commit comments

Comments
 (0)