Fix compilation with -fno-exceptions (#402, #405)

This commit is contained in:
Victor Zverovich 2018-01-20 17:10:14 -08:00
parent 3f24a38840
commit a1e7e4a768
2 changed files with 15 additions and 14 deletions

View File

@ -70,7 +70,7 @@ fmt::BufferedFile::BufferedFile(
fmt::cstring_view filename, fmt::cstring_view mode) {
FMT_RETRY_VAL(file_, FMT_SYSTEM(fopen(filename.c_str(), mode.c_str())), 0);
if (!file_)
throw system_error(errno, "cannot open file {}", filename.c_str());
FMT_THROW(system_error(errno, "cannot open file {}", filename.c_str()));
}
void fmt::BufferedFile::close() {
@ -79,7 +79,7 @@ void fmt::BufferedFile::close() {
int result = FMT_SYSTEM(fclose(file_));
file_ = 0;
if (result != 0)
throw system_error(errno, "cannot close file");
FMT_THROW(system_error(errno, "cannot close file"));
}
// A macro used to prevent expansion of fileno on broken versions of MinGW.
@ -88,7 +88,7 @@ void fmt::BufferedFile::close() {
int fmt::BufferedFile::fileno() const {
int fd = FMT_POSIX_CALL(fileno FMT_ARGS(file_));
if (fd == -1)
throw system_error(errno, "cannot get file descriptor");
FMT_THROW(system_error(errno, "cannot get file descriptor"));
return fd;
}
@ -101,7 +101,7 @@ fmt::File::File(fmt::cstring_view path, int oflag) {
FMT_RETRY(fd_, FMT_POSIX_CALL(open(path.c_str(), oflag, mode)));
#endif
if (fd_ == -1)
throw system_error(errno, "cannot open file {}", path.c_str());
FMT_THROW(system_error(errno, "cannot open file {}", path.c_str()));
}
fmt::File::~File() FMT_NOEXCEPT {
@ -119,7 +119,7 @@ void fmt::File::close() {
int result = FMT_POSIX_CALL(close(fd_));
fd_ = -1;
if (result != 0)
throw system_error(errno, "cannot close file");
FMT_THROW(system_error(errno, "cannot close file"));
}
long long fmt::File::size() const {
@ -133,7 +133,7 @@ long long fmt::File::size() const {
if (size_lower == INVALID_FILE_SIZE) {
DWORD error = GetLastError();
if (error != NO_ERROR)
throw windows_error(GetLastError(), "cannot get file size");
FMT_THROW(windows_error(GetLastError(), "cannot get file size"));
}
unsigned long long long_size = size_upper;
return (long_size << sizeof(DWORD) * CHAR_BIT) | size_lower;
@ -141,7 +141,7 @@ long long fmt::File::size() const {
typedef struct stat Stat;
Stat file_stat = Stat();
if (FMT_POSIX_CALL(fstat(fd_, &file_stat)) == -1)
throw system_error(errno, "cannot get file attributes");
FMT_THROW(system_error(errno, "cannot get file attributes"));
static_assert(sizeof(long long) >= sizeof(file_stat.st_size),
"return type of File::size is not large enough");
return file_stat.st_size;
@ -152,7 +152,7 @@ std::size_t fmt::File::read(void *buffer, std::size_t count) {
RWResult result = 0;
FMT_RETRY(result, FMT_POSIX_CALL(read(fd_, buffer, convert_rwcount(count))));
if (result < 0)
throw system_error(errno, "cannot read from file");
FMT_THROW(system_error(errno, "cannot read from file"));
return internal::to_unsigned(result);
}
@ -160,7 +160,7 @@ std::size_t fmt::File::write(const void *buffer, std::size_t count) {
RWResult result = 0;
FMT_RETRY(result, FMT_POSIX_CALL(write(fd_, buffer, convert_rwcount(count))));
if (result < 0)
throw system_error(errno, "cannot write to file");
FMT_THROW(system_error(errno, "cannot write to file"));
return internal::to_unsigned(result);
}
@ -169,7 +169,7 @@ fmt::File fmt::File::dup(int fd) {
// http://pubs.opengroup.org/onlinepubs/009695399/functions/dup.html
int new_fd = FMT_POSIX_CALL(dup(fd));
if (new_fd == -1)
throw system_error(errno, "cannot duplicate file descriptor {}", fd);
FMT_THROW(system_error(errno, "cannot duplicate file descriptor {}", fd));
return File(new_fd);
}
@ -205,7 +205,7 @@ void fmt::File::pipe(File &read_end, File &write_end) {
int result = FMT_POSIX_CALL(pipe(fds));
#endif
if (result != 0)
throw system_error(errno, "cannot create pipe");
FMT_THROW(system_error(errno, "cannot create pipe"));
// The following assignments don't throw because read_fd and write_fd
// are closed.
read_end = File(fds[0]);
@ -216,7 +216,8 @@ fmt::BufferedFile fmt::File::fdopen(const char *mode) {
// Don't retry as fdopen doesn't return EINTR.
FILE *f = FMT_POSIX_CALL(fdopen(fd_, mode));
if (!f)
throw system_error(errno, "cannot associate stream with file descriptor");
FMT_THROW(system_error(errno,
"cannot associate stream with file descriptor"));
BufferedFile file(f);
fd_ = -1;
return file;
@ -230,7 +231,7 @@ long fmt::getpagesize() {
#else
long size = FMT_POSIX_CALL(sysconf(_SC_PAGESIZE));
if (size < 0)
throw system_error(errno, "cannot get memory page size");
FMT_THROW(system_error(errno, "cannot get memory page size"));
return size;
#endif
}

View File

@ -388,7 +388,7 @@ class Locale {
Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", NULL)) {
if (!locale_)
throw fmt::system_error(errno, "cannot create locale");
FMT_THROW(fmt::system_error(errno, "cannot create locale"));
}
~Locale() { freelocale(locale_); }