stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r328908 - in /incubator/stdcxx/trunk/etc/config/src: BAD_ALLOC_DTOR.cpp BAD_CAST_DTOR.cpp BAD_EXCEPTION_DTOR.cpp BAD_TYPEID_DTOR.cpp EXCEPTION_DTOR.cpp TYPE_INFO_DTOR.cpp
Date Thu, 27 Oct 2005 16:22:07 GMT
Author: sebor
Date: Thu Oct 27 09:21:57 2005
New Revision: 328908

URL: http://svn.apache.org/viewcvs?rev=328908&view=rev
Log:
2005-10-27  Martin Sebor  <sebor@roguewave.com>

	* BAD_ALLOC_DTOR.cpp: Introduced additional class and virtual
	inheritance to thwart aggressive optimizers' efforts to eliminate
	the tested class' dtor.
	* BAD_CAST_DTOR.cpp: Implemented in terms of BAD_ALLOC_DTOR.cpp
	to eliminate code duplication and reduce the maintenance effort.
	* BAD_TYPEID_DTOR.cpp: Same.
	* BAD_TYPEID_DTOR.cpp: Same.
	* EXCEPTION_DTOR.cpp: Same.
	* TYPE_INFO_DTOR.cpp: Same as BAD_ALLOC_DTOR.cpp.


Modified:
    incubator/stdcxx/trunk/etc/config/src/BAD_ALLOC_DTOR.cpp
    incubator/stdcxx/trunk/etc/config/src/BAD_CAST_DTOR.cpp
    incubator/stdcxx/trunk/etc/config/src/BAD_EXCEPTION_DTOR.cpp
    incubator/stdcxx/trunk/etc/config/src/BAD_TYPEID_DTOR.cpp
    incubator/stdcxx/trunk/etc/config/src/EXCEPTION_DTOR.cpp
    incubator/stdcxx/trunk/etc/config/src/TYPE_INFO_DTOR.cpp

Modified: incubator/stdcxx/trunk/etc/config/src/BAD_ALLOC_DTOR.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/etc/config/src/BAD_ALLOC_DTOR.cpp?rev=328908&r1=328907&r2=328908&view=diff
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/BAD_ALLOC_DTOR.cpp (original)
+++ incubator/stdcxx/trunk/etc/config/src/BAD_ALLOC_DTOR.cpp Thu Oct 27 09:21:57 2005
@@ -1,5 +1,13 @@
 // checking for bad_alloc dtor
 
+// NOTE: this file is #included from the following tests,
+//       each of which #defines bad_alloc to the name of
+//       the corresponding exception class:
+//   BAD_CAST_DTOR.cpp
+//   BAD_EXCEPTION_DTOR.cpp
+//   BAD_TYPEID_DTOR.cpp
+//   EXCEPTION_DTOR.cpp
+
 #if defined (_RWSTD_USE_CONFIG)
 #  include "config.h"
 #endif
@@ -14,14 +22,10 @@
 {
     static int *ip;
 
-loop:
-
-    while ((ip [0] = ip [1])) {  // force a SIGSEGV
+    if ((ip [0] = ip [1])) {  // force a SIGSEGV
         ++ip;
-        terminate ();            // recurse infinitely
+        terminate ();         // recurse infinitely
     }
-
-    goto loop;
 }
 
 }
@@ -30,10 +34,10 @@
 #endif   // _RWSTD_NO_HONOR_STD
 
 
-#ifndef _RWSTD_NO_STD_BAD_ALLOC
+#ifndef _RWSTD_NO_STD_EXCEPTION
 #  define NAMESPACE(name)   namespace name
 #else
-#  ifndef _RWSTD_NO_GLOBAL_BAD_ALLOC
+#  ifndef _RWSTD_NO_GLOBAL_EXCEPTION
 #    define NAMESPACE(ignore)   extern "C++"
 #    define std                 /* empty */
 #  else
@@ -43,8 +47,15 @@
 #      define NAMESPACE(ignore)   extern "C++"
 #      define std                 /* empty */
 #    endif   // _RWSTD_NO_RUNTIME_IN_STD
