From d359ca6885fe5e0a87e09124ec446bb64f4392ef Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 6 Oct 2016 08:07:29 -0700 Subject: [PATCH] folly/io: avoid shadowing warnings Summary: Fix shadowing warnings. Reviewed By: russoue Differential Revision: D3979165 fbshipit-source-id: 19a3940e210e4d5a698dbc0e6d74b317a74a94fa --- folly/io/async/AsyncServerSocket.cpp | 6 +- .../io/async/test/AsyncSSLSocketWriteTest.cpp | 118 +++++++++--------- folly/io/async/test/HHWheelTimerSlowTests.cpp | 14 +-- folly/io/async/test/NotificationQueueTest.cpp | 12 +- 4 files changed, 75 insertions(+), 75 deletions(-) diff --git a/folly/io/async/AsyncServerSocket.cpp b/folly/io/async/AsyncServerSocket.cpp index 99e1feb1..e163da68 100644 --- a/folly/io/async/AsyncServerSocket.cpp +++ b/folly/io/async/AsyncServerSocket.cpp @@ -361,7 +361,7 @@ void AsyncServerSocket::bind( } void AsyncServerSocket::bind(uint16_t port) { - struct addrinfo hints, *res, *res0; + struct addrinfo hints, *res0; char sport[sizeof("65536")]; memset(&hints, 0, sizeof(hints)); @@ -423,7 +423,7 @@ void AsyncServerSocket::bind(uint16_t port) { // - 0.0.0.0 (IPv4-only) // - :: (IPv6+IPv4) in this order // See: https://sourceware.org/bugzilla/show_bug.cgi?id=9981 - for (res = res0; res; res = res->ai_next) { + for (struct addrinfo* res = res0; res; res = res->ai_next) { if (res->ai_family == AF_INET6) { setupAddress(res); } @@ -440,7 +440,7 @@ void AsyncServerSocket::bind(uint16_t port) { } try { - for (res = res0; res; res = res->ai_next) { + for (struct addrinfo* res = res0; res; res = res->ai_next) { if (res->ai_family != AF_INET6) { setupAddress(res); } diff --git a/folly/io/async/test/AsyncSSLSocketWriteTest.cpp b/folly/io/async/test/AsyncSSLSocketWriteTest.cpp index 9b67ba3c..023bbdc9 100644 --- a/folly/io/async/test/AsyncSSLSocketWriteTest.cpp +++ b/folly/io/async/test/AsyncSSLSocketWriteTest.cpp @@ -125,8 +125,8 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing1) { int n = 3; auto vec = makeVec({3, 3, 3}); EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 9)) - .WillOnce(Invoke([this] (SSL *, const void *buf, int n) { - verifyVec(buf, n, 0); + .WillOnce(Invoke([this] (SSL *, const void *buf, int m) { + verifyVec(buf, m, 0); return 9; })); uint32_t countWritten = 0; uint32_t partialWritten = 0; @@ -142,15 +142,15 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing2) { auto vec = makeVec({1500, 3, 3}); int pos = 0; EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500)) - .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { - verifyVec(buf, n, pos); - pos += n; - return n; })); + .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) { + verifyVec(buf, m, pos); + pos += m; + return m; })); EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 6)) - .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { - verifyVec(buf, n, pos); - pos += n; - return n; })); + .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) { + verifyVec(buf, m, pos); + pos += m; + return m; })); uint32_t countWritten = 0; uint32_t partialWritten = 0; sock_->testPerformWrite(vec.get(), n, WriteFlags::NONE, &countWritten, @@ -166,10 +166,10 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing3) { int pos = 0; EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500)) .Times(2) - .WillRepeatedly(Invoke([this, &pos] (SSL *, const void *buf, int n) { - verifyVec(buf, n, pos); - pos += n; - return n; })); + .WillRepeatedly(Invoke([this, &pos] (SSL *, const void *buf, int m) { + verifyVec(buf, m, pos); + pos += m; + return m; })); uint32_t countWritten = 0; uint32_t partialWritten = 0; sock_->testPerformWrite(vec.get(), n, WriteFlags::NONE, &countWritten, @@ -184,8 +184,8 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing4) { auto vec = makeVec({300, 300, 300, 300, 300}); int pos = 0; EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500)) - .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { - verifyVec(buf, n, pos); + .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) { + verifyVec(buf, m, pos); pos += 1000; return 1000; /* 500 bytes "pending" */ })); uint32_t countWritten = 0; @@ -196,9 +196,9 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing4) { EXPECT_EQ(partialWritten, 100); consumeVec(vec.get(), countWritten, partialWritten); EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 500)) - .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { - verifyVec(buf, n, pos); - pos += n; + .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) { + verifyVec(buf, m, pos); + pos += m; return 500; })); sock_->testPerformWrite(vec.get() + countWritten, n - countWritten, WriteFlags::NONE, @@ -213,15 +213,15 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing5) { auto vec = makeVec({1000, 500, 500}); int pos = 0; EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500)) - .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { - verifyVec(buf, n, pos); - pos += n; - return n; })); + .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) { + verifyVec(buf, m, pos); + pos += m; + return m; })); EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 500)) - .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { - verifyVec(buf, n, pos); - pos += n; - return n; })); + .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) { + verifyVec(buf, m, pos); + pos += m; + return m; })); uint32_t countWritten = 0; uint32_t partialWritten = 0; sock_->testPerformWrite(vec.get(), n, WriteFlags::NONE, &countWritten, @@ -236,8 +236,8 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing6) { auto vec = makeVec({1000, 500}); int pos = 0; EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500)) - .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { - verifyVec(buf, n, pos); + .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) { + verifyVec(buf, m, pos); pos += 700; return 700; })); uint32_t countWritten = 0; @@ -248,10 +248,10 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing6) { EXPECT_EQ(partialWritten, 700); consumeVec(vec.get(), countWritten, partialWritten); EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 800)) - .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { - verifyVec(buf, n, pos); - pos += n; - return n; })); + .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) { + verifyVec(buf, m, pos); + pos += m; + return m; })); sock_->testPerformWrite(vec.get() + countWritten, n - countWritten, WriteFlags::NONE, &countWritten, &partialWritten); @@ -280,18 +280,18 @@ TEST_F(AsyncSSLSocketWriteTest, write_with_eor1) { // + some random SSL overhead .WillOnce(Return(3728)); EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500)) - .WillOnce(Invoke([=, &pos] (SSL *, const void *buf, int n) { + .WillOnce(Invoke([=, &pos] (SSL *, const void *buf, int m) { // the first 1500 does not have the EOR byte sock_->checkEor(0, 0); - verifyVec(buf, n, pos); - pos += n; - return n; })); + verifyVec(buf, m, pos); + pos += m; + return m; })); EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 6)) - .WillOnce(Invoke([=, &pos] (SSL *, const void *buf, int n) { - sock_->checkEor(appEor, 3600 + n); - verifyVec(buf, n, pos); - pos += n; - return n; })); + .WillOnce(Invoke([=, &pos] (SSL *, const void *buf, int m) { + sock_->checkEor(appEor, 3600 + m); + verifyVec(buf, m, pos); + pos += m; + return m; })); uint32_t countWritten = 0; uint32_t partialWritten = 0; @@ -322,18 +322,18 @@ TEST_F(AsyncSSLSocketWriteTest, write_with_eor2) { // + some random SSL overhead .WillOnce(Return(4100)); EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500)) - .WillOnce(Invoke([=, &pos] (SSL *, const void *buf, int n) { + .WillOnce(Invoke([=, &pos] (SSL *, const void *buf, int m) { // the first 1500 does not have the EOR byte sock_->checkEor(0, 0); - verifyVec(buf, n, pos); - pos += n; - return n; })); + verifyVec(buf, m, pos); + pos += m; + return m; })); EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 300)) - .WillOnce(Invoke([=, &pos] (SSL *, const void *buf, int n) { - sock_->checkEor(appEor, 3600 + n); - verifyVec(buf, n, pos); - pos += n; - return n; })); + .WillOnce(Invoke([=, &pos] (SSL *, const void *buf, int m) { + sock_->checkEor(appEor, 3600 + m); + verifyVec(buf, m, pos); + pos += m; + return m; })); uint32_t countWritten = 0; uint32_t partialWritten = 0; @@ -365,9 +365,9 @@ TEST_F(AsyncSSLSocketWriteTest, write_with_eor3) { // + some random SSL overhead .WillOnce(Return(3100)); EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1600)) - .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { - sock_->checkEor(appEor, 2000 + n); - verifyVec(buf, n, pos); + .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) { + sock_->checkEor(appEor, 2000 + m); + verifyVec(buf, m, pos); pos += 1000; return 1000; })); @@ -384,11 +384,11 @@ TEST_F(AsyncSSLSocketWriteTest, write_with_eor3) { .WillOnce(Return(3100)) .WillOnce(Return(3800)); EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 600)) - .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { - sock_->checkEor(appEor, 3100 + n); - verifyVec(buf, n, pos); - pos += n; - return n; })); + .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) { + sock_->checkEor(appEor, 3100 + m); + verifyVec(buf, m, pos); + pos += m; + return m; })); sock_->testPerformWrite(vec.get() + countWritten, n - countWritten, WriteFlags::EOR, &countWritten, &partialWritten); diff --git a/folly/io/async/test/HHWheelTimerSlowTests.cpp b/folly/io/async/test/HHWheelTimerSlowTests.cpp index 3c412fb0..6e71ed7d 100644 --- a/folly/io/async/test/HHWheelTimerSlowTests.cpp +++ b/folly/io/async/test/HHWheelTimerSlowTests.cpp @@ -281,13 +281,13 @@ TEST_F(HHWheelTimerTest, Stress) { TestTimeout timeouts[10000]; long runtimeouts = 0; for (long i = 0; i < timeoutcount; i++) { - long newtimeout = Random::rand32(1, 10000); + long timeout = Random::rand32(1, 10000); if (Random::rand32(3)) { // NOTE: hhwheel timer runs before eventbase runAfterDelay, // so runAfterDelay cancelTimeout() must run at least one timerwheel // before scheduleTimeout, to ensure it runs first. - newtimeout += 256; - t.scheduleTimeout(&timeouts[i], std::chrono::milliseconds(newtimeout)); + timeout += 256; + t.scheduleTimeout(&timeouts[i], std::chrono::milliseconds(timeout)); eventBase.runAfterDelay( [&, i]() { timeouts[i].fn = nullptr; @@ -295,13 +295,13 @@ TEST_F(HHWheelTimerTest, Stress) { runtimeouts++; LOG(INFO) << "Ran " << runtimeouts << " timeouts, cancelled"; }, - newtimeout - 256); - timeouts[i].fn = [&, i, newtimeout]() { - LOG(INFO) << "FAIL:timer " << i << " still fired in " << newtimeout; + timeout - 256); + timeouts[i].fn = [&, i, timeout]() { + LOG(INFO) << "FAIL:timer " << i << " still fired in " << timeout; EXPECT_FALSE(true); }; } else { - t.scheduleTimeout(&timeouts[i], std::chrono::milliseconds(newtimeout)); + t.scheduleTimeout(&timeouts[i], std::chrono::milliseconds(timeout)); timeouts[i].fn = [&, i]() { timeoutcount++; long newtimeout = Random::rand32(1, 10000); diff --git a/folly/io/async/test/NotificationQueueTest.cpp b/folly/io/async/test/NotificationQueueTest.cpp index bd7a54a4..78e7eed5 100644 --- a/folly/io/async/test/NotificationQueueTest.cpp +++ b/folly/io/async/test/NotificationQueueTest.cpp @@ -466,10 +466,10 @@ TEST(NotificationQueueTest, ConsumeUntilDrainedStress) { EventBase eventBase; IntQueue queue; QueueConsumer consumer; - consumer.fn = [&](int i) { - EXPECT_THROW(queue.tryPutMessage(i), std::runtime_error); - EXPECT_FALSE(queue.tryPutMessageNoThrow(i)); - EXPECT_THROW(queue.putMessage(i), std::runtime_error); + consumer.fn = [&](int j) { + EXPECT_THROW(queue.tryPutMessage(j), std::runtime_error); + EXPECT_FALSE(queue.tryPutMessageNoThrow(j)); + EXPECT_THROW(queue.putMessage(j), std::runtime_error); std::vector ints{1, 2, 3}; EXPECT_THROW( queue.putMessages(ints.begin(), ints.end()), @@ -477,8 +477,8 @@ TEST(NotificationQueueTest, ConsumeUntilDrainedStress) { }; consumer.setMaxReadAtOnce(10); // We should ignore this consumer.startConsuming(&eventBase, &queue); - for (int i = 0; i < 20; i++) { - queue.putMessage(i); + for (int j = 0; j < 20; j++) { + queue.putMessage(j); } EXPECT_TRUE(consumer.consumeUntilDrained()); EXPECT_EQ(20, consumer.messages.size()); -- 2.34.1