Skip to content

Commit 9b54d57

Browse files
committed
Code style: don't patch expressions/statements with conditional compilation
1 parent 493594d commit 9b54d57

20 files changed

Lines changed: 322 additions & 235 deletions

File tree

core/libc_include_fixes/errno.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515
extern "C" {
1616
#endif
1717

18-
extern int* __errno_location(void)
1918
#ifdef __THROW
20-
__THROW
19+
#define USERVER_IMPL_LIBC_INCLUDE_FIXES_THROW __THROW
20+
#else
21+
#define USERVER_IMPL_LIBC_INCLUDE_FIXES_THROW
2122
#endif
22-
;
23+
24+
extern int* __errno_location(void) USERVER_IMPL_LIBC_INCLUDE_FIXES_THROW;
25+
26+
#undef USERVER_IMPL_LIBC_INCLUDE_FIXES_THROW
2327

2428
#ifdef __cplusplus
2529
}

core/libc_include_fixes/pthread.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515
extern "C" {
1616
#endif
1717

18-
extern pthread_t pthread_self(void)
1918
#ifdef __THROW
20-
__THROW
19+
#define USERVER_IMPL_LIBC_INCLUDE_FIXES_THROW __THROW
20+
#else
21+
#define USERVER_IMPL_LIBC_INCLUDE_FIXES_THROW
2122
#endif
22-
;
23+
24+
extern pthread_t pthread_self(void) USERVER_IMPL_LIBC_INCLUDE_FIXES_THROW;
25+
26+
#undef USERVER_IMPL_LIBC_INCLUDE_FIXES_THROW
2327

2428
#ifdef __cplusplus
2529
}

core/src/clients/dns/net_resolver.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,14 @@ class NetResolver::Impl {
236236
}
237237