-#  endif   // _RWSTD_NO_GLOBAL_BAD_ALLOC
-#endif   // _RWSTD_NO_STD_BAD_ALLOC
+#  endif   // _RWSTD_NO_GLOBAL_EXCEPTION
+#endif   // _RWSTD_NO_STD_EXCEPTION
+
+
+#if !defined (bad_alloc)
+#  ifdef _RWSTD_NO_BAD_ALLOC_DEFAULT_CTOR
+#    define NO_DEFAULT_CTOR
+#  endif   // _RWSTD_NO_BAD_ALLOC_DEFAULT_CTOR
+#endif
 
 
 NAMESPACE (std) {
@@ -53,16 +64,16 @@
 {
 public:
 
-#ifndef _RWSTD_NO_BAD_ALLOC_DEFAULT_CTOR
+#  if !defined (NO_DEFAULT_CTOR)
 
     // defined in the language support library
     bad_alloc ();
 
-#else   // if defined (_RWSTD_NO_BAD_ALLOC_DEFAULT_CTOR)
+#  else   // if defined (NO_DEFAULT_CTOR)
 
     bad_alloc () { }
 
-#endif   // _RWSTD_NO_BAD_ALLOC_DEFAULT_CTOR
+#  endif   // NO_DEFAULT_CTOR
 
     virtual ~bad_alloc ();   // not defined here
 };
@@ -71,12 +82,22 @@
 }   // namespace std
 
 
-struct Derived: std::bad_alloc
+// use virtual inheritance here to prevent aggressive optimizers
+// (like VisualAge C++) from optimizing the base class dtor away
+struct B0: virtual std::bad_alloc { };
+struct B1: virtual std::bad_alloc { };
+
+struct Derived: B0, B1
 {
     virtual ~Derived ();
 };
 
 
+int dtor;
+
+// other tests that #include this file #define main to a function
+// with a different name (such as test_bad_cast_dtor) and call it
+// from their main()
 int main (int argc, char *argv[])
 {
     // avoid executing the body of main unless explicitly requested
@@ -87,12 +108,17 @@
         return 0;
 
     // try to prevent the compiler from optimizing the dtor call away
-    std::bad_alloc *ptr = argc > 2 ? new Derived : new std::bad_alloc;
+    std::bad_alloc *ptr;
+
+    if (1 < argc)
+        ptr = new Derived;
+    else
+        ptr = new std::bad_alloc;
 
     delete ptr;
 
-    // link only test 
-    return 0;
+    return !(1 < argc ? 1 == dtor : 0 == dtor);
 }
 
-Derived::~Derived () { }
+
+Derived::~Derived () { ++dtor; }

Modified: incubator/stdcxx/trunk/etc/config/src/BAD_CAST_DTOR.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/etc/config/src/BAD_CAST_DTOR.cpp?rev=328908&r1=328907&r2=328908&view=diff
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/BAD_CAST_DTOR.cpp (original)
+++ incubator/stdcxx/trunk/etc/config/src/BAD_CAST_DTOR.cpp Thu Oct 27 09:21:57 2005
@@ -4,91 +4,16 @@
 #  include "config.h"
 #endif
 
-
-#ifndef _RWSTD_NO_HONOR_STD
-#  ifdef _RWSTD_NO_STD_TERMINATE
-
-namespace std {
-
-void terminate ()
-{
-    static int *ip;
-
-    if ((ip [0] = ip [1])) {  // force a SIGSEGV
-        ++ip;
-        terminate ();         // recurse infinitely
-    }
-}
-
-}
-
-#  endif   // _RWSTD_NO_STD_TERMINATE
-#endif   // _RWSTD_NO_HONOR_STD
-
-
-#ifndef _RWSTD_NO_STD_BAD_CAST
-#  define NAMESPACE(name)   namespace name
-#else
-#  ifndef _RWSTD_NO_GLOBAL_BAD_CAST
-#    define NAMESPACE(ignore)   extern "C++"
-#    define std                 /* empty */
-#  else
-#    ifndef _RWSTD_NO_RUNTIME_IN_STD
-#      define NAMESPACE(name)   namespace name
-#    else
-#      define NAMESPACE(ignore)   extern "C++"
-#      define std                 /* empty */
-#    endif   // _RWSTD_NO_RUNTIME_IN_STD
-#  endif   // _RWSTD_NO_GLOBAL_BAD_CAST
-#endif   // _RWSTD_NO_STD_BAD_CAST
-
-
-NAMESPACE (std) {
-
-class bad_cast
-{
-public:
-
-#ifndef _RWSTD_NO_BAD_CAST_DEFAULT_CTOR
-
-    // defined in the language support library
-    bad_cast ();
-
-#else   // if defined (_RWSTD_NO_BAD_CAST_DEFAULT_CTOR)
-
-    bad_cast () { }
-
+#ifdef _RWSTD_NO_BAD_CAST_DEFAULT_CTOR
+#  define NO_DEFAULT_CTOR
 #endif   // _RWSTD_NO_BAD_CAST_DEFAULT_CTOR
 
-    virtual ~bad_cast ();   // not defined here
-};
-
-
-}   // namespace std
-
-
-struct Derived: std::bad_cast
-{
-    virtual ~Derived ();
-};
-
+#define bad_alloc bad_cast
+#define main      test_bad_cast_dtor
+#include "BAD_ALLOC_DTOR.cpp"
+#undef main
 
 int main (int argc, char *argv[])
 {
-    // avoid executing the body of main unless explicitly requested
-    // by specifying at least one command line argument (this foils
-    // aggressive optimizers from eliminating the code)
-    (void)&argv;
-    if (argc < 2)
-        return 0;
-
-    // try to prevent the compiler from optimizing the dtor call away
-    std::bad_cast *ptr = argc > 2 ? new Derived : new std::bad_cast;
-
-    delete ptr;
-
-    // link only test 
-    return 0;
+    return test_bad_cast_dtor (argc, argv);
 }
