Skip to content

Commit

Permalink
Cleanup macros
Browse files Browse the repository at this point in the history
Be consistent in adding a comment at #endifs commenting which #ifdef
is ended remove some handling of ancient compilers.
  • Loading branch information
laudrup committed Feb 3, 2024
1 parent 7e51715 commit 2eee6e0
Show file tree
Hide file tree
Showing 36 changed files with 132 additions and 139 deletions.
8 changes: 4 additions & 4 deletions examples/echo_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

#ifdef WINTLS_USE_STANDALONE_ASIO
#include <asio.hpp>
#else
#else // WINTLS_USE_STANDALONE_ASIO
#include <boost/asio.hpp>
#endif
#endif // !WINTLS_USE_STANDALONE_ASIO

#include <cstdlib>
#include <cstring>
Expand All @@ -22,9 +22,9 @@

#ifdef WINTLS_USE_STANDALONE_ASIO
namespace net = asio;
#else
#else // WINTLS_USE_STANDALONE_ASIO
namespace net = boost::asio;
#endif
#endif //!WINTLS_USE_STANDALONE_ASIO

using net::ip::tcp;

Expand Down
8 changes: 4 additions & 4 deletions examples/echo_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@

#ifdef WINTLS_USE_STANDALONE_ASIO
#include <asio.hpp>
#else
#else // WINTLS_USE_STANDALONE_ASIO
#include <boost/asio.hpp>
#endif
#endif // !WINTLS_USE_STANDALONE_ASIO

#include <cstdlib>
#include <functional>
#include <iostream>

#ifdef WINTLS_USE_STANDALONE_ASIO
namespace net = asio;
#else
#else // WINTLS_USE_STANDALONE_ASIO
namespace net = boost::asio;
#endif
#endif // !WINTLS_USE_STANDALONE_ASIO

using net::ip::tcp;

Expand Down
2 changes: 1 addition & 1 deletion include/boost/wintls/certificate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,4 @@ inline void assign_private_key(const CERT_CONTEXT* cert, const std::string& name
} // namespace wintls
} // namespace boost

#endif
#endif // BOOST_WINTLS_CERTIFICATE_HPP
29 changes: 11 additions & 18 deletions include/boost/wintls/detail/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,22 @@

#include <cassert>

#if defined(NDEBUG)
#ifdef NDEBUG
#define WINTLS_ASSERT_MSG(expr, msg) ((void)(expr))
#else
#else // NDEBUG
#define WINTLS_ASSERT_MSG(expr, msg) assert((expr) && (msg))
#endif
#endif // !NDEBUG

#if defined(NDEBUG)
#ifdef NDEBUG
#define WINTLS_VERIFY_MSG(expr, msg) ((void)(expr))
#else
#else // NDEBUG
#define WINTLS_VERIFY_MSG(expr, msg) assert((expr) && (msg))
#endif
#endif // !NDEBUG

#if defined(__clang__)
#define WINTLS_UNREACHABLE_RETURN(x) __builtin_unreachable();
#elif defined(__GNUC__) || defined(__GNUG__)
#define WINTLS_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#if BOOST_GCC_VERSION >= 40500
#define WINTLS_UNREACHABLE_RETURN(x) __builtin_unreachable();
#else
#define WINTLS_UNREACHABLE_RETURN(x) ;
#endif
#elif defined(_MSC_VER)
#ifdef _MSC_VER
#define WINTLS_UNREACHABLE_RETURN(x) __assume(0);
#endif
#else // _MSC_VER
#define WINTLS_UNREACHABLE_RETURN(x) __builtin_unreachable();
#endif // !_MSC_VER

