Skip to content

Commit

Permalink
Upgrade to the r27 NDK and fix a ton of new lints.
Browse files Browse the repository at this point in the history
  • Loading branch information
saurik committed Sep 2, 2024
1 parent e9ef95d commit b585827
Show file tree
Hide file tree
Showing 28 changed files with 120 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ jobs:

build-lnx-bad:
needs: [cache-submodule]
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Orchid is a decentralized marketplace "for bandwidth"; providers run a server (i

Many users would like to compile Orchid. Thankfully, Orchid is extremely easy to build... so easy, in fact, that a lot of people seem confused by a lack of complex instructions :(. Every single library dependency of Orchid is included as a git submodule (so don't forget to run "git submodule update --init --recursive") and is compiled by the Orchid build system, so there is no need for a lengthy DEPS list: there are no "external" steps (as you often see with many other C/C++ projects).

Of course, you do need to have the requisite build tooling installed... in addition to the standard set of C/C++ development tools (autotools, bison/flex, make, etc.) we specifically require clang (for which I'm truly sorry: maybe one day we'll support gcc) and ldd (neither binutils ld nor gold are sufficient). Some of the build scripts for our dependencies use Python (I think only 3.x), one insists on being built using meson/ninja, and we use a couple libraries that are written in Rust.
Of course, you do need to have the requisite build tooling installed... in addition to the standard set of C/C++ development tools (autotools, bison/flex, make, etc.) we specifically require clang 16+ (for which I'm truly sorry: maybe one day we'll support gcc) and ldd (neither binutils ld nor gold are sufficient). Some of the build scripts for our dependencies use Python (I think only 3.x), one insists on being built using meson/ninja, and we use a couple libraries that are written in Rust.

(At this point I will note, as this has come up multiple times: it is neither practical nor appropriate for Orchid's documentation to detail how to install any of these toolchains. The instructions are different for every operating system, are different for every single distribution of Linux, and are often even different for specific versions of a distribution. FWIW, developers already have most of this software installed; and, if you don't, these projects have their own documentation.)

Expand Down
2 changes: 1 addition & 1 deletion app-linux/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct _MyApplication {
char **dart_entrypoint_arguments;
};

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables,performance-no-int-to-ptr)
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange,cppcoreguidelines-avoid-non-const-global-variables,performance-no-int-to-ptr)
G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)

