From 392d7540edc84cbbee590a8cc433ccb96311c592 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Thu, 16 Nov 2023 14:56:34 -0800 Subject: [PATCH 1/2] Make `fml/...` compatible with `.clang-tidy`. --- fml/memory/ref_ptr.h | 1 + fml/memory/weak_ptr.h | 4 ++-- fml/platform/darwin/weak_nsobject.h | 16 +++++++++++----- fml/platform/darwin/weak_nsobject.mm | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/fml/memory/ref_ptr.h b/fml/memory/ref_ptr.h index 149c058987a8e..2b829fc4f9f78 100644 --- a/fml/memory/ref_ptr.h +++ b/fml/memory/ref_ptr.h @@ -108,6 +108,7 @@ class RefPtr final { // Destructor. ~RefPtr() { if (ptr_) { + // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDelete) ptr_->Release(); } } diff --git a/fml/memory/weak_ptr.h b/fml/memory/weak_ptr.h index 8507b8aefed9f..56734167483a3 100644 --- a/fml/memory/weak_ptr.h +++ b/fml/memory/weak_ptr.h @@ -117,7 +117,7 @@ class WeakPtr { explicit WeakPtr(T* ptr, fml::RefPtr&& flag, - DebugThreadChecker checker) + const DebugThreadChecker& checker) : ptr_(ptr), flag_(std::move(flag)), checker_(checker) {} T* ptr_; fml::RefPtr flag_; @@ -204,7 +204,7 @@ class TaskRunnerAffineWeakPtr { T* ptr, fml::RefPtr&& flag, DebugTaskRunnerChecker checker) - : ptr_(ptr), flag_(std::move(flag)), checker_(checker) {} + : ptr_(ptr), flag_(std::move(flag)), checker_(std::move(checker)) {} T* ptr_; fml::RefPtr flag_; diff --git a/fml/platform/darwin/weak_nsobject.h b/fml/platform/darwin/weak_nsobject.h index c636c6dc895ba..6ce7b040e2337 100644 --- a/fml/platform/darwin/weak_nsobject.h +++ b/fml/platform/darwin/weak_nsobject.h @@ -9,6 +9,8 @@ #import #include + +#include #include "flutter/fml/compiler_specific.h" #include "flutter/fml/logging.h" #include "flutter/fml/memory/ref_counted.h" @@ -73,7 +75,7 @@ class WeakNSObjectFactory; // receives nullify() from the object's sentinel. class WeakContainer : public fml::RefCountedThreadSafe { public: - explicit WeakContainer(id object, debug::DebugThreadChecker checker); + explicit WeakContainer(id object, const debug::DebugThreadChecker& checker); id object() { CheckThreadSafety(); @@ -154,6 +156,8 @@ class WeakNSProtocol { return get() != that; } + // This appears to be intentional to allow truthiness? + // NOLINTNEXTLINE(google-explicit-constructor) operator NST() const { CheckThreadSafety(); return get(); @@ -162,8 +166,9 @@ class WeakNSProtocol { protected: friend class WeakNSObjectFactory; - explicit WeakNSProtocol(RefPtr container, debug::DebugThreadChecker checker) - : container_(container), checker_(checker) {} + explicit WeakNSProtocol(RefPtr container, + const debug::DebugThreadChecker& checker) + : container_(std::move(container)), checker_(checker) {} // Refecounted reference to the container tracking the ObjectiveC object this // class encapsulates. @@ -217,8 +222,9 @@ class WeakNSObject : public WeakNSProtocol { private: friend class WeakNSObjectFactory; - explicit WeakNSObject(RefPtr container, debug::DebugThreadChecker checker) - : WeakNSProtocol(container, checker) {} + explicit WeakNSObject(RefPtr container, + const debug::DebugThreadChecker& checker) + : WeakNSProtocol(std::move(container), checker) {} }; // Class that produces (valid) |WeakNSObject|s. Typically, this is used as a diff --git a/fml/platform/darwin/weak_nsobject.mm b/fml/platform/darwin/weak_nsobject.mm index 4ac709755a58f..e255515cafa21 100644 --- a/fml/platform/darwin/weak_nsobject.mm +++ b/fml/platform/darwin/weak_nsobject.mm @@ -13,7 +13,7 @@ namespace fml { -WeakContainer::WeakContainer(id object, debug::DebugThreadChecker checker) +WeakContainer::WeakContainer(id object, const debug::DebugThreadChecker& checker) : object_(object), checker_(checker) {} WeakContainer::~WeakContainer() {} From bed3a30d8ffbb28dc0adfe272cae1b760ca10fad Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Fri, 17 Nov 2023 13:22:25 -0800 Subject: [PATCH 2/2] ++ --- fml/memory/weak_ptr.h | 4 ++-- fml/platform/darwin/weak_nsobject.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fml/memory/weak_ptr.h b/fml/memory/weak_ptr.h index 56734167483a3..bd09610cf309c 100644 --- a/fml/memory/weak_ptr.h +++ b/fml/memory/weak_ptr.h @@ -203,8 +203,8 @@ class TaskRunnerAffineWeakPtr { explicit TaskRunnerAffineWeakPtr( T* ptr, fml::RefPtr&& flag, - DebugTaskRunnerChecker checker) - : ptr_(ptr), flag_(std::move(flag)), checker_(std::move(checker)) {} + const DebugTaskRunnerChecker& checker) + : ptr_(ptr), flag_(std::move(flag)), checker_(checker) {} T* ptr_; fml::RefPtr flag_; diff --git a/fml/platform/darwin/weak_nsobject.h b/fml/platform/darwin/weak_nsobject.h index 6ce7b040e2337..cf657d0b5d9e8 100644 --- a/fml/platform/darwin/weak_nsobject.h +++ b/fml/platform/darwin/weak_nsobject.h @@ -222,9 +222,9 @@ class WeakNSObject : public WeakNSProtocol { private: friend class WeakNSObjectFactory; - explicit WeakNSObject(RefPtr container, + explicit WeakNSObject(const RefPtr& container, const debug::DebugThreadChecker& checker) - : WeakNSProtocol(std::move(container), checker) {} + : WeakNSProtocol(container, checker) {} }; // Class that produces (valid) |WeakNSObject|s. Typically, this is used as a