Skip to content

Commit

Permalink
build: fix linking when used in several translation units
Browse files Browse the repository at this point in the history
All non-template methods defined outside classes are not implicitly
`inline` - that violates one definition rule when the connector is
included in several translaction units. Let's mark such methods as
`inline` to fix this issue.
  • Loading branch information
drewdzzz committed Oct 21, 2024
1 parent 3cfffe0 commit 59644b7
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
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

0 comments on commit 59644b7

Please sign in to comment.