Require C++14 (#2596)

This only has some minor additions of std::make_unique, digits
separators, std::string literals, and more flexible constexpr.
References #2469.
This commit is contained in:
Andrew Gaul
2025-05-18 12:34:53 +09:00
committed by GitHub
parent 3421025074
commit f2542f22fe
27 changed files with 89 additions and 86 deletions

View File

@ -54,7 +54,6 @@ Checks: '
-misc-use-internal-linkage, -misc-use-internal-linkage,
-modernize-avoid-c-arrays, -modernize-avoid-c-arrays,
-modernize-loop-convert, -modernize-loop-convert,
-modernize-make-unique,
-modernize-use-nodiscard, -modernize-use-nodiscard,
-modernize-raw-string-literal, -modernize-raw-string-literal,
-modernize-return-braced-init-list, -modernize-return-braced-init-list,

View File

@ -146,7 +146,7 @@ jobs:
- name: Build - name: Build
run: | run: |
./autogen.sh ./autogen.sh
PKG_CONFIG_PATH=/usr/local/opt/curl/lib/pkgconfig:/usr/local/opt/openssl/lib/pkgconfig ./configure CXXFLAGS='-std=c++11 -DS3FS_PTHREAD_ERRORCHECK=1' PKG_CONFIG_PATH=/usr/local/opt/curl/lib/pkgconfig:/usr/local/opt/openssl/lib/pkgconfig ./configure CXXFLAGS='-std=c++14 -DS3FS_PTHREAD_ERRORCHECK=1'
make --jobs=$(sysctl -n hw.ncpu) make --jobs=$(sysctl -n hw.ncpu)
- name: Cppcheck - name: Cppcheck

View File

@ -38,7 +38,7 @@ clang-tidy:
cppcheck: cppcheck:
cppcheck --quiet --error-exitcode=1 \ cppcheck --quiet --error-exitcode=1 \
--inline-suppr \ --inline-suppr \
--std=c++11 \ --std=c++14 \
--xml \ --xml \
-D HAVE_ATTR_XATTR_H \ -D HAVE_ATTR_XATTR_H \
-D HAVE_SYS_EXTATTR_H \ -D HAVE_SYS_EXTATTR_H \

View File

@ -34,7 +34,7 @@ AC_CHECK_HEADERS([attr/xattr.h])
AC_CHECK_HEADERS([sys/extattr.h]) AC_CHECK_HEADERS([sys/extattr.h])
AC_CHECK_FUNCS([fallocate]) AC_CHECK_FUNCS([fallocate])
CXXFLAGS="-Wall -fno-exceptions -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=3 -std=c++11 $CXXFLAGS" CXXFLAGS="-Wall -fno-exceptions -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=3 -std=c++14 $CXXFLAGS"
dnl ---------------------------------------------- dnl ----------------------------------------------
dnl For macOS dnl For macOS

View File

@ -102,7 +102,7 @@ TESTS = \
test_string_util test_string_util
clang-tidy: clang-tidy:
clang-tidy -extra-arg-before=-xc++ \ clang-tidy -extra-arg-before=-xc++ -extra-arg=-std=c++14 \
*.h $(s3fs_SOURCES) test_curl_util.cpp test_page_list.cpp test_string_util.cpp \ *.h $(s3fs_SOURCES) test_curl_util.cpp test_page_list.cpp test_string_util.cpp \
-- $(DEPS_CFLAGS) $(CPPFLAGS) -- $(DEPS_CFLAGS) $(CPPFLAGS)

View File

@ -44,7 +44,7 @@ static void SetStatCacheTime(struct timespec& ts)
} }
} }
static int CompareStatCacheTime(const struct timespec& ts1, const struct timespec& ts2) static constexpr int CompareStatCacheTime(const struct timespec& ts1, const struct timespec& ts2)
{ {
// return -1: ts1 < ts2 // return -1: ts1 < ts2
// 0: ts1 == ts2 // 0: ts1 == ts2
@ -119,7 +119,7 @@ std::mutex StatCache::stat_cache_lock;
//------------------------------------------------------------------- //-------------------------------------------------------------------
// Constructor/Destructor // Constructor/Destructor
//------------------------------------------------------------------- //-------------------------------------------------------------------
StatCache::StatCache() : IsExpireTime(true), IsExpireIntervalType(false), ExpireTime(15 * 60), CacheSize(100000), IsCacheNoObject(true) StatCache::StatCache() : IsExpireTime(true), IsExpireIntervalType(false), ExpireTime(15 * 60), CacheSize(100'000), IsCacheNoObject(true)
{ {
if(this == StatCache::getStatCacheData()){ if(this == StatCache::getStatCacheData()){
stat_cache.clear(); stat_cache.clear();

View File

@ -203,7 +203,7 @@ CURLSH* S3fsCurlShare::GetCurlShareHandle()
S3FS_PRN_ERR("Failed to create curl share handle"); S3FS_PRN_ERR("Failed to create curl share handle");
return nullptr; return nullptr;
} }
ShareLocksPtr pLocks(new curl_share_locks); auto pLocks = std::make_unique<curl_share_locks>();
// Initialize curl share handle // Initialize curl share handle
if(!S3fsCurlShare::InitializeCurlShare(hShare, pLocks)){ if(!S3fsCurlShare::InitializeCurlShare(hShare, pLocks)){

View File

@ -30,6 +30,8 @@
#include "s3fs_auth.h" #include "s3fs_auth.h"
#include "s3fs_cred.h" #include "s3fs_cred.h"
using namespace std::string_literals;
//------------------------------------------------------------------- //-------------------------------------------------------------------
// Utility Functions // Utility Functions
//------------------------------------------------------------------- //-------------------------------------------------------------------
@ -47,7 +49,7 @@ struct curl_slist* curl_slist_sort_insert(struct curl_slist* list, const char* k
// key & value are trimmed and lower (only key) // key & value are trimmed and lower (only key)
std::string strkey = trim(key); std::string strkey = trim(key);
std::string strval = value ? trim(value) : ""; std::string strval = value ? trim(value) : "";
std::string strnew = key + std::string(": ") + strval; std::string strnew = key + ": "s + strval;
char* data; char* data;
if(nullptr == (data = strdup(strnew.c_str()))){ if(nullptr == (data = strdup(strnew.c_str()))){
return list; return list;

View File

@ -49,7 +49,7 @@
//------------------------------------------------ //------------------------------------------------
// Symbols // Symbols
//------------------------------------------------ //------------------------------------------------
static constexpr int MAX_MULTIPART_CNT = 10 * 1000; // S3 multipart max count static constexpr int MAX_MULTIPART_CNT = 10'000; // S3 multipart max count
//------------------------------------------------ //------------------------------------------------
// FdEntity class variables // FdEntity class variables
@ -247,7 +247,7 @@ int FdEntity::DupWithLock(int fd)
return -1; return -1;
} }
const PseudoFdInfo* org_pseudoinfo = iter->second.get(); const PseudoFdInfo* org_pseudoinfo = iter->second.get();
std::unique_ptr<PseudoFdInfo> ppseudoinfo(new PseudoFdInfo(physical_fd, (org_pseudoinfo ? org_pseudoinfo->GetFlags() : 0))); auto ppseudoinfo = std::make_unique<PseudoFdInfo>(physical_fd, (org_pseudoinfo ? org_pseudoinfo->GetFlags() : 0));
int pseudo_fd = ppseudoinfo->GetPseudoFd(); int pseudo_fd = ppseudoinfo->GetPseudoFd();
pseudo_fd_map[pseudo_fd] = std::move(ppseudoinfo); pseudo_fd_map[pseudo_fd] = std::move(ppseudoinfo);
@ -263,7 +263,7 @@ int FdEntity::OpenPseudoFd(int flags)
if(-1 == physical_fd){ if(-1 == physical_fd){
return -1; return -1;
} }
std::unique_ptr<PseudoFdInfo> ppseudoinfo(new PseudoFdInfo(physical_fd, flags)); auto ppseudoinfo = std::make_unique<PseudoFdInfo>(physical_fd, flags);
int pseudo_fd = ppseudoinfo->GetPseudoFd(); int pseudo_fd = ppseudoinfo->GetPseudoFd();
pseudo_fd_map[pseudo_fd] = std::move(ppseudoinfo); pseudo_fd_map[pseudo_fd] = std::move(ppseudoinfo);
@ -456,7 +456,7 @@ int FdEntity::Open(const headers_t* pmeta, off_t size, const struct timespec& ts
} }
// open cache and cache stat file, load page info. // open cache and cache stat file, load page info.
pcfstat.reset(new CacheFileStat(path.c_str())); pcfstat = std::make_unique<CacheFileStat>(path.c_str());
// try to open cache file // try to open cache file
if( -1 != (physical_fd = open(cachepath.c_str(), O_RDWR)) && if( -1 != (physical_fd = open(cachepath.c_str(), O_RDWR)) &&
@ -628,7 +628,7 @@ int FdEntity::Open(const headers_t* pmeta, off_t size, const struct timespec& ts
} }
// create new pseudo fd, and set it to map // create new pseudo fd, and set it to map
std::unique_ptr<PseudoFdInfo> ppseudoinfo(new PseudoFdInfo(physical_fd, flags)); auto ppseudoinfo = std::make_unique<PseudoFdInfo>(physical_fd, flags);
int pseudo_fd = ppseudoinfo->GetPseudoFd(); int pseudo_fd = ppseudoinfo->GetPseudoFd();
pseudo_fd_map[pseudo_fd] = std::move(ppseudoinfo); pseudo_fd_map[pseudo_fd] = std::move(ppseudoinfo);

View File

@ -234,7 +234,7 @@ bool PageList::GetSparseFilePages(int fd, size_t file_size, fdpage_list_t& spars
// //
bool PageList::CheckZeroAreaInFile(int fd, off_t start, size_t bytes) bool PageList::CheckZeroAreaInFile(int fd, off_t start, size_t bytes)
{ {
std::unique_ptr<char[]> readbuff(new char[CHECK_CACHEFILE_PART_SIZE]); auto readbuff = std::make_unique<char[]>(CHECK_CACHEFILE_PART_SIZE);
for(size_t comp_bytes = 0, check_bytes = 0; comp_bytes < bytes; comp_bytes += check_bytes){ for(size_t comp_bytes = 0, check_bytes = 0; comp_bytes < bytes; comp_bytes += check_bytes){
if(CHECK_CACHEFILE_PART_SIZE < (bytes - comp_bytes)){ if(CHECK_CACHEFILE_PART_SIZE < (bytes - comp_bytes)){
@ -868,7 +868,7 @@ bool PageList::Deserialize(CacheFileStat& file, ino_t inode)
Init(0, false, false); Init(0, false, false);
return true; return true;
} }
std::unique_ptr<char[]> ptmp(new char[st.st_size + 1]); auto ptmp = std::make_unique<char[]>(st.st_size + 1);
ssize_t result; ssize_t result;
// read from file // read from file
if(0 >= (result = pread(file.GetFd(), ptmp.get(), st.st_size, 0))){ if(0 >= (result = pread(file.GetFd(), ptmp.get(), st.st_size, 0))){

View File

@ -111,7 +111,7 @@ std::unique_ptr<unsigned char[]> s3fs_HMAC(const void* key, size_t keylen, const
return nullptr; return nullptr;
} }
std::unique_ptr<unsigned char[]> digest(new unsigned char[SHA1_DIGEST_SIZE]); auto digest = std::make_unique<unsigned char[]>(SHA1_DIGEST_SIZE);
struct hmac_sha1_ctx ctx_hmac; struct hmac_sha1_ctx ctx_hmac;
hmac_sha1_set_key(&ctx_hmac, keylen, reinterpret_cast<const uint8_t*>(key)); hmac_sha1_set_key(&ctx_hmac, keylen, reinterpret_cast<const uint8_t*>(key));
@ -128,7 +128,7 @@ std::unique_ptr<unsigned char[]> s3fs_HMAC256(const void* key, size_t keylen, co
return nullptr; return nullptr;
} }
std::unique_ptr<unsigned char[]> digest(new unsigned char[SHA256_DIGEST_SIZE]); auto digest = std::make_unique<unsigned char[]>(SHA256_DIGEST_SIZE);
struct hmac_sha256_ctx ctx_hmac; struct hmac_sha256_ctx ctx_hmac;
hmac_sha256_set_key(&ctx_hmac, keylen, reinterpret_cast<const uint8_t*>(key)); hmac_sha256_set_key(&ctx_hmac, keylen, reinterpret_cast<const uint8_t*>(key));
@ -150,7 +150,7 @@ std::unique_ptr<unsigned char[]> s3fs_HMAC(const void* key, size_t keylen, const
if(0 == (*digestlen = gnutls_hmac_get_len(GNUTLS_MAC_SHA1))){ if(0 == (*digestlen = gnutls_hmac_get_len(GNUTLS_MAC_SHA1))){
return nullptr; return nullptr;
} }
std::unique_ptr<unsigned char[]> digest(new unsigned char[*digestlen + 1]); auto digest = std::make_unique<unsigned char[]>(*digestlen + 1);
if(0 > gnutls_hmac_fast(GNUTLS_MAC_SHA1, key, keylen, data, datalen, digest.get())){ if(0 > gnutls_hmac_fast(GNUTLS_MAC_SHA1, key, keylen, data, datalen, digest.get())){
return nullptr; return nullptr;
} }
@ -166,7 +166,7 @@ std::unique_ptr<unsigned char[]> s3fs_HMAC256(const void* key, size_t keylen, co
if(0 == (*digestlen = gnutls_hmac_get_len(GNUTLS_MAC_SHA256))){ if(0 == (*digestlen = gnutls_hmac_get_len(GNUTLS_MAC_SHA256))){
return nullptr; return nullptr;
} }
std::unique_ptr<unsigned char[]> digest(new unsigned char[*digestlen + 1]); auto digest = std::make_unique<unsigned char[]>(*digestlen + 1);
if(0 > gnutls_hmac_fast(GNUTLS_MAC_SHA256, key, keylen, data, datalen, digest.get())){ if(0 > gnutls_hmac_fast(GNUTLS_MAC_SHA256, key, keylen, data, datalen, digest.get())){
return nullptr; return nullptr;
} }

View File

@ -126,7 +126,7 @@ static std::unique_ptr<unsigned char[]> s3fs_HMAC_RAW(const void* key, size_t ke
PK11_FreeSymKey(pKey); PK11_FreeSymKey(pKey);
PK11_FreeSlot(Slot); PK11_FreeSlot(Slot);
std::unique_ptr<unsigned char[]> digest(new unsigned char[*digestlen]); auto digest = std::make_unique<unsigned char[]>(*digestlen);
memcpy(digest.get(), tmpdigest, *digestlen); memcpy(digest.get(), tmpdigest, *digestlen);
return digest; return digest;

View File

@ -25,6 +25,7 @@
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cerrno> #include <cerrno>
#include <memory>
#include <mutex> #include <mutex>
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -138,7 +139,7 @@ bool s3fs_init_crypt_mutex()
return false; return false;
} }
} }
s3fs_crypt_mutex.reset(new std::mutex[CRYPTO_num_locks()]); s3fs_crypt_mutex = std::make_unique<std::mutex[]>(CRYPTO_num_locks());
// static lock // static lock
CRYPTO_set_locking_callback(s3fs_crypt_mutex_lock); CRYPTO_set_locking_callback(s3fs_crypt_mutex_lock);
CRYPTO_set_id_callback(s3fs_crypt_get_threadid); CRYPTO_set_id_callback(s3fs_crypt_get_threadid);
@ -177,7 +178,7 @@ static std::unique_ptr<unsigned char[]> s3fs_HMAC_RAW(const void* key, size_t ke
return nullptr; return nullptr;
} }
(*digestlen) = EVP_MAX_MD_SIZE * sizeof(unsigned char); (*digestlen) = EVP_MAX_MD_SIZE * sizeof(unsigned char);
std::unique_ptr<unsigned char[]> digest(new unsigned char[*digestlen]); auto digest = std::make_unique<unsigned char[]>(*digestlen);
if(is_sha256){ if(is_sha256){
HMAC(EVP_sha256(), key, static_cast<int>(keylen), data, datalen, digest.get(), digestlen); HMAC(EVP_sha256(), key, static_cast<int>(keylen), data, datalen, digest.get(), digestlen);
}else{ }else{

View File

@ -204,17 +204,17 @@ static std::atomic<bool> has_mp_stat;
//------------------------------------------------------------------- //-------------------------------------------------------------------
// Functions // Functions
//------------------------------------------------------------------- //-------------------------------------------------------------------
static bool IS_REPLACEDIR(dirtype type) static constexpr bool IS_REPLACEDIR(dirtype type)
{ {
return dirtype::OLD == type || dirtype::FOLDER == type || dirtype::NOOBJ == type; return dirtype::OLD == type || dirtype::FOLDER == type || dirtype::NOOBJ == type;
} }
static bool IS_RMTYPEDIR(dirtype type) static constexpr bool IS_RMTYPEDIR(dirtype type)
{ {
return dirtype::OLD == type || dirtype::FOLDER == type; return dirtype::OLD == type || dirtype::FOLDER == type;
} }
static bool IS_CREATE_MP_STAT(const char* path) static constexpr bool IS_CREATE_MP_STAT(const char* path)
{ {
// [NOTE] has_mp_stat is set in get_object_attribute() // [NOTE] has_mp_stat is set in get_object_attribute()
return (path != nullptr && 0 == strcmp(path, "/") && !has_mp_stat); return (path != nullptr && 0 == strcmp(path, "/") && !has_mp_stat);
@ -5386,7 +5386,7 @@ int main(int argc, char* argv[])
// set credential object // set credential object
// //
ps3fscred.reset(new S3fsCred()); ps3fscred = std::make_unique<S3fsCred>();
if(!S3fsCurl::InitCredentialObject(ps3fscred.get())){ if(!S3fsCurl::InitCredentialObject(ps3fscred.get())){
S3FS_PRN_EXIT("Failed to setup credential object to s3fs curl."); S3FS_PRN_EXIT("Failed to setup credential object to s3fs curl.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

View File

@ -38,6 +38,8 @@
#include "threadpoolman.h" #include "threadpoolman.h"
#include "s3fs_threadreqs.h" #include "s3fs_threadreqs.h"
using namespace std::string_literals;
//------------------------------------------------------------------- //-------------------------------------------------------------------
// Symbols // Symbols
//------------------------------------------------------------------- //-------------------------------------------------------------------
@ -1012,7 +1014,7 @@ bool S3fsCred::InitialS3fsCredentials()
} }
// 3b - check ${HOME}/.aws/credentials // 3b - check ${HOME}/.aws/credentials
std::string aws_credentials = std::string(getpwuid(getuid())->pw_dir) + "/.aws/credentials"; std::string aws_credentials = getpwuid(getuid())->pw_dir + "/.aws/credentials"s;
if(ReadAwsCredentialFile(aws_credentials)){ if(ReadAwsCredentialFile(aws_credentials)){
return true; return true;
}else if(aws_profile != DEFAULT_AWS_PROFILE_NAME){ }else if(aws_profile != DEFAULT_AWS_PROFILE_NAME){
@ -1409,7 +1411,7 @@ int S3fsCred::DetectParam(const char* arg)
S3FS_PRN_EXIT("option ibm_iam_endpoint has invalid format, missing http / https protocol"); S3FS_PRN_EXIT("option ibm_iam_endpoint has invalid format, missing http / https protocol");
return -1; return -1;
} }
endpoint_url = std::string(iam_endpoint) + "/identity/token"; endpoint_url = iam_endpoint + "/identity/token"s;
SetIAMCredentialsURL(endpoint_url.c_str()); SetIAMCredentialsURL(endpoint_url.c_str());
set_builtin_cred_opts = true; set_builtin_cred_opts = true;
return 0; return 0;

View File

@ -258,7 +258,7 @@ void s3fs_low_logprn(S3fsLog::s3fs_log_level level, const char* file, const char
size_t len = vsnprintf(nullptr, 0, fmt, va) + 1; size_t len = vsnprintf(nullptr, 0, fmt, va) + 1;
va_end(va); va_end(va);
std::unique_ptr<char[]> message(new char[len]); auto message = std::make_unique<char[]>(len);
va_start(va, fmt); va_start(va, fmt);
vsnprintf(message.get(), len, fmt, va); vsnprintf(message.get(), len, fmt, va);
va_end(va); va_end(va);
@ -282,7 +282,7 @@ void s3fs_low_logprn2(S3fsLog::s3fs_log_level level, int nest, const char* file,
size_t len = vsnprintf(nullptr, 0, fmt, va) + 1; size_t len = vsnprintf(nullptr, 0, fmt, va) + 1;
va_end(va); va_end(va);
std::unique_ptr<char[]> message(new char[len]); auto message = std::make_unique<char[]>(len);
va_start(va, fmt); va_start(va, fmt);
vsnprintf(message.get(), len, fmt, va); vsnprintf(message.get(), len, fmt, va);
va_end(va); va_end(va);

View File

@ -101,11 +101,11 @@ std::string get_username(uid_t uid)
struct passwd* ppwinfo = nullptr; struct passwd* ppwinfo = nullptr;
// make buffer // make buffer
std::unique_ptr<char[]> pbuf(new char[maxlen]); auto pbuf = std::make_unique<char[]>(maxlen);
// get pw information // get pw information
while(ERANGE == (result = getpwuid_r(uid, &pwinfo, pbuf.get(), maxlen, &ppwinfo))){ while(ERANGE == (result = getpwuid_r(uid, &pwinfo, pbuf.get(), maxlen, &ppwinfo))){
maxlen *= 2; maxlen *= 2;
pbuf.reset(new char[maxlen]); pbuf = std::make_unique<char[]>(maxlen);
} }
if(0 != result){ if(0 != result){
@ -129,11 +129,11 @@ int is_uid_include_group(uid_t uid, gid_t gid)
struct group* pginfo = nullptr; struct group* pginfo = nullptr;
// make buffer // make buffer
std::unique_ptr<char[]> pbuf(new char[maxlen]); auto pbuf = std::make_unique<char[]>(maxlen);
// get group information // get group information
while(ERANGE == (result = getgrgid_r(gid, &ginfo, pbuf.get(), maxlen, &pginfo))){ while(ERANGE == (result = getgrgid_r(gid, &ginfo, pbuf.get(), maxlen, &pginfo))){
maxlen *= 2; maxlen *= 2;
pbuf.reset(new char[maxlen]); pbuf = std::make_unique<char[]>(maxlen);
} }
if(0 != result){ if(0 != result){
@ -410,7 +410,7 @@ void print_launch_message(int argc, char** argv)
// 0 ts1 == ts2 // 0 ts1 == ts2
// 1 ts1 > ts2 // 1 ts1 > ts2
// //
int compare_timespec(const struct timespec& ts1, const struct timespec& ts2) constexpr int compare_timespec(const struct timespec& ts1, const struct timespec& ts2)
{ {
if(ts1.tv_sec < ts2.tv_sec){ if(ts1.tv_sec < ts2.tv_sec){
return -1; return -1;

View File

@ -73,7 +73,7 @@ enum class stat_time_type : uint8_t {
//------------------------------------------------------------------- //-------------------------------------------------------------------
static constexpr struct timespec S3FS_OMIT_TS = {0, UTIME_OMIT}; static constexpr struct timespec S3FS_OMIT_TS = {0, UTIME_OMIT};
int compare_timespec(const struct timespec& ts1, const struct timespec& ts2); constexpr int compare_timespec(const struct timespec& ts1, const struct timespec& ts2);
int compare_timespec(const struct stat& st, stat_time_type type, const struct timespec& ts); int compare_timespec(const struct stat& st, stat_time_type type, const struct timespec& ts);
void set_timespec_to_stat(struct stat& st, stat_time_type type, const struct timespec& ts); void set_timespec_to_stat(struct stat& st, stat_time_type type, const struct timespec& ts);
struct timespec* set_stat_to_timespec(const struct stat& st, stat_time_type type, struct timespec& ts); struct timespec* set_stat_to_timespec(const struct stat& st, stat_time_type type, struct timespec& ts);

View File

@ -20,6 +20,7 @@
#include <cstdio> #include <cstdio>
#include <csignal> #include <csignal>
#include <memory>
#include <thread> #include <thread>
#include <utility> #include <utility>
@ -40,7 +41,7 @@ bool S3fsSignals::enableUsr1 = false;
bool S3fsSignals::Initialize() bool S3fsSignals::Initialize()
{ {
if(!S3fsSignals::pSingleton){ if(!S3fsSignals::pSingleton){
S3fsSignals::pSingleton.reset(new S3fsSignals); S3fsSignals::pSingleton = std::make_unique<S3fsSignals>();
} }
return true; return true;
} }
@ -193,8 +194,8 @@ bool S3fsSignals::InitUsr1Handler()
} }
// create thread // create thread
std::unique_ptr<Semaphore> pSemUsr1_tmp(new Semaphore(0)); auto pSemUsr1_tmp = std::make_unique<Semaphore>(0);
pThreadUsr1.reset(new std::thread(S3fsSignals::CheckCacheWorker, pSemUsr1_tmp.get())); pThreadUsr1 = std::make_unique<std::thread>(S3fsSignals::CheckCacheWorker, pSemUsr1_tmp.get());
pSemUsr1 = std::move(pSemUsr1_tmp); pSemUsr1 = std::move(pSemUsr1_tmp);
// set handler // set handler

View File

@ -50,13 +50,12 @@ class S3fsSignals
static void HandlerHUP(int sig); static void HandlerHUP(int sig);
static bool InitHupHandler(); static bool InitHupHandler();
S3fsSignals();
bool InitUsr1Handler(); bool InitUsr1Handler();
bool DestroyUsr1Handler(); bool DestroyUsr1Handler();
bool WakeupUsr1Thread(); bool WakeupUsr1Thread();
public: public:
S3fsSignals();
~S3fsSignals(); ~S3fsSignals();
S3fsSignals(const S3fsSignals&) = delete; S3fsSignals(const S3fsSignals&) = delete;
S3fsSignals(S3fsSignals&&) = delete; S3fsSignals(S3fsSignals&&) = delete;

View File

@ -404,25 +404,23 @@ std::string s3fs_base64(const unsigned char* input, size_t length)
return result; return result;
} }
static inline unsigned char char_decode64(const char ch) static constexpr unsigned char char_decode64(const char ch)
{ {
unsigned char by;
if('A' <= ch && ch <= 'Z'){ // A - Z if('A' <= ch && ch <= 'Z'){ // A - Z
by = static_cast<unsigned char>(ch - 'A'); return static_cast<unsigned char>(ch - 'A');
}else if('a' <= ch && ch <= 'z'){ // a - z }else if('a' <= ch && ch <= 'z'){ // a - z
by = static_cast<unsigned char>(ch - 'a' + 26); return static_cast<unsigned char>(ch - 'a' + 26);
}else if('0' <= ch && ch <= '9'){ // 0 - 9 }else if('0' <= ch && ch <= '9'){ // 0 - 9
by = static_cast<unsigned char>(ch - '0' + 52); return static_cast<unsigned char>(ch - '0' + 52);
}else if('+' == ch){ // + }else if('+' == ch){ // +
by = 62; return 62;
}else if('/' == ch){ // / }else if('/' == ch){ // /
by = 63; return 63;
}else if('=' == ch){ // = }else if('=' == ch){ // =
by = 64; return 64;
}else{ // something wrong }else{ // something wrong
by = UCHAR_MAX; return UCHAR_MAX;
} }
return by;
} }
std::string s3fs_decode64(const char* input, size_t input_len) std::string s3fs_decode64(const char* input, size_t input_len)
@ -509,7 +507,7 @@ bool s3fs_wtf8_encode(const char *s, std::string *result)
// four byte encoding // four byte encoding
if ((c & 0xf8) == 0xf0 && (s[1] & 0xc0) == 0x80 && (s[2] & 0xc0) == 0x80 && (s[3] & 0xc0) == 0x80) { if ((c & 0xf8) == 0xf0 && (s[1] & 0xc0) == 0x80 && (s[2] & 0xc0) == 0x80 && (s[3] & 0xc0) == 0x80) {
const unsigned code = ((c & 0x07) << 18) | ((s[1] & 0x3f) << 12) | ((s[2] & 0x3f) << 6) | (s[3] & 0x3f); const unsigned code = ((c & 0x07) << 18) | ((s[1] & 0x3f) << 12) | ((s[2] & 0x3f) << 6) | (s[3] & 0x3f);
if (code >= 0x10000 && code <= 0x10ffff) { if (code >= 0x10'000 && code <= 0x10f'fff) {
// not overlong and in defined unicode space // not overlong and in defined unicode space
if (result) { if (result) {
*result += c; *result += c;

View File

@ -27,6 +27,8 @@
#include "string_util.h" #include "string_util.h"
#include "test_util.h" #include "test_util.h"
using namespace std::string_literals;
//------------------------------------------------------------------- //-------------------------------------------------------------------
// Global variables for test_string_util // Global variables for test_string_util
//------------------------------------------------------------------- //-------------------------------------------------------------------
@ -35,29 +37,29 @@ std::string instance_name;
void test_trim() void test_trim()
{ {
ASSERT_EQUALS(std::string("1234"), trim(" 1234 ")); ASSERT_EQUALS("1234"s, trim(" 1234 "));
ASSERT_EQUALS(std::string("1234"), trim("1234 ")); ASSERT_EQUALS("1234"s, trim("1234 "));
ASSERT_EQUALS(std::string("1234"), trim(" 1234")); ASSERT_EQUALS("1234"s, trim(" 1234"));
ASSERT_EQUALS(std::string("1234"), trim("1234")); ASSERT_EQUALS("1234"s, trim("1234"));
ASSERT_EQUALS(std::string("1234 "), trim_left(" 1234 ")); ASSERT_EQUALS("1234 "s, trim_left(" 1234 "));
ASSERT_EQUALS(std::string("1234 "), trim_left("1234 ")); ASSERT_EQUALS("1234 "s, trim_left("1234 "));
ASSERT_EQUALS(std::string("1234"), trim_left(" 1234")); ASSERT_EQUALS("1234"s, trim_left(" 1234"));
ASSERT_EQUALS(std::string("1234"), trim_left("1234")); ASSERT_EQUALS("1234"s, trim_left("1234"));
ASSERT_EQUALS(std::string(" 1234"), trim_right(" 1234 ")); ASSERT_EQUALS(" 1234"s, trim_right(" 1234 "));
ASSERT_EQUALS(std::string("1234"), trim_right("1234 ")); ASSERT_EQUALS("1234"s, trim_right("1234 "));
ASSERT_EQUALS(std::string(" 1234"), trim_right(" 1234")); ASSERT_EQUALS(" 1234"s, trim_right(" 1234"));
ASSERT_EQUALS(std::string("1234"), trim_right("1234")); ASSERT_EQUALS("1234"s, trim_right("1234"));
ASSERT_EQUALS(std::string("1234"), peeloff("\"1234\"")); // "1234" -> 1234 ASSERT_EQUALS("1234"s, peeloff("\"1234\"")); // "1234" -> 1234
ASSERT_EQUALS(std::string("\"1234\""), peeloff("\"\"1234\"\"")); // ""1234"" -> "1234" ASSERT_EQUALS("\"1234\""s, peeloff("\"\"1234\"\"")); // ""1234"" -> "1234"
ASSERT_EQUALS(std::string("\"1234"), peeloff("\"\"1234\"")); // ""1234" -> "1234 ASSERT_EQUALS("\"1234"s, peeloff("\"\"1234\"")); // ""1234" -> "1234
ASSERT_EQUALS(std::string("1234\""), peeloff("\"1234\"\"")); // "1234"" -> 1234" ASSERT_EQUALS("1234\""s, peeloff("\"1234\"\"")); // "1234"" -> 1234"
ASSERT_EQUALS(std::string("\"1234"), peeloff("\"1234")); // "1234 -> "1234 ASSERT_EQUALS("\"1234"s, peeloff("\"1234")); // "1234 -> "1234
ASSERT_EQUALS(std::string("1234\""), peeloff("1234\"")); // 1234" -> 1234" ASSERT_EQUALS("1234\""s, peeloff("1234\"")); // 1234" -> 1234"
ASSERT_EQUALS(std::string(" \"1234\""), peeloff(" \"1234\"")); // _"1234" -> _"1234" ASSERT_EQUALS(" \"1234\""s, peeloff(" \"1234\"")); // _"1234" -> _"1234"
ASSERT_EQUALS(std::string("\"1234\" "), peeloff("\"1234\" ")); // "1234"_ -> "1234"_ ASSERT_EQUALS("\"1234\" "s, peeloff("\"1234\" ")); // "1234"_ -> "1234"_
} }
void test_base64() void test_base64()
@ -65,30 +67,30 @@ void test_base64()
std::string buf; std::string buf;
char tmpbuf = '\0'; char tmpbuf = '\0';
ASSERT_EQUALS(s3fs_base64(nullptr, 0), std::string("")); ASSERT_EQUALS(s3fs_base64(nullptr, 0), ""s);
buf = s3fs_decode64(nullptr, 0); buf = s3fs_decode64(nullptr, 0);
ASSERT_BUFEQUALS(buf.c_str(), buf.length(), &tmpbuf, 0); ASSERT_BUFEQUALS(buf.c_str(), buf.length(), &tmpbuf, 0);
ASSERT_EQUALS(s3fs_base64(reinterpret_cast<const unsigned char *>(""), 0), std::string("")); ASSERT_EQUALS(s3fs_base64(reinterpret_cast<const unsigned char *>(""), 0), ""s);
buf = s3fs_decode64("", 0); buf = s3fs_decode64("", 0);
ASSERT_BUFEQUALS(buf.c_str(), buf.length(), &tmpbuf, 0); ASSERT_BUFEQUALS(buf.c_str(), buf.length(), &tmpbuf, 0);
ASSERT_EQUALS(s3fs_base64(reinterpret_cast<const unsigned char *>("1"), 1), std::string("MQ==")); ASSERT_EQUALS(s3fs_base64(reinterpret_cast<const unsigned char *>("1"), 1), "MQ=="s);
buf = s3fs_decode64("MQ==", 4); buf = s3fs_decode64("MQ==", 4);
ASSERT_BUFEQUALS(buf.c_str(), buf.length(), "1", 1); ASSERT_BUFEQUALS(buf.c_str(), buf.length(), "1", 1);
ASSERT_EQUALS(buf.length(), static_cast<size_t>(1)); ASSERT_EQUALS(buf.length(), static_cast<size_t>(1));
ASSERT_EQUALS(s3fs_base64(reinterpret_cast<const unsigned char *>("12"), 2), std::string("MTI=")); ASSERT_EQUALS(s3fs_base64(reinterpret_cast<const unsigned char *>("12"), 2), "MTI="s);
buf = s3fs_decode64("MTI=", 4); buf = s3fs_decode64("MTI=", 4);
ASSERT_BUFEQUALS(buf.c_str(), buf.length(), "12", 2); ASSERT_BUFEQUALS(buf.c_str(), buf.length(), "12", 2);
ASSERT_EQUALS(buf.length(), static_cast<size_t>(2)); ASSERT_EQUALS(buf.length(), static_cast<size_t>(2));
ASSERT_EQUALS(s3fs_base64(reinterpret_cast<const unsigned char *>("123"), 3), std::string("MTIz")); ASSERT_EQUALS(s3fs_base64(reinterpret_cast<const unsigned char *>("123"), 3), "MTIz"s);
buf = s3fs_decode64("MTIz", 4); buf = s3fs_decode64("MTIz", 4);
ASSERT_BUFEQUALS(buf.c_str(), buf.length(), "123", 3); ASSERT_BUFEQUALS(buf.c_str(), buf.length(), "123", 3);
ASSERT_EQUALS(buf.length(), static_cast<size_t>(3)); ASSERT_EQUALS(buf.length(), static_cast<size_t>(3));
ASSERT_EQUALS(s3fs_base64(reinterpret_cast<const unsigned char *>("1234"), 4), std::string("MTIzNA==")); ASSERT_EQUALS(s3fs_base64(reinterpret_cast<const unsigned char *>("1234"), 4), "MTIzNA=="s);
buf = s3fs_decode64("MTIzNA==", 8); buf = s3fs_decode64("MTIzNA==", 8);
ASSERT_BUFEQUALS(buf.c_str(), buf.length(), "1234", 4); ASSERT_BUFEQUALS(buf.c_str(), buf.length(), "1234", 4);
ASSERT_EQUALS(buf.length(), static_cast<size_t>(4)); ASSERT_EQUALS(buf.length(), static_cast<size_t>(4));
@ -121,7 +123,7 @@ void test_strtoofft()
ASSERT_EQUALS(value, static_cast<off_t>(15L)); ASSERT_EQUALS(value, static_cast<off_t>(15L));
ASSERT_TRUE(s3fs_strtoofft(&value, "deadbeef", /*base=*/ 16)); ASSERT_TRUE(s3fs_strtoofft(&value, "deadbeef", /*base=*/ 16));
ASSERT_EQUALS(value, static_cast<off_t>(3735928559L)); ASSERT_EQUALS(value, static_cast<off_t>(3'735'928'559L));
} }
void test_wtf8_encoding() void test_wtf8_encoding()

View File

@ -49,7 +49,7 @@ bool ThreadPoolMan::Initialize(int count)
if(-1 != count){ if(-1 != count){
ThreadPoolMan::SetWorkerCount(count); ThreadPoolMan::SetWorkerCount(count);
} }
ThreadPoolMan::singleton.reset(new ThreadPoolMan(ThreadPoolMan::worker_count)); ThreadPoolMan::singleton = std::make_unique<ThreadPoolMan>(ThreadPoolMan::worker_count);
return true; return true;
} }

View File

@ -76,8 +76,6 @@ class ThreadPoolMan
private: private:
static void Worker(ThreadPoolMan* psingleton, std::promise<int> promise); static void Worker(ThreadPoolMan* psingleton, std::promise<int> promise);
explicit ThreadPoolMan(int count = 1);
bool IsExit() const; bool IsExit() const;
void SetExitFlag(bool exit_flag); void SetExitFlag(bool exit_flag);
@ -86,6 +84,7 @@ class ThreadPoolMan
void SetInstruction(const thpoolman_param& pparam); void SetInstruction(const thpoolman_param& pparam);
public: public:
explicit ThreadPoolMan(int count = 1);
~ThreadPoolMan(); ~ThreadPoolMan();
ThreadPoolMan(const ThreadPoolMan&) = delete; ThreadPoolMan(const ThreadPoolMan&) = delete;
ThreadPoolMan(ThreadPoolMan&&) = delete; ThreadPoolMan(ThreadPoolMan&&) = delete;

View File

@ -67,7 +67,7 @@ enum class acl_t : uint8_t {
UNKNOWN UNKNOWN
}; };
inline const char* str(acl_t value) constexpr const char* str(acl_t value)
{ {
switch(value){ switch(value){
case acl_t::PRIVATE: case acl_t::PRIVATE:

View File

@ -43,7 +43,7 @@ truncate_read_file_SOURCES = truncate_read_file.cc
cr_filename_SOURCES = cr_filename.cc cr_filename_SOURCES = cr_filename.cc
clang-tidy: clang-tidy:
clang-tidy \ clang-tidy -extra-arg=-std=c++14 \
$(junk_data_SOURCES) \ $(junk_data_SOURCES) \
$(write_multiblock_SOURCES) \ $(write_multiblock_SOURCES) \
$(mknod_test_SOURCES) \ $(mknod_test_SOURCES) \

View File

@ -62,7 +62,7 @@ static std::unique_ptr<unsigned char[]> create_random_data(off_t size)
return nullptr; return nullptr;
} }
std::unique_ptr<unsigned char[]> pbuff(new unsigned char[size]); auto pbuff = std::make_unique<unsigned char[]>(size);
for(ssize_t readpos = 0, readcnt = 0; readpos < size; readpos += readcnt){ for(ssize_t readpos = 0, readcnt = 0; readpos < size; readpos += readcnt){
if(-1 == (readcnt = read(fd, &(pbuff[readpos]), static_cast<size_t>(size - readpos)))){ if(-1 == (readcnt = read(fd, &(pbuff[readpos]), static_cast<size_t>(size - readpos)))){
if(EAGAIN != errno && EWOULDBLOCK != errno && EINTR != errno){ if(EAGAIN != errno && EWOULDBLOCK != errno && EINTR != errno){