238238
void InitChannel() {
239-
constexpr int kOptmask =
240-
ARES_OPT_FLAGS | ARES_OPT_TIMEOUTMS | ARES_OPT_TRIES | ARES_OPT_DOMAINS |
239+
constexpr int kSockStateCbOptmask =
241240
#if ARES_VERSION < 0x011400
242-
ARES_OPT_SOCK_STATE_CB |
241+
ARES_OPT_SOCK_STATE_CB;
242+
#else
243+
0;
243244
#endif
245+
constexpr int kOptmask =
246+
ARES_OPT_FLAGS | ARES_OPT_TIMEOUTMS | ARES_OPT_TRIES | ARES_OPT_DOMAINS | kSockStateCbOptmask |
244247
ARES_OPT_LOOKUPS;
245248
struct ares_options options {};
246249
options.flags =

core/src/dist_lock/dist_lock_test.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,12 @@ UTEST_MT(LockedWorker, OkAfterFail, 3) {
234234

235235
// TODO: TAXICOMMON-1059
236236
#if defined(__APPLE__) || defined(BSD)
237-
UTEST_MT(LockedWorker, DISABLED_OkFailOk, 3) {
237+
#define USERVER_IMPL_LOCKED_WORKER_OK_FAIL_OK DISABLED_OkFailOk
238238
#else
239-
UTEST_MT(LockedWorker, OkFailOk, 3) {
239+
#define USERVER_IMPL_LOCKED_WORKER_OK_FAIL_OK OkFailOk
240240
#endif
241+
242+
UTEST_MT(LockedWorker, USERVER_IMPL_LOCKED_WORKER_OK_FAIL_OK, 3) {
241243
auto strategy = MakeMockStrategy();
242244
DistLockWorkload work;
243245
dist_lock::DistLockedWorker locked_worker(kWorkerName, [&] { work.Work(); }, strategy, MakeSettings());

core/src/engine/ev/watcher/io_watcher_test.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
USERVER_NAMESPACE_BEGIN
1111

1212
#if defined(BSD) && !defined(__APPLE__)
13-
UTEST(IoWatcher, DISABLED_DevNull) {
13+
#define USERVER_IMPL_IO_WATCHER_DEV_NULL DISABLED_DevNull
1414
#else
15-
UTEST(IoWatcher, DevNull) {
15+
#define USERVER_IMPL_IO_WATCHER_DEV_NULL DevNull
1616
#endif
17+
18+
UTEST(IoWatcher, USERVER_IMPL_IO_WATCHER_DEV_NULL) {
1719
LOG_DEBUG() << "Opening /dev/null";
1820
engine::ev::Thread thread{"test_thread"};
1921
engine::ev::ThreadControl thread_control(thread);

core/src/engine/io/fd_control.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ enum class ErrorMode {
4141
kFatal, ///< break execute operation
4242
};
4343

44+
constexpr bool IsRetryableIoError(int error_code) noexcept {
45+
#if EWOULDBLOCK != EAGAIN
46+
return error_code == EWOULDBLOCK || error_code == EAGAIN;
47+
#else
48+
return error_code == EWOULDBLOCK;
49+
#endif
50+
}
51+
4452
class FdControl;
4553

4654
class Direction final {
@@ -166,12 +174,7 @@ ErrorMode Direction::TryHandleError(
166174
) {
167175
if (error_code == EINTR) {
168176
return ErrorMode::kProcessed;
169-
} else if (error_code == EWOULDBLOCK
170-
#if EWOULDBLOCK != EAGAIN
171-
|| error_code == EAGAIN
172-
#endif
173-
)
174-
{
177+
} else if (IsRetryableIoError(error_code)) {
175178
if (processed_bytes != 0 && mode != TransferMode::kWhole) {
176179
return ErrorMode::kFatal;
177180
}

core/src/engine/io/poller_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,11 @@ UTEST(Poller, ReadWriteMultipleTorture) {
222222

223223
// Disabled for mac, see https://st.yandex-team.ru/TAXICOMMON-4196
224224
#ifdef BSD
225-
UTEST(Poller, DISABLED_AwaitedEventsChange) {
225+
#define USERVER_IMPL_POLLER_AWAITED_EVENTS_CHANGE DISABLED_AwaitedEventsChange
226226
#else
227-
UTEST(Poller, AwaitedEventsChange) {
227+
#define USERVER_IMPL_POLLER_AWAITED_EVENTS_CHANGE AwaitedEventsChange
228228
#endif
229+
UTEST(Poller, USERVER_IMPL_POLLER_AWAITED_EVENTS_CHANGE) {
229230
TcpListener listener;
230231
auto socket_pair = listener.MakeSocketPair(engine::Deadline::FromDuration(utest::kMaxTestWaitTime));
231232

core/src/engine/io/socket.cpp

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,41 @@ namespace {
2626
constexpr size_t kMaxStackSizeVector = 32;
2727

2828
// MAC_COMPAT: does not accept flags in type
29-
impl::FdControlHolder MakeSocket(AddrDomain domain, SocketType type) {
30-
return impl::FdControl::Adopt(utils::CheckSyscallCustomException<IoSystemError>(
31-
::socket(
32-
static_cast<int>(domain),
29+
constexpr int kSockNonblockFlag =
3330
#ifdef SOCK_NONBLOCK
34-
SOCK_NONBLOCK |
31+
SOCK_NONBLOCK;
32+
#else
33+
0;
3534
#endif
35+
36+
constexpr int kSockCloexecFlag =
3637
#ifdef SOCK_CLOEXEC
37-
SOCK_CLOEXEC |
38+
SOCK_CLOEXEC;
39+
#else
40+
0;
41+
#endif
42+
43+
// MAC_COMPAT: does not support MSG_NOSIGNAL
44+
constexpr int kMsgNosignalFlag =
45+
#ifdef MSG_NOSIGNAL
46+
MSG_NOSIGNAL;
47+
#else
48+
0;
49+
#endif
50+
51+
bool IsWouldBlock() noexcept {
52+
#if EAGAIN != EWOULDBLOCK
53+
return errno == EAGAIN || errno == EWOULDBLOCK;
54+
#else
55+
return errno == EAGAIN;
3856
#endif
39-
static_cast<int>(type),
57+
}
58+
59+
impl::FdControlHolder MakeSocket(AddrDomain domain, SocketType type) {
60+
return impl::FdControl::Adopt(utils::CheckSyscallCustomException<IoSystemError>(
61+
::socket(
62+
static_cast<int>(domain),
63+
kSockNonblockFlag | kSockCloexecFlag | static_cast<int>(type),
4064
/* protocol=*/0
4165
),
4266
"creating socket"
@@ -68,11 +92,7 @@ Sockaddr& MemoizeAddr(
6892
fd,
6993
buf,
7094
len,
71-
// MAC_COMPAT: does not support MSG_NOSIGNAL
72-
#ifdef MSG_NOSIGNAL
73-
MSG_NOSIGNAL |
74-
#endif
75-
0
95+
kMsgNosignalFlag
7696
);
7797
}
7898

@@ -106,11 +126,7 @@ class SendToWrapper {
106126
fd,
107127
buf,
108128
len,
109-
// MAC_COMPAT: does not support MSG_NOSIGNAL
110-
#ifdef MSG_NOSIGNAL
111-
MSG_NOSIGNAL |
112-
#endif
113-
0,
129+
kMsgNosignalFlag,
114130
dest_addr_.Data(),
115131
dest_addr_.Size()
116132
);
@@ -275,14 +291,9 @@ std::optional<size_t> Socket::RecvNoblock(void* buf, size_t len) {
275291
const auto bytes_read = RecvWrapper(fd_control_->Fd(), buf, len);
276292
if (bytes_read >= 0) {
277293
return {bytes_read};
278-
} else if (
279-
#if EAGAIN != EWOULDBLOCK
280-
EWOULDBLOCK == errno
281-
#else
282-
EAGAIN == errno
283-
#endif
284-
)
294+
} else if (IsWouldBlock()) {
285295
return {};
296+
}
286297

287298
throw IoException("Attempt to RecvNoblock from closed socket");
288299
}

core/src/server/http/http_response_cookie_test.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
USERVER_NAMESPACE_BEGIN
99

10+
#if defined(BSD) && !defined(__APPLE__)
11+
#define USERVER_IMPL_HTTP_COOKIE_TIMEZONE "UTC; "
12+
#else
13+
#define USERVER_IMPL_HTTP_COOKIE_TIMEZONE "GMT; "
14+
#endif
15+
1016
TEST(HttpCookie, Simple) {
1117
server::http::Cookie cookie{"name1", "value1"};
1218
EXPECT_EQ(cookie.ToString(), "name1=value1");
@@ -27,23 +33,15 @@ TEST(HttpCookie, Simple) {
2733
const auto* const expected =
2834
"name1=value1; Domain=domain.com; Path=/; Expires=Wed, 12 Jun 2019 "
2935
"16:51:45 "
30-
#if defined(BSD) && !defined(__APPLE__)
31-
"UTC; "
32-
#else
33-
"GMT; "
34-
#endif
36+
USERVER_IMPL_HTTP_COOKIE_TIMEZONE
3537
"Max-Age=3600; Secure; HttpOnly";
3638
EXPECT_EQ(cookie.ToString(), expected);
3739

3840
cookie.SetSameSite("None");
3941
const auto* const expected2 =
4042
"name1=value1; Domain=domain.com; Path=/; Expires=Wed, 12 Jun 2019 "
4143
"16:51:45 "
42-
#if defined(BSD) && !defined(__APPLE__)
43-
"UTC; "
44-
#else
45-
"GMT; "
46-
#endif
44+
USERVER_IMPL_HTTP_COOKIE_TIMEZONE
4745
"Max-Age=3600; Secure; SameSite=None; HttpOnly";
4846
EXPECT_EQ(cookie.ToString(), expected2);
4947

kafka/tests/producer_kafkatest.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,14 @@ UTEST_F(ProducerTest, MessageTimeout) {
252252
}
253253
}
254254

255+
// Test flaps on GithubCI
255256
#ifndef ARCADIA_ROOT
256-
// Test flaps on GithubCI
257-
GTEST_SKIP()
257+
#define USERVER_IMPL_KAFKA_TRIGGER_FAILURES_RESULT GTEST_SKIP()
258258
#else
259-
FAIL()
259+
#define USERVER_IMPL_KAFKA_TRIGGER_FAILURES_RESULT FAIL()
260260
#endif
261-
<< "Failed to trigger failures after " << kMaxRetries << " retries.";
261+
262+
USERVER_IMPL_KAFKA_TRIGGER_FAILURES_RESULT << "Failed to trigger failures after " << kMaxRetries << " retries.";
262263
}
263264

264265
UTEST_F(ProducerTest, FullQueueBulk) {

0 commit comments

Comments
 (0)