Loading include/ftl/Flags.h→include/ftl/flags.h +12 −12 Original line number Diff line number Diff line Loading @@ -25,9 +25,9 @@ #include <string> #include <type_traits> // TODO(b/185536303): Align with FTL style and namespace. // TODO(b/185536303): Align with FTL style. namespace android { namespace android::ftl { /* A class for handling flags defined by an enum or enum class in a type-safe way. */ template <typename F> Loading @@ -48,10 +48,10 @@ public: // should force them to be explicitly constructed from their underlying types to make full use // of the type checker. template <typename T = U> constexpr Flags(T t, std::enable_if_t<!ftl::is_scoped_enum_v<F>, T>* = nullptr) : mFlags(t) {} constexpr Flags(T t, std::enable_if_t<!is_scoped_enum_v<F>, T>* = nullptr) : mFlags(t) {} template <typename T = U> explicit constexpr Flags(T t, std::enable_if_t<ftl::is_scoped_enum_v<F>, T>* = nullptr) explicit constexpr Flags(T t, std::enable_if_t<is_scoped_enum_v<F>, T>* = nullptr) : mFlags(t) {} class Iterator { Loading Loading @@ -175,7 +175,7 @@ public: bool first = true; U unstringified = 0; for (const F f : *this) { if (const auto flagName = ftl::flag_name(f)) { if (const auto flagName = flag_name(f)) { appendFlag(result, flagName.value(), first); } else { unstringified |= static_cast<U>(f); Loading @@ -183,8 +183,8 @@ public: } if (unstringified != 0) { constexpr auto radix = sizeof(U) == 1 ? ftl::Radix::kBin : ftl::Radix::kHex; appendFlag(result, ftl::to_string(unstringified, radix), first); constexpr auto radix = sizeof(U) == 1 ? Radix::kBin : Radix::kHex; appendFlag(result, to_string(unstringified, radix), first); } if (first) { Loading @@ -211,15 +211,15 @@ private: // as flags. In order to use these, add them via a `using namespace` declaration. namespace flag_operators { template <typename F, typename = std::enable_if_t<ftl::is_scoped_enum_v<F>>> template <typename F, typename = std::enable_if_t<is_scoped_enum_v<F>>> inline Flags<F> operator~(F f) { return static_cast<F>(~ftl::to_underlying(f)); return static_cast<F>(~to_underlying(f)); } template <typename F, typename = std::enable_if_t<ftl::is_scoped_enum_v<F>>> template <typename F, typename = std::enable_if_t<is_scoped_enum_v<F>>> Flags<F> operator|(F lhs, F rhs) { return static_cast<F>(ftl::to_underlying(lhs) | ftl::to_underlying(rhs)); return static_cast<F>(to_underlying(lhs) | to_underlying(rhs)); } } // namespace flag_operators } // namespace android } // namespace android::ftl libs/binder/Binder.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -582,6 +582,10 @@ void BBinder::removeRpcServerLink(const sp<RpcServerLink>& link) { BBinder::~BBinder() { if (!wasParceled() && getExtension()) { ALOGW("Binder %p destroyed with extension attached before being parceled.", this); } Extras* e = mExtras.load(std::memory_order_relaxed); if (e) delete e; } Loading libs/binder/tests/binderBinderUnitTest.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -41,3 +41,10 @@ TEST(Binder, DetachObject) { EXPECT_EQ(kObject1, binder->detachObject(kObjectId1)); EXPECT_EQ(nullptr, binder->attachObject(kObjectId1, kObject2, nullptr, nullptr)); } TEST(Binder, AttachExtension) { auto binder = sp<BBinder>::make(); auto ext = sp<BBinder>::make(); binder->setExtension(ext); EXPECT_EQ(ext, binder->getExtension()); } libs/ftl/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -14,11 +14,11 @@ cc_test { address: true, }, srcs: [ "Flags_test.cpp", "cast_test.cpp", "concat_test.cpp", "enum_test.cpp", "fake_guard_test.cpp", "flags_test.cpp", "future_test.cpp", "small_map_test.cpp", "small_vector_test.cpp", Loading libs/ftl/Flags_test.cpp→libs/ftl/flags_test.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -14,14 +14,15 @@ * limitations under the License. */ #include <ftl/flags.h> #include <gtest/gtest.h> #include <ftl/Flags.h> #include <type_traits> namespace android::test { using namespace android::flag_operators; using ftl::Flags; using namespace ftl::flag_operators; enum class TestFlags : uint8_t { ONE = 0x1, TWO = 0x2, THREE = 0x4 }; Loading Loading
include/ftl/Flags.h→include/ftl/flags.h +12 −12 Original line number Diff line number Diff line Loading @@ -25,9 +25,9 @@ #include <string> #include <type_traits> // TODO(b/185536303): Align with FTL style and namespace. // TODO(b/185536303): Align with FTL style. namespace android { namespace android::ftl { /* A class for handling flags defined by an enum or enum class in a type-safe way. */ template <typename F> Loading @@ -48,10 +48,10 @@ public: // should force them to be explicitly constructed from their underlying types to make full use // of the type checker. template <typename T = U> constexpr Flags(T t, std::enable_if_t<!ftl::is_scoped_enum_v<F>, T>* = nullptr) : mFlags(t) {} constexpr Flags(T t, std::enable_if_t<!is_scoped_enum_v<F>, T>* = nullptr) : mFlags(t) {} template <typename T = U> explicit constexpr Flags(T t, std::enable_if_t<ftl::is_scoped_enum_v<F>, T>* = nullptr) explicit constexpr Flags(T t, std::enable_if_t<is_scoped_enum_v<F>, T>* = nullptr) : mFlags(t) {} class Iterator { Loading Loading @@ -175,7 +175,7 @@ public: bool first = true; U unstringified = 0; for (const F f : *this) { if (const auto flagName = ftl::flag_name(f)) { if (const auto flagName = flag_name(f)) { appendFlag(result, flagName.value(), first); } else { unstringified |= static_cast<U>(f); Loading @@ -183,8 +183,8 @@ public: } if (unstringified != 0) { constexpr auto radix = sizeof(U) == 1 ? ftl::Radix::kBin : ftl::Radix::kHex; appendFlag(result, ftl::to_string(unstringified, radix), first); constexpr auto radix = sizeof(U) == 1 ? Radix::kBin : Radix::kHex; appendFlag(result, to_string(unstringified, radix), first); } if (first) { Loading @@ -211,15 +211,15 @@ private: // as flags. In order to use these, add them via a `using namespace` declaration. namespace flag_operators { template <typename F, typename = std::enable_if_t<ftl::is_scoped_enum_v<F>>> template <typename F, typename = std::enable_if_t<is_scoped_enum_v<F>>> inline Flags<F> operator~(F f) { return static_cast<F>(~ftl::to_underlying(f)); return static_cast<F>(~to_underlying(f)); } template <typename F, typename = std::enable_if_t<ftl::is_scoped_enum_v<F>>> template <typename F, typename = std::enable_if_t<is_scoped_enum_v<F>>> Flags<F> operator|(F lhs, F rhs) { return static_cast<F>(ftl::to_underlying(lhs) | ftl::to_underlying(rhs)); return static_cast<F>(to_underlying(lhs) | to_underlying(rhs)); } } // namespace flag_operators } // namespace android } // namespace android::ftl
libs/binder/Binder.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -582,6 +582,10 @@ void BBinder::removeRpcServerLink(const sp<RpcServerLink>& link) { BBinder::~BBinder() { if (!wasParceled() && getExtension()) { ALOGW("Binder %p destroyed with extension attached before being parceled.", this); } Extras* e = mExtras.load(std::memory_order_relaxed); if (e) delete e; } Loading
libs/binder/tests/binderBinderUnitTest.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -41,3 +41,10 @@ TEST(Binder, DetachObject) { EXPECT_EQ(kObject1, binder->detachObject(kObjectId1)); EXPECT_EQ(nullptr, binder->attachObject(kObjectId1, kObject2, nullptr, nullptr)); } TEST(Binder, AttachExtension) { auto binder = sp<BBinder>::make(); auto ext = sp<BBinder>::make(); binder->setExtension(ext); EXPECT_EQ(ext, binder->getExtension()); }
libs/ftl/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -14,11 +14,11 @@ cc_test { address: true, }, srcs: [ "Flags_test.cpp", "cast_test.cpp", "concat_test.cpp", "enum_test.cpp", "fake_guard_test.cpp", "flags_test.cpp", "future_test.cpp", "small_map_test.cpp", "small_vector_test.cpp", Loading
libs/ftl/Flags_test.cpp→libs/ftl/flags_test.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -14,14 +14,15 @@ * limitations under the License. */ #include <ftl/flags.h> #include <gtest/gtest.h> #include <ftl/Flags.h> #include <type_traits> namespace android::test { using namespace android::flag_operators; using ftl::Flags; using namespace ftl::flag_operators; enum class TestFlags : uint8_t { ONE = 0x1, TWO = 0x2, THREE = 0x4 }; Loading