Author: sebor
Date: Mon Jul 31 10:10:08 2006
New Revision: 427175
URL: http://svn.apache.org/viewvc?rev=427175&view=rev
Log:
2006-07-31 Martin Sebor <[EMAIL PROTECTED]>
* exception.cpp: Replaced Windows \r\n sequences with \n alone.
Modified:
incubator/stdcxx/trunk/tests/src/exception.cpp
Modified: incubator/stdcxx/trunk/tests/src/exception.cpp
URL:
http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/exception.cpp?rev=427175&r1=427174&r2=427175&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/exception.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/exception.cpp Mon Jul 31 10:10:08 2006
@@ -42,9 +42,9 @@
_TEST_EXPORT int
rw_vasnprintf (char**, size_t*, const char*, va_list);
-static int
-_rw_format (char** pbuf, size_t* pbufsize, const char* file, int line,
- const char* function, const char* fmt, va_list va);
+static int
+_rw_format (char** pbuf, size_t* pbufsize, const char* file, int line,
+ const char* function, const char* fmt, va_list va);
/**************************************************************************/
@@ -54,98 +54,98 @@
/**************************************************************************/
-struct ExceptionBase
-{
-private:
+struct ExceptionBase
+{
+private:
struct ExceptionString;
-public:
+public:
char buf_ [256];
- ExceptionString* ex_str_;
-
- ExceptionBase ();
- ExceptionBase (const ExceptionBase&);
-
- ~ExceptionBase ();
-
- ExceptionBase& operator= (const ExceptionBase&);
-
- void format (const char* file, int line, const char* function,
- const char* fmt, va_list va);
-
- const char* what () const;
-
-private:
-
+ ExceptionString* ex_str_;
+
+ ExceptionBase ();
+ ExceptionBase (const ExceptionBase&);
+
+ ~ExceptionBase ();
+
+ ExceptionBase& operator= (const ExceptionBase&);
+
+ void format (const char* file, int line, const char* function,
+ const char* fmt, va_list va);
+
+ const char* what () const;
+
+private:
+
struct ExceptionString
- {
- long refs_;
- char* str_;
-
- void init (char* str)
- {
- refs_ = 1;
- str_ = str;
- }
-
- void addref () { ++refs_; }
-
- long release ()
- {
- if (0 == --refs_) {
- free (str_);
- str_ = 0;
- }
- return refs_;
- }
-
- private:
- // not defined
- ExceptionString (const ExceptionString&);
- ExceptionString& operator= (const ExceptionString&);
+ {
+ long refs_;
+ char* str_;
+
+ void init (char* str)
+ {
+ refs_ = 1;
+ str_ = str;
+ }
+
+ void addref () { ++refs_; }
+
+ long release ()
+ {
+ if (0 == --refs_) {
+ free (str_);
+ str_ = 0;
+ }
+ return refs_;
+ }
+
+ private:
+ // not defined
+ ExceptionString (const ExceptionString&);
+ ExceptionString& operator= (const ExceptionString&);
};
-
- void free_ ();
-};
-
-ExceptionBase::ExceptionBase () : ex_str_ (0)
-{
- buf_ [0] = '\0';
-}
-
-ExceptionBase::ExceptionBase (const ExceptionBase& ex) : ex_str_ (0)
-{
- *this = ex;
-}
-
-ExceptionBase::~ExceptionBase ()
-{
- free_ ();
-}
-
-ExceptionBase& ExceptionBase::operator= (const ExceptionBase& ex)
-{
- if (&ex != this) {
-
- free_ ();
-
- if (ex.ex_str_) {
- ex_str_ = ex.ex_str_;
- ex_str_->addref ();
- }
- else
- strncpy (buf_, ex.buf_, sizeof (buf_));
- }
-
- return *this;
-}
-
-void ExceptionBase::format (const char* file, int line,
- const char* function, const char* fmt, va_list va)
-{
- free_ ();
-
+
+ void free_ ();
+};
+
+ExceptionBase::ExceptionBase () : ex_str_ (0)
+{
+ buf_ [0] = '\0';
+}
+
+ExceptionBase::ExceptionBase (const ExceptionBase& ex) : ex_str_ (0)
+{
+ *this = ex;
+}
+
+ExceptionBase::~ExceptionBase ()
+{
+ free_ ();
+}
+
+ExceptionBase& ExceptionBase::operator= (const ExceptionBase& ex)
+{
+ if (&ex != this) {
+
+ free_ ();
+
+ if (ex.ex_str_) {
+ ex_str_ = ex.ex_str_;
+ ex_str_->addref ();
+ }
+ else
+ strncpy (buf_, ex.buf_, sizeof (buf_));
+ }
+
+ return *this;
+}
+
+void ExceptionBase::format (const char* file, int line,
+ const char* function, const char* fmt, va_list va)
+{
+ free_ ();
+
char* buf = 0;
size_t bufsize = 0;
@@ -155,57 +155,57 @@
if (0 > nchars)
return;
- if (sizeof (buf_) <= nchars) {
- // buf_ size is too small
- ex_str_ = _RWSTD_STATIC_CAST (ExceptionString*,
- malloc (sizeof (*ex_str_)));
-
- if (ex_str_) {
- ex_str_->init (buf);
- return;
- }
+ if (sizeof (buf_) <= nchars) {
+ // buf_ size is too small
+ ex_str_ = _RWSTD_STATIC_CAST (ExceptionString*,
+ malloc (sizeof (*ex_str_)));
+
+ if (ex_str_) {
+ ex_str_->init (buf);
+ return;
+ }
}
// buf_ size if enough or cannot allocate memory for the ex_str_
const size_t max_len = sizeof (buf_) - 1;
- strncpy (buf_, buf, max_len);
- buf_ [max_len] = '\0';
- free (buf);
-}
-
-const char* ExceptionBase::what () const
-{
- return ex_str_ && ex_str_->str_ ? ex_str_->str_ : buf_;
-}
-
-void ExceptionBase::free_ ()
-{
- buf_ [0] = '\0';
-
- if (ex_str_ && 0 == ex_str_->release ()) {
- free (ex_str_);
- ex_str_ = 0;
- }
-}
-
+ strncpy (buf_, buf, max_len);
+ buf_ [max_len] = '\0';
+ free (buf);
+}
+
+const char* ExceptionBase::what () const
+{
+ return ex_str_ && ex_str_->str_ ? ex_str_->str_ : buf_;
+}
+
+void ExceptionBase::free_ ()
+{
+ buf_ [0] = '\0';
+
+ if (ex_str_ && 0 == ex_str_->release ()) {
+ free (ex_str_);
+ ex_str_ = 0;
+ }
+}
+
/**************************************************************************/
struct BadAlloc : std::bad_alloc, ExceptionBase
{
BadAlloc ()
- {
+ {
}
BadAlloc (const ExceptionBase& ex) : ExceptionBase (ex)
- {
+ {
}
~BadAlloc () _THROWS (()) {}
const char* what () const _THROWS (())
- {
- const char* msg = ExceptionBase::what ();
- return (msg && msg[0]) ? msg : std::bad_alloc::what ();
+ {
+ const char* msg = ExceptionBase::what ();
+ return (msg && msg[0]) ? msg : std::bad_alloc::what ();
}
};
@@ -214,26 +214,26 @@
struct StreamException : Exception, ExceptionBase
{
StreamException () : Exception (ex_stream)
- {
+ {
}
StreamException (const ExceptionBase& ex) :
Exception (ex_stream), ExceptionBase (ex)
- {
+ {
}
const char* what () const
- {
- return ExceptionBase::what ();
+ {
+ return ExceptionBase::what ();
}
};
/**************************************************************************/
-static int
-_rw_format (char** pbuf, size_t* pbufsize, const char* file, int line,
- const char* function, const char* fmt, va_list va)
-{
+static int
+_rw_format (char** pbuf, size_t* pbufsize, const char* file, int line,
+ const char* function, const char* fmt, va_list va)
+{
const int nchars1 = function ?
rw_asnprintf (pbuf, pbufsize, "\"%s\", %d, \"%s\" ",
file, line, function) :
@@ -242,44 +242,44 @@
if (0 > nchars1)
return nchars1;
- char *tmpbuf = 0;
- size_t tmpsize = 0;
-
- const int nchars2 = rw_vasnprintf (&tmpbuf, &tmpsize, fmt, va);
-
+ char *tmpbuf = 0;
+ size_t tmpsize = 0;
+
+ const int nchars2 = rw_vasnprintf (&tmpbuf, &tmpsize, fmt, va);
+
if (0 > nchars2) {
- free (tmpbuf);
+ free (tmpbuf);
return nchars1;
}
const int nchars3 = rw_asnprintf (pbuf, pbufsize, "%{+}%s", tmpbuf);
-
- free (tmpbuf);
-
- return 0 > nchars3 ? nchars1 : nchars1 + nchars3;
-}
-
+
+ free (tmpbuf);
+
+ return 0 > nchars3 ? nchars1 : nchars1 + nchars3;
+}
+
_TEST_EXPORT void
rw_throw (ExceptionId exid, const char *file, int line,
const char *function, const char *fmt, ...)
{
- va_list va;
- va_start (va, fmt);
+ va_list va;
+ va_start (va, fmt);
ExceptionBase base;
base.format (file, line, function, fmt, va);
-
- va_end (va);
-
- switch (exid) {
-
- case ex_stream:
- throw StreamException (base);
-
- case ex_bad_alloc:
- throw BadAlloc (base);
-
- default:
- throw ex_unknown;
+
+ va_end (va);
+
+ switch (exid) {
+
+ case ex_stream:
+ throw StreamException (base);
+
+ case ex_bad_alloc:
+ throw BadAlloc (base);
+
+ default:
+ throw ex_unknown;
}
}