提交 576d2dba 编写于 作者: A Alexander Alekhin

refactor: don't use CV_ErrorNoReturn() internally

上级 4ec456f0
......@@ -371,7 +371,7 @@ It is possible to alternate error processing by using redirectError().
@param _func - function name. Available only when the compiler supports getting it
@param _file - source file name where the error has occurred
@param _line - line number in the source file where the error has occurred
@see CV_Error, CV_Error_, CV_ErrorNoReturn, CV_ErrorNoReturn_, CV_Assert, CV_DbgAssert
@see CV_Error, CV_Error_, CV_Assert, CV_DbgAssert
*/
CV_EXPORTS void error(int _code, const String& _err, const char* _func, const char* _file, int _line);
......@@ -414,8 +414,6 @@ CV_INLINE CV_NORETURN void errorNoReturn(int _code, const String& _err, const ch
// We need to use simplified definition for them.
#define CV_Error(...) do { abort(); } while (0)
#define CV_Error_( code, args ) do { cv::format args; abort(); } while (0)
#define CV_ErrorNoReturn(...) do { abort(); } while (0)
#define CV_ErrorNoReturn_(...) do { abort(); } while (0)
#define CV_Assert_1( expr ) do { if (!(expr)) abort(); } while (0)
#else // CV_STATIC_ANALYSIS
......@@ -446,22 +444,22 @@ for example:
*/
#define CV_Error_( code, args ) cv::error( code, cv::format args, CV_Func, __FILE__, __LINE__ )
/** same as CV_Error(code,msg), but does not return */
#define CV_ErrorNoReturn( code, msg ) cv::errorNoReturn( code, msg, CV_Func, __FILE__, __LINE__ )
/** same as CV_Error_(code,args), but does not return */
#define CV_ErrorNoReturn_( code, args ) cv::errorNoReturn( code, cv::format args, CV_Func, __FILE__, __LINE__ )
#define CV_Assert_1( expr ) if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ )
//! @cond IGNORED
#define CV__ErrorNoReturn( code, msg ) cv::errorNoReturn( code, msg, CV_Func, __FILE__, __LINE__ )
#define CV__ErrorNoReturn_( code, args ) cv::errorNoReturn( code, cv::format args, CV_Func, __FILE__, __LINE__ )
#ifdef __OPENCV_BUILD
#undef CV_Error
#define CV_Error CV_ErrorNoReturn
#define CV_Error CV__ErrorNoReturn
#undef CV_Error_
#define CV_Error_ CV_ErrorNoReturn_
#define CV_Error_ CV__ErrorNoReturn_
#undef CV_Assert_1
#define CV_Assert_1( expr ) if(!!(expr)) ; else cv::errorNoReturn( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ )
#else
// backward compatibility
#define CV_ErrorNoReturn CV__ErrorNoReturn
#define CV_ErrorNoReturn_ CV__ErrorNoReturn_
#endif
//! @endcond
......
......@@ -93,7 +93,7 @@ static void dumpOpenCLInformation()
const Device& device = Device::getDefault();
if (!device.available())
CV_ErrorNoReturn(Error::OpenCLInitError, "OpenCL device is not available");
CV_Error(Error::OpenCLInitError, "OpenCL device is not available");
DUMP_MESSAGE_STDOUT("Current OpenCL device: ");
......
......@@ -76,7 +76,7 @@
#endif
#ifndef CL_VERSION_1_2
#define CV_REQUIRE_OPENCL_1_2_ERROR CV_ErrorNoReturn(cv::Error::OpenCLApiCallError, "OpenCV compiled without OpenCL v1.2 support, so we can't use functionality from OpenCL v1.2")
#define CV_REQUIRE_OPENCL_1_2_ERROR CV_Error(cv::Error::OpenCLApiCallError, "OpenCV compiled without OpenCL v1.2 support, so we can't use functionality from OpenCL v1.2")
#endif
#endif // HAVE_OPENCL
......
......@@ -50,11 +50,11 @@
#include <vector>
# include "directx.inc.hpp"
#else // HAVE_DIRECTX
#define NO_DIRECTX_SUPPORT_ERROR CV_ErrorNoReturn(cv::Error::StsBadFunc, "OpenCV was build without DirectX support")
#define NO_DIRECTX_SUPPORT_ERROR CV_Error(cv::Error::StsBadFunc, "OpenCV was build without DirectX support")
#endif
#ifndef HAVE_OPENCL
# define NO_OPENCL_SUPPORT_ERROR CV_ErrorNoReturn(cv::Error::StsBadFunc, "OpenCV was build without OpenCL support")
# define NO_OPENCL_SUPPORT_ERROR CV_Error(cv::Error::StsBadFunc, "OpenCV was build without OpenCL support")
#endif // HAVE_OPENCL
namespace cv { namespace directx {
......
......@@ -133,7 +133,7 @@ namespace cv { namespace ocl {
int refcount
#ifndef HAVE_OPENCL
#define CV_OPENCL_NO_SUPPORT() CV_ErrorNoReturn(cv::Error::OpenCLApiCallError, "OpenCV build without OpenCL support")
#define CV_OPENCL_NO_SUPPORT() CV_Error(cv::Error::OpenCLApiCallError, "OpenCV build without OpenCL support")
namespace {
struct DummyImpl
{
......@@ -2177,7 +2177,7 @@ struct Context::Impl
if (!ptr)
{
CV_OPENCL_SVM_TRACE_ERROR_P("clSVMAlloc returned NULL...\n");
CV_ErrorNoReturn(Error::StsBadArg, "clSVMAlloc returned NULL");
CV_Error(Error::StsBadArg, "clSVMAlloc returned NULL");
}
try
{
......@@ -2186,7 +2186,7 @@ struct Context::Impl
if (CL_SUCCESS != clEnqueueSVMMap(q, CL_TRUE, CL_MAP_WRITE, ptr, 100, 0, NULL, NULL))
{
CV_OPENCL_SVM_TRACE_ERROR_P("clEnqueueSVMMap failed...\n");
CV_ErrorNoReturn(Error::StsBadArg, "clEnqueueSVMMap FAILED");
CV_Error(Error::StsBadArg, "clEnqueueSVMMap FAILED");
}
clFinish(q);
try
......@@ -2201,12 +2201,12 @@ struct Context::Impl
if (CL_SUCCESS != clEnqueueSVMUnmap(q, ptr, 0, NULL, NULL))
{
CV_OPENCL_SVM_TRACE_ERROR_P("clEnqueueSVMUnmap failed...\n");
CV_ErrorNoReturn(Error::StsBadArg, "clEnqueueSVMUnmap FAILED");
CV_Error(Error::StsBadArg, "clEnqueueSVMUnmap FAILED");
}
clFinish(q);
if (error)
{
CV_ErrorNoReturn(Error::StsBadArg, "OpenCL SVM buffer access test was FAILED");
CV_Error(Error::StsBadArg, "OpenCL SVM buffer access test was FAILED");
}
}
catch (...)
......@@ -2412,7 +2412,7 @@ void Context::setUseSVM(bool enabled)
i->svmInit();
if (enabled && !i->svmAvailable)
{
CV_ErrorNoReturn(Error::StsError, "OpenCL Shared Virtual Memory (SVM) is not supported by OpenCL device");
CV_Error(Error::StsError, "OpenCL Shared Virtual Memory (SVM) is not supported by OpenCL device");
}
i->svmEnabled = enabled;
}
......@@ -2483,7 +2483,7 @@ void attachContext(const String& platformName, void* platformID, void* context,
CV_OCL_CHECK(clGetPlatformIDs(0, 0, &cnt));
if (cnt == 0)
CV_ErrorNoReturn(cv::Error::OpenCLApiCallError, "no OpenCL platform available!");
CV_Error(cv::Error::OpenCLApiCallError, "no OpenCL platform available!");
std::vector<cl_platform_id> platforms(cnt);
......@@ -2505,13 +2505,13 @@ void attachContext(const String& platformName, void* platformID, void* context,
}
if (!platformAvailable)
CV_ErrorNoReturn(cv::Error::OpenCLApiCallError, "No matched platforms available!");
CV_Error(cv::Error::OpenCLApiCallError, "No matched platforms available!");
// check if platformID corresponds to platformName
String actualPlatformName;
get_platform_name((cl_platform_id)platformID, actualPlatformName);
if (platformName != actualPlatformName)
CV_ErrorNoReturn(cv::Error::OpenCLApiCallError, "No matched platforms available!");
CV_Error(cv::Error::OpenCLApiCallError, "No matched platforms available!");
// do not initialize OpenCL context
Context ctx = Context::getDefault(false);
......@@ -3305,7 +3305,7 @@ struct ProgramSource::Impl
hash = crc64(sourceAddr_, sourceSize_);
break;
default:
CV_ErrorNoReturn(Error::StsInternal, "Internal error");
CV_Error(Error::StsInternal, "Internal error");
}
sourceHash_ = cv::format("%08llx", hash);
isHashUpdated = true;
......@@ -3427,7 +3427,7 @@ const String& ProgramSource::source() const
ProgramSource::hash_t ProgramSource::hash() const
{
CV_ErrorNoReturn(Error::StsNotImplemented, "Removed method: ProgramSource::hash()");
CV_Error(Error::StsNotImplemented, "Removed method: ProgramSource::hash()");
}
ProgramSource ProgramSource::fromBinary(const String& module, const String& name,
......@@ -3597,11 +3597,11 @@ struct Program::Impl
}
else if (src_->kind_ == ProgramSource::Impl::PROGRAM_SPIRV)
{
CV_ErrorNoReturn(Error::StsNotImplemented, "OpenCL: SPIR-V is not supported");
CV_Error(Error::StsNotImplemented, "OpenCL: SPIR-V is not supported");
}
else
{
CV_ErrorNoReturn(Error::StsInternal, "Internal error");
CV_Error(Error::StsInternal, "Internal error");
}
CV_Assert(handle != NULL);
#if OPENCV_HAVE_FILESYSTEM_SUPPORT
......@@ -3948,19 +3948,19 @@ void* Program::ptr() const
#ifndef OPENCV_REMOVE_DEPRECATED_API
const ProgramSource& Program::source() const
{
CV_ErrorNoReturn(Error::StsNotImplemented, "Removed API");
CV_Error(Error::StsNotImplemented, "Removed API");
}
bool Program::read(const String& bin, const String& buildflags)
{
CV_UNUSED(bin); CV_UNUSED(buildflags);
CV_ErrorNoReturn(Error::StsNotImplemented, "Removed API");
CV_Error(Error::StsNotImplemented, "Removed API");
}
bool Program::write(String& bin) const
{
CV_UNUSED(bin);
CV_ErrorNoReturn(Error::StsNotImplemented, "Removed API");
CV_Error(Error::StsNotImplemented, "Removed API");
}
String Program::getPrefix() const
......@@ -5627,7 +5627,7 @@ public:
}
if (id != NULL && strcmp(id, "OCL") != 0)
{
CV_ErrorNoReturn(cv::Error::StsBadArg, "getBufferPoolController(): unknown BufferPool ID\n");
CV_Error(cv::Error::StsBadArg, "getBufferPoolController(): unknown BufferPool ID\n");
}
return &bufferPool;
}
......
......@@ -316,7 +316,7 @@ static void* opencl_check_fn(int ID)
#endif
else
{
CV_ErrorNoReturn(cv::Error::StsBadArg, "Invalid function ID");
CV_Error(cv::Error::StsBadArg, "Invalid function ID");
}
void* func = CV_CL_GET_PROC_ADDRESS(e->fnName);
if (!func)
......
......@@ -48,7 +48,7 @@
# include <cuda_gl_interop.h>
# endif
#else // HAVE_OPENGL
# define NO_OPENGL_SUPPORT_ERROR CV_ErrorNoReturn(cv::Error::StsBadFunc, "OpenCV was build without OpenGL support")
# define NO_OPENGL_SUPPORT_ERROR CV_Error(cv::Error::StsBadFunc, "OpenCV was build without OpenGL support")
#endif // HAVE_OPENGL
using namespace cv;
......@@ -1563,10 +1563,10 @@ void cv::ogl::render(const ogl::Arrays& arr, InputArray indices, int mode, Scala
# ifdef cl_khr_gl_sharing
# define HAVE_OPENCL_OPENGL_SHARING
# else
# define NO_OPENCL_SHARING_ERROR CV_ErrorNoReturn(cv::Error::StsBadFunc, "OpenCV was build without OpenCL/OpenGL sharing support")
# define NO_OPENCL_SHARING_ERROR CV_Error(cv::Error::StsBadFunc, "OpenCV was build without OpenCL/OpenGL sharing support")
# endif
#else // HAVE_OPENCL
# define NO_OPENCL_SUPPORT_ERROR CV_ErrorNoReturn(cv::Error::StsBadFunc, "OpenCV was build without OpenCL support")
# define NO_OPENCL_SUPPORT_ERROR CV_Error(cv::Error::StsBadFunc, "OpenCV was build without OpenCL support")
#endif // HAVE_OPENCL
#if defined(HAVE_OPENGL)
......
......@@ -239,7 +239,7 @@ namespace
#if CV__EXCEPTION_PTR
std::rethrow_exception(pException);
#else
CV_ErrorNoReturn(Error::StsError, "Exception in parallel_for() body: " + exception_message);
CV_Error(Error::StsError, "Exception in parallel_for() body: " + exception_message);
#endif
}
}
......
......@@ -85,7 +85,7 @@ char* icvGets( CvFileStorage* fs, char* str, int maxCount )
return ptr;
}
#endif
CV_ErrorNoReturn(CV_StsError, "The storage is not opened");
CV_Error(CV_StsError, "The storage is not opened");
}
int icvEof( CvFileStorage* fs )
......
......@@ -76,7 +76,7 @@ static bool param_dumpErrors = utils::getConfigurationParameterBool("OPENCV_DUMP
# define CV_ERROR_SET_TERMINATE_HANDLER 1
# endif
#endif
#if CV_ERROR_SET_TERMINATE_HANDLER == 0
#if defined(CV_ERROR_SET_TERMINATE_HANDLER) && !CV_ERROR_SET_TERMINATE_HANDLER
# undef CV_ERROR_SET_TERMINATE_HANDLER
#endif
......@@ -532,7 +532,7 @@ struct HWFeatures
"******************************************************************\n");
fprintf(stderr, "\nRequired baseline features:\n");
checkFeatures(baseline_features, sizeof(baseline_features) / sizeof(baseline_features[0]), true);
CV_ErrorNoReturn(cv::Error::StsAssert, "Missing support for required CPU baseline features. Check OpenCV build configuration and required CPU/HW setup.");
CV_Error(cv::Error::StsAssert, "Missing support for required CPU baseline features. Check OpenCV build configuration and required CPU/HW setup.");
}
readSettings(baseline_features, sizeof(baseline_features) / sizeof(baseline_features[0]));
......@@ -1657,7 +1657,7 @@ bool utils::getConfigurationParameterBool(const char* name, bool defaultValue)
{
return false;
}
CV_ErrorNoReturn(cv::Error::StsBadArg, cv::format("Invalid value for %s parameter: %s", name, value.c_str()));
CV_Error(cv::Error::StsBadArg, cv::format("Invalid value for %s parameter: %s", name, value.c_str()));
}
......@@ -1688,7 +1688,7 @@ size_t utils::getConfigurationParameterSizeT(const char* name, size_t defaultVal
return v * 1024 * 1024;
else if (suffixStr == "KB" || suffixStr == "Kb" || suffixStr == "kb")
return v * 1024;
CV_ErrorNoReturn(cv::Error::StsBadArg, cv::format("Invalid value for %s parameter: %s", name, value.c_str()));
CV_Error(cv::Error::StsBadArg, cv::format("Invalid value for %s parameter: %s", name, value.c_str()));
}
cv::String utils::getConfigurationParameterString(const char* name, const char* defaultValue)
......
......@@ -265,7 +265,7 @@ struct FileLock::Impl
}
else
{
CV_ErrorNoReturn_(Error::StsAssert, ("Can't open lock file: %s", fname));
CV_Error_(Error::StsAssert, ("Can't open lock file: %s", fname));
}
}
break;
......@@ -517,7 +517,7 @@ cv::String getCacheDirectory(const char* sub_directory_name, const char* configu
}
#else
#define NOT_IMPLEMENTED CV_ErrorNoReturn(Error::StsNotImplemented, "");
#define NOT_IMPLEMENTED CV_Error(Error::StsNotImplemented, "");
CV_EXPORTS bool exists(const cv::String& /*path*/) { NOT_IMPLEMENTED }
CV_EXPORTS void remove_all(const cv::String& /*path*/) { NOT_IMPLEMENTED }
CV_EXPORTS bool createDirectory(const cv::String& /*path*/) { NOT_IMPLEMENTED }
......
......@@ -10,7 +10,7 @@
#ifdef HAVE_VA
# include <va/va.h>
#else // HAVE_VA
# define NO_VA_SUPPORT_ERROR CV_ErrorNoReturn(cv::Error::StsBadFunc, "OpenCV was build without VA support (libva)")
# define NO_VA_SUPPORT_ERROR CV_Error(cv::Error::StsBadFunc, "OpenCV was build without VA support (libva)")
#endif // HAVE_VA
using namespace cv;
......
......@@ -1941,7 +1941,7 @@ Net::Net() : impl(new Net::Impl)
Net Net::readFromModelOptimizer(const String& xml, const String& bin)
{
#ifndef HAVE_INF_ENGINE
CV_ErrorNoReturn(Error::StsError, "Build OpenCV with Inference Engine to enable loading models from Model Optimizer.");
CV_Error(Error::StsError, "Build OpenCV with Inference Engine to enable loading models from Model Optimizer.");
#else
InferenceEngine::CNNNetReader reader;
reader.ReadNetwork(xml);
......@@ -2930,7 +2930,7 @@ Net readNet(const String& _model, const String& _config, const String& _framewor
std::swap(model, config);
return readNetFromModelOptimizer(config, model);
}
CV_ErrorNoReturn(Error::StsError, "Cannot determine an origin framework of files: " +
CV_Error(Error::StsError, "Cannot determine an origin framework of files: " +
model + (config.empty() ? "" : ", " + config));
}
......
......@@ -151,7 +151,7 @@ public:
message += " layer parameter does not contain ";
message += parameterName;
message += " parameter.";
CV_ErrorNoReturn(Error::StsBadArg, message);
CV_Error(Error::StsBadArg, message);
}
else
{
......@@ -471,12 +471,12 @@ public:
{
int label = it->first;
if (confidenceScores.rows <= label)
CV_ErrorNoReturn_(cv::Error::StsError, ("Could not find confidence predictions for label %d", label));
CV_Error_(cv::Error::StsError, ("Could not find confidence predictions for label %d", label));
const std::vector<float>& scores = confidenceScores.row(label);
int locLabel = _shareLocation ? -1 : label;
LabelBBox::const_iterator label_bboxes = decodeBBoxes.find(locLabel);
if (label_bboxes == decodeBBoxes.end())
CV_ErrorNoReturn_(cv::Error::StsError, ("Could not find location predictions for label %d", locLabel));
CV_Error_(cv::Error::StsError, ("Could not find location predictions for label %d", locLabel));
const std::vector<int>& indices = it->second;
for (size_t j = 0; j < indices.size(); ++j, ++count)
......@@ -507,14 +507,14 @@ public:
if (c == _backgroundLabelId)
continue; // Ignore background class.
if (c >= confidenceScores.rows)
CV_ErrorNoReturn_(cv::Error::StsError, ("Could not find confidence predictions for label %d", c));
CV_Error_(cv::Error::StsError, ("Could not find confidence predictions for label %d", c));
const std::vector<float> scores = confidenceScores.row(c);
int label = _shareLocation ? -1 : c;
LabelBBox::const_iterator label_bboxes = decodeBBoxes.find(label);
if (label_bboxes == decodeBBoxes.end())
CV_ErrorNoReturn_(cv::Error::StsError, ("Could not find location predictions for label %d", label));
CV_Error_(cv::Error::StsError, ("Could not find location predictions for label %d", label));
if (_bboxesNormalized)
NMSFast_(label_bboxes->second, scores, _confidenceThreshold, _nmsThreshold, 1.0, _topK,
indices[c], util::caffe_norm_box_overlap);
......@@ -532,7 +532,7 @@ public:
int label = it->first;
const std::vector<int>& labelIndices = it->second;
if (label >= confidenceScores.rows)
CV_ErrorNoReturn_(cv::Error::StsError, ("Could not find location predictions for label %d", label));
CV_Error_(cv::Error::StsError, ("Could not find location predictions for label %d", label));
const std::vector<float>& scores = confidenceScores.row(label);
for (size_t j = 0; j < labelIndices.size(); ++j)
{
......@@ -645,7 +645,7 @@ public:
decode_bbox.ymax = decode_bbox_center_y + decode_bbox_height * .5;
}
else
CV_ErrorNoReturn(Error::StsBadArg, "Unknown type.");
CV_Error(Error::StsBadArg, "Unknown type.");
if (clip_bbox)
{
......@@ -714,7 +714,7 @@ public:
continue; // Ignore background class.
LabelBBox::const_iterator label_loc_preds = loc_preds.find(label);
if (label_loc_preds == loc_preds.end())
CV_ErrorNoReturn_(cv::Error::StsError, ("Could not find location predictions for label %d", label));
CV_Error_(cv::Error::StsError, ("Could not find location predictions for label %d", label));
DecodeBBoxes(prior_bboxes, prior_variances,
code_type, variance_encoded_in_target, clip, clip_bounds,
normalized_bbox, label_loc_preds->second, decode_bboxes[label]);
......
......@@ -89,7 +89,7 @@ public:
if (net.node(i).name() == name)
return net.node(i);
}
CV_ErrorNoReturn(Error::StsParseError, "Input node with name " + name + " not found");
CV_Error(Error::StsParseError, "Input node with name " + name + " not found");
}
// Match TensorFlow subgraph starting from <nodeId> with a set of nodes to be fused.
......
......@@ -490,7 +490,7 @@ decode_rle8_bad: ;
result = true;
break;
default:
CV_ErrorNoReturn(cv::Error::StsError, "Invalid/unsupported mode");
CV_Error(cv::Error::StsError, "Invalid/unsupported mode");
}
}
CV_CATCH_ALL
......
......@@ -409,7 +409,7 @@ bool GdalDecoder::readData( Mat& img ){
color = 3;
break;
default:
CV_ErrorNoReturn(cv::Error::StsError, "Invalid/unsupported mode");
CV_Error(cv::Error::StsError, "Invalid/unsupported mode");
}
// make sure the image band has the same dimensions as the image
......
......@@ -77,7 +77,7 @@ static int ReadNumber(RLByteStream& strm, int maxdigits = 0)
else
{
#if 1
CV_ErrorNoReturn_(Error::StsError, ("PXM: Unexpected code in ReadNumber(): 0x%x (%d)", code, code));
CV_Error_(Error::StsError, ("PXM: Unexpected code in ReadNumber(): 0x%x (%d)", code, code));
#else
code = strm.getByte();
#endif
......@@ -354,7 +354,7 @@ bool PxMDecoder::readData( Mat& img )
break;
}
default:
CV_ErrorNoReturn(Error::StsError, "m_bpp is not supported");
CV_Error(Error::StsError, "m_bpp is not supported");
}
}
CV_CATCH (cv::Exception, e)
......
......@@ -722,7 +722,7 @@ bool imwrite( const String& filename, InputArray _img,
else if (_img.isMatVector() || _img.isUMatVector())
_img.getMatVector(img_vec);
else
CV_ErrorNoReturn(Error::StsBadArg, "Unknown/unsupported input encountered");
CV_Error(Error::StsBadArg, "Unknown/unsupported input encountered");
CV_Assert(!img_vec.empty());
return imwrite_(filename, img_vec, params, false);
......
......@@ -836,7 +836,7 @@ std::string findDataFile(const std::string& relative_path, bool required)
#endif
#endif
if (required)
CV_ErrorNoReturn(cv::Error::StsError, cv::format("OpenCV tests: Can't find required data file: %s", relative_path.c_str()));
CV_Error(cv::Error::StsError, cv::format("OpenCV tests: Can't find required data file: %s", relative_path.c_str()));
throw SkipTestException(cv::format("OpenCV tests: Can't find data file: %s", relative_path.c_str()));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册