Skip to content

Commit

Permalink
remove c++14 feature
Browse files Browse the repository at this point in the history
Change-Id: I88cfd548b7cb2c7c1e1190cc8cc92d1dac729d12
  • Loading branch information
wu-hanqing committed Jul 23, 2020
1 parent d985678 commit 0a9dab3
Show file tree
Hide file tree
Showing 31 changed files with 235 additions and 103 deletions.
2 changes: 1 addition & 1 deletion curvefs_python/BUILD_bak
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ COPTS = [
"-Woverloaded-virtual",
"-Wnon-virtual-dtor",
"-Wno-missing-field-initializers",
"-std=c++14",
"-std=c++11",
]

cc_library(
Expand Down
2 changes: 1 addition & 1 deletion curvesnapshot_python/BUILD_bak
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ COPTS = [
"-Woverloaded-virtual",
"-Wnon-virtual-dtor",
"-Wno-missing-field-initializers",
"-std=c++14",
"-std=c++11",
]

cc_library(
Expand Down
2 changes: 1 addition & 1 deletion nbd/src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ COPTS = [
"-Woverloaded-virtual",
"-Wnon-virtual-dtor",
"-Wno-missing-field-initializers",
"-std=c++14",
"-std=c++11",
"-I /usr/include/libnl3",
]

Expand Down
26 changes: 6 additions & 20 deletions nbd/src/argparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* Author: yangyaokai
*/

#include <experimental/string_view>
#include <limits.h>
#include <string.h>
#include <string>
Expand All @@ -35,13 +34,12 @@
namespace curve {
namespace nbd {

using std::experimental::string_view;
using std::ostringstream;

float strict_strtof(string_view str, std::string *err) {
float strict_strtof(const char *str, std::string *err) {
char *endptr;
errno = 0; /* To distinguish success/failure after call (see man page) */
float ret = strtof(str.data(), &endptr);
float ret = strtof(str, &endptr);
if (errno == ERANGE) {
ostringstream oss;
oss << "strict_strtof: floating point overflow or underflow parsing '"
Expand All @@ -65,15 +63,11 @@ float strict_strtof(string_view str, std::string *err) {
return ret;
}

float strict_strtof(const char *str, std::string *err) {
return strict_strtof(string_view(str), err);
}

int64_t strict_strtoll(string_view str, int base, std::string *err) {
int64_t strict_strtoll(const char *str, int base, std::string *err) {
char *endptr;
errno = 0; /* To distinguish success/failure after call (see man page) */
int64_t ret = strtoll(str.data(), &endptr, base);
if (endptr == str.data() || endptr != str.data() + str.size()) {
int64_t ret = strtoll(str, &endptr, base);
if (endptr == str || endptr != str + strlen(str)) {
*err = (std::string {"Expected option value to be integer, got '"} +
std::string {str} + "'");
return 0;
Expand All @@ -87,11 +81,7 @@ int64_t strict_strtoll(string_view str, int base, std::string *err) {
return ret;
}

int64_t strict_strtoll(const char *str, int base, std::string *err) {
return strict_strtoll(string_view(str), base, err);
}

int strict_strtol(string_view str, int base, std::string *err) {
int strict_strtol(const char *str, int base, std::string *err) {
int64_t ret = strict_strtoll(str, base, err);
if (!err->empty())
return 0;
Expand All @@ -104,10 +94,6 @@ int strict_strtol(string_view str, int base, std::string *err) {
return static_cast<int>(ret);
}

int strict_strtol(const char *str, int base, std::string *err) {
return strict_strtol(string_view(str), base, err);
}

struct strict_str_convert {
const char *str;
std::string *err;
Expand Down
1 change: 1 addition & 0 deletions nbd/src/argparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <stdarg.h>
#include <vector>
#include <string>

namespace curve {
namespace nbd {
Expand Down
2 changes: 1 addition & 1 deletion nbd/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ COPTS = [
"-Woverloaded-virtual",
"-Wnon-virtual-dtor",
"-Wno-missing-field-initializers",
"-std=c++14",
"-std=c++11",
"-I /usr/include/libnl3",
]

Expand Down
146 changes: 146 additions & 0 deletions nbd/test/test_argparse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Copyright (c) 2020 NetEase Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* Project: curve
* Created Date: Wed Jul 22 11:19:30 CST 2020
* Author: wuhanqing
*/

#include <glog/logging.h>
#include <gtest/gtest.h>
#include <limits>
#include <string>
#include "nbd/src/argparse.h"

namespace curve {
namespace nbd {

std::string Quoted(const std::string& str) {
return '\'' + str + '\'';
}

float strict_strtof(const char* str, std::string* err);
int64_t strict_strtoll(const char* str, int base, std::string* err);
int strict_strtol(const char* str, int base, std::string* err);

TEST(TestArgParse, Test_strict_strtof) {
std::string error;
const std::vector<const char*> validNums = {
"1.2345",
"-1.2345",
" 1"
};

for (const auto& num : validNums) {
error.clear();
LOG(INFO) << "testing: " << Quoted(num);
EXPECT_FLOAT_EQ(std::stof(num), strict_strtof(num, &error));
EXPECT_EQ(0, error.size());
}

const std::vector<const char*> invalidNums = {
"-1.2 ", // trailing whitespace is illegal
" 1.2 ",
"-1.2-1.2",
"1 0",
"------1.2",
};

for (const auto& num : invalidNums) {
error.clear();
LOG(INFO) << "testing: " << Quoted(num);
EXPECT_FLOAT_EQ(0.0f, strict_strtof(num, &error));
ASSERT_NE(0, error.size());
}
}

TEST(TestArgParse, Test_strict_strtol) {
std::string error;
std::vector<const char*> validNums = {
"12345",
"-12345",
" 12345",
" -12456",
"+12345",
"+2147483647",
"-2147483648",
};

for (const auto& num : validNums) {
error.clear();
LOG(INFO) << "testing: " << Quoted(num);
ASSERT_EQ(std::stol(num), strict_strtol(num, 10, &error));
ASSERT_EQ(0, error.size());
}

std::vector<const char*> invalidNums = {
"-----------1",
"++++++++++++1",
"1234567890123124", // out of range
"-1234567890123", // out of range
"12345 ",
"12345 1",
};

for (const auto& num : invalidNums) {
error.clear();
LOG(INFO) << "testing: " << Quoted(num);
ASSERT_EQ(0, strict_strtol(num, 10, &error));
ASSERT_NE(0, error.size());
}
}

TEST(TestArgParse, Test_strict_strtoll) {
std::string error;
std::vector<const char*> validNums = {
"12345",
"-12345",
" 12345",
" -12456",
"+12345",
"+9223372036854775807",
"-9223372036854775808",
};

for (const auto& num : validNums) {
error.clear();
LOG(INFO) << "testing: " << Quoted(num);
ASSERT_EQ(std::stoll(num), strict_strtoll(num, 10, &error));
ASSERT_EQ(0, error.size());
}

std::vector<const char*> invalidNums = {
"-----------1",
"++++++++++++1",
"9223372036854775808", // out of range
"-9223372036854775809", // out of range
"12345 ",
"12345 1",
};

for (const auto& num : invalidNums) {
error.clear();
LOG(INFO) << "testing: " << Quoted(num);
ASSERT_EQ(0, strict_strtoll(num, 10, &error));
ASSERT_NE(0, error.size());
}
}

} // namespace nbd
} // namespace curve
2 changes: 1 addition & 1 deletion nebd/src/part1/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ COPTS = [
"-DHAVE_ZLIB",
"-DHAVE_SSE42",
"-DNDEBUG",
"-std=c++14",
"-std=c++11",
"-pipe",
"-W",
"-Wall",
Expand Down
2 changes: 1 addition & 1 deletion nebd/src/part2/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ COPTS = [
"-DHAVE_ZLIB",
"-DHAVE_SSE42",
"-DNDEBUG",
"-std=c++14",
"-std=c++11",
"-pipe",
"-W",
"-Wall",
Expand Down
1 change: 1 addition & 0 deletions nebd/src/part2/file_entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <atomic>
#include <mutex> // NOLINT
#include <unordered_map>
#include <functional>

#include "nebd/src/common/rw_lock.h"
#include "nebd/src/common/timeutility.h"
Expand Down
2 changes: 1 addition & 1 deletion src/chunkserver/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ COPTS = [
"-Woverloaded-virtual",
"-Wnon-virtual-dtor",
"-Wno-missing-field-initializers",
"-std=c++14",
"-std=c++11",
]

cc_library(
Expand Down
2 changes: 1 addition & 1 deletion src/chunkserver/copyset_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int CopysetNode::Init(const CopysetNodeOptions &options) {
copysetDirPath_.append("/").append(groupId);
fs_ = options.localFileSystem;
CHECK(nullptr != fs_) << "local file sytem is null";
epochFile_ = std::make_unique<ConfEpochFile>(fs_);
epochFile_.reset(new ConfEpochFile(fs_));

chunkDataRpath_ = RAFT_DATA_DIR;
chunkDataApath_.append("/").append(RAFT_DATA_DIR);
Expand Down
2 changes: 1 addition & 1 deletion src/client/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ COPTS = [
"-Woverloaded-virtual",
"-Wnon-virtual-dtor",
"-Wno-missing-field-initializers",
"-std=c++14",
"-std=c++11",
]

cc_library(
Expand Down
2 changes: 1 addition & 1 deletion src/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ COPTS = [
"-Woverloaded-virtual",
"-Wnon-virtual-dtor",
"-Wno-missing-field-initializers",
"-std=c++14",
"-std=c++11",
]

cc_library(
Expand Down
2 changes: 1 addition & 1 deletion src/common/concurrent/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ COPTS = [
"-Woverloaded-virtual",
"-Wnon-virtual-dtor",
"-Wno-missing-field-initializers",
"-std=c++14",
"-std=c++11",
]

cc_library(
Expand Down
2 changes: 1 addition & 1 deletion src/snapshotcloneserver/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ COPTS = [
"-Woverloaded-virtual",
"-Wnon-virtual-dtor",
"-Wno-missing-field-initializers",
"-std=c++14",
"-std=c++11",
]

cc_library(
Expand Down
34 changes: 17 additions & 17 deletions src/tools/BUILD
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#
# Copyright (c) 2020 NetEase Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# Copyright (c) 2020 NetEase Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# tools

# https://docs.bazel.build/versions/master/be/c-cpp.html#cc_library
Expand All @@ -33,7 +33,7 @@ COPTS = [
"-Woverloaded-virtual",
"-Wnon-virtual-dtor",
"-Wno-missing-field-initializers",
"-std=c++14",
"-std=c++11",
]

cc_test(
Expand Down
Loading

0 comments on commit 0a9dab3

Please sign in to comment.