Skip to content

Commit dec6d24

Browse files
authored
Update gsl-lite dependency to v1.0 (#264)
* Update gsl-lite dependency to v1.0 * `gsl_lite::span<>::iterator` is not a pointer anymore * `gsl_lite::span<>` does not define comparison operators by default The least invasive fix would be to re-enable span comparison operators by defining `gsl_CONFIG_ALLOWS_SPAN_COMPARISON=1`. However, comparison operators are no longer provided by default for good reason (unclear semantics), and C++20 `std::span<>` doesn't have comparison operators either, so this appears to be the most forward-looking way to handle it. * Bump version number of package requirement * Remove unnecessary build switch The gsl-lite build script is well-behaved an d does not build tests by default. * Avoid warning about parameter shadowing
1 parent 5e0fc6e commit dec6d24

File tree

10 files changed

+68
-32
lines changed

10 files changed

+68
-32
lines changed

.ci/fetch_system_dependencies.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
#!/bin/bash
1+
#!/bin/bash
22
if [ -z ${EXTERNAL_ROOT+x} ]; then echo EXTERNAL_ROOT not set; exit 1; fi
33

44
export EXTERNAL_BUILD_ROOT=$HOME/external_build
55

66
mkdir "$EXTERNAL_BUILD_ROOT" || true
77

88
# Install gsl-lite dependency
9-
if [ ! -f "$EXTERNAL_ROOT/include/gsl/gsl-lite.hpp" ]; then
9+
if [ ! -f "$EXTERNAL_ROOT/include/gsl-lite/gsl-lite.hpp" ]; then
1010
cd "$EXTERNAL_BUILD_ROOT";
11-
wget https://github.com/gsl-lite/gsl-lite/archive/refs/tags/v0.38.1.tar.gz;
12-
tar -xzf v0.38.1.tar.gz;
13-
cd gsl-lite-0.38.1;
14-
cmake -DCMAKE_INSTALL_PREFIX="$EXTERNAL_ROOT" -DGSL_LITE_OPT_BUILD_TESTS=Off .;
11+
wget https://github.com/gsl-lite/gsl-lite/archive/refs/tags/v1.0.1.tar.gz;
12+
tar -xzf v1.0.1.tar.gz;
13+
cd gsl-lite-1.0.1;
14+
cmake -DCMAKE_INSTALL_PREFIX="$EXTERNAL_ROOT" .;
1515
make -j2 && make install;
1616
fi
1717

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
22
cmake_policy(VERSION 3.13)
33

44
option(TELNETPP_WITH_ZLIB "Build using ZLib" False)
@@ -51,8 +51,8 @@ endif()
5151
# Telnet++ requires at least Boost 1.69.
5252
find_package(Boost 1.69.0 REQUIRED)
5353

54-
# Telnet++ requires at least version 0.38 of gsl-lite.
55-
find_package(gsl-lite 0.38.0 REQUIRED)
54+
# Telnet++ requires at least version 1.0.1 of gsl-lite.
55+
find_package(gsl-lite 1.0.1 REQUIRED)
5656

5757
# If we are building with ZLib, then we require the ZLib library
5858
if (${TELNETPP_WITH_ZLIB})
@@ -168,7 +168,7 @@ target_sources(telnetpp
168168
target_link_libraries(telnetpp
169169
PUBLIC
170170
Boost::boost
171-
gsl::gsl-lite
171+
gsl-lite::gsl-lite
172172
)
173173

174174
# The zlib compressors for MCCP should only be compiled into the library

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Telnet++ is an implementation of the Telnet Session Layer protocol that is used
1717

1818
Telnet++ requires a C++17 compiler and the following libraries:
1919
* Boost (At least version 1.69.0)
20-
* GSL-lite (At least version 1.38)
20+
* gsl-lite (At least version 1.0)
2121
* (Optionally) ZLib
2222
* (For testing only) Google Test
2323

2424
# Installation - CMake
2525

26-
Telnet++ can be installed from source using CMake. This requires Boost, GSL-Lite and any other dependencies to have been installed beforehand, using their own instructions, or for the call to `cmake --configure` to be adjusted appropriately (e.g. `-DBOOST_ROOT=...` or `-Dgsl-lite_DIR=...`). If you do not wish to install into a system directory, and thus avoid the use of sudo, you can also pass `-DCMAKE_INSTALL_PREFIX=...` into the `cmake --configure` call.
26+
Telnet++ can be installed from source using CMake. This requires Boost, gsl-lite and any other dependencies to have been installed beforehand, using their own instructions, or for the call to `cmake --configure` to be adjusted appropriately (e.g. `-DBOOST_ROOT=...` or `-Dgsl-lite_DIR=...`). If you do not wish to install into a system directory, and thus avoid the use of sudo, you can also pass `-DCMAKE_INSTALL_PREFIX=...` into the `cmake --configure` call.
2727

2828
git clone https://github.com/KazDragon/telnetpp.git && cd telnetpp
2929
mkdir build && cd build

include/telnetpp/core.hpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
#pragma once
1+
#pragma once
22

33
#include "telnetpp/detail/export.hpp" // IWYU pragma: export
44

5-
#include <gsl/gsl-lite.hpp>
5+
#include <gsl-lite/gsl-lite.hpp>
66

77
#include <string>
88
#include <cstdint>
9+
#include <algorithm>
910

1011
namespace telnetpp {
1112

13+
namespace gsl = ::gsl_lite;
14+
1215
using byte = std::uint8_t;
1316
using option_type = std::uint8_t;
1417
using command_type = std::uint8_t;
@@ -44,6 +47,17 @@ using bytes = gsl::span<byte const>;
4447
// string optimization, meaning that most cases will not cause an allocation.
4548
using byte_storage = std::basic_string<byte>;
4649

50+
// Comparison function for bytes.
51+
// gsl::span<>, like std::span<> in C++20, does not define comparison
52+
// operators by default because the semantics are unclear (deep or shallow?).
53+
// This named comparison function is provided because we cannot define a
54+
// useful operator== because ADL would not find it in our namespace.
55+
constexpr inline auto bytes_equal = [](
56+
bytes const &lhs, bytes const &rhs) noexcept
57+
{
58+
return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
59+
};
60+
4761
namespace literals {
4862

4963
// A simple function to convert from string literals to stored bytes.

include/telnetpp/element.hpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
#include "telnetpp/command.hpp" // IWYU pragma: export
44
#include "telnetpp/core.hpp"
@@ -18,6 +18,28 @@ namespace telnetpp {
1818
//* =========================================================================
1919
using element = std::variant<bytes, negotiation, subnegotiation, command>;
2020

21+
//* =========================================================================
22+
/// \brief Equality comparison operator for a telnetpp::element.
23+
//* =========================================================================
24+
gsl_constexpr20 inline bool operator==(
25+
element const &lhs, element const &rhs) noexcept
26+
{
27+
auto visitor = [&rhs](auto const& _lhs) noexcept
28+
{
29+
using T = gsl::std20::remove_cvref_t<decltype(_lhs)>;
30+
if constexpr (std::is_same_v<T, bytes>)
31+
{
32+
return telnetpp::bytes_equal(_lhs, std::get<bytes>(rhs));
33+
}
34+
else
35+
{
36+
return _lhs == std::get<T>(rhs);
37+
}
38+
};
39+
if (lhs.index() != rhs.index()) return false;
40+
return std::visit(visitor, lhs);
41+
}
42+
2143
//* =========================================================================
2244
/// \brief A contiguous range of elements.
2345
//* =========================================================================

include/telnetpp/options/new_environ/detail/for_each_request.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
#include "telnetpp/core.hpp"
44
#include "telnetpp/options/new_environ/detail/request_parser_helper.hpp"
@@ -10,8 +10,8 @@ void for_each_request(telnetpp::bytes requests, Continuation &&cont)
1010
{
1111
request_parsing_state state;
1212

13-
auto const *current = requests.begin();
14-
auto const *end = requests.end();
13+
auto current = requests.begin();
14+
auto end = requests.end();
1515

1616
while (current != end)
1717
{

include/telnetpp/options/new_environ/detail/for_each_response.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
#include "telnetpp/options/new_environ/detail/response_parser_helper.hpp"
44

@@ -9,8 +9,8 @@ void for_each_response(telnetpp::bytes content, Continuation &&cont)
99
{
1010
parsing_state state;
1111

12-
auto const *current = content.begin();
13-
auto const *end = content.end();
12+
auto current = content.begin();
13+
auto end = content.end();
1414

1515
while (current != end)
1616
{

include/telnetpp/subnegotiation.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
#include "telnetpp/core.hpp"
44

@@ -45,11 +45,11 @@ class TELNETPP_EXPORT subnegotiation
4545
//* =========================================================================
4646
/// \brief Comparison function for subnegotiations
4747
//* =========================================================================
48-
TELNETPP_EXPORT
49-
constexpr bool operator==(
48+
gsl_constexpr20 inline bool operator==(
5049
subnegotiation const &lhs, subnegotiation const &rhs) noexcept
5150
{
52-
return lhs.option() == rhs.option() && lhs.content() == rhs.content();
51+
return lhs.option() == rhs.option() &&
52+
telnetpp::bytes_equal(lhs.content(), rhs.content());
5353
}
5454

5555
//* =========================================================================

test/mccp_zlib_compressor_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <boost/range/algorithm/generate.hpp>
1+
#include <boost/range/algorithm/generate.hpp>
22
#include <gtest/gtest.h>
33
#include <telnetpp/options/mccp/zlib/compressor.hpp>
44
#include <zlib.h>
@@ -110,7 +110,7 @@ TEST_F(a_started_zlib_compressor, compresses_received_data)
110110

111111
auto const expected_data = telnetpp::bytes{test_data};
112112

113-
ASSERT_EQ(expected_data, output_data);
113+
ASSERT_TRUE(telnetpp::bytes_equal(expected_data, output_data));
114114
ASSERT_FALSE(compression_ended_);
115115

116116
inflateEnd(&stream);
@@ -141,7 +141,7 @@ TEST_F(a_started_zlib_compressor, sends_a_stream_end_when_compression_is_ended)
141141

142142
auto const expected_data = telnetpp::bytes{test_data};
143143

144-
ASSERT_EQ(expected_data, output_data);
144+
ASSERT_TRUE(telnetpp::bytes_equal(expected_data, output_data));
145145
ASSERT_TRUE(compression_ended_);
146146

147147
inflateEnd(&stream);

test/parser_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <gtest/gtest.h>
1+
#include <gtest/gtest.h>
22
#include <telnetpp/element.hpp>
33
#include <telnetpp/parser.hpp>
44

@@ -71,7 +71,7 @@ TEST_F(parser_test, two_normal_characters_parse_to_string)
7171
static constexpr telnetpp::bytes const expected{expected_values};
7272

7373
auto const actual = std::get<telnetpp::bytes>(elem);
74-
ASSERT_EQ(expected, actual);
74+
ASSERT_TRUE(telnetpp::bytes_equal(expected, actual));
7575
});
7676

7777
ASSERT_EQ(size_t{1}, result_.size());
@@ -95,7 +95,7 @@ TEST_F(parser_test, byte_then_iac_emits_byte_only)
9595
static constexpr telnetpp::bytes const expected{expected_values};
9696

9797
auto const actual = std::get<telnetpp::bytes>(elem);
98-
ASSERT_EQ(expected, actual);
98+
ASSERT_TRUE(telnetpp::bytes_equal(expected, actual));
9999
});
100100

101101
ASSERT_EQ(size_t{1}, result_.size());
@@ -110,7 +110,7 @@ TEST_F(parser_test, double_iac_parses_to_iac)
110110
static constexpr telnetpp::bytes const expected{expected_values};
111111

112112
auto const actual = std::get<telnetpp::bytes>(elem);
113-
ASSERT_EQ(expected, actual);
113+
ASSERT_TRUE(telnetpp::bytes_equal(expected, actual));
114114
});
115115

116116
ASSERT_EQ(size_t{1}, result_.size());

0 commit comments

Comments
 (0)