|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r57592 - in trunk: boost/xpressive boost/xpressive/detail/core boost/xpressive/detail/utility libs/xpressive/test
From: eric_at_[hidden]
Date: 2009-11-11 21:18:38
Author: eric_niebler
Date: 2009-11-11 21:18:37 EST (Wed, 11 Nov 2009)
New Revision: 57592
URL: http://svn.boost.org/trac/boost/changeset/57592
Log:
do NOT copy singular iterators, fixes #3538
Text files modified:
trunk/boost/xpressive/detail/core/access.hpp | 5 +++
trunk/boost/xpressive/detail/core/state.hpp | 4 +-
trunk/boost/xpressive/detail/core/sub_match_impl.hpp | 21 ++--------------
trunk/boost/xpressive/detail/utility/sequence_stack.hpp | 51 +++++++++++++++++++++++++++++----------
trunk/boost/xpressive/match_results.hpp | 37 +++++++++++++---------------
trunk/libs/xpressive/test/Jamfile.v2 | 1
6 files changed, 66 insertions(+), 53 deletions(-)
Modified: trunk/boost/xpressive/detail/core/access.hpp
==============================================================================
--- trunk/boost/xpressive/detail/core/access.hpp (original)
+++ trunk/boost/xpressive/detail/core/access.hpp 2009-11-11 21:18:37 EST (Wed, 11 Nov 2009)
@@ -119,6 +119,11 @@
{
what.set_base_(base);
}
+
+ static BidiIter get_base(match_results<BidiIter> &what)
+ {
+ return *what.base_;
+ }
};
}}} // namespace boost::xpressive::detail
Modified: trunk/boost/xpressive/detail/core/state.hpp
==============================================================================
--- trunk/boost/xpressive/detail/core/state.hpp (original)
+++ trunk/boost/xpressive/detail/core/state.hpp 2009-11-11 21:18:37 EST (Wed, 11 Nov 2009)
@@ -289,7 +289,7 @@
this->context_.results_ptr_ = &what;
this->context_.traits_ = impl.traits_.get();
this->mark_count_ = impl.mark_count_ + 1;
- this->sub_matches_ = this->extras_->sub_match_stack_.push_sequence(total_mark_count, detail::sub_match_impl_default());
+ this->sub_matches_ = this->extras_->sub_match_stack_.push_sequence(total_mark_count, sub_match_impl(begin_), detail::fill);
this->sub_matches_ += impl.hidden_mark_count_;
// initialize the match_results struct
@@ -329,7 +329,7 @@
{
memento<BidiIter> mem =
{
- state.extras_->sub_match_stack_.push_sequence(state.mark_count_)
+ state.extras_->sub_match_stack_.push_sequence(state.mark_count_, sub_match_impl<BidiIter>(state.begin_))
, state.context_.results_ptr_->nested_results().size()
, state.action_list_.next
, state.action_list_tail_
Modified: trunk/boost/xpressive/detail/core/sub_match_impl.hpp
==============================================================================
--- trunk/boost/xpressive/detail/core/sub_match_impl.hpp (original)
+++ trunk/boost/xpressive/detail/core/sub_match_impl.hpp 2009-11-11 21:18:37 EST (Wed, 11 Nov 2009)
@@ -23,13 +23,6 @@
// need is trivial constructor/destructor. (???)
///////////////////////////////////////////////////////////////////////////////
-// sub_match_impl_default
-//
-struct sub_match_impl_default
-{
-};
-
-///////////////////////////////////////////////////////////////////////////////
// sub_match_impl
//
template<typename BidiIter>
@@ -40,21 +33,13 @@
BidiIter begin_;
bool zero_width_;
- sub_match_impl()
- : sub_match<BidiIter>()
+ sub_match_impl(BidiIter const &begin)
+ : sub_match<BidiIter>(begin, begin)
, repeat_count_(0)
- , begin_()
+ , begin_(begin)
, zero_width_(false)
{
}
-
- sub_match_impl &operator =(sub_match_impl_default const &)
- {
- this->matched = false;
- this->repeat_count_ = 0;
- this->zero_width_ = false;
- return *this;
- }
};
}}} // namespace boost::xpressive::detail
Modified: trunk/boost/xpressive/detail/utility/sequence_stack.hpp
==============================================================================
--- trunk/boost/xpressive/detail/utility/sequence_stack.hpp (original)
+++ trunk/boost/xpressive/detail/utility/sequence_stack.hpp 2009-11-11 21:18:37 EST (Wed, 11 Nov 2009)
@@ -21,6 +21,8 @@
namespace boost { namespace xpressive { namespace detail
{
+struct fill_t {} const fill = {};
+
//////////////////////////////////////////////////////////////////////////
// sequence_stack
//
@@ -30,11 +32,35 @@
struct sequence_stack
{
private:
+ static T *allocate(std::size_t size, T const &t)
+ {
+ std::size_t i = 0;
+ T *p = (T *)std::malloc(size * sizeof(T));
+ if(!p) throw std::bad_alloc();
+ try
+ {
+ for(; i < size; ++i)
+ new((void *)(p+i)) T(t);
+ }
+ catch(...)
+ {
+ deallocate(p, i);
+ throw;
+ }
+ return p;
+ }
+
+ static void deallocate(T *p, std::size_t i)
+ {
+ while(i-- > 0)
+ (p+i)->~T();
+ std::free(p);
+ }
struct chunk
{
- chunk(std::size_t size, std::size_t count, chunk *back, chunk *next)
- : begin_(new T[ size ])
+ chunk(std::size_t size, T const &t, std::size_t count, chunk *back, chunk *next)
+ : begin_(allocate(size, t))
, curr_(begin_ + count)
, end_(begin_ + size)
, back_(back)
@@ -48,7 +74,7 @@
~chunk()
{
- delete[] this->begin_;
+ deallocate(this->begin_, this->size());
}
std::size_t size() const
@@ -70,7 +96,7 @@
T *curr_;
T *end_;
- T *grow_(std::size_t count)
+ T *grow_(std::size_t count, T const &t)
{
if(this->current_chunk_)
{
@@ -85,7 +111,7 @@
this->curr_ = this->current_chunk_->curr_ = this->current_chunk_->begin_ + count;
this->end_ = this->current_chunk_->end_;
this->begin_ = this->current_chunk_->begin_;
- std::fill_n(this->begin_, count, T());
+ std::fill_n(this->begin_, count, t);
return this->begin_;
}
@@ -93,7 +119,7 @@
std::size_t new_size = (std::max)(count, static_cast<std::size_t>(this->current_chunk_->size() * 1.5));
// Create a new expr and insert it into the list
- this->current_chunk_ = new chunk(new_size, count, this->current_chunk_, this->current_chunk_->next_);
+ this->current_chunk_ = new chunk(new_size, t, count, this->current_chunk_, this->current_chunk_->next_);
}
else
{
@@ -101,7 +127,7 @@
std::size_t new_size = (std::max)(count, static_cast<std::size_t>(256U));
// Create a new expr and insert it into the list
- this->current_chunk_ = new chunk(new_size, count, 0, 0);
+ this->current_chunk_ = new chunk(new_size, t, count, 0, 0);
}
this->begin_ = this->current_chunk_->begin_;
@@ -173,7 +199,7 @@
this->begin_ = this->curr_ = this->end_ = 0;
}
- T *push_sequence(std::size_t count)
+ T *push_sequence(std::size_t count, T const &t)
{
// This is the ptr to return
T *ptr = this->curr_;
@@ -188,17 +214,16 @@
this->curr_ = ptr;
// allocate a new block and return a ptr to the new memory
- return this->grow_(count);
+ return this->grow_(count, t);
}
return ptr;
}
- template<typename U>
- T *push_sequence(std::size_t count, U const &u)
+ T *push_sequence(std::size_t count, T const &t, fill_t)
{
- T *ptr = this->push_sequence(count);
- std::fill_n(ptr, count, u);
+ T *ptr = this->push_sequence(count, t);
+ std::fill_n(ptr, count, t);
return ptr;
}
Modified: trunk/boost/xpressive/match_results.hpp
==============================================================================
--- trunk/boost/xpressive/match_results.hpp (original)
+++ trunk/boost/xpressive/match_results.hpp 2009-11-11 21:18:37 EST (Wed, 11 Nov 2009)
@@ -40,6 +40,7 @@
#include <boost/utility/enable_if.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/numeric/conversion/converter.hpp>
+#include <boost/optional.hpp>
#include <boost/range/end.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/as_literal.hpp>
@@ -410,14 +411,14 @@
{
extras_type &extras = this->get_extras_();
std::size_t size = that.sub_matches_.size();
- detail::sub_match_impl<BidiIter> *sub_matches = extras.sub_match_stack_.push_sequence(size, detail::sub_match_impl_default());
+ detail::sub_match_impl<BidiIter> *sub_matches = extras.sub_match_stack_.push_sequence(size, detail::sub_match_impl<BidiIter>(*that.base_), detail::fill);
detail::core_access<BidiIter>::init_sub_match_vector(this->sub_matches_, sub_matches, size, that.sub_matches_);
- // BUGBUG this doesn't share the extras::sequence_stack
- this->nested_results_ = that.nested_results_;
+ this->base_ = that.base_;
this->prefix_ = that.prefix_;
this->suffix_ = that.suffix_;
- this->base_ = that.base_;
+ // BUGBUG this doesn't share the extras::sequence_stack
+ this->nested_results_ = that.nested_results_;
this->traits_ = that.traits_;
}
}
@@ -469,7 +470,7 @@
/// of a repeated search with a regex_iterator then base is the same as prefix().first - end note]
difference_type position(size_type sub = 0) const
{
- return this->sub_matches_[ sub ].matched ? std::distance(this->base_, this->sub_matches_[ sub ].first) : -1;
+ return this->sub_matches_[ sub ].matched ? std::distance(*this->base_, this->sub_matches_[ sub ].first) : -1;
}
/// Returns (*this)[sub].str().
@@ -492,18 +493,20 @@
/// Returns a reference to the sub_match object representing the character sequence from
/// the start of the string being matched/searched, to the start of the match found.
- ///
+ ///
+ /// \pre (*this)[0].matched is true
const_reference prefix() const
{
- return this->prefix_;
+ return this->prefix_ ? *this->prefix_ : this->sub_matches_[this->sub_matches_.size()];
}
/// Returns a reference to the sub_match object representing the character sequence from
/// the end of the match found to the end of the string being matched/searched.
///
+ /// \pre (*this)[0].matched is true
const_reference suffix() const
{
- return this->suffix_;
+ return this->suffix_ ? *this->suffix_ : this->sub_matches_[this->sub_matches_.size()];
}
/// Returns a starting iterator that enumerates over all the marked sub-expression matches
@@ -526,7 +529,7 @@
///
operator bool_type() const
{
- return this->sub_matches_[ 0 ].matched ? &dummy::i_ : 0;
+ return (!this->empty() && this->sub_matches_[ 0 ].matched) ? &dummy::i_ : 0;
}
/// Returns true if empty() || !(*this)[0].matched, else returns false.
@@ -738,14 +741,8 @@
void set_prefix_suffix_(BidiIter begin, BidiIter end)
{
this->base_ = begin;
-
- this->prefix_.first = begin;
- this->prefix_.second = this->sub_matches_[ 0 ].first;
- this->prefix_.matched = this->prefix_.first != this->prefix_.second;
-
- this->suffix_.first = this->sub_matches_[ 0 ].second;
- this->suffix_.second = end;
- this->suffix_.matched = this->suffix_.first != this->suffix_.second;
+ this->prefix_ = sub_match<BidiIter>(begin, this->sub_matches_[ 0 ].first, begin != this->sub_matches_[ 0 ].first);
+ this->suffix_ = sub_match<BidiIter>(this->sub_matches_[ 0 ].second, end, this->sub_matches_[ 0 ].second != end);
typename nested_results_type::iterator ibegin = this->nested_results_.begin();
typename nested_results_type::iterator iend = this->nested_results_.end();
@@ -1335,9 +1332,9 @@
regex_id_type regex_id_;
detail::sub_match_vector<BidiIter> sub_matches_;
- BidiIter base_;
- sub_match<BidiIter> prefix_;
- sub_match<BidiIter> suffix_;
+ boost::optional<BidiIter> base_;
+ boost::optional<sub_match<BidiIter> > prefix_;
+ boost::optional<sub_match<BidiIter> > suffix_;
nested_results_type nested_results_;
intrusive_ptr<extras_type> extras_ptr_;
intrusive_ptr<detail::traits<char_type> const> traits_;
Modified: trunk/libs/xpressive/test/Jamfile.v2
==============================================================================
--- trunk/libs/xpressive/test/Jamfile.v2 (original)
+++ trunk/libs/xpressive/test/Jamfile.v2 2009-11-11 21:18:37 EST (Wed, 11 Nov 2009)
@@ -12,6 +12,7 @@
<toolset>msvc-8.0:<define>_SCL_SECURE_NO_DEPRECATE
<toolset>msvc-8.0:<define>_CRT_SECURE_NO_DEPRECATE
<toolset>msvc-9.0:<define>_SCL_SECURE_NO_DEPRECATE
+ <toolset>msvc-10.0:<define>_SCL_SECURE_NO_WARNINGS
<toolset>gcc:<cxxflags>-ftemplate-depth-1024
<toolset>darwin:<cxxflags>-ftemplate-depth-1024
# <toolset>gcc:<cxxflags>-W
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk