[arrayfire] 57/84: Add AF_RETURN_ERROR macro to return errors and print msg
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Jan 4 23:22:25 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch master
in repository arrayfire.
commit ca6ed2b5a8b10855a60a77689953756aa65592ff
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date: Mon Dec 28 21:27:32 2015 -0500
Add AF_RETURN_ERROR macro to return errors and print msg
---
src/api/c/err_common.cpp | 20 ++++++++++----------
src/api/c/err_common.hpp | 14 ++++++++++++++
2 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/src/api/c/err_common.cpp b/src/api/c/err_common.cpp
index 7f8d89e..945857e 100644
--- a/src/api/c/err_common.cpp
+++ b/src/api/c/err_common.cpp
@@ -138,14 +138,14 @@ static const int MAX_ERR_SIZE = 1024;
static std::string global_err_string;
void
-print_error(const stringstream &msg)
+print_error(const string &msg)
{
const char* perr = getenv("AF_PRINT_ERRORS");
if(perr != nullptr) {
if(std::strncmp(perr, "0", 1) != 0)
- fprintf(stderr, "%s\n", msg.str().c_str());
+ fprintf(stderr, "%s\n", msg.c_str());
}
- global_err_string = msg.str();
+ global_err_string = msg;
}
void af_get_last_error(char **str, dim_t *len)
@@ -202,7 +202,7 @@ af_err processException()
<< "Invalid dimension for argument " << ex.getArgIndex() << "\n"
<< "Expected: " << ex.getExpectedCondition() << "\n";
- print_error(ss);
+ print_error(ss.str());
err = AF_ERR_SIZE;
} catch (const ArgumentError &ex) {
ss << "In function " << ex.getFunctionName()
@@ -210,37 +210,37 @@ af_err processException()
<< "Invalid argument at index " << ex.getArgIndex() << "\n"
<< "Expected: " << ex.getExpectedCondition() << "\n";
- print_error(ss);
+ print_error(ss.str());
err = AF_ERR_ARG;
} catch (const SupportError &ex) {
ss << ex.getFunctionName()
<< " not supported for " << ex.getBackendName()
<< " backend\n";
- print_error(ss);
+ print_error(ss.str());
err = AF_ERR_NOT_SUPPORTED;
} catch (const TypeError &ex) {
ss << "In function " << ex.getFunctionName()
<< "(" << ex.getLine() << "):\n"
<< "Invalid type for argument " << ex.getArgIndex() << "\n";
- print_error(ss);
+ print_error(ss.str());
err = AF_ERR_TYPE;
} catch (const AfError &ex) {
ss << "Error in " << ex.getFunctionName()
<< "(" << ex.getLine() << "):\n"
<< ex.what() << "\n";
- print_error(ss);
+ print_error(ss.str());
err = ex.getError();
#if defined(WITH_GRAPHICS) && !defined(AF_UNIFIED)
} catch (const fg::Error &ex) {
ss << ex << "\n";
- print_error(ss);
+ print_error(ss.str());
err = AF_ERR_INTERNAL;
#endif
} catch (...) {
- print_error(ss);
+ print_error(ss.str());
err = AF_ERR_UNKNOWN;
}
diff --git a/src/api/c/err_common.hpp b/src/api/c/err_common.hpp
index 0c40a7d..66d2f4a 100644
--- a/src/api/c/err_common.hpp
+++ b/src/api/c/err_common.hpp
@@ -120,6 +120,8 @@ public:
af_err processException();
+void print_error(const std::string &msg);
+
#define DIM_ASSERT(INDEX, COND) do { \
if((COND) == false) { \
throw DimensionError(__AF_FILENAME__, __LINE__, \
@@ -145,6 +147,18 @@ af_err processException();
MSG, ERR_TYPE); \
} while(0)
+#define AF_RETURN_ERROR(MSG, ERR_TYPE) do { \
+ AfError err(__AF_FILENAME__, __LINE__, \
+ MSG, ERR_TYPE); \
+ std::string str = "Error in " \
+ + err,getFunctionName() \
+ + "(" + ex.getLine() \
+ + "):\n" \
+ + ex.what() + "\n"; \
+ print_error(str); \
+ return ERR_TYPE; \
+ } while(0)
+
#define TYPE_ASSERT(COND) do { \
if ((COND) == false) { \
AF_ERROR("Type mismatch inputs", \
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git
More information about the debian-science-commits
mailing list