1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Merge pull request #22935 from alalek:gapi_error

G-API: replace GAPI_Assert() with 'false' and '0' to GAPI_Error()

* gapi: GAPI_Error() macro

* gapi: replace GAPI_Assert() with 'false' and '0' to GAPI_Error()

* build: eliminate 'unreachable code' after CV_Error() (MSVC 2015)

* build: eliminate 'unreachable code' warning for MSVS 2015/2017

- observed in constructors stubs with throwing exception
This commit is contained in:
Alexander Alekhin
2022-12-19 09:05:15 +03:00
committed by GitHub
parent 420db56ffd
commit 91998d6424
72 changed files with 254 additions and 238 deletions
@@ -8,9 +8,9 @@
#ifndef OPENCV_GAPI_GCPUKERNEL_HPP
#define OPENCV_GAPI_GCPUKERNEL_HPP
#ifdef _MSC_VER
#pragma warning(disable: 4702) // "Unreachable code"
// on postprocess(...) call inside OCVCallHelper
#if defined _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4702) // "Unreachable code" on postprocess(...) call inside OCVCallHelper
#endif
#include <functional>
@@ -535,4 +535,8 @@ gapi::cpu::GOCVFunctor gapi::cpu::ocv_kernel(const Callable& c)
} // namespace cv
#if defined _MSC_VER
#pragma warning(pop)
#endif
#endif // OPENCV_GAPI_GCPUKERNEL_HPP
@@ -248,11 +248,11 @@ struct scratch_helper<false, Impl, Ins...>
const cv::GArgs &,
gapi::fluid::Buffer &)
{
GAPI_Assert(false);
GAPI_Error("InternalError");
}
static void help_reset(gapi::fluid::Buffer &)
{
GAPI_Assert(false);
GAPI_Error("InternalError");
}
};
+1 -1
View File
@@ -177,7 +177,7 @@ namespace detail
{
util::get<rw_own_t>(m_ref).clear();
}
else GAPI_Assert(false); // shouldn't be called in *EXT modes
else GAPI_Error("InternalError"); // shouldn't be called in *EXT modes
}
// Obtain a WRITE reference to underlying object
@@ -171,7 +171,7 @@ namespace detail
{
util::get<rw_own_t>(m_ref) = {};
}
else GAPI_Assert(false); // shouldn't be called in *EXT modes
else GAPI_Error("InternalError"); // shouldn't be called in *EXT modes
}
// Obtain a WRITE reference to underlying object
+2 -2
View File
@@ -397,7 +397,7 @@ void inline unpackBlobs(const cv::GInferInputs::Map& blobs,
kinds.emplace_back(cv::detail::OpaqueKind::CV_UNKNOWN);
break;
default:
GAPI_Assert(false);
GAPI_Error("InternalError");
}
}
}
@@ -629,7 +629,7 @@ infer2(const std::string& tag,
kinds.emplace_back(cv::detail::OpaqueKind::CV_RECT);
break;
default:
GAPI_Assert(false);
GAPI_Error("InternalError");
}
}
+2 -2
View File
@@ -242,11 +242,11 @@ public:
// The default implementation does nothing
virtual cv::util::any blobParams() const;
virtual void serialize(cv::gapi::s11n::IOStream&) {
GAPI_Assert(false && "Generic serialize method of MediaFrame::IAdapter does nothing by default. "
GAPI_Error("Generic serialize method of MediaFrame::IAdapter does nothing by default. "
"Please, implement it in derived class to properly serialize the object.");
}
virtual void deserialize(cv::gapi::s11n::IIStream&) {
GAPI_Assert(false && "Generic deserialize method of MediaFrame::IAdapter does nothing by default. "
GAPI_Error("Generic deserialize method of MediaFrame::IAdapter does nothing by default. "
"Please, implement it in derived class to properly deserialize the object.");
}
};
@@ -25,6 +25,8 @@
# define GAPI_DbgAssert(expr) GAPI_DbgAssertNoOp(expr)
#endif
#define GAPI_Error(msg) CV_Error(cv::Error::StsError, msg)
#else
#include <stdexcept>
#include <sstream>
@@ -49,6 +51,10 @@ namespace detail
# define GAPI_DbgAssert(expr) GAPI_Assert(expr)
#endif
#define GAPI_Error(msg) { \
::detail::assert_abort(msg, __LINE__, __FILE__, __func__); \
}
#endif // GAPI_STANDALONE
#endif // OPENCV_GAPI_OWN_ASSERT_HPP
+2 -2
View File
@@ -112,11 +112,11 @@ public:
// is transferred to the device when the view is destroyed
virtual View access(Access) = 0;
virtual void serialize(cv::gapi::s11n::IOStream&) {
GAPI_Assert(false && "Generic serialize method of RMat::IAdapter does nothing by default. "
GAPI_Error("Generic serialize method of RMat::IAdapter does nothing by default. "
"Please, implement it in derived class to properly serialize the object.");
}
virtual void deserialize(cv::gapi::s11n::IIStream&) {
GAPI_Assert(false && "Generic deserialize method of RMat::IAdapter does nothing by default. "
GAPI_Error("Generic deserialize method of RMat::IAdapter does nothing by default. "
"Please, implement it in derived class to properly deserialize the object.");
}
};
+9 -4
View File
@@ -17,7 +17,8 @@
#include <opencv2/gapi/util/util.hpp>
// FIXME: caused by deserialize_runarg
#if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
#if defined _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4702)
#endif
@@ -335,7 +336,7 @@ IIStream& operator>> (IIStream& is, std::vector<T> &ts) {
namespace detail {
template<typename V>
IOStream& put_v(IOStream&, const V&, std::size_t) {
GAPI_Assert(false && "variant>>: requested index is invalid");
GAPI_Error("variant>>: requested index is invalid");
};
template<typename V, typename X, typename... Xs>
@@ -347,7 +348,7 @@ IOStream& put_v(IOStream& os, const V& v, std::size_t x) {
template<typename V>
IIStream& get_v(IIStream&, V&, std::size_t, std::size_t) {
GAPI_Assert(false && "variant<<: requested index is invalid");
GAPI_Error("variant<<: requested index is invalid");
}
template<typename V, typename X, typename... Xs>
@@ -423,7 +424,7 @@ static GRunArg exec(cv::gapi::s11n::IIStream& is) {
template<typename RA>
struct deserialize_arg_with_adapter<RA, void> {
static GRunArg exec(cv::gapi::s11n::IIStream&) {
GAPI_Assert(false && "No suitable adapter class found during RMat/MediaFrame deserialization. "
GAPI_Error("No suitable adapter class found during RMat/MediaFrame deserialization. "
"Please, make sure you've passed them in cv::gapi::deserialize() template");
return GRunArg{};
}
@@ -505,4 +506,8 @@ cv::GRunArgs getRunArgsWithAdapters(const std::vector<char> &bytes) {
} // namespace gapi
} // namespace cv
#if defined _MSC_VER
#pragma warning(pop)
#endif
#endif // OPENCV_GAPI_S11N_HPP
@@ -52,7 +52,7 @@ struct S11N: public NotImplemented {
* properly overload the function to use it.
*/
static void serialize(IOStream &, const T &) {
GAPI_Assert(false && "No serialization routine is provided!");
GAPI_Error("No serialization routine is provided!");
}
/**
* @brief This function allows user to deserialize their custom type.
@@ -61,7 +61,7 @@ struct S11N: public NotImplemented {
* properly overload the function to use it.
*/
static T deserialize(IIStream &) {
GAPI_Assert(false && "No deserialization routine is provided!");
GAPI_Error("No deserialization routine is provided!");
}
};
+1 -1
View File
@@ -62,7 +62,7 @@ G_TYPED_KERNEL(GStereo, <GMat(GMat, GMat, const StereoOutputFormat)>, "org.openc
case StereoOutputFormat::DISPARITY_FIXED16_12_4:
return left.withDepth(CV_16SC1);
default:
GAPI_Assert(false && "Unknown output format!");
GAPI_Error("Unknown output format!");
}
}
};
@@ -67,7 +67,7 @@ protected:
cv::Mat tmp;
if (!cap.read(tmp))
{
GAPI_Assert(false && "Couldn't grab the very first frame");
GAPI_Error("Couldn't grab the very first frame");
}
// NOTE: Some decode/media VideoCapture backends continue
// owning the video buffer under cv::Mat so in order to