You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by se...@apache.org on 2005/12/02 00:30:29 UTC

svn commit: r351518 - /incubator/stdcxx/trunk/etc/config/src/RUNTIME_IN_STD.cpp

Author: sebor
Date: Thu Dec  1 15:30:23 2005
New Revision: 351518

URL: http://svn.apache.org/viewcvs?rev=351518&view=rev
Log:
2005-12-01  Martin Sebor  <se...@roguewave.com>

	* RUNTIME_IN_STD.cpp: In preparation for fixing STDCXX-73 enhanced
	to #undef configuration macros (presumably) #defined due to the
	false negative results of the respective configuration tests.
	Printed out comments with the number of runtime library symbols
	examined, the number of symbols found to be defined in namespace
	std, in the global namespace, in both, and in neither (likely as
	a result of a false negative test result).

Modified:
    incubator/stdcxx/trunk/etc/config/src/RUNTIME_IN_STD.cpp

Modified: incubator/stdcxx/trunk/etc/config/src/RUNTIME_IN_STD.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/etc/config/src/RUNTIME_IN_STD.cpp?rev=351518&r1=351517&r2=351518&view=diff
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/RUNTIME_IN_STD.cpp (original)
+++ incubator/stdcxx/trunk/etc/config/src/RUNTIME_IN_STD.cpp Thu Dec  1 15:30:23 2005
@@ -4,145 +4,282 @@
 #  include "config.h"
 #endif   // _RWSTD_USE_CONFIG
 
-// for debugging convenience
-enum {
-    STD_BAD_ALLOC = 1,
-    STD_BAD_CAST = 1,
-    STD_BAD_EXCEPTION = 1,
-    STD_BAD_TYPEID = 1,
-    STD_EXCEPTION = 1,
-    STD_SET_NEW_HANDLER = 1,
-    STD_SET_TERMINATE = 1,
-    STD_SET_UNEXPECTED = 1,
-    STD_TERMINATE = 1,
-    STD_UNCAUGHT_EXCEPTION = 1,
-    STD_UNEXPECTED = 1
-};
-
+#include <stdio.h>
 
-int std_defs = 0
 
 #ifndef _RWSTD_NO_HONOR_STD