-
-Derived::~Derived () { }

Modified: incubator/stdcxx/trunk/etc/config/src/BAD_EXCEPTION_DTOR.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/etc/config/src/BAD_EXCEPTION_DTOR.cpp?rev=328908&r1=328907&r2=328908&view=diff
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/BAD_EXCEPTION_DTOR.cpp (original)
+++ incubator/stdcxx/trunk/etc/config/src/BAD_EXCEPTION_DTOR.cpp Thu Oct 27 09:21:57 2005
@@ -4,91 +4,16 @@
 #  include "config.h"
 #endif
 
-
-#ifndef _RWSTD_NO_HONOR_STD
-#  ifdef _RWSTD_NO_STD_TERMINATE
-
-namespace std {
-
-void terminate ()
-{
-    static int *ip;
-
-    if ((ip [0] = ip [1])) {  // force a SIGSEGV
-        ++ip;
-        terminate ();         // recurse infinitely
-    }
-}
-
-}
-
-#  endif   // _RWSTD_NO_STD_TERMINATE
-#endif   // _RWSTD_NO_HONOR_STD
-
-
-#ifndef _RWSTD_NO_STD_BAD_EXCEPTION
-#  define NAMESPACE(name)   namespace name
-#else
-#  ifndef _RWSTD_NO_GLOBAL_BAD_EXCEPTION
-#    define NAMESPACE(ignore)   extern "C++"
-#    define std                 /* empty */
-#  else
-#    ifndef _RWSTD_NO_RUNTIME_IN_STD
-#      define NAMESPACE(name)   namespace name
-#    else
-#      define NAMESPACE(ignore)   extern "C++"
-#      define std                 /* empty */
-#    endif   // _RWSTD_NO_RUNTIME_IN_STD
-#  endif   // _RWSTD_NO_GLOBAL_BAD_EXCEPTION
-#endif   // _RWSTD_NO_STD_BAD_EXCEPTION
-
-
-NAMESPACE (std) {
-
-class bad_exception
-{
-public:
-
-#ifndef _RWSTD_NO_BAD_EXCEPTION_DEFAULT_CTOR
-
-    // defined in the language support library
-    bad_exception ();
-
-#else   // if defined (_RWSTD_NO_BAD_EXCEPTION_DEFAULT_CTOR)
-
-    bad_exception () { }
-
+#ifdef _RWSTD_NO_BAD_EXCEPTION_DEFAULT_CTOR
+#  define NO_DEFAULT_CTOR
 #endif   // _RWSTD_NO_BAD_EXCEPTION_DEFAULT_CTOR
 
-    virtual ~bad_exception ();   // not defined here
-};
-
-
-}   // namespace std
-
-
-struct Derived: std::bad_exception
-{
-    virtual ~Derived ();
-};
-
+#define bad_alloc bad_exception
+#define main      test_bad_exception_dtor
+#include "BAD_ALLOC_DTOR.cpp"
+#undef main
 
 int main (int argc, char *argv[])
 {
-    // avoid executing the body of main unless explicitly requested
-    // by specifying at least one command line argument (this foils
-    // aggressive optimizers from eliminating the code)
-    (void)&argv;
-    if (argc < 2)
-        return 0;
-
-    // try to prevent the compiler from optimizing the dtor call away
-    std::bad_exception *ptr = argc > 2 ? new Derived : new std::bad_exception;
-
-    delete ptr;
-
-    // link only test 
-    return 0;
+    return test_bad_exception_dtor (argc, argv);
 }