static void my_application_activate(GApplication *application) {
Expand Down
26 changes: 21 additions & 5 deletions env/checks.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ checks += bugprone-*
checks/bugprone-argument-comment.StrictMode := true
checks += -bugprone-branch-clone
checks += -bugprone-easily-swappable-parameters
# XXX: I should enable this check and do a comprehensive audit
checks += -bugprone-empty-catch
# XXX: this is higher priority but I'm not ready for this yet
checks += -bugprone-exception-escape
checks/bugprone-exception-escape.IgnoredExceptions := "broken_promise"
Expand All @@ -34,9 +36,12 @@ checks += -cert-env33-c
checks += -cert-err58-cpp

checks += clang-analyzer-*
# XXX: this flags something in boost multiprecision (of course)
checks += -clang-analyzer-core.BitwiseShift

checks += cppcoreguidelines-*
checks += -cppcoreguidelines-avoid-c-arrays
checks += -cppcoreguidelines-avoid-capturing-lambda-coroutines
# this check is the exact opposite of a good guideline :/
checks += -cppcoreguidelines-avoid-const-or-ref-data-members
checks += -cppcoreguidelines-avoid-do-while
Expand All @@ -49,6 +54,10 @@ checks += -cppcoreguidelines-avoid-reference-coroutine-parameters
checks += -cppcoreguidelines-init-variables
# XXX: I didn't pay any attention to whether this check was interesting or not
checks += -cppcoreguidelines-macro-usage
# this was accidentally helpful, actually, but isn't an acceptable decision :/
checks += -cppcoreguidelines-misleading-capture-default-by-value
# this check doesn't handle unused parameters; am I doing this wrong?!
checks += -cppcoreguidelines-missing-std-forward
checks += -cppcoreguidelines-non-private-member-variables-in-classes
# XXX: the code which most hates this apparently does allow for memory leaks :(
checks += -cppcoreguidelines-prefer-member-initializer
Expand All @@ -57,8 +66,13 @@ checks += -cppcoreguidelines-pro-bounds-array-to-pointer-decay
checks += -cppcoreguidelines-pro-bounds-pointer-arithmetic
checks += -cppcoreguidelines-pro-type-reinterpret-cast
checks += -cppcoreguidelines-pro-type-union-access
# XXX: this check is interesting, but I'm unsure about move/forward confusion
checks += -cppcoreguidelines-rvalue-reference-param-not-moved
checks/cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams := true
# this check makes utility classes super frustrating :/
checks += -cppcoreguidelines-special-member-functions
# this check makes separates definitions of related variables
checks += -cppcoreguidelines-use-default-member-init

# XXX: I'm using a lot of statically constructed objects
#checks += fuchsia-statically-constructed-objects
Expand All @@ -67,6 +81,9 @@ checks += fuchsia-virtual-inheritance
checks += google-build-*

checks += misc-*
# I love the idea of this check, but boost does this a lot
checks += -misc-header-include-cycle
checks += -misc-include-cleaner
checks += -misc-misplaced-const
checks += -misc-no-recursion
# this check doesn't allow for any protected members :/
Expand All @@ -76,6 +93,8 @@ checks += -misc-unused-parameters

checks += modernize-*
checks += -modernize-avoid-c-arrays
# XXX: I don't want this, but it also crashes on boost::multiprecision::abs
checks += -modernize-use-constraints
checks += -modernize-use-default-member-init
checks += -modernize-use-nodiscard
checks += -modernize-use-trailing-return-type
Expand All @@ -84,6 +103,8 @@ checks += -modernize-use-using

checks += performance-*
checks/performance-move-const-arg.CheckTriviallyCopyableMove := 0
# XXX: I am pretty sure I just disagree with this optimization
checks += -performance-avoid-endl

checks += readability-const-return-type
checks += readability-container-size-empty
Expand All @@ -98,11 +119,6 @@ checks += readability-redundant-string-init
checks += readability-static-definition-in-anonymous-namespace
checks += readability-uniqueptr-delete-release

ifeq ($(target),and)
# XXX: boost multiprecision on android
#checks += -clang-analyzer-core.UndefinedBinaryOperatorResult
endif

ifeq ($(target),win)
# XXX: boost::asio::detail::do_throw_error should be [[noreturn]]
# (though, marking it [[noreturn]] didn't actually make it work)
Expand Down
2 changes: 1 addition & 1 deletion env/output.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ code = $(patsubst @/%,$(output)/$(arch)/%,$(header)) $(sysroot)
# in this model, cflags would be something controlled only by the user
flags_ = $(if $(filter ./,$(1)),,$(call flags_,$(dir $(patsubst %/,%,$(1)))) $(cflags/$(1)))
flags- = $(call flags_,$(patsubst ./$(output)/%,%,$(patsubst ./$(output)/$(arch)/%,./$(output)/%,./$(dir $<))))
flags = $(qflags) $(patsubst -I@/%,-I$(output)/$(arch)/%,$(filter -I%,$(cflags/./$<) $(flags-) $(cflags)) $(filter-out -I%,$(cflags) $(flags-) $(cflags/./$<)))
flags = $(filter-out $(dflags/./$<),$(qflags)) $(patsubst -I@/%,-I$(output)/$(arch)/%,$(filter -I%,$(cflags/./$<) $(flags-) $(cflags)) $(filter-out -I%,$(cflags) $(flags-) $(cflags/./$<)))
flags += $(if $(filter $(output)/%,$<),-D__FILE__='"$(patsubst $(output)/%,%,$<)"' -Wno-builtin-macro-redefined)

define compile
Expand Down
2 changes: 1 addition & 1 deletion env/setup-ndk.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
set -e
set -o pipefail
echo y | "${ANDROID_HOME}"/cmdline-tools/latest/bin/sdkmanager "build-tools;30.0.3" "ndk;26.3.11579264" "platforms;android-34" >/dev/null
echo y | "${ANDROID_HOME}"/cmdline-tools/latest/bin/sdkmanager "build-tools;30.0.3" "ndk;27.0.12077973" "platforms;android-34" >/dev/null
2 changes: 1 addition & 1 deletion lib-protocol/source/drain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Sunk {
}
};