+#  define STD_NAME(name)     name
+#else   // if defined (_RWSTD_NO_HONOR_STD)
+#  define STD_NAME(ignore)   ""
+#endif   // _RWSTD_NO_HONOR_STD
+
+const char* const std_defs[] = {
 
    // avoid false positives if namespace std is not honored
 
-#  ifndef _RWSTD_NO_STD_BAD_ALLOC
-    + STD_BAD_ALLOC
-#  endif   // _RWSTD_NO_STD_BAD_ALLOC
-
-#  ifndef _RWSTD_NO_STD_BAD_CAST
-    + STD_BAD_CAST
-#  endif   // _RWSTD_NO_STD_BAD_CAST
-
-#  ifndef _RWSTD_NO_STD_BAD_EXCEPTION
-    + STD_BAD_EXCEPTION
-#  endif   // _RWSTD_NO_STD_BAD_EXCEPTION
-
-#  ifndef _RWSTD_NO_STD_BAD_TYPEID
-    + STD_BAD_TYPEID
-#  endif   // _RWSTD_NO_STD_BAD_TYPEID
-
-#  ifndef _RWSTD_NO_STD_EXCEPTION
-    + STD_EXCEPTION
-#  endif   // _RWSTD_NO_STD_EXCEPTION
-
-#  ifndef _RWSTD_NO_STD_SET_NEW_HANDLER
-    + STD_SET_NEW_HANDLER
-#  endif   // _RWSTD_NO_STD_SET_NEW_HANDLER
-
-#  ifndef _RWSTD_NO_STD_SET_TERMINATE
-    + STD_SET_TERMINATE
-#  endif   // _RWSTD_NO_STD_SET_TERMINATE
-
-#  ifndef _RWSTD_NO_STD_SET_UNEXPECTED
-    + STD_SET_UNEXPECTED
-#  endif   // _RWSTD_NO_STD_SET_UNEXPECTED
-
-#  ifndef _RWSTD_NO_STD_TERMINATE
-    + STD_TERMINATE
-#  endif   // _RWSTD_NO_STD_TERMINATE
-
-#  ifndef _RWSTD_NO_STD_UNCAUGHT_EXCEPTION
-    + STD_UNCAUGHT_EXCEPTION
-#  endif   // _RWSTD_NO_STD_UNCAUGHT_EXCEPTION
-
-#  ifndef _RWSTD_NO_STD_UNEXPECTED
-    + STD_UNEXPECTED
-#  endif   // _RWSTD_NO_STD_UNEXPECTED
-#endif   // _RWSDT_NO_HONOR_STD
-    + 0;
-
-
-// for debugging convenience
-enum {
-    GLOBAL_BAD_ALLOC = 1,
-    GLOBAL_BAD_CAST = 1,
-    GLOBAL_BAD_EXCEPTION = 1,
-    GLOBAL_BAD_TYPEID = 1,
-    GLOBAL_EXCEPTION = 1,
-    GLOBAL_SET_NEW_HANDLER = 1,
-    GLOBAL_SET_TERMINATE = 1,
-    GLOBAL_SET_UNEXPECTED = 1,
-    GLOBAL_TERMINATE = 1,
-    GLOBAL_UNCAUGHT_EXCEPTION = 1,
-    GLOBAL_UNEXPECTED = 1
+#ifdef _RWSTD_NO_STD_BAD_ALLOC
+    STD_NAME ("BAD_ALLOC"),
+#else
+    "",
+#endif   // _RWSTD_NO_STD_BAD_ALLOC
+
+#ifdef _RWSTD_NO_STD_BAD_CAST
+    STD_NAME ("BAD_CAST"),
+#else
+    "",
+#endif   // _RWSTD_NO_STD_BAD_CAST
+
+#ifdef _RWSTD_NO_STD_BAD_EXCEPTION
+    STD_NAME ("BAD_EXCEPTION"),
+#else
+    "",
+#endif   // _RWSTD_NO_STD_BAD_EXCEPTION
+
+#ifdef _RWSTD_NO_STD_BAD_TYPEID
+    STD_NAME ("BAD_TYPEID"),
+#else
+    "",
+#endif   // _RWSTD_NO_STD_BAD_TYPEID
+
+#ifdef _RWSTD_NO_STD_EXCEPTION
+    STD_NAME ("EXCEPTION"),
+#else
+    "",
+#endif   // _RWSTD_NO_STD_EXCEPTION
+
+#ifdef _RWSTD_NO_STD_SET_NEW_HANDLER
+    STD_NAME ("SET_NEW_HANDLER"),
+#else
+    "",
+#endif   // _RWSTD_NO_STD_SET_NEW_HANDLER
+
+#ifdef _RWSTD_NO_STD_SET_TERMINATE
+    STD_NAME ("SET_TERMINATE"),
+#else
+    "",
+#endif   // _RWSTD_NO_STD_SET_TERMINATE
+
+#ifdef _RWSTD_NO_STD_SET_UNEXPECTED
+    STD_NAME ("SET_UNEXPECTED"),
+#else
+    "",
+#endif   // _RWSTD_NO_STD_SET_UNEXPECTED
+
+#ifdef _RWSTD_NO_STD_TERMINATE
+    STD_NAME ("TERMINATE"),
+#else
+    "",
+#endif   // _RWSTD_NO_STD_TERMINATE
+
+#ifdef _RWSTD_NO_STD_UNCAUGHT_EXCEPTION
+    STD_NAME ("UNCAUGHT_EXCEPTION"),
+#else
+    "",
+#endif   // _RWSTD_NO_STD_UNCAUGHT_EXCEPTION
+
+#ifdef _RWSTD_NO_STD_UNEXPECTED
+    STD_NAME ("UNEXPECTED"),
+#else
+    "",
+#endif   // _RWSTD_NO_STD_UNEXPECTED
+
+    0   // sentinel
 };
 
 
-int global_defs = 0
-#ifndef _RWSTD_NO_GLOBAL_BAD_ALLOC
-    + GLOBAL_BAD_ALLOC
+const char* const global_defs[] = {
+
+#ifdef _RWSTD_NO_GLOBAL_BAD_ALLOC
+    "BAD_ALLOC",
+#else
+    "",
 #endif   // _RWSTD_NO_GLOBAL_BAD_ALLOC
 
-#ifndef _RWSTD_NO_GLOBAL_BAD_CAST
-    + GLOBAL_BAD_CAST
+#ifdef _RWSTD_NO_GLOBAL_BAD_CAST
+    "BAD_CAST",
+#else
+    "",
 #endif   // _RWSTD_NO_GLOBAL_BAD_CAST
 
-#ifndef _RWSTD_NO_GLOBAL_BAD_EXCEPTION
-    + GLOBAL_BAD_EXCEPTION
+#ifdef _RWSTD_NO_GLOBAL_BAD_EXCEPTION
+    "BAD_EXCEPTION",
+#else
+    "",
 #endif   // _RWSTD_NO_GLOBAL_BAD_EXCEPTION
 
-#ifndef _RWSTD_NO_GLOBAL_BAD_TYPEID
-    + GLOBAL_BAD_TYPEID
+#ifdef _RWSTD_NO_GLOBAL_BAD_TYPEID
+    "BAD_TYPEID",
+#else
+    "",
 #endif   // _RWSTD_NO_GLOBAL_BAD_TYPEID
 
-#ifndef _RWSTD_NO_GLOBAL_EXCEPTION
-    + GLOBAL_EXCEPTION
+#ifdef _RWSTD_NO_GLOBAL_EXCEPTION
+    "EXCEPTION",
+#else
+    "",
 #endif   // _RWSTD_NO_GLOBAL_EXCEPTION
 
-#ifndef _RWSTD_NO_GLOBAL_SET_NEW_HANDLER
-    + GLOBAL_SET_NEW_HANDLER
+#ifdef _RWSTD_NO_GLOBAL_SET_NEW_HANDLER
+    "SET_NEW_HANDLER",
+#else
+    "",
 #endif   // _RWSTD_NO_GLOBAL_SET_NEW_HANDLER
 
-#ifndef _RWSTD_NO_GLOBAL_SET_TERMINATE
-    + GLOBAL_SET_TERMINATE
+#ifdef _RWSTD_NO_GLOBAL_SET_TERMINATE
+    "SET_TERMINATE",
+#else
+    "",
 #endif   // _RWSTD_NO_GLOBAL_SET_TERMINATE
 
-#ifndef _RWSTD_NO_GLOBAL_SET_UNEXPECTED
-    + GLOBAL_SET_UNEXPECTED
+#ifdef _RWSTD_NO_GLOBAL_SET_UNEXPECTED
+    "SET_UNEXPECTED",
+#else
+    "",
 #endif   // _RWSTD_NO_GLOBAL_SET_UNEXPECTED
 
-#ifndef _RWSTD_NO_GLOBAL_TERMINATE
-    + GLOBAL_TERMINATE
+#ifdef _RWSTD_NO_GLOBAL_TERMINATE
+    "TERMINATE",
+#else
+    "",
 #endif   // _RWSTD_NO_GLOBAL_TERMINATE
 
-#ifndef _RWSTD_NO_GLOBAL_UNCAUGHT_EXCEPTION
-    + GLOBAL_UNCAUGHT_EXCEPTION
+#ifdef _RWSTD_NO_GLOBAL_UNCAUGHT_EXCEPTION
+    "UNCAUGHT_EXCEPTION",
+#else
+    "",
 #endif   // _RWSTD_NO_GLOBAL_UNCAUGHT_EXCEPTION
 
-#ifndef _RWSTD_NO_GLOBAL_UNEXPECTED
-    + GLOBAL_UNEXPECTED
+#ifdef _RWSTD_NO_GLOBAL_UNEXPECTED
+    "UNEXPECTED",
+#else
+    "",
 #endif   // _RWSTD_NO_GLOBAL_UNEXPECTED
-    + 0;
+
+    0   // sentinel
+};
+
 
 int main ()
 {
+#if !defined (_RWSTD_USE_CONFIG)
+
+    printf ("/**/\n#undef _RWSTD_NO_RUNTIME_IN_STD\n");
+
+#endif   // _RWSTD_USE_CONFIG
+
     // since some (possibly many) individual config tests fail
     // to detect either an STD or a GLOBAL version of the feature,
-    // this test #defines a convenience macro based on the overall
-    // findings to avoid complex #ifdef logic in the library
+    // this test overrides (#undef-ines) one of the matching pair
+    // of macros based on the overall findings to avoid complex
+    // #ifdef logic in the library headers
+
+    unsigned n_std_defs      = 0;   // number of macros defined for std names
+    unsigned n_global_defs   = 0;   // number of macros defined for global names
+    unsigned n_both_defs     = 0;   // number of macros defined for both
+    unsigned n_neither_defs  = 0;   // number of macros defined for neither
+    unsigned n_count         = 0;   // total number of symbols
+
+    // numbers of symbols found to be defined only in namespace std
+    // and not in the global namespace, and vice versa
+    unsigned n_std_only_syms    = 0;
+    unsigned n_global_only_syms = 0;
+
+    unsigned i;
+
+    // count the number of macro definitions for the symbols
+    // found to be missing in namespace std and in the global
+    // namespace, the number of symbols found to be defined
+    // in both namespaces, and the total number of symbols
+    for (i = 0; std_defs [i]; ++i, ++n_count) {
+
+        // number of macros defined
+        int cnt = 0;
+
+        if (*std_defs [i]) {
+            ++n_std_defs;
+            ++cnt;
+        }
+
+        if (*global_defs [i]) {
+
+            if (0 == cnt) {
+                // increment the number of symbols that are found to be
+                // defined in namespace std and not in the global namespace
+                ++n_std_only_syms;
+            }
+
+            ++n_global_defs;
+            ++cnt;
+        }
+        else {
+            if (1 == cnt) {
+                // increment the number of symbols that are found to be
+                // defined in the global namespace and not also in std
+                ++n_global_only_syms;
+            }
+        }
+
+        if (2 == cnt)
+            ++n_both_defs;
+        else if (0 == cnt)
+            ++n_neither_defs;
+    }
+
+    // #undef macros that are (assumed to be) #defined due to
+    // false negative test results
+    for (i = 0; std_defs [i]; ++i) {
+        if (*std_defs [i] && *global_defs [i]) {
+
+            // both the NO_STD and NO_GLOBAL forms of the same macro
+            // are #defined (i.e., the symbol wasn't found in either
+            // namespace, presumably because of a false negative
+            // result of one or both tests for the symbol)
+
+            const char *symbol_scope;
+
+            if (n_std_only_syms && n_global_only_syms <= n_std_only_syms) {
+                // there are at least as many names defined only in
+                // namespace std and not also in the global namespace
+                // than there are those defined in the global namespace
+                // that are not also defined in namespace std (and this
+                // number is non-zero)
+                symbol_scope = "STD";
+            }
+            else if (n_global_defs < n_std_defs) {
+                // there are more symbols found to be defined in the global
+                // namespace than there are those defined in namespace std
+                symbol_scope = "GLOBAL";
+            }
+            else
+                symbol_scope = "STD";
+
+            // undefine the macro
+            printf ("#undef _RWSTD_NO_%s_%s\n", symbol_scope, std_defs [i]);
+        }
+    }
+
+    // in a comment print out the number of symbols found to be defined
+    // in namespace std, in the global namespace, in both namespaces,
+    // and in neither
+    printf ("// number of runtime library symbols examined: %2u\n"
+            "// symbols found only in namespace std:        %2u\n"
+            "// symbols found only in the global namespace: %2u\n"
+            "// symbols found in both namespaces:           %2u\n"
+            "// symbols found in neither namespace:         %2u\n",
+            n_count,
+            n_std_only_syms,
+            n_global_only_syms,
+            n_neither_defs,
+            n_both_defs);
+
+    if (n_std_only_syms) {
+        // comment out the NO_RUNTIME_IN_STD macro when at least one symbol
+        // is defined in namespace std and not also defined in the global
+        // namespace
+        printf ("%s ", "//");
+    }
+
+    printf ("#define %s\n", "_RWSTD_NO_RUNTIME_IN_STD\n");
 
-    // the test succeeds (exits with a 0 exit status) with if at
-    // least one symbol is found to exist in the C++ runtime library
-    return !std_defs;
+    return 0;
 }