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

build: fix linking when used in several translation units #98

Merged
merged 1 commit into from
Nov 22, 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
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,8 @@ TNTCXX_TEST(NAME SchemalessExample TYPE other
SOURCES examples/Schemaless.cpp
LIBRARIES ${COMMON_LIB}
)

TNTCXX_TEST(NAME LinkTest TYPE other
SOURCES test/LinkTest/Main.cpp test/LinkTest/Secondary.cpp
LIBRARIES ${COMMON_LIB}
)
2 changes: 1 addition & 1 deletion src/Client/Scramble.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

namespace tnt {

tnt::Sha1_type
inline tnt::Sha1_type
scramble(std::string_view password, const char *salt)
{
Sha1_type hash1 = sha1(password);
Expand Down
8 changes: 4 additions & 4 deletions src/Client/Stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class Stream {
////////////////////////// Implementation //////////////////////////
/////////////////////////////////////////////////////////////////////

std::ostream &
inline std::ostream &
operator<<(std::ostream &strm, enum StreamTransport transport)
{
if (transport == STREAM_PLAIN)
Expand All @@ -192,7 +192,7 @@ operator<<(std::ostream &strm, enum StreamTransport transport)
return strm << "unknown transport";
}

std::ostream &
inline std::ostream &
operator<<(std::ostream &strm, const ConnectOptions &opts)
{
strm << opts.address;
Expand All @@ -203,7 +203,7 @@ operator<<(std::ostream &strm, const ConnectOptions &opts)
return strm;
}

int
inline int
Stream::set_status(uint32_t st)
{
if (st & SS_READINESS_STATUS)
Expand All @@ -219,7 +219,7 @@ Stream::set_status(uint32_t st)
return 0;
}

int
inline int
Stream::remove_status(uint32_t st)
{
assert(!(st & SS_READINESS_STATUS));
Expand Down
8 changes: 4 additions & 4 deletions src/Client/UnixPlainStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class UnixPlainStream : public UnixStream {
////////////////////////// Implementation //////////////////////////
/////////////////////////////////////////////////////////////////////

int
inline int
UnixPlainStream::connect(const ConnectOptions &opts)
{
if (opts.transport != STREAM_PLAIN)
Expand All @@ -81,7 +81,7 @@ UnixPlainStream::connect(const ConnectOptions &opts)
}

namespace internal {
struct msghdr
inline struct msghdr
create_msghdr(struct iovec *iov, size_t iov_count)
{
struct msghdr msg{};
Expand All @@ -91,7 +91,7 @@ create_msghdr(struct iovec *iov, size_t iov_count)
}
} // namespace internal

ssize_t
inline ssize_t
UnixPlainStream::send(struct iovec *iov, size_t iov_count)
{
if (!(has_status(SS_ESTABLISHED))) {
Expand Down Expand Up @@ -120,7 +120,7 @@ UnixPlainStream::send(struct iovec *iov, size_t iov_count)
}
}

ssize_t
inline ssize_t
UnixPlainStream::recv(struct iovec *iov, size_t iov_count)
{
if (!(has_status(SS_ESTABLISHED))) {
Expand Down
8 changes: 5 additions & 3 deletions src/Client/UnixStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ UnixStream::tell(StreamStatus st, const char *file, int line,
return 0;
}

int
inline int
UnixStream::check_pending()
{
assert(has_status(SS_CONNECT_PENDING));
Expand All @@ -154,7 +154,7 @@ UnixStream::check_pending()
return US_DIE("Failed to connect", strerror(rc == 0 ? err : errno));
}

int
inline int
UnixStream::connect(const ConnectOptions &opts_arg)
{
if (!has_status(SS_DEAD))
Expand Down Expand Up @@ -217,12 +217,14 @@ UnixStream::connect(const ConnectOptions &opts_arg)
return US_DIE("Failed to connect");
}

inline
UnixStream::~UnixStream() noexcept
{
close();
}

void UnixStream::close()
inline void
UnixStream::close()
{
if (fd >= 0) {
if (::close(fd) == 0)
Expand Down
1 change: 1 addition & 0 deletions src/Utils/AddrInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ AddrInfo::~AddrInfo() noexcept
freeaddrinfo(infos);
}

inline
AddrInfo::AddrInfo(const std::string &addr, const std::string &service)
{
resolve(addr, service);
Expand Down
1 change: 1 addition & 0 deletions src/Utils/Sha1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ inline void sha1_xor(Sha1_type &a, const Sha1_type &b);
////////////////////////// Implementation //////////////////////////
/////////////////////////////////////////////////////////////////////

inline
Sha1Calc::Sha1Calc()
{
SHA1Init(&ctx);
Expand Down
53 changes: 53 additions & 0 deletions test/LinkTest/IncludeHeaders.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#pragma once
/*
* Copyright 2010-2024, Tarantool AUTHORS, please see AUTHORS file.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

#include "src/Buffer/Buffer.hpp"
#include "src/Client/Connection.hpp"
#include "src/Client/Connector.hpp"
#include "src/Client/IprotoConstants.hpp"
#include "src/Client/LibevNetProvider.hpp"
#include "src/Client/RequestEncoder.hpp"
#include "src/Client/ResponseDecoder.hpp"
#include "src/Client/ResponseReader.hpp"
#include "src/Client/Scramble.hpp"
#include "src/Client/Stream.hpp"
#include "src/Client/UnixPlainStream.hpp"
#include "src/Client/UnixStream.hpp"
#include "src/mpp/mpp.hpp"

#ifdef __linux__
#include "src/Client/EpollNetProvider.hpp"
#endif

#ifdef TNTCXX_ENABLE_SSL
#include "src/Client/UnixSSLStream.hpp"
#endif
46 changes: 46 additions & 0 deletions test/LinkTest/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2010-2024, Tarantool AUTHORS, please see AUTHORS file.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "IncludeHeaders.h"

using Buf_t = tnt::Buffer<16 * 1024>;

#ifdef __linux__
using NetProvider = EpollNetProvider<Buf_t, DefaultStream>;
#else
using NetProvider = LibevNetProvider<Buf_t, DefaultStream>;
#endif

int
main()
{
Connector<Buf_t, NetProvider> client;
return 0;
}
46 changes: 46 additions & 0 deletions test/LinkTest/Secondary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2010-2024, Tarantool AUTHORS, please see AUTHORS file.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

#include "IncludeHeaders.h"

using Buf_t = tnt::Buffer<16 * 1024>;

#ifdef __linux__
using NetProvider = EpollNetProvider<Buf_t, DefaultStream>;
#else
using NetProvider = LibevNetProvider<Buf_t, DefaultStream>;
#endif

int foo()
{
Connector<Buf_t, NetProvider> client;
return 0;
}
Loading