Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for span<T> as a sequence view-type #1969

Merged
merged 8 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@
"xtree": "cpp",
"execution": "cpp",
"type_traits": "cpp",
"cassert": "cpp"
"cassert": "cpp",
"span": "cpp"
},
"C_Cpp.default.cppStandard": "c++20",
"cSpell.words": [
"unmarshal",
"unmarshaling"
],
}
2 changes: 1 addition & 1 deletion cpp/include/Ice/AsyncResponseHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace IceInternal
// else we ignore this call.
}

void sendResponse(bool ok, const std::pair<const std::byte*, const std::byte*>& encaps) noexcept
void sendResponse(bool ok, std::pair<const std::byte*, const std::byte*> encaps) noexcept
{
if (!_responseSent.test_and_set())
{
Expand Down
1 change: 0 additions & 1 deletion cpp/include/Ice/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "ProxyF.h"
#include "ValueF.h"
#include "Exception.h"
#include "StreamHelpers.h"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated cleanup - should have been included in a separate PR.

#include "Comparable.h"
#include "ObjectAdapterF.h"
#include "Ice/Identity.h"
Expand Down
1 change: 0 additions & 1 deletion cpp/include/Ice/Endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "ProxyF.h"
#include "ValueF.h"
#include "Exception.h"
#include "StreamHelpers.h"
#include "Comparable.h"
#include "Ice/Version.h"
#include "Ice/BuiltinSequences.h"
Expand Down
10 changes: 5 additions & 5 deletions cpp/include/Ice/InputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "CommunicatorF.h"
#include "InstanceF.h"
#include "Object.h"
#include "ValueF.h"
#include "ProxyF.h"
#include "LoggerF.h"
Expand All @@ -22,6 +21,7 @@

#include <cassert>
#include <cstdint>
#include <map>
#include <string>
#include <string_view>

Expand Down Expand Up @@ -81,7 +81,7 @@ namespace Ice
* You can supply a communicator later by calling initialize().
* @param bytes The encoded data.
*/
InputStream(const std::pair<const std::byte*, const std::byte*>& bytes);
InputStream(std::pair<const std::byte*, const std::byte*> bytes);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now pass pairs of pointers by value instead of const&, just like other "view types".


/// \cond INTERNAL
InputStream(IceInternal::Buffer&, bool = false);
Expand All @@ -105,7 +105,7 @@ namespace Ice
* @param communicator The communicator to use for unmarshaling tasks.
* @param bytes The encoded data.
*/
InputStream(const CommunicatorPtr& communicator, const std::pair<const std::byte*, const std::byte*>& bytes);
InputStream(const CommunicatorPtr& communicator, std::pair<const std::byte*, const std::byte*> bytes);

/// \cond INTERNAL
InputStream(const CommunicatorPtr& communicator, IceInternal::Buffer&, bool = false);
Expand Down Expand Up @@ -138,7 +138,7 @@ namespace Ice
* @param version The encoding version used to encode the data to be unmarshaled.
* @param bytes The encoded data.
*/
InputStream(const EncodingVersion& version, const std::pair<const std::byte*, const std::byte*>& bytes);
InputStream(const EncodingVersion& version, std::pair<const std::byte*, const std::byte*> bytes);

/// \cond INTERNAL
InputStream(const EncodingVersion&, IceInternal::Buffer&, bool = false);
Expand Down Expand Up @@ -171,7 +171,7 @@ namespace Ice
InputStream(
const CommunicatorPtr& communicator,
const EncodingVersion& version,
const std::pair<const std::byte*, const std::byte*>& bytes);
std::pair<const std::byte*, const std::byte*> bytes);

/// \cond INTERNAL
InputStream(const CommunicatorPtr&, const EncodingVersion&, IceInternal::Buffer&, bool = false);
Expand Down
1 change: 0 additions & 1 deletion cpp/include/Ice/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "ProxyF.h"
#include "ValueF.h"
#include "Exception.h"
#include "StreamHelpers.h"
#include "Comparable.h"
#include "IceUtil/UndefSysMacros.h"

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/Ice/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ namespace Ice
*/
virtual void ice_invokeAsync(
std::pair<const std::byte*, const std::byte*> inEncaps,
std::function<void(bool, const std::pair<const std::byte*, const std::byte*>&)> response,
std::function<void(bool, std::pair<const std::byte*, const std::byte*>)> response,
std::function<void(std::exception_ptr)> error,
const Current& current) = 0;

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/Ice/OutgoingResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace Ice
*/
ICE_API OutgoingResponse makeOutgoingResponse(
bool ok,
const std::pair<const std::byte*, const std::byte*>& encapsulation,
std::pair<const std::byte*, const std::byte*> encapsulation,
const Current& current) noexcept;

/**
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/Ice/OutputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace Ice
OutputStream(
const CommunicatorPtr& communicator,
const EncodingVersion& version,
const std::pair<const std::byte*, const std::byte*>& bytes);
std::pair<const std::byte*, const std::byte*> bytes);

/**
* Move constructor.
Expand Down
1 change: 0 additions & 1 deletion cpp/include/Ice/Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "ProxyF.h"
#include "ValueF.h"
#include "Exception.h"
#include "StreamHelpers.h"
#include "Comparable.h"
#include "LoggerF.h"
#include "Ice/BuiltinSequences.h"
Expand Down
6 changes: 3 additions & 3 deletions cpp/include/Ice/Proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ namespace Ice
bool ice_invoke(
std::string_view operation,
Ice::OperationMode mode,
const std::pair<const std::byte*, const std::byte*>& inParams,
std::pair<const std::byte*, const std::byte*> inParams,
std::vector<std::byte>& outParams,
const Ice::Context& context = Ice::noExplicitContext) const;

Expand All @@ -495,7 +495,7 @@ namespace Ice
std::future<std::tuple<bool, std::vector<std::byte>>> ice_invokeAsync(
std::string_view operation,
Ice::OperationMode mode,
const std::pair<const std::byte*, const std::byte*>& inParams,
std::pair<const std::byte*, const std::byte*> inParams,
const Ice::Context& context = Ice::noExplicitContext) const;

/**
Expand All @@ -512,7 +512,7 @@ namespace Ice
std::function<void()> ice_invokeAsync(
std::string_view operation,
Ice::OperationMode mode,
const std::pair<const std::byte*, const std::byte*>& inParams,
std::pair<const std::byte*, const std::byte*> inParams,
std::function<void(bool, std::pair<const std::byte*, const std::byte*>)> response,
std::function<void(std::exception_ptr)> ex = nullptr,
std::function<void(bool)> sent = nullptr,
Expand Down
22 changes: 21 additions & 1 deletion cpp/include/Ice/StreamHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <optional>
#include <string_view>

#if __has_include(<span>)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the preferred and portable way to conditionally include span. Span is a c++20 and up feature.

# include <span>
#endif

namespace Ice
{
/// \cond STREAM
Expand Down Expand Up @@ -491,14 +495,30 @@ namespace Ice
*/
template<typename T> struct StreamHelper<std::pair<const T*, const T*>, StreamHelperCategorySequence>
{
template<class S> static inline void write(S* stream, const std::pair<const T*, const T*>& v)
template<class S> static inline void write(S* stream, std::pair<const T*, const T*> v)
{
stream->write(v.first, v.second);
}

template<class S> static inline void read(S* stream, std::pair<const T*, const T*>& v) { stream->read(v); }
};

#ifdef __cpp_lib_span
/**
* Helper for span (C++20 or later).
* \headerfile Ice/Ice.h
*/
template<typename T> struct StreamHelper<std::span<T>, StreamHelperCategorySequence>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the actual core for this PR - not much. The bulk of the additional code is the new span test.

{
template<class S> inline static void write(S* stream, const std::span<T>& v)
{
stream->write(v.data(), v.data() + v.size());
}

// No read. span are only for view types.
};
#endif

/**
* Helper for dictionaries.
* \headerfile Ice/Ice.h
Expand Down
1 change: 0 additions & 1 deletion cpp/include/IceBT/ConnectionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <Ice/ProxyF.h>
#include <Ice/ValueF.h>
#include <Ice/Exception.h>
#include <Ice/StreamHelpers.h>
#include <Ice/Comparable.h>
#include <optional>
#include <Ice/Connection.h>
Expand Down
1 change: 0 additions & 1 deletion cpp/include/IceBT/EndpointInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <Ice/ProxyF.h>
#include <Ice/ValueF.h>
#include <Ice/Exception.h>
#include <Ice/StreamHelpers.h>
#include <Ice/Comparable.h>
#include <optional>
#include <Ice/Endpoint.h>
Expand Down
1 change: 0 additions & 1 deletion cpp/include/IceIAP/ConnectionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <Ice/ProxyF.h>
#include <Ice/ValueF.h>
#include <Ice/Exception.h>
#include <Ice/StreamHelpers.h>
#include <Ice/Comparable.h>
#include <optional>
#include <Ice/Connection.h>
Expand Down
1 change: 0 additions & 1 deletion cpp/include/IceIAP/EndpointInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <Ice/ProxyF.h>
#include <Ice/ValueF.h>
#include <Ice/Exception.h>
#include <Ice/StreamHelpers.h>
#include <Ice/Comparable.h>
#include <optional>
#include <Ice/Endpoint.h>
Expand Down
1 change: 0 additions & 1 deletion cpp/include/IceSSL/ConnectionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <Ice/ProxyF.h>
#include <Ice/ValueF.h>
#include <Ice/Exception.h>
#include <Ice/StreamHelpers.h>
#include <Ice/Comparable.h>
#include <optional>
#include <Ice/Connection.h>
Expand Down
1 change: 0 additions & 1 deletion cpp/include/IceSSL/EndpointInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <Ice/ProxyF.h>
#include <Ice/ValueF.h>
#include <Ice/Exception.h>
#include <Ice/StreamHelpers.h>
#include <Ice/Comparable.h>
#include <optional>
#include <Ice/Endpoint.h>
Expand Down
59 changes: 59 additions & 0 deletions cpp/msbuild/ice.test.sln
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,28 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "..\test\IceStorm\
{C7223CC8-0AAA-470B-ACB3-12B9DE75525C} = {C7223CC8-0AAA-470B-ACB3-12B9DE75525C}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "span", "span", "{1F7C0DCA-55EC-4906-9614-57F41E482721}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "..\test\Ice\span\msbuild\client\client.vcxproj", "{C1C9DE0E-4DFD-4E60-A04F-02CC305F8A28}"
ProjectSection(ProjectDependencies) = postProject
{C7223CC8-0AAA-470B-ACB3-12B9DE75525C} = {C7223CC8-0AAA-470B-ACB3-12B9DE75525C}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server", "..\test\Ice\span\msbuild\server\server.vcxproj", "{9420E497-D3F4-41B0-B4D0-B44F201AE733}"
ProjectSection(ProjectDependencies) = postProject
{C7223CC8-0AAA-470B-ACB3-12B9DE75525C} = {C7223CC8-0AAA-470B-ACB3-12B9DE75525C}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "collocated", "..\test\Ice\span\msbuild\collocated\collocated.vcxproj", "{CE3F4137-F8A0-4488-B67A-A2A5D6225573}"
ProjectSection(ProjectDependencies) = postProject
{C7223CC8-0AAA-470B-ACB3-12B9DE75525C} = {C7223CC8-0AAA-470B-ACB3-12B9DE75525C}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "serveramd", "..\test\Ice\span\msbuild\serveramd\serveramd.vcxproj", "{990E8CB2-4A3B-44EA-86C4-FECAC29B9E01}"
ProjectSection(ProjectDependencies) = postProject
{C7223CC8-0AAA-470B-ACB3-12B9DE75525C} = {C7223CC8-0AAA-470B-ACB3-12B9DE75525C}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Expand Down Expand Up @@ -2594,6 +2616,38 @@ Global
{7D48DD81-247D-467E-B94C-D23EC94BDAB0}.Release|Win32.Build.0 = Release|Win32
{7D48DD81-247D-467E-B94C-D23EC94BDAB0}.Release|x64.ActiveCfg = Release|x64
{7D48DD81-247D-467E-B94C-D23EC94BDAB0}.Release|x64.Build.0 = Release|x64
{C1C9DE0E-4DFD-4E60-A04F-02CC305F8A28}.Debug|Win32.ActiveCfg = Debug|Win32
{C1C9DE0E-4DFD-4E60-A04F-02CC305F8A28}.Debug|Win32.Build.0 = Debug|Win32
{C1C9DE0E-4DFD-4E60-A04F-02CC305F8A28}.Debug|x64.ActiveCfg = Debug|x64
{C1C9DE0E-4DFD-4E60-A04F-02CC305F8A28}.Debug|x64.Build.0 = Debug|x64
{C1C9DE0E-4DFD-4E60-A04F-02CC305F8A28}.Release|Win32.ActiveCfg = Release|Win32
{C1C9DE0E-4DFD-4E60-A04F-02CC305F8A28}.Release|Win32.Build.0 = Release|Win32
{C1C9DE0E-4DFD-4E60-A04F-02CC305F8A28}.Release|x64.ActiveCfg = Release|x64
{C1C9DE0E-4DFD-4E60-A04F-02CC305F8A28}.Release|x64.Build.0 = Release|x64
{9420E497-D3F4-41B0-B4D0-B44F201AE733}.Debug|Win32.ActiveCfg = Debug|Win32
{9420E497-D3F4-41B0-B4D0-B44F201AE733}.Debug|Win32.Build.0 = Debug|Win32
{9420E497-D3F4-41B0-B4D0-B44F201AE733}.Debug|x64.ActiveCfg = Debug|x64
{9420E497-D3F4-41B0-B4D0-B44F201AE733}.Debug|x64.Build.0 = Debug|x64
{9420E497-D3F4-41B0-B4D0-B44F201AE733}.Release|Win32.ActiveCfg = Release|Win32
{9420E497-D3F4-41B0-B4D0-B44F201AE733}.Release|Win32.Build.0 = Release|Win32
{9420E497-D3F4-41B0-B4D0-B44F201AE733}.Release|x64.ActiveCfg = Release|x64
{9420E497-D3F4-41B0-B4D0-B44F201AE733}.Release|x64.Build.0 = Release|x64
{CE3F4137-F8A0-4488-B67A-A2A5D6225573}.Debug|Win32.ActiveCfg = Debug|Win32
{CE3F4137-F8A0-4488-B67A-A2A5D6225573}.Debug|Win32.Build.0 = Debug|Win32
{CE3F4137-F8A0-4488-B67A-A2A5D6225573}.Debug|x64.ActiveCfg = Debug|x64
{CE3F4137-F8A0-4488-B67A-A2A5D6225573}.Debug|x64.Build.0 = Debug|x64
{CE3F4137-F8A0-4488-B67A-A2A5D6225573}.Release|Win32.ActiveCfg = Release|Win32
{CE3F4137-F8A0-4488-B67A-A2A5D6225573}.Release|Win32.Build.0 = Release|Win32
{CE3F4137-F8A0-4488-B67A-A2A5D6225573}.Release|x64.ActiveCfg = Release|x64
{CE3F4137-F8A0-4488-B67A-A2A5D6225573}.Release|x64.Build.0 = Release|x64
{990E8CB2-4A3B-44EA-86C4-FECAC29B9E01}.Debug|Win32.ActiveCfg = Debug|Win32
{990E8CB2-4A3B-44EA-86C4-FECAC29B9E01}.Debug|Win32.Build.0 = Debug|Win32
{990E8CB2-4A3B-44EA-86C4-FECAC29B9E01}.Debug|x64.ActiveCfg = Debug|x64
{990E8CB2-4A3B-44EA-86C4-FECAC29B9E01}.Debug|x64.Build.0 = Debug|x64
{990E8CB2-4A3B-44EA-86C4-FECAC29B9E01}.Release|Win32.ActiveCfg = Release|Win32
{990E8CB2-4A3B-44EA-86C4-FECAC29B9E01}.Release|Win32.Build.0 = Release|Win32
{990E8CB2-4A3B-44EA-86C4-FECAC29B9E01}.Release|x64.ActiveCfg = Release|x64
{990E8CB2-4A3B-44EA-86C4-FECAC29B9E01}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2868,6 +2922,11 @@ Global
{0DDD44E0-E425-47BE-8DAA-06CA0E8704D2} = {C167C995-BD18-4BF1-828E-66F7FA0A6BE6}
{372EA6E7-43FD-49F2-A7CB-FC863BAD9E14} = {CEF4EDB3-7782-4B65-9D97-55783C166F4D}
{7D48DD81-247D-467E-B94C-D23EC94BDAB0} = {372EA6E7-43FD-49F2-A7CB-FC863BAD9E14}
{1F7C0DCA-55EC-4906-9614-57F41E482721} = {2CAF9731-CB18-498C-A3EF-24F3D8A334AC}
{C1C9DE0E-4DFD-4E60-A04F-02CC305F8A28} = {1F7C0DCA-55EC-4906-9614-57F41E482721}
{9420E497-D3F4-41B0-B4D0-B44F201AE733} = {1F7C0DCA-55EC-4906-9614-57F41E482721}
{CE3F4137-F8A0-4488-B67A-A2A5D6225573} = {1F7C0DCA-55EC-4906-9614-57F41E482721}
{990E8CB2-4A3B-44EA-86C4-FECAC29B9E01} = {1F7C0DCA-55EC-4906-9614-57F41E482721}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E6FDB68A-64BA-4577-ABCD-40A01257F8AB}
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/Glacier2/Blobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ Glacier2::Blobject::updateObserver(const shared_ptr<Glacier2::Instrumentation::S
void
Glacier2::Blobject::invoke(
ObjectPrx& proxy,
const std::pair<const byte*, const byte*>& inParams,
function<void(bool, const pair<const byte*, const byte*>&)> response,
pair<const byte*, const byte*> inParams,
function<void(bool, pair<const byte*, const byte*>)> response,
function<void(exception_ptr)> exception,
const Current& current)
{
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/Glacier2/Blobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ namespace Glacier2
protected:
void invoke(
Ice::ObjectPrx&,
const std::pair<const std::byte*, const std::byte*>&,
std::function<void(bool, const std::pair<const std::byte*, const std::byte*>&)>,
std::pair<const std::byte*, const std::byte*>,
std::function<void(bool, std::pair<const std::byte*, const std::byte*>)>,
std::function<void(std::exception_ptr)>,
const Ice::Current&);

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Glacier2/ClientBlobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Glacier2::ClientBlobject::ClientBlobject(
void
Glacier2::ClientBlobject::ice_invokeAsync(
pair<const byte*, const byte*> inParams,
function<void(bool, const pair<const byte*, const byte*>&)> response,
function<void(bool, pair<const byte*, const byte*>)> response,
function<void(exception_ptr)> error,
const Current& current)
{
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Glacier2/ClientBlobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Glacier2

void ice_invokeAsync(
std::pair<const std::byte*, const std::byte*> inEncaps,
std::function<void(bool, const std::pair<const std::byte*, const std::byte*>&)> response,
std::function<void(bool, std::pair<const std::byte*, const std::byte*>)> response,
std::function<void(std::exception_ptr)> error,
const Ice::Current& current) override;

Expand Down
1 change: 0 additions & 1 deletion cpp/src/Glacier2/Instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <Ice/ProxyF.h>
#include <Ice/ValueF.h>
#include <Ice/Exception.h>
#include <Ice/StreamHelpers.h>
#include <Ice/Comparable.h>
#include <optional>
#include <Ice/Instrumentation.h>
Expand Down
Loading