| Bug #47502 | require() defined multiple times in storage/ndb | ||
|---|---|---|---|
| Submitted: | 22 Sep 5:11 | Modified: | 22 Sep 5:56 |
| Reporter: | jack andrews | ||
| Status: | Patch pending | ||
| Category: | Server: Cluster | Severity: | S3 (Non-critical) |
| Version: | mysql-5.1-telco-7.0 | OS: | Any |
| Assigned to: | jack andrews | Target Version: | |
[22 Sep 5:55]
jack andrews
Index: bug45447/storage/ndb/include/ndb_global.h.in =================================================================== --- bug45447.orig/storage/ndb/include/ndb_global.h.in 2009-07-06 21:46:50.000000000 +1000 +++ bug45447/storage/ndb/include/ndb_global.h.in 2009-09-22 13:37:49.972000000 +1000 @@ -165,4 +165,23 @@ #define NDB_ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) +//used by the always* macros. behaves just like require +inline void +_always(long long v, int retval, const char* expr, const char* file, int line) +{ + if (likely(v)) + return; + fprintf(stderr, "%s:%d: always('%s') failed\n", file, line, expr); + fflush(stderr); + if (!retval) + abort(); + exit(retval); +} + +//always_or_exit exits if v is zero. if v is zero and retval is zero, it aborts +#define always_or_exit(v, retval) _always((long long)(v), retval, #v, __FILE__, __LINE__) + +//always aborts if v is zero +#define always(v) always_or_exit((v), 0) + #endif
[22 Sep 5:56]
jack andrews
see previous comment for the patch
[22 Sep 10:36]
jack andrews
sorry, left out {} for if statements:
Index: bug45447/storage/ndb/include/ndb_global.h.in
===================================================================
--- bug45447.orig/storage/ndb/include/ndb_global.h.in 2009-09-22 17:30:14.392000000
+1000
+++ bug45447/storage/ndb/include/ndb_global.h.in 2009-09-22 18:34:53.029000000 +1000
@@ -165,4 +165,25 @@
#define NDB_ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+//used by the always* macros. behaves just like require
+inline void
+_always(long long v, int retval, const char* expr, const char* file, int line)
+{
+ if (likely(v)){
+ return;
+ }
+ fprintf(stderr, "%s:%d: always('%s') failed\n", file, line, expr);
+ fflush(stderr);
+ if (!retval){
+ abort();
+ }
+ exit(retval);
+}
+
+//always_or_exit exits if v is zero. if v is zero and retval is zero, it aborts
+#define always_or_exit(v, retval) _always((long long)(v), retval, #v, __FILE__,
__LINE__)
+
+//always aborts if v is zero
+#define always(v) always_or_exit((v), 0)
+
#endif
[1 Dec 2:21]
jack andrews
just a bump -- posted a new patch to dev-ndb@

Description: /* * there seems to be a need for a global 'require' * different files define require in different ways: * * $ grep -rIwn require storage/ndb/ --include=*.?pp |grep -v ';' * * storage/ndb/test/run-test/main.cpp:1387:require(bool x) * storage/ndb/test/newtonapi/basic_test/common.hpp:63:inline void require(bool test){ * storage/ndb/src/kernel/vm/testDataBuffer/testDataBuffer.cpp:37:require(bool b){ * storage/ndb/src/kernel/vm/testSimplePropertiesSection/test.cpp:38:require(bool b){ * storage/ndb/src/kernel/vm/DynArr256.cpp:50:#define require(x) require_impl(x, __LINE__) * storage/ndb/src/kernel/vm/mt.cpp:264:require(bool x) * storage/ndb/src/common/util/testConfigValues/testConfigValues.cpp:71:require(bool b){ * * and there are a few more... so it would be good to have a standard * or default implementation */ How to repeat: . Suggested fix: patch will need to use a different name than ndb_require or require. put function/macro in ndb_global.h maybe call it 'always'