-
-Derived::~Derived () { }

Modified: incubator/stdcxx/trunk/etc/config/src/BAD_TYPEID_DTOR.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/etc/config/src/BAD_TYPEID_DTOR.cpp?rev=328908&r1=328907&r2=328908&view=diff
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/BAD_TYPEID_DTOR.cpp (original)
+++ incubator/stdcxx/trunk/etc/config/src/BAD_TYPEID_DTOR.cpp Thu Oct 27 09:21:57 2005
@@ -4,86 +4,16 @@
 #  include "config.h"
 #endif
 
-
-#ifndef _RWSTD_NO_HONOR_STD
-#  ifdef _RWSTD_NO_STD_TERMINATE
-
-namespace std {
-
-void terminate ()
-{
-    static int *ip;
-
-    if ((ip [0] = ip [1])) {  // force a SIGSEGV
-        ++ip;
-        terminate ();         // recurse infinitely
-    }
-}
-
-}
-
-#  endif   // _RWSTD_NO_STD_TERMINATE
-#endif   // _RWSTD_NO_HONOR_STD
-
-
-#ifndef _RWSTD_NO_STD_BAD_TYPEID
-#  define NAMESPACE(name)   namespace name
-#else
-#  ifndef _RWSTD_NO_GLOBAL_BAD_TYPEID
-#    define NAMESPACE(ignore)   extern "C++"
-#    define std                 /* empty */
-#  else
-#    ifndef _RWSTD_NO_RUNTIME_IN_STD
-#      define NAMESPACE(name)   namespace name
-#    else
-#      define NAMESPACE(ignore)   extern "C++"
-#      define std                 /* empty */
-#    endif   // _RWSTD_NO_RUNTIME_IN_STD
-#  endif   // _RWSTD_NO_GLOBAL_BAD_TYPEID
-#endif   // _RWSTD_NO_STD_BAD_TYPEID
-
-
-NAMESPACE (std) {
-
-class bad_typeid
-{
-public:
-
-#ifndef _RWSTD_NO_BAD_TYPEID_DEFAULT_CTOR
-
-    // defined in the language support library
-    bad_typeid ();
-
-#else   // if defined (_RWSTD_NO_BAD_TYPEID_DEFAULT_CTOR)
-
-    bad_typeid () { }
-
+#ifdef _RWSTD_NO_BAD_TYPEID_DEFAULT_CTOR
+#  define NO_DEFAULT_CTOR
 #endif   // _RWSTD_NO_BAD_TYPEID_DEFAULT_CTOR
 
-    virtual ~bad_typeid ();   // not defined here
-};
-
-
-}   // namespace std
-
-
-struct Derived: std::bad_typeid
-{
-    virtual ~Derived ();
-};
-
+#define bad_alloc bad_typeid
+#define main      test_bad_typeid_dtor
+#include "BAD_ALLOC_DTOR.cpp"
+#undef main
 
 int main (int argc, char *argv[])
 {
-    (void)&argv;
-
-    // try to prevent the compiler from optimizing the dtor call away
-    std::bad_typeid *ptr = argc > 1 ? new Derived : new std::bad_typeid;
-
-    delete ptr;
-
-    // link only test 
-    return 0;
+    return test_bad_typeid_dtor (argc, argv);
 }
-
-Derived::~Derived () { }

Modified: incubator/stdcxx/trunk/etc/config/src/EXCEPTION_DTOR.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/etc/config/src/EXCEPTION_DTOR.cpp?rev=328908&r1=328907&r2=328908&view=diff
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/EXCEPTION_DTOR.cpp (original)
+++ incubator/stdcxx/trunk/etc/config/src/EXCEPTION_DTOR.cpp Thu Oct 27 09:21:57 2005
@@ -4,97 +4,16 @@
 #  include "config.h"
 #endif
 
