all: misc and noexcept updates

This commit is contained in:
Markus F.X.J. Oberhumer
2023-07-09 17:36:24 +02:00
parent 300fa29446
commit 7ec0faca1e
41 changed files with 589 additions and 69 deletions
+6 -6
View File
@@ -81,8 +81,8 @@ private:
// disable copy and move
AbstractPolicy(const AbstractPolicy &) = delete;
AbstractPolicy &operator=(const AbstractPolicy &) = delete;
AbstractPolicy(AbstractPolicy &&) = delete;
AbstractPolicy &operator=(AbstractPolicy &&) = delete;
AbstractPolicy(AbstractPolicy &&) noexcept = delete;
AbstractPolicy &operator=(AbstractPolicy &&) noexcept = delete;
// disable dynamic allocation
ACC_CXX_DISABLE_NEW_DELETE
};
@@ -149,8 +149,8 @@ private:
// disable copy and move
BEPolicy(const BEPolicy &) = delete;
BEPolicy &operator=(const BEPolicy &) = delete;
BEPolicy(BEPolicy &&) = delete;
BEPolicy &operator=(BEPolicy &&) = delete;
BEPolicy(BEPolicy &&) noexcept = delete;
BEPolicy &operator=(BEPolicy &&) noexcept = delete;
// disable dynamic allocation
ACC_CXX_DISABLE_NEW_DELETE
};
@@ -211,8 +211,8 @@ private:
// disable copy and move
LEPolicy(const LEPolicy &) = delete;
LEPolicy &operator=(const LEPolicy &) = delete;
LEPolicy(LEPolicy &&) = delete;
LEPolicy &operator=(LEPolicy &&) = delete;
LEPolicy(LEPolicy &&) noexcept = delete;
LEPolicy &operator=(LEPolicy &&) noexcept = delete;
// disable dynamic allocation
ACC_CXX_DISABLE_NEW_DELETE
};
-1
View File
@@ -208,7 +208,6 @@ error:
// ensure proper nullptr usage
// TODO later: examine why we need this in the first place
#include <cstddef>
#undef NULL
// NOLINTBEGIN(clang-analyzer-optin.cplusplus.*)
#define NULL nullptr
+1 -1
View File
@@ -412,7 +412,7 @@ noinline void throwAssertFailed(const char *expr, const char *file, int line, co
#if defined(__GNUC__)
#undef assert
#if DEBUG || 0
// generate a warning if assert() is used inside a "noexcept" function
// generate a warning if assert() is used inside a "noexcept" context
#define assert(e) ((void)(__acc_cte(e) || (assertFailed(#e, __FILE__, __LINE__, __func__), throw 1, 0)))
#else
// turn assertion failures into exceptions
+1 -1
View File
@@ -93,7 +93,7 @@ bool FileBase::do_sopen() {
return true;
}
bool FileBase::close() {
bool FileBase::close() noexcept {
bool ok = true;
if (isOpen() && _fd != STDIN_FILENO && _fd != STDOUT_FILENO && _fd != STDERR_FILENO)
if (::close(_fd) == -1)
+1 -3
View File
@@ -37,7 +37,7 @@ protected:
virtual ~FileBase();
public:
bool close();
bool close() noexcept;
void closex();
bool isOpen() const { return _fd >= 0; }
int getFd() const { return _fd; }
@@ -77,7 +77,6 @@ class InputFile final : public FileBase {
public:
InputFile() = default;
virtual ~InputFile() {}
void sopen(const char *name, int flags, int shflags);
void open(const char *name, int flags) { sopen(name, flags, -1); }
@@ -101,7 +100,6 @@ class OutputFile final : public FileBase {
public:
OutputFile() = default;
virtual ~OutputFile() {}
void sopen(const char *name, int flags, int shflags, int mode);
void open(const char *name, int flags, int mode) { sopen(name, flags, -1, mode); }
+1
View File
@@ -91,6 +91,7 @@ static_assert(sizeof(void *) == 8);
#endif
// C++ system headers
#include <cstddef>
#include <exception>
#include <new>
#include <type_traits>
+1 -1
View File
@@ -38,7 +38,7 @@ LeFile::LeFile(InputFile *f) : fif(f), fof(nullptr), le_offset(0), exe_offset(0)
mem_clear(&oh);
}
LeFile::~LeFile() {
LeFile::~LeFile() noexcept {
delete[] iobject_table;
delete[] oobject_table;
delete[] ifpage_table;
+3 -3
View File
@@ -39,7 +39,7 @@ class OutputFile;
class LeFile {
protected:
LeFile(InputFile *);
virtual ~LeFile();
virtual ~LeFile() noexcept;
virtual bool readFileHeader();
virtual void writeFile(OutputFile *, bool);
@@ -225,8 +225,8 @@ private:
// disable copy and move
LeFile(const LeFile &) = delete;
LeFile &operator=(const LeFile &) = delete;
LeFile(LeFile &&) = delete;
LeFile &operator=(LeFile &&) = delete;
LeFile(LeFile &&) noexcept = delete;
LeFile &operator=(LeFile &&) noexcept = delete;
};
#endif /* already included */
+2 -2
View File
@@ -1317,11 +1317,11 @@ int __acc_cdecl_main main(int argc, char *argv[]) {
// srand((int) time(nullptr));
srand((int) clock());
// info: calling upx_main() here violates implicit "noexcept", so we need a try block
// info: main() is implicitly "noexcept", so we need a try block
#if 0
int r = upx_main(argc, argv);
#else
int r = EXIT_INTERNAL;
int r;
try {
r = upx_main(argc, argv);
} catch (const Throwable &e) {
+1 -1
View File
@@ -42,7 +42,7 @@ static const CLANG_FORMAT_DUMMY_STATEMENT
PackW32PeI386::PackW32PeI386(InputFile *f) : super(f) {}
PackW32PeI386::~PackW32PeI386() {}
PackW32PeI386::~PackW32PeI386() noexcept {}
const int *PackW32PeI386::getCompressionMethods(int method, int level) const {
bool small = ih.codesize + ih.datasize <= 256 * 1024;
+1 -1
View File
@@ -36,7 +36,7 @@ class PackW32PeI386 final : public PeFile32 {
public:
PackW32PeI386(InputFile *f);
virtual ~PackW32PeI386();
virtual ~PackW32PeI386() noexcept;
virtual int getFormat() const override { return UPX_F_W32PE_I386; }
virtual const char *getName() const override { return isrtm ? "rtm32/pe" : "win32/pe"; }
virtual const char *getFullName(const Options *) const override { return "i386-win32.pe"; }
+1 -1
View File
@@ -47,7 +47,7 @@ static const CLANG_FORMAT_DUMMY_STATEMENT
PackW64PeAmd64::PackW64PeAmd64(InputFile *f) : super(f) { use_stub_relocs = false; }
PackW64PeAmd64::~PackW64PeAmd64() {}
PackW64PeAmd64::~PackW64PeAmd64() noexcept {}
const int *PackW64PeAmd64::getCompressionMethods(int method, int level) const {
bool small = ih.codesize + ih.datasize <= 256 * 1024;
+1 -1
View File
@@ -36,7 +36,7 @@ class PackW64PeAmd64 final : public PeFile64 {
public:
PackW64PeAmd64(InputFile *f);
virtual ~PackW64PeAmd64();
virtual ~PackW64PeAmd64() noexcept;
virtual int getFormat() const override { return UPX_F_W64PE_AMD64; }
virtual const char *getName() const override { return "win64/pe"; }
virtual const char *getFullName(const Options *) const override { return "amd64-win64.pe"; }
+1 -1
View File
@@ -36,7 +36,7 @@ class PackW64PeArm64 : public PeFile64 {
public:
PackW64PeArm64(InputFile *f);
virtual ~PackW64PeArm64() {}
virtual ~PackW64PeArm64() noexcept {}
virtual int getFormat() const override { return UPX_F_W64PE_ARM64; }
virtual const char *getName() const override { return "win64/arm64"; }
virtual const char *getFullName(const Options *) const override { return "arm64-win64.pe"; }
+1 -1
View File
@@ -44,7 +44,7 @@ static const CLANG_FORMAT_DUMMY_STATEMENT
PackWinCeArm::PackWinCeArm(InputFile *f) : super(f) {}
PackWinCeArm::~PackWinCeArm() {}
PackWinCeArm::~PackWinCeArm() noexcept {}
Linker *PackWinCeArm::newLinker() const { return new ElfLinkerArmLE; }
+1 -1
View File
@@ -36,7 +36,7 @@ class PackWinCeArm final : public PeFile32 {
public:
PackWinCeArm(InputFile *f);
virtual ~PackWinCeArm();
virtual ~PackWinCeArm() noexcept;
virtual int getFormat() const override { return UPX_F_WINCE_ARM; }
virtual const char *getName() const override { return "wince/arm"; }
virtual const char *getFullName(const Options *) const override { return "arm-wince.pe"; }
+2 -2
View File
@@ -353,8 +353,8 @@ private:
// disable copy and move
Packer(const Packer &) = delete;
Packer &operator=(const Packer &) = delete;
Packer(Packer &&) = delete;
Packer &operator=(Packer &&) = delete;
Packer(Packer &&) noexcept = delete;
Packer &operator=(Packer &&) noexcept = delete;
};
int force_method(int method) noexcept; // (0x80ul<<24)|method
+8 -8
View File
@@ -215,7 +215,7 @@ int PeFile::readFileHeader() {
PeFile::Interval::Interval(void *b) : capacity(0), base(b), ivarr(nullptr), ivnum(0) {}
PeFile::Interval::~Interval() { free(ivarr); }
PeFile::Interval::~Interval() noexcept { free(ivarr); }
void PeFile::Interval::add(const void *start, unsigned len) {
add(ptr_diff_bytes(start, base), len);
@@ -598,7 +598,7 @@ class PeFile::ImportLinker final : public ElfLinkerAMD64 {
struct tstr : private ::noncopyable {
char *s = nullptr;
explicit tstr(char *str) : s(str) {}
~tstr() { delete[] s; }
~tstr() noexcept { delete[] s; }
operator char *() const { return s; }
};
@@ -1069,7 +1069,7 @@ PeFile::Export::Export(char *_base) : base(_base), iv(_base) {
size = 0;
}
PeFile::Export::~Export() {
PeFile::Export::~Export() noexcept {
free(ename);
delete[] functionptrs;
delete[] ordinals;
@@ -1491,7 +1491,7 @@ PeFile::Resource::Resource(const byte *p, const byte *ibufstart_, const byte *ib
init(p);
}
PeFile::Resource::~Resource() {
PeFile::Resource::~Resource() noexcept {
if (root) {
destroy(root, 0);
root = nullptr;
@@ -1670,7 +1670,7 @@ byte *PeFile::Resource::build() {
return newstart;
}
void PeFile::Resource::destroy(upx_rnode *node, unsigned level) {
void PeFile::Resource::destroy(upx_rnode *node, unsigned level) noexcept {
xcheck(node);
if (level == 3) {
upx_rleaf *leaf = ACC_STATIC_CAST(upx_rleaf *, node);
@@ -2974,7 +2974,7 @@ upx_uint64_t PeFile::ilinkerGetAddress(const char *d, const char *n) const {
return ilinker->getAddress(d, n);
}
PeFile::~PeFile() {
PeFile::~PeFile() noexcept {
oimpdlls = nullptr;
delete[] oxrelocs;
delete ilinker;
@@ -2993,7 +2993,7 @@ PeFile32::PeFile32(InputFile *f) : super(f) {
oddirs = oh.ddirs;
}
PeFile32::~PeFile32() {}
PeFile32::~PeFile32() noexcept {}
void PeFile32::readPeHeader() {
fi->readx(&ih, sizeof(ih));
@@ -3046,7 +3046,7 @@ PeFile64::PeFile64(InputFile *f) : super(f) {
oddirs = oh.ddirs;
}
PeFile64::~PeFile64() {}
PeFile64::~PeFile64() noexcept {}
void PeFile64::readPeHeader() {
fi->readx(&ih, sizeof(ih));
+7 -7
View File
@@ -46,7 +46,7 @@ protected:
struct pe_section_t;
PeFile(InputFile *f);
virtual ~PeFile();
virtual ~PeFile() noexcept;
void readSectionHeaders(unsigned objs, unsigned sizeof_ih);
unsigned readSections(unsigned objs, unsigned usize, unsigned ih_filealign,
@@ -371,7 +371,7 @@ protected:
unsigned ivnum;
Interval(void *b);
~Interval();
~Interval() noexcept;
void add(unsigned start, unsigned len);
void add(const void *start, unsigned len);
@@ -433,14 +433,14 @@ protected:
void build(const upx_rnode *, unsigned &, unsigned &, unsigned);
void clear(byte *, unsigned, Interval *);
void dump(const upx_rnode *, unsigned) const;
void destroy(upx_rnode *urd, unsigned level);
void destroy(upx_rnode *urd, unsigned level) noexcept;
void ibufcheck(const void *m, unsigned size);
public:
Resource(const byte *ibufstart, const byte *ibufen);
Resource(const byte *p, const byte *ibufstart, const byte *ibufend);
~Resource();
~Resource() noexcept;
void init(const byte *);
unsigned dirsize() const;
@@ -488,7 +488,7 @@ protected:
public:
Export(char *_base);
~Export();
~Export() noexcept;
void convert(unsigned eoffs, unsigned esize);
void build(char *base, unsigned newoffs);
@@ -500,7 +500,7 @@ class PeFile32 : public PeFile {
typedef PeFile super;
protected:
PeFile32(InputFile *f);
virtual ~PeFile32();
virtual ~PeFile32() noexcept;
void pack0(OutputFile *fo, unsigned subsystem_mask, upx_uint64_t default_imagebase,
bool last_section_rsrc_only);
@@ -561,7 +561,7 @@ class PeFile64 : public PeFile {
typedef PeFile super;
protected:
PeFile64(InputFile *f);
virtual ~PeFile64();
virtual ~PeFile64() noexcept;
void pack0(OutputFile *fo, unsigned subsystem_mask, upx_uint64_t default_imagebase);
+3 -3
View File
@@ -49,7 +49,7 @@ protected:
public:
inline MemBufferBase() noexcept : ptr(nullptr), size_in_bytes(0) {}
inline ~MemBufferBase() noexcept {}
forceinline ~MemBufferBase() noexcept {}
// IMPORTANT NOTE: automatic conversion to underlying pointer
// HINT: for fully bound-checked pointer use XSPAN_S from xspan.h
@@ -213,8 +213,8 @@ private:
MemBuffer(const MemBuffer &) DELETED_FUNCTION;
MemBuffer &operator=(const MemBuffer &) DELETED_FUNCTION;
#if __cplusplus >= 201103L
MemBuffer(MemBuffer &&) DELETED_FUNCTION;
MemBuffer &operator=(MemBuffer &&) DELETED_FUNCTION;
MemBuffer(MemBuffer &&) noexcept DELETED_FUNCTION;
MemBuffer &operator=(MemBuffer &&) noexcept DELETED_FUNCTION;
#endif
// disable dynamic allocation
ACC_CXX_DISABLE_NEW_DELETE
+1 -2
View File
@@ -27,8 +27,6 @@
#include "../headers.h"
#include <algorithm>
#include "../conf.h"
#define ACC_WANT_ACC_INCI_H 1
#include "../miniacc.h"
#define ACC_WANT_ACCLIB_GETOPT 1
@@ -38,6 +36,7 @@
#define ACC_WANT_ACCLIB_WILDARGV 1
#undef HAVE_MKDIR
#include "../miniacc.h"
#include "../conf.h"
/*************************************************************************
// assert sane memory buffer sizes to protect against integer overflows
+7 -1
View File
@@ -101,7 +101,13 @@ forceinline void assertInvariants() const noexcept {}
public:
#if DEBUG
inline ~CSelf() { invalidate(); }
~CSelf() noexcept {
try {
invalidate();
} catch (...) {
std::terminate();
}
}
#else
forceinline ~CSelf() noexcept {}
#endif
+8 -2
View File
@@ -63,9 +63,15 @@ public:
#endif
#if DEBUG
inline ~CSelf() { invalidate(); }
~CSelf() noexcept {
try {
invalidate();
} catch (...) {
std::terminate();
}
}
#else
inline ~CSelf() noexcept {}
forceinline ~CSelf() noexcept {}
#endif
noinline void invalidate() {
assertInvariants();