stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From far...@apache.org
Subject svn commit: r549766 - in /incubator/stdcxx/trunk: examples/manual/rwexcept.cpp include/rw/_error.h src/exception.cpp
Date Fri, 22 Jun 2007 10:15:52 GMT
Author: faridz
Date: Fri Jun 22 03:15:46 2007
New Revision: 549766

URL: http://svn.apache.org/viewvc?view=rev&rev=549766
Log:
2007-06-22 Farid Zaripov <Farid_Zaripov@epam.com>

	STDCXX-454
	* _error.h: Added declaration of the __rw_free_what_buf.
	* exception.cpp (__rw_free_what_buf): Added _RWSTD_EXPORT to prototype.
	Added assertion on __rw_what_refcnt value.
	(_C_assign): If whatstr == __rw_what_buf, just reuse it without allocation
	of the new buffer.
	* rwexcept.cpp: Use __rw_free_what_buf() instead of delete[].

Modified:
    incubator/stdcxx/trunk/examples/manual/rwexcept.cpp
    incubator/stdcxx/trunk/include/rw/_error.h
    incubator/stdcxx/trunk/src/exception.cpp

Modified: incubator/stdcxx/trunk/examples/manual/rwexcept.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/examples/manual/rwexcept.cpp?view=diff&rev=549766&r1=549765&r2=549766
==============================================================================
--- incubator/stdcxx/trunk/examples/manual/rwexcept.cpp (original)
+++ incubator/stdcxx/trunk/examples/manual/rwexcept.cpp Fri Jun 22 03:15:46 2007
@@ -3,7 +3,7 @@
  * rwexcept.cpp - Example program demonstrating the use of the optional
  *                C++ Standard Library exception mechanism.
  *
- * $Id: //stdlib/dev/examples/stdlib/manual/rwexcept.cpp#10 $
+ * $Id$
  *
  ***************************************************************************
  *
@@ -35,9 +35,9 @@
 {
     std::cerr << "exception #" <<  id << ": " << what << '\n';
 
-    // 
-    if (id >= _RWSTD_ERROR_BAD_CAST)
-        delete[] what;
+    // free what buffer
+    if (what)
+        __rw::__rw_free_what_buf (what);
 
     // a real program would call abort() here to prevent the potentially
     // dangerous destruction of objects with static storage duration

Modified: incubator/stdcxx/trunk/include/rw/_error.h
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/include/rw/_error.h?view=diff&rev=549766&r1=549765&r2=549766
==============================================================================
--- incubator/stdcxx/trunk/include/rw/_error.h (original)
+++ incubator/stdcxx/trunk/include/rw/_error.h Fri Jun 22 03:15:46 2007
@@ -39,9 +39,12 @@
 // (if any) used to format the exception object's what() string
 void _RWSTD_EXPORT __rw_throw (int, ...);
 
+// frees memory buffer used for what() message
+void _RWSTD_EXPORT __rw_free_what_buf (char*);
+
 // throws an exception identified by first argument with the second
 // argument containing the exception object's what() string, which
-// if non-0, is dynamically allocated and must be delete[]'d
+// if non-0, is must be freed using __rw_free_what_buf()
 // may be assigned to a user-defined handler (e.g., to prevent
 // the library from throwing exceptions or to implement logging)
 extern void _RWSTD_EXPORT (*__rw_throw_proc)(int, char*);

Modified: incubator/stdcxx/trunk/src/exception.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/src/exception.cpp?view=diff&rev=549766&r1=549765&r2=549766
==============================================================================
--- incubator/stdcxx/trunk/src/exception.cpp (original)
+++ incubator/stdcxx/trunk/src/exception.cpp Fri Jun 22 03:15:46 2007
@@ -438,10 +438,13 @@
 static _RWSTD_THREAD int
 __rw_what_refcnt;
 
-inline void __rw_free_what_buf (char* buf)
+// free memory buffer allocated in __rw_vfmtwhat()
+_RWSTD_EXPORT inline void __rw_free_what_buf (char* buf)
 {
-    if (__rw_what_buf == buf)
+    if (__rw_what_buf == buf) {
+        _RWSTD_ASSERT (0 < __rw_what_refcnt);
         _RWSTD_THREAD_PREDECREMENT (__rw_what_refcnt, false);
+    }
     else
         delete[] buf;
 }
@@ -838,12 +841,7 @@
 __rw_exception::__rw_exception (const __rw_exception &rhs)
     : _STD::exception (rhs), _C_what (0)
 {
-    if (rhs._C_what == __rw_what_buf) {
-        _RWSTD_THREAD_PREINCREMENT (__rw_what_refcnt, false);
-        _C_what = __rw_what_buf;
-    }
-    else
-        _C_assign (rhs.what ());
+    _C_assign (rhs.what ());
 }
 
   
@@ -910,17 +908,24 @@
 
         if (whatstr && *whatstr) {
 
-            if (_RWSTD_SIZE_MAX == len)
-                len = strlen (whatstr);
-
-            if (len) {
-                // allocate own buffer and copy string
-                tmp = new char [len + 1];
-                memcpy (tmp, whatstr, len + 1);
+            if (whatstr == __rw_what_buf) {
+                if (len)
+                    _RWSTD_THREAD_PREINCREMENT (__rw_what_refcnt, false);
+                tmp = __rw_what_buf;
             }
             else {
-                // special case: do not allocate, just use passed in pointer
-                tmp = _RWSTD_CONST_CAST (char*, whatstr);
+                if (_RWSTD_SIZE_MAX == len)
+                    len = strlen (whatstr);
+
+                if (len) {
+                    // allocate own buffer and copy string
+                    tmp = new char [len + 1];
+                    memcpy (tmp, whatstr, len + 1);
+                }
+                else {
+                    // special case: do not allocate, just use passed in pointer
+                    tmp = _RWSTD_CONST_CAST (char*, whatstr);
+                }
             }
         }
 



Mime
View raw message