Skip to content

Commit

Permalink
Remove uses of BOOST_SYSTEM_HAS_SYSTEM_ERROR
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Jan 17, 2024
1 parent 80e0190 commit 3ded81e
Show file tree
Hide file tree
Showing 33 changed files with 16 additions and 357 deletions.
4 changes: 0 additions & 4 deletions include/boost/system/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
//
// https://github.com/boostorg/system/issues/92

// BOOST_SYSTEM_HAS_SYSTEM_ERROR

#define BOOST_SYSTEM_HAS_SYSTEM_ERROR

// BOOST_SYSTEM_NOEXCEPT
// Retained for backward compatibility

Expand Down
19 changes: 2 additions & 17 deletions include/boost/system/detail/error_category.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
#include <string>
#include <functional>
#include <cstddef>

#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
# include <system_error>
# include <atomic>
#endif
#include <system_error>
#include <atomic>

namespace boost
{
Expand Down Expand Up @@ -81,16 +78,8 @@ class BOOST_SYMBOL_VISIBLE error_category
void const* stdcat_align_;
};

#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

mutable std::atomic< unsigned > sc_init_;

#else

unsigned sc_init_;

#endif

protected:

~error_category() = default;
Expand Down Expand Up @@ -156,17 +145,13 @@ class BOOST_SYMBOL_VISIBLE error_category
return std::less<error_category const *>()( &lhs, &rhs );
}

#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

void init_stdcat() const;

# if defined(__SUNPRO_CC) // trailing __global is not supported
operator std::error_category const & () const;
# else
operator std::error_category const & () const BOOST_SYMBOL_VISIBLE;
# endif

#endif
};

#if defined(BOOST_MSVC) && BOOST_MSVC < 1900
Expand Down
4 changes: 0 additions & 4 deletions include/boost/system/detail/error_category_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ inline char const * error_category::message( int ev, char * buffer, std::size_t

// interoperability with std::error_code, std::error_condition

#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

#include <boost/system/detail/std_category_impl.hpp>
#include <boost/system/detail/mutex.hpp>
#include <new>
Expand Down Expand Up @@ -165,6 +163,4 @@ inline BOOST_NOINLINE error_category::operator std::error_category const & () co
} // namespace system
} // namespace boost

#endif // #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

#endif // #ifndef BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_IMPL_HPP_INCLUDED
61 changes: 5 additions & 56 deletions include/boost/system/detail/error_code.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,15 @@
#include <boost/system/detail/append_int.hpp>
#include <boost/system/detail/snprintf.hpp>
#include <boost/system/detail/config.hpp>

#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
# include <boost/system/detail/std_category.hpp>
#endif

#include <boost/system/detail/std_category.hpp>
#include <boost/assert/source_location.hpp>
#include <boost/cstdint.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <ostream>
#include <new>
#include <cstdio>

#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
# include <system_error>
#endif
#include <system_error>

#if defined(BOOST_GCC) && BOOST_GCC >= 40600 && BOOST_GCC < 70000
# pragma GCC diagnostic push
Expand Down Expand Up @@ -79,9 +72,7 @@ class error_code
union
{
data d1_;
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
unsigned char d2_[ sizeof(std::error_code) ];
#endif
};

// 0: default constructed, d1_ value initialized
Expand Down Expand Up @@ -142,9 +133,7 @@ class error_code
template<class ErrorCodeEnum> BOOST_SYSTEM_CONSTEXPR error_code( ErrorCodeEnum e,
typename detail::enable_if<
is_error_code_enum<ErrorCodeEnum>::value
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|| std::is_error_code_enum<ErrorCodeEnum>::value
#endif
>::type* = 0 ) BOOST_NOEXCEPT: d1_(), lc_flags_( 0 )
{
*this = make_error_code( e );
Expand All @@ -161,8 +150,6 @@ class error_code
}
}

#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

error_code( std::error_code const& ec ) BOOST_NOEXCEPT:
d1_(), lc_flags_( 0 )
{
Expand All @@ -181,8 +168,6 @@ class error_code
}
}

#endif

// modifiers:

BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) BOOST_NOEXCEPT
Expand Down Expand Up @@ -223,18 +208,12 @@ class error_code
}
else
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );

unsigned cv = static_cast<unsigned>( ec.value() );
unsigned ch = static_cast<unsigned>( reinterpret_cast<boost::uintptr_t>( &ec.category() ) % 2097143 ); // 2^21-9, prime

return static_cast<int>( cv + 1000 * ch );
#else

return -1;
#endif
}
}

Expand Down Expand Up @@ -262,17 +241,12 @@ class error_code

std::string message() const
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

