From 280bd320b49fab430080105c827974db66da04b1 Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Fri, 2 Jun 2023 10:44:01 -0700 Subject: [PATCH] Fix more OSS warnings and build errors -Wc++98-compat-extra-semi * in type_map.h -Winconsistent-missing-override * in gl_texture_buffer.h -Wdeprecated-declarations * usage of (absl) Status in * status_util.cc * api2/packet.h * output_stream_shard.cc -Wimplicit-const-int-float-conversion * Adds a static_cast to handle the precision loss when converting from large ints to floating point ANNOTATE_THREAD_NAME * explicitly uses ABSL_ANNOTATE_THREAD_NAME instead. This is useful in Chromium's build where there are multiple ANNOTATE_THREAD_NAME symbols Also ran clang-format over all of each edited file PiperOrigin-RevId: 537351290 --- mediapipe/framework/api2/packet.h | 16 ++++++++-------- mediapipe/framework/deps/safe_int.h | 13 ++++++++----- mediapipe/framework/output_stream_shard.cc | 8 ++++---- mediapipe/framework/tool/status_util.cc | 4 ++-- mediapipe/framework/type_map.h | 4 ++-- mediapipe/gpu/gl_context.cc | 2 +- mediapipe/gpu/gl_texture_buffer.h | 6 +++--- 7 files changed, 28 insertions(+), 25 deletions(-) diff --git a/mediapipe/framework/api2/packet.h b/mediapipe/framework/api2/packet.h index b1ebb0410..c059a988b 100644 --- a/mediapipe/framework/api2/packet.h +++ b/mediapipe/framework/api2/packet.h @@ -165,7 +165,7 @@ template struct IsCompatibleType> : std::integral_constant || ...)> {}; -}; // namespace internal +} // namespace internal template inline Packet PacketBase::As() const { @@ -259,19 +259,19 @@ struct First { template struct AddStatus { - using type = StatusOr; + using type = absl::StatusOr; }; template -struct AddStatus> { - using type = StatusOr; +struct AddStatus> { + using type = absl::StatusOr; }; template <> -struct AddStatus { - using type = Status; +struct AddStatus { + using type = absl::Status; }; template <> struct AddStatus { - using type = Status; + using type = absl::Status; }; template @@ -282,7 +282,7 @@ struct CallAndAddStatusImpl { }; template struct CallAndAddStatusImpl { - Status operator()(const F& f, A&&... a) { + absl::Status operator()(const F& f, A&&... a) { f(std::forward(a)...); return {}; } diff --git a/mediapipe/framework/deps/safe_int.h b/mediapipe/framework/deps/safe_int.h index 4c120bc1b..f6dbb931d 100644 --- a/mediapipe/framework/deps/safe_int.h +++ b/mediapipe/framework/deps/safe_int.h @@ -88,10 +88,13 @@ class SafeIntStrongIntValidator { // If the argument is floating point, we can do a simple check to make // sure the value is in range. It is undefined behavior to convert to int - // from a float that is out of range. + // from a float that is out of range. Since large integers will loose some + // precision when being converted to floating point, the integer max and min + // are explicitly converted back to floating point for this comparison, in + // order to satisfy compiler warnings. if (std::is_floating_point::value) { - if (arg < std::numeric_limits::min() || - arg > std::numeric_limits::max()) { + if (arg < static_cast(std::numeric_limits::min()) || + arg > static_cast(std::numeric_limits::max())) { ErrorType::Error("SafeInt: init from out of bounds float", arg, "="); } } else { @@ -284,11 +287,11 @@ class SafeIntStrongIntValidator { // A SafeIntStrongIntValidator policy class to LOG(FATAL) on errors. struct LogFatalOnError { template - static void Error(const char *error, Tlhs lhs, Trhs rhs, const char *op) { + static void Error(const char* error, Tlhs lhs, Trhs rhs, const char* op) { LOG(FATAL) << error << ": (" << lhs << " " << op << " " << rhs << ")"; } template - static void Error(const char *error, Tval val, const char *op) { + static void Error(const char* error, Tval val, const char* op) { LOG(FATAL) << error << ": (" << op << val << ")"; } }; diff --git a/mediapipe/framework/output_stream_shard.cc b/mediapipe/framework/output_stream_shard.cc index 1b096efbb..682c704c0 100644 --- a/mediapipe/framework/output_stream_shard.cc +++ b/mediapipe/framework/output_stream_shard.cc @@ -94,7 +94,7 @@ const Packet& OutputStreamShard::Header() const { // binary. This function can be defined in the .cc file because only two // versions are ever instantiated, and all call sites are within this .cc file. template -Status OutputStreamShard::AddPacketInternal(T&& packet) { +absl::Status OutputStreamShard::AddPacketInternal(T&& packet) { if (IsClosed()) { return mediapipe::FailedPreconditionErrorBuilder(MEDIAPIPE_LOC) << "Packet sent to closed stream \"" << Name() << "\"."; @@ -113,7 +113,7 @@ Status OutputStreamShard::AddPacketInternal(T&& packet) { << timestamp.DebugString(); } - Status result = output_stream_spec_->packet_type->Validate(packet); + absl::Status result = output_stream_spec_->packet_type->Validate(packet); if (!result.ok()) { return StatusBuilder(result, MEDIAPIPE_LOC).SetPrepend() << absl::StrCat( "Packet type mismatch on calculator outputting to stream \"", @@ -132,14 +132,14 @@ Status OutputStreamShard::AddPacketInternal(T&& packet) { } void OutputStreamShard::AddPacket(const Packet& packet) { - Status status = AddPacketInternal(packet); + absl::Status status = AddPacketInternal(packet); if (!status.ok()) { output_stream_spec_->TriggerErrorCallback(status); } } void OutputStreamShard::AddPacket(Packet&& packet) { - Status status = AddPacketInternal(std::move(packet)); + absl::Status status = AddPacketInternal(std::move(packet)); if (!status.ok()) { output_stream_spec_->TriggerErrorCallback(status); } diff --git a/mediapipe/framework/tool/status_util.cc b/mediapipe/framework/tool/status_util.cc index 401a1b63c..0c277a003 100644 --- a/mediapipe/framework/tool/status_util.cc +++ b/mediapipe/framework/tool/status_util.cc @@ -59,8 +59,8 @@ absl::Status CombinedStatus(absl::string_view general_comment, } } } - if (error_code == StatusCode::kOk) return OkStatus(); - Status combined; + if (error_code == absl::StatusCode::kOk) return absl::OkStatus(); + absl::Status combined; combined = absl::Status( error_code, absl::StrCat(general_comment, "\n", absl::StrJoin(errors, "\n"))); diff --git a/mediapipe/framework/type_map.h b/mediapipe/framework/type_map.h index 8fb324e98..42f6fe6bf 100644 --- a/mediapipe/framework/type_map.h +++ b/mediapipe/framework/type_map.h @@ -241,9 +241,9 @@ class StaticMap { #define DEFINE_MEDIAPIPE_TYPE_MAP(MapName, KeyType) \ class MapName : public type_map_internal::StaticMap {}; // Defines a map from unique typeid number to MediaPipeTypeData. -DEFINE_MEDIAPIPE_TYPE_MAP(PacketTypeIdToMediaPipeTypeData, size_t); +DEFINE_MEDIAPIPE_TYPE_MAP(PacketTypeIdToMediaPipeTypeData, size_t) // Defines a map from unique type string to MediaPipeTypeData. -DEFINE_MEDIAPIPE_TYPE_MAP(PacketTypeStringToMediaPipeTypeData, std::string); +DEFINE_MEDIAPIPE_TYPE_MAP(PacketTypeStringToMediaPipeTypeData, std::string) // MEDIAPIPE_REGISTER_TYPE can be used to register a type. // Convention: diff --git a/mediapipe/gpu/gl_context.cc b/mediapipe/gpu/gl_context.cc index 3244f22aa..d7381babd 100644 --- a/mediapipe/gpu/gl_context.cc +++ b/mediapipe/gpu/gl_context.cc @@ -65,7 +65,7 @@ static void SetThreadName(const char* name) { #elif __APPLE__ pthread_setname_np(name); #endif - ANNOTATE_THREAD_NAME(name); + ABSL_ANNOTATE_THREAD_NAME(name); } GlContext::DedicatedThread::DedicatedThread() { diff --git a/mediapipe/gpu/gl_texture_buffer.h b/mediapipe/gpu/gl_texture_buffer.h index f785571a1..7b9140646 100644 --- a/mediapipe/gpu/gl_texture_buffer.h +++ b/mediapipe/gpu/gl_texture_buffer.h @@ -91,9 +91,9 @@ class GlTextureBuffer // TODO: turn into a single call? GLuint name() const { return name_; } GLenum target() const { return target_; } - int width() const { return width_; } - int height() const { return height_; } - GpuBufferFormat format() const { return format_; } + int width() const override { return width_; } + int height() const override { return height_; } + GpuBufferFormat format() const override { return format_; } GlTextureView GetReadView(internal::types, int plane) const override;