#endif
#endif // BOOST_WINTLS_DETAIL_ASSERT_HPP
16 changes: 8 additions & 8 deletions include/boost/wintls/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#endif
#endif // __clang__
#ifdef WINTLS_USE_STANDALONE_ASIO
#include <system_error>
#include <asio.hpp>
#else
#else // WINTLS_USE_STANDALONE_ASIO
#include <boost/config.hpp>
#include <boost/system/system_error.hpp>
#include <boost/system/error_code.hpp>
#include <boost/asio.hpp>
#endif
#endif // !WINTLS_USE_STANDALONE_ASIO
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // __clang__

#if !defined(__MINGW32__)
#ifndef __MINGW32__
#pragma comment(lib, "crypt32")
#pragma comment(lib, "secur32")
#endif // __MINGW32__
#endif // !__MINGW32__

namespace boost {
namespace wintls {
Expand All @@ -38,13 +38,13 @@ using system_error = std::system_error;
using error_code = std::error_code;

constexpr auto system_category = std::system_category;
#else
#else // WINTLS_USE_STANDALONE_ASIO
namespace net = boost::asio;
using system_error = boost::system::system_error;
using error_code = boost::system::error_code;

constexpr auto system_category = boost::system::system_category;
#endif
#endif // !WINTLS_USE_STANDALONE_ASIO

} // namespace wintls
} // namespace boost
Expand Down
6 changes: 3 additions & 3 deletions include/boost/wintls/detail/coroutine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#include <asio/coroutine.hpp>
#define WINTLS_ASIO_CORO_YIELD ASIO_CORO_YIELD
#define WINTLS_ASIO_CORO_REENTER ASIO_CORO_REENTER
#else
#else // WINTLS_USE_STANDALONE_ASIO
#include <boost/asio/coroutine.hpp>
#define WINTLS_ASIO_CORO_YIELD BOOST_ASIO_CORO_YIELD
#define WINTLS_ASIO_CORO_REENTER BOOST_ASIO_CORO_REENTER
#endif
#endif // !WINTLS_USE_STANDALONE_ASIO

#endif
#endif // BOOST_WINTLS_DETAIL_COROUTINE_HPP
4 changes: 2 additions & 2 deletions include/boost/wintls/detail/sspi_buffer_sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

#ifdef WINTLS_USE_STANDALONE_ASIO
#include <asio/buffer.hpp>
#else
#else // WINTLS_USE_STANDALONE_ASIO
#include <boost/asio/buffer.hpp>
#endif
#endif // !WINTLS_USE_STANDALONE_ASIO

#include <array>

Expand Down
12 changes: 6 additions & 6 deletions include/boost/wintls/method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@

#ifndef SP_PROT_TLS1_1_SERVER
#define SP_PROT_TLS1_1_SERVER 0x100
#endif
#endif // SP_PROT_TLS1_1_SERVER

#ifndef SP_PROT_TLS1_1_CLIENT
#define SP_PROT_TLS1_1_CLIENT 0x200
#endif
#endif // SP_PROT_TLS1_1_CLIENT

#ifndef SP_PROT_TLS1_2_SERVER
#define SP_PROT_TLS1_2_SERVER 0x400
#endif
#endif // SP_PROT_TLS1_2_SERVER

#ifndef SP_PROT_TLS1_2_CLIENT
#define SP_PROT_TLS1_2_CLIENT 0x800
#endif
#endif // SP_PROT_TLS1_2_CLIENT

#ifndef SP_PROT_TLS1_3_SERVER
#define SP_PROT_TLS1_3_SERVER 0x1000
#endif
#endif // SP_PROT_TLS1_3_SERVER

#ifndef SP_PROT_TLS1_3_CLIENT
#define SP_PROT_TLS1_3_CLIENT 0x2000
#endif
#endif // SP_PROT_TLS1_3_CLIENT