template <typename Super_, typename Drain_, typename Inner_ = typename std::remove_reference<decltype(std::declval<Outer<Super_>>().Inner())>::type>
template <typename Super_, typename Drain_, typename Inner_ = typename std::remove_reference_t<decltype(std::declval<Outer<Super_>>().Inner())>>
class Sink :
public Super_,
public Sunk<Drain_, Inner_>
Expand Down
10 changes: 5 additions & 5 deletions lib-protocol/source/jsonrpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct Numeric<true, Size_, Type_> {
};

template <typename Type_>
struct Coded<Type_, typename std::enable_if<std::is_unsigned<Type_>::value>::type> :
struct Coded<Type_, typename std::enable_if_t<std::is_unsigned_v<Type_>>> :
public Numeric<false, sizeof(Type_), Type_>
{
static void Name(std::ostringstream &signature) {
Expand All @@ -88,7 +88,7 @@ struct Coded<Type_, typename std::enable_if<std::is_unsigned<Type_>::value>::typ
};

template <typename Type_>
struct Coded<Type_, typename std::enable_if<std::is_signed<Type_>::value>::type> :
struct Coded<Type_, typename std::enable_if_t<std::is_signed_v<Type_>>> :
public Numeric<true, sizeof(Type_), Type_>
{
static void Name(std::ostringstream &signature) {
Expand All @@ -97,7 +97,7 @@ struct Coded<Type_, typename std::enable_if<std::is_signed<Type_>::value>::type>
};

template <size_t Bits_, boost::multiprecision::cpp_int_check_type Check_>
struct Coded<boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<Bits_, Bits_, boost::multiprecision::unsigned_magnitude, Check_, void>>, typename std::enable_if<Bits_ % 8 == 0>::type> :
struct Coded<boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<Bits_, Bits_, boost::multiprecision::unsigned_magnitude, Check_, void>>, typename std::enable_if_t<Bits_ % 8 == 0>> :
public Numeric<false, (Bits_ >> 3), boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<Bits_, Bits_, boost::multiprecision::unsigned_magnitude, Check_, void>>>
{
static void Name(std::ostringstream &signature) {
Expand All @@ -106,7 +106,7 @@ struct Coded<boost::multiprecision::number<boost::multiprecision::backends::cpp_
};

template <size_t Bits_, boost::multiprecision::cpp_int_check_type Check_>
struct Coded<boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<Bits_, Bits_, boost::multiprecision::signed_magnitude, Check_, void>>, typename std::enable_if<Bits_ % 8 == 0>::type> :
struct Coded<boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<Bits_, Bits_, boost::multiprecision::signed_magnitude, Check_, void>>, typename std::enable_if_t<Bits_ % 8 == 0>> :
public Numeric<true, (Bits_ >> 3), boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<Bits_, Bits_, boost::multiprecision::signed_magnitude, Check_, void>>>
{
static void Name(std::ostringstream &signature) {
Expand Down Expand Up @@ -161,7 +161,7 @@ struct Coded<bool, void> {
};

template <size_t Size_>
struct Coded<Brick<Size_>, typename std::enable_if<Size_ == 32>::type> {
struct Coded<Brick<Size_>, typename std::enable_if_t<Size_ == 32>> {
static const bool dynamic_ = false;

static void Name(std::ostringstream &signature) {
Expand Down
1 change: 1 addition & 0 deletions lib-protocol/source/lwip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ typedef int SOCKET;
using namespace rtc;

// Event constants for the Dispatcher class.
// NOLINTNEXTLINE(performance-enum-size)
enum DispatcherEvent {
DE_READ = 0x0001,
DE_WRITE = 0x0002,
Expand Down
58 changes: 30 additions & 28 deletions lib-protocol/source/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)

namespace orc {
namespace {

static int file_(-1);
int file_(-1);

// XXX: there are a number of arrays in this file; are they correct?

Expand Down Expand Up @@ -74,7 +75,7 @@ class Out {
if (value == 0)
*--end = '0';
else do {
unsigned digit(value % 10);
const unsigned digit(value % 10);
value /= 10;
*--end = static_cast<char>('0' + digit);
} while (value != 0);
Expand All @@ -100,7 +101,7 @@ class Out {
if (value == 0)
*--end = '0';
else do {
unsigned digit(value & 0xf);
const unsigned digit(value & 0xf);
value >>= 4;
*--end = static_cast<char>((digit < 10 ? '0' : 'a' - 10) + digit);
} while (value != 0);
Expand All @@ -110,9 +111,9 @@ class Out {
}
};

static size_t total_(0);
size_t total_(0);

static void Audit(size_t add, size_t sub) {
void Audit(size_t add, size_t sub) {
total_ += add;
total_ -= sub;
if (add < sub)
Expand All @@ -122,8 +123,8 @@ static void Audit(size_t add, size_t sub) {
Out() << total_ << " (" << (add - sub) << ")";
}

static decltype(std::declval<_malloc_zone_t *>()->malloc) apl_malloc;
static void *orc_malloc(struct _malloc_zone_t *zone, size_t size) {
decltype(std::declval<_malloc_zone_t *>()->malloc) apl_malloc;
void *orc_malloc(struct _malloc_zone_t *zone, size_t size) {
auto value(apl_malloc(zone, size));
if (value == nullptr)
return nullptr;
Expand All @@ -134,8 +135,8 @@ static void *orc_malloc(struct _malloc_zone_t *zone, size_t size) {
return value;
}

static decltype(std::declval<_malloc_zone_t *>()->calloc) apl_calloc;
static void *orc_calloc(struct _malloc_zone_t *zone, size_t count, size_t size) {
decltype(std::declval<_malloc_zone_t *>()->calloc) apl_calloc;
void *orc_calloc(struct _malloc_zone_t *zone, size_t count, size_t size) {
auto value(apl_calloc(zone, count, size));
if (value == nullptr)
return nullptr;
Expand All @@ -146,8 +147,8 @@ static void *orc_calloc(struct _malloc_zone_t *zone, size_t count, size_t size)
return value;
}

static decltype(std::declval<_malloc_zone_t *>()->valloc) apl_valloc;
static void *orc_valloc(struct _malloc_zone_t *zone, size_t size) {
decltype(std::declval<_malloc_zone_t *>()->valloc) apl_valloc;
void *orc_valloc(struct _malloc_zone_t *zone, size_t size) {
auto value(apl_valloc(zone, size));
if (value == nullptr)
return nullptr;
Expand All @@ -158,8 +159,8 @@ static void *orc_valloc(struct _malloc_zone_t *zone, size_t size) {
return value;
}

static decltype(std::declval<_malloc_zone_t *>()->realloc) apl_realloc;
static void *orc_realloc(struct _malloc_zone_t *zone, void *old, size_t size) {
decltype(std::declval<_malloc_zone_t *>()->realloc) apl_realloc;
void *orc_realloc(struct _malloc_zone_t *zone, void *old, size_t size) {
auto before(zone->size(zone, old));
auto value(apl_realloc(zone, old, size));
auto after(zone->size(zone, value));
Expand All @@ -169,42 +170,42 @@ static void *orc_realloc(struct _malloc_zone_t *zone, void *old, size_t size) {
return value;
}

static decltype(std::declval<_malloc_zone_t *>()->free) apl_free;
static void orc_free(struct _malloc_zone_t *zone, void *value) {
decltype(std::declval<_malloc_zone_t *>()->free) apl_free;
void orc_free(struct _malloc_zone_t *zone, void *value) {
auto full(zone->size(zone, value));
if (file_ != -1)
Out() << "free(" << value << ")";
Audit(0, full);
return apl_free(zone, value);
}

static decltype(std::declval<_malloc_zone_t *>()->batch_malloc) apl_batch_malloc;
static unsigned orc_batch_malloc(struct _malloc_zone_t *zone, size_t size, void **values, unsigned count) {
decltype(std::declval<_malloc_zone_t *>()->batch_malloc) apl_batch_malloc;
unsigned orc_batch_malloc(struct _malloc_zone_t *zone, size_t size, void **values, unsigned count) {
count = apl_batch_malloc(zone, size, values, count);
size_t full(0);
for (size_t i(0); i != count; ++i) {
full += zone->size(zone, values[i]);
if (file_ != -1)
Out() << "batch_malloc(" << size << ", " << values << "[" << i << "]) = " << values[i];
Out() << "batch_malloc(" << size << ", " << reinterpret_cast<void *>(values) << "[" << i << "]) = " << values[i];
}
Audit(full, 0);
return count;
}

static decltype(std::declval<_malloc_zone_t *>()->batch_free) apl_batch_free;
static void orc_batch_free(struct _malloc_zone_t *zone, void **values, unsigned count) {
decltype(std::declval<_malloc_zone_t *>()->batch_free) apl_batch_free;
void orc_batch_free(struct _malloc_zone_t *zone, void **values, unsigned count) {
size_t full(0);
for (size_t i(0); i != count; ++i) {
full += zone->size(zone, values[i]);
if (file_ != -1)
Out() << "batch_free(" << values << "[" << i << "] = " << values[i] << ")";
Out() << "batch_free(" << reinterpret_cast<void *>(values) << "[" << i << "] = " << values[i] << ")";
}
Audit(0, full);
return apl_batch_free(zone, values, count);
}

static decltype(std::declval<_malloc_zone_t *>()->memalign) apl_memalign;
static void *orc_memalign(struct _malloc_zone_t *zone, size_t alignment, size_t size) {
decltype(std::declval<_malloc_zone_t *>()->memalign) apl_memalign;
void *orc_memalign(struct _malloc_zone_t *zone, size_t alignment, size_t size) {
auto value(apl_memalign(zone, alignment, size));
auto full(zone->size(zone, value));
if (file_ != -1)
Expand All @@ -213,8 +214,8 @@ static void *orc_memalign(struct _malloc_zone_t *zone, size_t alignment, size_t
return value;
}

static decltype(std::declval<_malloc_zone_t *>()->free_definite_size) apl_free_definite_size;
static void orc_free_definite_size(struct _malloc_zone_t *zone, void *value, size_t size) {
decltype(std::declval<_malloc_zone_t *>()->free_definite_size) apl_free_definite_size;
void orc_free_definite_size(struct _malloc_zone_t *zone, void *value, size_t size) {
auto full(zone->size(zone, value));
if (file_ != -1)
Out() << "free_definite_size(" << value << ", " << size << ")";
Expand All @@ -229,6 +230,9 @@ static void orc_free_definite_size(struct _malloc_zone_t *zone, void *value, siz
zone->name = &orc_ ## name; \
} while (false)

} }

namespace orc {
void Hook() {
return;

Expand Down Expand Up @@ -257,9 +261,7 @@ void Hook() {
orc_swizzle(batch_free);
orc_swizzle(memalign);
orc_swizzle(free_definite_size);
}

}
} }

#else
namespace orc {
Expand Down
2 changes: 1 addition & 1 deletion lib-protocol/source/nest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Nest final :
}

template <typename Code_>
auto Hatch(Code_ code, const char *name) noexcept -> typename std::enable_if<noexcept(code()), bool>::type {
auto Hatch(Code_ code, const char *name) noexcept -> typename std::enable_if_t<noexcept(code()), bool> {
Count count(this);
if (count > limit_)
return false;
Expand Down
2 changes: 1 addition & 1 deletion lib-protocol/source/spawn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Detached {
};

template <typename Code_>
auto Spawn(Code_ code, const char *name) noexcept -> typename std::enable_if<noexcept(code())>::type {
auto Spawn(Code_ code, const char *name) noexcept -> typename std::enable_if_t<noexcept(code())> {
[](Code_ code, const char *name) mutable noexcept -> Detached {
co_await Schedule();
#ifdef ORC_FIBER
Expand Down
Loading

0 comments on commit b585827

Please sign in to comment.