-
-#ifndef _RWSTD_NO_HONOR_STD
-#  ifdef _RWSTD_NO_STD_TERMINATE
-
-namespace std {
-
-void terminate ()
-{
-    static int *ip;
-
-    if ((ip [0] = ip [1])) {  // force a SIGSEGV
-        ++ip;
-        terminate ();         // recurse infinitely
-    }
-}
-
-}
-
-#  endif   // _RWSTD_NO_STD_TERMINATE
-#endif   // _RWSTD_NO_HONOR_STD
-
-
-#ifndef _RWSTD_NO_STD_EXCEPTION
-#  define NAMESPACE(name)   namespace name
-#else
-#  ifndef _RWSTD_NO_GLOBAL_EXCEPTION
-#    define NAMESPACE(ignore)   extern "C++"
-#    define std                 /* empty */
-#  else
-#    ifndef _RWSTD_NO_RUNTIME_IN_STD
-#      define NAMESPACE(name)   namespace name
-#    else
-#      define NAMESPACE(ignore)   extern "C++"
-#      define std                 /* empty */
-#    endif   // _RWSTD_NO_RUNTIME_IN_STD
-#  endif   // _RWSTD_NO_GLOBAL_EXCEPTION
-#endif   // _RWSTD_NO_STD_EXCEPTION
-
-
-NAMESPACE (std) {
-
-class exception
-{
-public:
-
-#ifndef _RWSTD_NO_EXCEPTION_DEFAULT_CTOR
-
-    // defined in the language support library
-    exception ();
-
-#else   // if defined (_RWSTD_NO_EXCEPTION_DEFAULT_CTOR)
-
-    exception () { }
-
-#endif   // _RWSTD_NO_EXCEPTION_DEFAULT_CTOR
-
-    virtual ~exception ();   // not defined here
-};
-
-
-}   // namespace std
-
-struct Derived: std::exception
-{
-    virtual ~Derived ();
-};
-
-
-int dtor;
-
+#ifdef _RWSTD_NO_EXCEPTION_DEFAULT_CTOR
+#  define NO_DEFAULT_CTOR
+#endif
+
+#define bad_alloc exception
+#define main      test_exception_dtor
+#include "BAD_ALLOC_DTOR.cpp"
+#undef main
 
 int main (int argc, char *argv[])
 {
-    // avoid executing the body of main unless explicitly requested
-    // by specifying at least one command line argument (this foils
-    // aggressive optimizers from eliminating the code)
-    (void)&argv;
-    if (argc < 2)
-        return 0;
-
-    // try to prevent the compiler from optimizing the dtor call away
-    std::exception *ptr;
-
-    if (1 < argc)
-        ptr = new Derived;
-    else
-        ptr = new std::exception;
-
-    delete ptr;
-
-    return !(1 < argc ? 1 == dtor : 0 == dtor);
+    return test_exception_dtor (argc, argv);
 }
-
-Derived::~Derived () { ++dtor; }

Modified: incubator/stdcxx/trunk/etc/config/src/TYPE_INFO_DTOR.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/etc/config/src/TYPE_INFO_DTOR.cpp?rev=328908&r1=328907&r2=328908&view=diff
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/TYPE_INFO_DTOR.cpp (original)
+++ incubator/stdcxx/trunk/etc/config/src/TYPE_INFO_DTOR.cpp Thu Oct 27 09:21:57 2005
@@ -61,12 +61,17 @@
 }   // namespace std
 
 
-void foo (void *p)
+struct B0: virtual std::type_info { };
+struct B1: virtual std::type_info { };
+
+struct Derived: B0, B1
 {
-    delete (std::type_info*)p;
-}
+    virtual ~Derived ();
+};
 
 
+int dtor;
+
 int main (int argc, char *argv[])
 {
     // avoid executing the body of main unless explicitly requested
@@ -76,8 +81,20 @@
     if (argc < 2)
         return 0;
 
-    foo (argv [argc]);
+    // try to prevent the compiler from optimizing the dtor call away
+    std::type_info *ptr;
+
+    if (1 < argc)
+        ptr = (std::type_info*)argv[2];
+    else
+        ptr = (Derived*)argv[1];
 
-    // link only test 
-    return 0;
+    // this will most like crash if evaluated but under normal
+    // conditions the function should never reach this far
+    delete ptr;
+
+    return !(1 < argc ? 1 == dtor : 0 == dtor);
 }
+
+
+Derived::~Derived () { ++dtor; }



Mime
View raw message