Skip to content

Commit 39b61fd

Browse files
committed
build: fix linking when used in several translation units
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.
1 parent 3cfffe0 commit 39b61fd

File tree

10 files changed

+132
-12
lines changed

10 files changed

+132
-12
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,8 @@ TNTCXX_TEST(NAME SchemalessExample TYPE other
248248
SOURCES examples/Schemaless.cpp
249249
LIBRARIES ${COMMON_LIB}
250250
)
251+
252+
TNTCXX_TEST(NAME LinkTest TYPE other
253+
SOURCES test/LinkTest/Main.cpp test/LinkTest/Secondary.cpp
254+
LIBRARIES ${COMMON_LIB}
255+
)

src/Client/Scramble.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
namespace tnt {
3838

39-
tnt::Sha1_type
39+
inline tnt::Sha1_type
4040
scramble(std::string_view password, const char *salt)
4141
{
4242
Sha1_type hash1 = sha1(password);

src/Client/Stream.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class Stream {
181181
////////////////////////// Implementation //////////////////////////
182182
/////////////////////////////////////////////////////////////////////
183183

184-
std::ostream &
184+
inline std::ostream &
185185
operator<<(std::ostream &strm, enum StreamTransport transport)
186186
{
187187
if (transport == STREAM_PLAIN)
@@ -192,7 +192,7 @@ operator<<(std::ostream &strm, enum StreamTransport transport)
192192
return strm << "unknown transport";
193193
}
194194

195-
std::ostream &
195+
inline std::ostream &
196196
operator<<(std::ostream &strm, const ConnectOptions &opts)
197197
{
198198
strm << opts.address;
@@ -203,7 +203,7 @@ operator<<(std::ostream &strm, const ConnectOptions &opts)
203203
return strm;
204204
}
205205

206-
int
206+
inline int
207207
Stream::set_status(uint32_t st)
208208
{
209209
if (st & SS_READINESS_STATUS)
@@ -219,7 +219,7 @@ Stream::set_status(uint32_t st)
219219
return 0;
220220
}
221221

222-
int
222+
inline int
223223
Stream::remove_status(uint32_t st)
224224
{
225225
assert(!(st & SS_READINESS_STATUS));

src/Client/UnixPlainStream.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class UnixPlainStream : public UnixStream {
7171
////////////////////////// Implementation //////////////////////////
7272
/////////////////////////////////////////////////////////////////////
7373

74-
int
74+
inline int
7575
UnixPlainStream::connect(const ConnectOptions &opts)
7676
{
7777
if (opts.transport != STREAM_PLAIN)
@@ -81,7 +81,7 @@ UnixPlainStream::connect(const ConnectOptions &opts)
8181
}
8282

8383
namespace internal {
84-
struct msghdr
84+
inline struct msghdr
8585
create_msghdr(struct iovec *iov, size_t iov_count)
8686
{
8787
struct msghdr msg{};
@@ -91,7 +91,7 @@ create_msghdr(struct iovec *iov, size_t iov_count)
9191
}
9292
} // namespace internal
9393

94-
ssize_t
94+
inline ssize_t
9595
UnixPlainStream::send(struct iovec *iov, size_t iov_count)
9696
{
9797
if (!(has_status(SS_ESTABLISHED))) {
@@ -120,7 +120,7 @@ UnixPlainStream::send(struct iovec *iov, size_t iov_count)
120120
}
121121
}
122122

123-
ssize_t
123+
inline ssize_t
124124
UnixPlainStream::recv(struct iovec *iov, size_t iov_count)
125125
{
126126
if (!(has_status(SS_ESTABLISHED))) {

src/Client/UnixStream.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ UnixStream::tell(StreamStatus st, const char *file, int line,
142142
return 0;
143143
}
144144

145-
int
145+
inline int
146146
UnixStream::check_pending()
147147
{
148148
assert(has_status(SS_CONNECT_PENDING));
@@ -154,7 +154,7 @@ UnixStream::check_pending()
154154
return US_DIE("Failed to connect", strerror(rc == 0 ? err : errno));
155155
}
156156

157-
int
157+
inline int
158158
UnixStream::connect(const ConnectOptions &opts_arg)
159159
{
160160
if (!has_status(SS_DEAD))
@@ -217,12 +217,14 @@ UnixStream::connect(const ConnectOptions &opts_arg)
217217
return US_DIE("Failed to connect");
218218
}
219219

220+
inline
220221
UnixStream::~UnixStream() noexcept
221222
{
222223
close();
223224
}
224225

225-
void UnixStream::close()
226+
inline void
227+
UnixStream::close()
226228
{
227229
if (fd >= 0) {
228230
if (::close(fd) == 0)

src/Utils/AddrInfo.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ AddrInfo::~AddrInfo() noexcept
9191
freeaddrinfo(infos);
9292
}
9393

94+
inline
9495
AddrInfo::AddrInfo(const std::string &addr, const std::string &service)
9596
{
9697
resolve(addr, service);

src/Utils/Sha1.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ inline void sha1_xor(Sha1_type &a, const Sha1_type &b);
7171
////////////////////////// Implementation //////////////////////////
7272
/////////////////////////////////////////////////////////////////////
7373

74+
inline
7475
Sha1Calc::Sha1Calc()
7576
{
7677
SHA1Init(&ctx);

test/LinkTest/IncludeHeaders.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
#include "src/Buffer/Buffer.hpp"
4+
#include "src/Client/Connection.hpp"
5+
#include "src/Client/Connector.hpp"
6+
#include "src/Client/IprotoConstants.hpp"
7+
#include "src/Client/LibevNetProvider.hpp"
8+
#include "src/Client/RequestEncoder.hpp"
9+
#include "src/Client/ResponseDecoder.hpp"
10+
#include "src/Client/ResponseReader.hpp"
11+
#include "src/Client/Scramble.hpp"
12+
#include "src/Client/Stream.hpp"
13+
#include "src/Client/UnixPlainStream.hpp"
14+
#include "src/Client/UnixStream.hpp"
15+
#include "src/mpp/mpp.hpp"
16+
17+
#ifdef __linux__
18+
#include "src/Client/EpollNetProvider.hpp"
19+
#endif
20+
21+
#ifdef TNTCXX_ENABLE_SSL
22+
#include "src/Client/UnixSSLStream.hpp"
23+
#endif

test/LinkTest/Main.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2010-2020, Tarantool AUTHORS, please see AUTHORS file.
3+
*
4+
* Redistribution and use in source and binary forms, with or
5+
* without modification, are permitted provided that the following
6+
* conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above
9+
* copyright notice, this list of conditions and the
10+
* following disclaimer.
11+
*
12+
* 2. Redistributions in binary form must reproduce the above
13+
* copyright notice, this list of conditions and the following
14+
* disclaimer in the documentation and/or other materials
15+
* provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
18+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21+
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25+
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28+
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29+
* SUCH DAMAGE.
30+
*/
31+
#include "IncludeHeaders.h"
32+
33+
using Buf_t = tnt::Buffer<16 * 1024>;
34+
35+
using NetProvider = LibevNetProvider<Buf_t, DefaultStream>;
36+
37+
int
38+
main()
39+
{
40+
Connector<Buf_t, NetProvider> client;
41+
return 0;
42+
}

test/LinkTest/Secondary.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2010-2020, Tarantool AUTHORS, please see AUTHORS file.
3+
*
4+
* Redistribution and use in source and binary forms, with or
5+
* without modification, are permitted provided that the following
6+
* conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above
9+
* copyright notice, this list of conditions and the
10+
* following disclaimer.
11+
*
12+
* 2. Redistributions in binary form must reproduce the above
13+
* copyright notice, this list of conditions and the following
14+
* disclaimer in the documentation and/or other materials
15+
* provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
18+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21+
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25+
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28+
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29+
* SUCH DAMAGE.
30+
*/
31+
32+
#include "IncludeHeaders.h"
33+
34+
using Buf_t = tnt::Buffer<16 * 1024>;
35+
36+
#ifdef __linux__
37+
using NetProvider = EpollNetProvider<Buf_t, DefaultStream>;
38+
#else
39+
using NetProvider = LibevNetProvider<Buf_t, DefaultStream>;
40+
#endif
41+
42+
int foo()
43+
{
44+
Connector<Buf_t, NetProvider> client;
45+
return 0;
46+
}

0 commit comments

Comments
 (0)