if( lc_flags_ == 1 )
{
std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
return ec.message();
}

#endif

if( lc_flags_ == 0 )
else if( lc_flags_ == 0 )
{
return detail::system_error_category_message( value() );
}
Expand All @@ -284,7 +258,6 @@ class error_code

char const * message( char * buffer, std::size_t len ) const BOOST_NOEXCEPT
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( lc_flags_ == 1 )
{
std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
Expand All @@ -304,9 +277,7 @@ class error_code
}
#endif
}
#endif

if( lc_flags_ == 0 )
else if( lc_flags_ == 0 )
{
return detail::system_error_category_message( value(), buffer, len );
}
Expand All @@ -320,13 +291,12 @@ class error_code
{
if( lc_flags_ & 1 )
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( lc_flags_ == 1 )
{
std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
return ec.value() != 0;
}
#endif

return true;
}
else
Expand Down Expand Up @@ -382,8 +352,6 @@ class error_code

BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

bool s1 = lhs.lc_flags_ == 1;
bool s2 = rhs.lc_flags_ == 1;

Expand All @@ -397,16 +365,13 @@ class error_code
return e1 == e2;
}
else
#endif
{
return lhs.value() == rhs.value() && lhs.category() == rhs.category();
}
}

BOOST_SYSTEM_CONSTEXPR inline friend bool operator<( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

bool s1 = lhs.lc_flags_ == 1;
bool s2 = rhs.lc_flags_ == 1;

Expand All @@ -421,7 +386,6 @@ class error_code
return e1 < e2;
}
else
#endif
{
return lhs.category() < rhs.category() || (lhs.category() == rhs.category() && lhs.value() < rhs.value());
}
Expand All @@ -432,8 +396,6 @@ class error_code
return !( lhs == rhs );
}

#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

inline friend bool operator==( std::error_code const & lhs, error_code const & rhs ) BOOST_NOEXCEPT
{
return lhs == static_cast< std::error_code >( rhs );
Expand Down Expand Up @@ -582,14 +544,10 @@ class error_code
class E = typename std::enable_if<std::is_same<T, std::error_code>::value>::type>
operator T const& () = delete;

#endif

#endif

std::string to_string() const
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

if( lc_flags_ == 1 )
{
std::error_code const& e2 = *reinterpret_cast<std::error_code const*>( d2_ );
Expand All @@ -601,7 +559,6 @@ class error_code
return r;
}
else
#endif
{
std::string r = category_name();
detail::append_int( r, value() );
Expand Down Expand Up @@ -636,15 +593,11 @@ class error_code

inline bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

if( code.lc_flags_ == 1 )
{
return static_cast<std::error_code>( code ) == static_cast<std::error_condition>( condition );
}
else

#endif
{
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
}
Expand All @@ -667,16 +620,12 @@ inline bool operator!=( const error_condition & lhs, const error_code & rhs ) BO

inline std::size_t hash_value( error_code const & ec )
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

if( ec.lc_flags_ == 1 )
{
std::error_code const& e2 = *reinterpret_cast<std::error_code const*>( ec.d2_ );
return std::hash<std::error_code>()( e2 );
}

#endif

error_category const & cat = ec.category();

boost::ulong_long_type id_ = cat.id_;
Expand Down
4 changes: 0 additions & 4 deletions include/boost/system/detail/error_condition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ class error_condition
return !( lhs == rhs );
}

#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

operator std::error_condition () const
{
// This condition must be the same as the one in error_category_impl.hpp
Expand Down Expand Up @@ -294,8 +292,6 @@ class error_condition
return !( lhs == rhs );
}

#endif

std::string to_string() const
{
std::string r( "cond:" );
Expand Down
6 changes: 0 additions & 6 deletions test/ec_hash_value_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
#include <boost/system/system_category.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cerrno>
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
#include <system_error>
#endif

namespace sys = boost::system;

Expand Down Expand Up @@ -69,8 +67,6 @@ int main()
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}

#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

// std:: wrapping against normal
{
std::error_code e1( EINVAL, std::generic_category() );
Expand Down Expand Up @@ -126,7 +122,5 @@ int main()
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}

#endif

return boost::report_errors();
}
6 changes: 1 addition & 5 deletions test/ec_location_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ int main()
BOOST_TEST_EQ( ec.location().line(), 75 );
}

#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

{
std::error_code e2( val, std::generic_category() );

Expand All @@ -107,10 +105,8 @@ int main()
BOOST_TEST( ec.failed() );

BOOST_TEST( ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 100 );
BOOST_TEST_EQ( ec.location().line(), 98 );
}

#endif

return boost::report_errors();
}
Loading

0 comments on commit 3ded81e

Please sign in to comment.