You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@santuario.apache.org by Vadim Ismailov <wo...@gmail.com> on 2004/12/09 19:09:19 UTC

Proposal/Fix for XSECError.hpp

Hi,

Starting from VS.NET 7.0 operator new does not anymore return NULL in
case of allocation error. It throws std::bad_alloc exception instead
(the way it is supposed to be). Therefore following code in
XSECError.hpp not going to work as expected:

---------------------- start -------------------------
#if defined (_WIN32) && defined (_DEBUG)

#   define XSECnew( a, b ) \
      if (( a = DEBUG_NEW b ) == NULL) { \
        throw XSECException (XSECException::MemoryAllocationFail); \
      }

#else 

#   define XSECnew(a, b) \
      if ((a = new b) == NULL) { \
        throw XSECException (XSECException::MemoryAllocationFail); \
      }
#endif
---------------------- end -------------------------

In case allocation errors in higher code are catched by XSECException
when allocation fails (with 7.0 and 7.1 runtimes) std::bad_alloc is
raised instead of XSECException. Therefore I changed XSECError.hpp
like shown below. I didn't check where and how exceptions are catched,
but at least it will work the way author intended it to work.

---------------------- start -------------------------
#if defined(_WIN32) && (_MSC_VER < 1300)

#   define XSECnew(a, b) \
      if ((a = new b) == NULL) { \
        throw XSECException (XSECException::MemoryAllocationFail); \
      }

#else

#define XSECnew(a, b) \
      try { \
        a = new b; \
      } catch(...) { \
        throw XSECException (XSECException::MemoryAllocationFail); \
      }

#endif
---------------------- end -------------------------

I also got rid of DEBUG_NEW MFC macro and MFC dependency in debug
build altogether, but this is different story.

Regards,
Vadim

Re: Proposal/Fix for XSECError.hpp

Posted by Berin Lautenbach <be...@wingsofhermes.org>.
Hmm.  Yes sounds sensible.

As does getting rid of mfc dependency - something I've been promising to 
do for a while - and do want to do before a 1.2 release.

Cheers,
	Berin

Vadim Ismailov wrote:

> Hi,
> 
> Starting from VS.NET 7.0 operator new does not anymore return NULL in
> case of allocation error. It throws std::bad_alloc exception instead
> (the way it is supposed to be). Therefore following code in
> XSECError.hpp not going to work as expected:
> 
> ---------------------- start -------------------------
> #if defined (_WIN32) && defined (_DEBUG)
> 
> #   define XSECnew( a, b ) \
>       if (( a = DEBUG_NEW b ) == NULL) { \
>         throw XSECException (XSECException::MemoryAllocationFail); \
>       }
> 
> #else 
> 
> #   define XSECnew(a, b) \
>       if ((a = new b) == NULL) { \
>         throw XSECException (XSECException::MemoryAllocationFail); \
>       }
> #endif
> ---------------------- end -------------------------
> 
> In case allocation errors in higher code are catched by XSECException
> when allocation fails (with 7.0 and 7.1 runtimes) std::bad_alloc is
> raised instead of XSECException. Therefore I changed XSECError.hpp
> like shown below. I didn't check where and how exceptions are catched,
> but at least it will work the way author intended it to work.
> 
> ---------------------- start -------------------------
> #if defined(_WIN32) && (_MSC_VER < 1300)
> 
> #   define XSECnew(a, b) \
>       if ((a = new b) == NULL) { \
>         throw XSECException (XSECException::MemoryAllocationFail); \
>       }
> 
> #else
> 
> #define XSECnew(a, b) \
>       try { \
>         a = new b; \
>       } catch(...) { \
>         throw XSECException (XSECException::MemoryAllocationFail); \
>       }
> 
> #endif
> ---------------------- end -------------------------
> 
> I also got rid of DEBUG_NEW MFC macro and MFC dependency in debug
> build altogether, but this is different story.
> 
> Regards,
> Vadim
> 
>