Bug #47502 require() defined multiple times in storage/ndb

Submitted: 22 Sep 2009 3:11 Modified: 10 Dec 2009 6:26
Reporter: jack andrews Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: Cluster (NDB) storage engine Severity:S3 (Non-critical)
Version:mysql-5.1-telco-7.0 OS:Any
Assigned to: jack andrews CPU Architecture:Any

[22 Sep 2009 3:11] jack andrews
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'
[22 Sep 2009 3: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 2009 3:56] jack andrews
see previous comment for the patch
[22 Sep 2009 8: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 2009 1:21] jack andrews
just a bump -- posted a new patch to dev-ndb@
[4 Dec 2009 5:56] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/92822

3255 jack andrews	2009-12-04
      bug #47502 - centralize require()
        
          . removes the warning for slow_select
          . adds ndbout_printer for general use
            (removed the implementation from DynArr256.cpp)
            (because slow_select.cpp needs the same utility function)
[10 Dec 2009 6:26] Jonas Oreland
no docs needed

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.092 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.