From 4e9d5c79f732502fc8bc9fa506d78aef41724284 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Wed, 19 Apr 2023 10:43:25 -0400 Subject: [PATCH 1/2] Fix comparison of different signedness warning --- include/chainbase/undo_index.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/chainbase/undo_index.hpp b/include/chainbase/undo_index.hpp index 6377407..ec1d719 100644 --- a/include/chainbase/undo_index.hpp +++ b/include/chainbase/undo_index.hpp @@ -521,7 +521,7 @@ namespace chainbase { if( _undo_stack.size() != 0 ) BOOST_THROW_EXCEPTION( std::logic_error("cannot set revision while there is an existing undo stack") ); - if( revision > std::numeric_limits::max() ) + if( revision > static_cast(std::numeric_limits::max()) ) BOOST_THROW_EXCEPTION( std::logic_error("revision to set is too high") ); if( static_cast(revision) < _revision ) From 7d32482b6e757fed351a56a9d030ce34c60f17b2 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Wed, 19 Apr 2023 13:25:06 -0400 Subject: [PATCH 2/2] Change _revision from int64_t to uint64_t to have cleaner code and warnings free --- include/chainbase/chainbase.hpp | 4 ++-- include/chainbase/undo_index.hpp | 17 +++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/include/chainbase/chainbase.hpp b/include/chainbase/chainbase.hpp index 393aa07..546c03f 100644 --- a/include/chainbase/chainbase.hpp +++ b/include/chainbase/chainbase.hpp @@ -162,7 +162,7 @@ namespace chainbase { virtual uint32_t type_id()const = 0; virtual uint64_t row_count()const = 0; virtual const std::string& type_name()const = 0; - virtual std::pair undo_stack_revision_range()const = 0; + virtual std::pair undo_stack_revision_range()const = 0; virtual void remove_object( int64_t id ) = 0; @@ -189,7 +189,7 @@ namespace chainbase { virtual uint32_t type_id()const override { return BaseIndex::value_type::type_id; } virtual uint64_t row_count()const override { return _base.indices().size(); } virtual const std::string& type_name() const override { return BaseIndex_name; } - virtual std::pair undo_stack_revision_range()const override { return _base.undo_stack_revision_range(); } + virtual std::pair undo_stack_revision_range()const override { return _base.undo_stack_revision_range(); } virtual void remove_object( int64_t id ) override { return _base.remove_object( id ); } private: diff --git a/include/chainbase/undo_index.hpp b/include/chainbase/undo_index.hpp index ec1d719..1d146e7 100644 --- a/include/chainbase/undo_index.hpp +++ b/include/chainbase/undo_index.hpp @@ -511,7 +511,7 @@ namespace chainbase { bool _apply = true; }; - int64_t revision() const { return _revision; } + uint64_t revision() const { return _revision; } session start_undo_session( bool enabled ) { return session{*this, enabled}; @@ -521,28 +521,25 @@ namespace chainbase { if( _undo_stack.size() != 0 ) BOOST_THROW_EXCEPTION( std::logic_error("cannot set revision while there is an existing undo stack") ); - if( revision > static_cast(std::numeric_limits::max()) ) - BOOST_THROW_EXCEPTION( std::logic_error("revision to set is too high") ); - - if( static_cast(revision) < _revision ) + if( revision < _revision ) BOOST_THROW_EXCEPTION( std::logic_error("revision cannot decrease") ); - _revision = static_cast(revision); + _revision = revision; } - std::pair undo_stack_revision_range() const { + std::pair undo_stack_revision_range() const { return { _revision - _undo_stack.size(), _revision }; } /** * Discards all undo history prior to revision */ - void commit( int64_t revision ) noexcept { + void commit( uint64_t revision ) noexcept { revision = std::min(revision, _revision); if (revision == _revision) { dispose_undo(); _undo_stack.clear(); - } else if( static_cast(_revision - revision) < _undo_stack.size() ) { + } else if( _revision - revision < _undo_stack.size() ) { auto iter = _undo_stack.begin() + (_undo_stack.size() - (_revision - revision)); dispose(get_old_values_end(*iter), get_removed_values_end(*iter)); _undo_stack.erase(_undo_stack.begin(), iter); @@ -897,7 +894,7 @@ namespace chainbase { rebind_alloc_t _allocator; rebind_alloc_t _old_values_allocator; id_type _next_id = 0; - int64_t _revision = 0; + uint64_t _revision = 0; uint64_t _monotonic_revision = 0; uint32_t _size_of_value_type = sizeof(node); uint32_t _size_of_this = sizeof(undo_index);