zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #07367
[Merge] lp:~zorba-coders/zorba/ordpathmsgs into lp:zorba
David Graf has proposed merging lp:~zorba-coders/zorba/ordpathmsgs into lp:zorba.
Requested reviews:
Till Westmann (tillw)
Markos Zaharioudakis (markos-za)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/ordpathmsgs/+merge/101520
Introduced ZORBA_ASSERT_WITH_MSG macro to give additional debugging information in case an assertion fails. Currently used in Ordpath functions.
--
https://code.launchpad.net/~zorba-coders/zorba/ordpathmsgs/+merge/101520
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/diagnostics/assert.cpp'
--- src/diagnostics/assert.cpp 2012-03-28 05:19:57 +0000
+++ src/diagnostics/assert.cpp 2012-04-11 09:44:20 +0000
@@ -59,10 +59,16 @@
///////////////////////////////////////////////////////////////////////////////
-void assertion_failed( char const *condition, char const *file, int line ) {
+void assertion_failed( char const *condition,
+ char const *file,
+ int line,
+ char const *msg) {
print_stack_trace( cerr );
throw make_zorba_exception(
- file, line, zerr::ZXQP0002_ASSERT_FAILED, ERROR_PARAMS( condition )
+ file,
+ line,
+ zerr::ZXQP0002_ASSERT_FAILED,
+ ( msg ? ERROR_PARAMS( condition, msg ) : ERROR_PARAMS( condition ))
);
}
=== modified file 'src/diagnostics/assert.h'
--- src/diagnostics/assert.h 2012-03-28 05:19:57 +0000
+++ src/diagnostics/assert.h 2012-04-11 09:44:20 +0000
@@ -29,12 +29,18 @@
* @param condition The string representation of the condition that failed.
* @param file The C++ source-code file name where the assertion failed.
* @param line The C++ source-code line number where the assertion failed.
+ * @param msg An optional message that is output if the assertion fails.
* @throws ZXQP0002_ASSERT_FAILED
*/
-void assertion_failed( char const *condition, char const *file, int line );
+void assertion_failed( char const *condition,
+ char const *file,
+ int line,
+ char const *msg = 0);
/**
* Zorba version of the standard assert(3) macro.
+ * Is checked in RELEASE mode as well. And outputs a special
+ * error code with the failing condition.
*/
#define ZORBA_ASSERT(COND) \
do { \
@@ -44,6 +50,22 @@
} \
} while (0)
+/**
+ * Zorba version of the standard assert(3) macro.
+ * Is checked in RELEASE mode as well. And outputs a special
+ * error code with the failing condition as well as potentially
+ * useful information for further debugging.
+ */
+#define ZORBA_ASSERT_WITH_MSG(COND,MSG) \
+ do { \
+ if ( !(COND) ) { \
+ std::ostringstream oss; \
+ oss << MSG; \
+ zorba::assertion_failed( #COND, __FILE__, __LINE__, oss.str().c_str() ); \
+ throw 0; /* never gets here but suppresses warning */ \
+ } \
+ } while (0)
+
} // namespace zorba
#endif /* ZORBA_ASSERT_H */
/* vim:set et sw=2 ts=2: */
=== modified file 'src/diagnostics/diagnostic_en.xml'
--- src/diagnostics/diagnostic_en.xml 2012-03-28 05:19:57 +0000
+++ src/diagnostics/diagnostic_en.xml 2012-04-11 09:44:20 +0000
@@ -1589,7 +1589,7 @@
A Zorba programming assertion failed. If this error occurs, it is a bug
and should be reported.
</comment>
- <value>"$1": assertion failed</value>
+ <value>"$1": assertion failed.${ The following information might help: 2}</value>
</diagnostic>
<diagnostic code="ZXQP0003" name="INTERNAL_ERROR">
=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
--- src/diagnostics/pregenerated/dict_en.cpp 2012-03-28 05:19:57 +0000
+++ src/diagnostics/pregenerated/dict_en.cpp 2012-04-11 09:44:20 +0000
@@ -392,7 +392,7 @@
{ "ZXQD0006", "\"$1\": invalid UTF-8 byte sequence" },
{ "ZXQP0000", "no error" },
{ "ZXQP0001", "dynamic runtime error${: 1}" },
- { "ZXQP0002", "\"$1\": assertion failed" },
+ { "ZXQP0002", "\"$1\": assertion failed.${ The following information might help: 2}" },
{ "ZXQP0003", "internal error${: 1}" },
{ "ZXQP0004", "not yet implemented: $1" },
{ "ZXQP0005", "\"$1\": feature not enabled" },
=== modified file 'src/store/naive/ordpath.cpp'
--- src/store/naive/ordpath.cpp 2012-03-28 23:58:23 +0000
+++ src/store/naive/ordpath.cpp 2012-04-11 09:44:20 +0000
@@ -960,7 +960,14 @@
while (dewey1[compPos] == dewey2[compPos])
{
++compPos;
- ZORBA_ASSERT(compPos < numComps1 && compPos < numComps2);
+ ZORBA_ASSERT_WITH_MSG(compPos < numComps1 && compPos < numComps2, \
+ "Involved Parameters: " \
+ << "Parent: " << parent.show().c_str() << ", " \
+ << "Sib1: " << sib1.show().c_str() << ", " \
+ << "Sib2: " << sib2.show().c_str() << ", " \
+ << "compPos: " << compPos << ", " \
+ << "numComps1: " << numComps1 << ", " \
+ << "numComps2: " << numComps2 << ".");
}
int32_t comp1 = dewey1[compPos];
@@ -968,7 +975,14 @@
bool odd1 = (comp1 % 2 != 0);
bool odd2 = (comp2 % 2 != 0);
- ZORBA_ASSERT(comp1 < comp2);
+ ZORBA_ASSERT_WITH_MSG(comp1 < comp2, \
+ "Involved Parameters: " \
+ << "Parent: " << parent.show().c_str() << ", " \
+ << "Sib1: " << sib1.show().c_str() << ", " \
+ << "Sib2: " << sib2.show().c_str() << ", " \
+ << "comp1: " << comp1 << ", " \
+ << "comp2: " << comp2 << ", " \
+ << "compPos: " << compPos << ".");
ulong diff = comp2 - comp1;
Follow ups