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
This commit is contained in:
MediaPipe Team 2023-06-02 10:44:01 -07:00 committed by Copybara-Service
parent 9045a74ba3
commit 280bd320b4
7 changed files with 28 additions and 25 deletions

View File

@ -165,7 +165,7 @@ template <class V, class... U>
struct IsCompatibleType<V, OneOf<U...>>
: std::integral_constant<bool, (std::is_same_v<V, U> || ...)> {};
}; // namespace internal
} // namespace internal
template <typename T>
inline Packet<T> PacketBase::As() const {
@ -259,19 +259,19 @@ struct First {
template <class T>
struct AddStatus {
using type = StatusOr<T>;
using type = absl::StatusOr<T>;
};
template <class T>
struct AddStatus<StatusOr<T>> {
using type = StatusOr<T>;
struct AddStatus<absl::StatusOr<T>> {
using type = absl::StatusOr<T>;
};
template <>
struct AddStatus<Status> {
using type = Status;
struct AddStatus<absl::Status> {
using type = absl::Status;
};
template <>
struct AddStatus<void> {
using type = Status;
using type = absl::Status;
};
template <class R, class F, class... A>
@ -282,7 +282,7 @@ struct CallAndAddStatusImpl {
};
template <class F, class... A>
struct CallAndAddStatusImpl<void, F, A...> {
Status operator()(const F& f, A&&... a) {
absl::Status operator()(const F& f, A&&... a) {
f(std::forward<A>(a)...);
return {};
}

View File

@ -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<U>::value) {
if (arg < std::numeric_limits<T>::min() ||
arg > std::numeric_limits<T>::max()) {
if (arg < static_cast<U>(std::numeric_limits<T>::min()) ||
arg > static_cast<U>(std::numeric_limits<T>::max())) {
ErrorType::Error("SafeInt: init from out of bounds float", arg, "=");
}
} else {

View File

@ -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 <typename T>
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);
}

View File

@ -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")));

View File

@ -241,9 +241,9 @@ class StaticMap {
#define DEFINE_MEDIAPIPE_TYPE_MAP(MapName, KeyType) \
class MapName : public type_map_internal::StaticMap<MapName, KeyType> {};
// 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:

View File

@ -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() {

View File

@ -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<GlTextureView>,
int plane) const override;