namespace boost {
namespace wintls {
Expand Down
4 changes: 2 additions & 2 deletions include/boost/wintls/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#ifdef WINTLS_USE_STANDALONE_ASIO
#include <asio/compose.hpp>
#include <asio/io_context.hpp>
#else
#else // WINTLS_USE_STANDALONE_ASIO
#include <boost/asio/compose.hpp>
#include <boost/asio/io_context.hpp>
#endif
#endif // !WINTLS_USE_STANDALONE_ASIO

#include <memory>

Expand Down
6 changes: 3 additions & 3 deletions test/asio_ssl_client_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_SSL_CLIENT_STREAM_HPP
#define ASIO_SSL_CLIENT_STREAM_HPP
#ifndef BOOST_WINTLS_TEST_ASIO_SSL_CLIENT_STREAM_HPP
#define BOOST_WINTLS_TEST_ASIO_SSL_CLIENT_STREAM_HPP

#include "unittest.hpp"
#include "certificate.hpp"
Expand Down Expand Up @@ -51,4 +51,4 @@ struct asio_ssl_client_stream {
asio_ssl::stream<test_stream&> stream;
};

#endif // ASIO_SSL_CLIENT_STREAM_HPP
#endif // BOOST_WINTLS_TEST_ASIO_SSL_CLIENT_STREAM_HPP
6 changes: 3 additions & 3 deletions test/asio_ssl_server_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_SSL_SERVER_STREAM_HPP
#define ASIO_SSL_SERVER_STREAM_HPP
#ifndef BOOST_WINTLS_TEST_ASIO_SSL_SERVER_STREAM_HPP
#define BOOST_WINTLS_TEST_ASIO_SSL_SERVER_STREAM_HPP

#include "certificate.hpp"
#include "unittest.hpp"
Expand Down Expand Up @@ -37,4 +37,4 @@ struct asio_ssl_server_stream {
asio_ssl::stream<test_stream&> stream;
};

#endif // ASIO_SSL_SERVER_STREAM_HPP
#endif // BOOST_WINTLS_TEST_ASIO_SSL_SERVER_STREAM_HPP
6 changes: 3 additions & 3 deletions test/certificate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef WINTLS_CERTIFICATE_HPP
#define WINTLS_CERTIFICATE_HPP
#ifndef BOOST_WINTLS_TEST_CERTIFICATE_HPP
#define BOOST_WINTLS_TEST_CERTIFICATE_HPP

#include <string>

Expand Down Expand Up @@ -63,4 +63,4 @@ const std::string test_key =
"-----END PRIVATE KEY-----\n";

const std::string test_key_name="boost-wintls-test-key";
#endif
#endif // BOOST_WINTLS_TEST_CERTIFICATE_HPP
4 changes: 2 additions & 2 deletions test/certificate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ bool container_exists(const std::string& name) {
}
#ifdef WINTLS_USE_STANDALONE_ASIO
throw std::system_error(static_cast<int>(last_error), std::system_category());
#else
#else // WINTLS_USE_STANDALONE_ASIO
throw boost::system::system_error(static_cast<int>(last_error), boost::system::system_category());
#endif
#endif // !WINTLS_USE_STANDALONE_ASIO
}
CryptReleaseContext(ptr, 0);
return true;
Expand Down
4 changes: 2 additions & 2 deletions test/handshake_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ const auto& get_system_category = std::system_category;
#define WINTLS_TEST_ERROR_NAMESPACE_ALIAS() \
using std::errc; \
namespace err_help = std;
#else
#else // WINTLS_USE_STANDALONE_ASIO
const auto& get_system_category = boost::system::system_category;
#define WINTLS_TEST_ERROR_NAMESPACE_ALIAS()
using namespace boost::system; \
namespace err_help = boost::system::errc;
#endif
#endif // !WINTLS_USE_STANDALONE_ASIO

namespace boost {
namespace wintls {
Expand Down
6 changes: 3 additions & 3 deletions test/ocsp_responder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#ifndef BOOST_WINTLS_OCSP_RESPONDER_HPP
#define BOOST_WINTLS_OCSP_RESPONDER_HPP
#ifndef BOOST_WINTLS_TEST_OCSP_RESPONDER_HPP
#define BOOST_WINTLS_TEST_OCSP_RESPONDER_HPP

class ocsp_responder {
public:
Expand All @@ -17,4 +17,4 @@ class ocsp_responder {
void* proc_handle_ = nullptr;
};

#endif
#endif // BOOST_WINTLS_TEST_OCSP_RESPONDER_HPP
4 changes: 2 additions & 2 deletions test/stream_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

#ifdef WINTLS_USE_STANDALONE_ASIO
#include <asio/io_context.hpp>
#else
#else // WINTLS_USE_STANDALONE_ASIO
#include <boost/asio/io_context.hpp>
#endif
#endif // !WINTLS_USE_STANDALONE_ASIO

#include <array>
#include <thread>
Expand Down
6 changes: 3 additions & 3 deletions test/test_stream/allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
// Official repository: https://github.com/boostorg/beast
//

#ifndef BOOST_WINTLS_TEST_STREAM_ALLOCATOR_HPP
#define BOOST_WINTLS_TEST_STREAM_ALLOCATOR_HPP
#ifndef BOOST_WINTLS_TEST_TEST_STREAM_ALLOCATOR_HPP
#define BOOST_WINTLS_TEST_TEST_STREAM_ALLOCATOR_HPP

#include <memory>

Expand All @@ -26,4 +26,4 @@ using allocator_traits = std::allocator_traits<Alloc>;
} // namespace wintls
} // namespace boost

#endif
#endif // BOOST_WINTLS_TEST_TEST_STREAM_ALLOCATOR_HPP
14 changes: 7 additions & 7 deletions test/test_stream/config.hpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
#ifndef BOOST_WINTLS_TEST_STREAM_CONFIG_HPP
#define BOOST_WINTLS_TEST_STREAM_CONFIG_HPP
#ifndef BOOST_WINTLS_TEST_TEST_STREAM_CONFIG_HPP
#define BOOST_WINTLS_TEST_TEST_STREAM_CONFIG_HPP

#ifdef WINTLS_USE_STANDALONE_ASIO
#include <system_error>
#include <asio.hpp>
#else
#else // WINTLS_USE_STANDALONE_ASIO
#include <boost/config.hpp>
#include <boost/system/system_error.hpp>
#include <boost/system/error_code.hpp>
#include <boost/asio.hpp>
#endif
#endif // !WINTLS_USE_STANDALONE_ASIO

#ifdef WINTLS_USE_STANDALONE_ASIO
namespace net = asio;
using system_error = std::system_error;
using error_code = std::error_code;
using error_category = std::error_category;
using error_condition = std::error_condition;
#else
#else // WINTLS_USE_STANDALONE_ASIO
namespace net = boost::asio;
using system_error = boost::system::system_error;
using error_code = boost::system::error_code;
using error_category = boost::system::error_category;
using error_condition = boost::system::error_condition;
#endif
#endif // !WINTLS_USE_STANDALONE_ASIO

#endif
#endif // BOOST_WINTLS_TEST_TEST_STREAM_CONFIG_HPP
6 changes: 3 additions & 3 deletions test/test_stream/empty_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Copyright 2018 Glen Joseph Fernandes
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_WINTLS_TEST_STREAM_EMPTY_VALUE_HPP
#define BOOST_WINTLS_TEST_STREAM_EMPTY_VALUE_HPP
#ifndef BOOST_WINTLS_TEST_TEST_STREAM_EMPTY_VALUE_HPP
#define BOOST_WINTLS_TEST_TEST_STREAM_EMPTY_VALUE_HPP

#include <utility>

Expand Down Expand Up @@ -84,4 +84,4 @@ using empty_::empty_value;
} // namespace wintls
} // namespace boost

#endif
#endif // BOOST_WINTLS_TEST_TEST_STREAM_EMPTY_VALUE_HPP
Loading

0 comments on commit 2eee6e0

Please sign in to comment.