From 8334b8d261d61dc1a6654e8d537af1ae73476df4 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Thu, 25 Apr 2002 18:26:33 +0000 Subject: [PATCH] placement new issues --- src/ca/netIO.h | 96 +++++++++++++++++-------------------- src/ca/netReadNotifyIO.cpp | 23 ++++++++- src/ca/netSubscription.cpp | 23 +++++++++ src/ca/netWriteNotifyIO.cpp | 23 +++++++++ 4 files changed, 111 insertions(+), 54 deletions(-) diff --git a/src/ca/netIO.h b/src/ca/netIO.h index 09e8c93d8..5528ef95f 100644 --- a/src/ca/netIO.h +++ b/src/ca/netIO.h @@ -20,6 +20,19 @@ #include "nciu.h" +// does the local compiler support placement delete +#if defined (_MSC_VER) +# if _MSC_VER >= 1200 +# define NETIO_PLACEMENT_DELETE +# endif +#elif defined (__GNUC__) && 0 +# if __GNUC__>2 || ( __GNUC__==2 && __GNUC_MINOR_>=96 ) +# define NETIO_PLACEMENT_DELETE +# endif +#else +# define NETIO_PLACEMENT_DELETE +#endif + class baseNMIU : public tsDLNode < baseNMIU >, public chronIntIdRes < baseNMIU > { public: @@ -38,7 +51,7 @@ public: ca_uint32_t getID () const; nciu & channel () const; protected: - virtual ~baseNMIU () = 0; + virtual ~baseNMIU (); // // perhaps we should not store the channel here and instead fetch it out of the // notify @@ -68,8 +81,6 @@ public: void exception ( int status, const char *pContext, unsigned type, arrayElementCount count ); -protected: - ~netSubscription (); private: const arrayElementCount count; cacStateNotify ¬ify; @@ -80,12 +91,19 @@ private: class netSubscription * isSubscription (); void * operator new ( size_t, tsFreeList < class netSubscription, 1024, epicsMutexNOOP > & ); -# if ! defined ( NO_PLACEMENT_DELETE ) - void operator delete ( void *, size_t, +# if defined ( NETIO_PLACEMENT_DELETE ) + void operator delete ( void *, tsFreeList < class netSubscription, 1024, epicsMutexNOOP > & ); # endif netSubscription ( const netSubscription & ); netSubscription & operator = ( const netSubscription & ); + ~netSubscription (); +# if defined (_MSC_VER) && _MSC_VER == 1300 + void operator delete ( void * ); // avoid visual c++ 7 bug +# endif +# if __GNUC__==2 && __GNUC_MINOR_<96 + void operator delete ( void *, size_t ); // avoid gnu g++ bug +# endif }; class netReadNotifyIO : public baseNMIU { @@ -101,19 +119,24 @@ public: arrayElementCount count, const void *pData ); void exception ( int status, const char *pContext, unsigned type, arrayElementCount count ); -protected: - ~netReadNotifyIO (); private: - cacReadNotify ¬ify; - netReadNotifyIO ( nciu &chan, cacReadNotify ¬ify ); + cacReadNotify & notify; + netReadNotifyIO ( nciu & chan, cacReadNotify & notify ); void * operator new ( size_t, tsFreeList < class netReadNotifyIO, 1024, epicsMutexNOOP > & ); -# if ! defined ( NO_PLACEMENT_DELETE ) - void operator delete ( void *, size_t, +# if defined ( NETIO_PLACEMENT_DELETE ) + void operator delete ( void *, tsFreeList < class netReadNotifyIO, 1024, epicsMutexNOOP > & ); # endif + ~netReadNotifyIO (); netReadNotifyIO ( const netReadNotifyIO & ); netReadNotifyIO & operator = ( const netReadNotifyIO & ); +# if defined (_MSC_VER) && _MSC_VER == 1300 + void operator delete ( void * ); // avoid visual c++ 7 bug +# endif +# if __GNUC__==2 && __GNUC_MINOR_<96 + void operator delete ( void *, size_t ); // avoid gnu g++ bug +# endif }; class netWriteNotifyIO : public baseNMIU { @@ -129,19 +152,24 @@ public: arrayElementCount count, const void *pData ); void exception ( int status, const char *pContext, unsigned type, arrayElementCount count ); -protected: - ~netWriteNotifyIO (); private: cacWriteNotify ¬ify; netWriteNotifyIO ( nciu &chan, cacWriteNotify ¬ify ); void * operator new ( size_t, tsFreeList < class netWriteNotifyIO, 1024, epicsMutexNOOP > & ); -# if ! defined ( NO_PLACEMENT_DELETE ) - void operator delete ( void *, size_t, +# if defined ( NETIO_PLACEMENT_DELETE ) + void operator delete ( void *, tsFreeList < class netWriteNotifyIO, 1024, epicsMutexNOOP > & ); # endif netWriteNotifyIO ( const netWriteNotifyIO & ); netWriteNotifyIO & operator = ( const netWriteNotifyIO & ); + ~netWriteNotifyIO (); +# if defined (_MSC_VER) && _MSC_VER == 1300 + void operator delete ( void * ); // avoid visual c++ 7 bug +# endif +# if __GNUC__==2 && __GNUC_MINOR_<96 + void operator delete ( void *, size_t ); // avoid gnu g++ bug +# endif }; inline ca_uint32_t baseNMIU::getID () const @@ -160,19 +188,6 @@ inline void * netSubscription::operator new ( size_t size, return freeList.allocate ( size ); } -// NOTE: The constructor for netSubscription::netSubscription() currently does -// not throw an exception, but we should eventually have placement delete -// defined for class netSubscription when compilers support this so that -// there is no possibility of a leak if there was an exception in -// a future version of netSubscription::netSubscription() -#if ! defined ( NO_PLACEMENT_DELETE ) -inline void netSubscription::operator delete ( void *pCadaver, size_t size, - tsFreeList < class netSubscription, 1024, epicsMutexNOOP > &freeList ) -{ - freeList.release ( pCadaver, size ); -} -#endif - inline netSubscription * netSubscription::factory ( tsFreeList < class netSubscription, 1024, epicsMutexNOOP > &freeList, nciu &chan, unsigned type, arrayElementCount count, @@ -216,18 +231,6 @@ inline void * netReadNotifyIO::operator new ( size_t size, return freeList.allocate ( size ); } -// NOTE: The constructor for netReadNotifyIO::netReadNotifyIO() currently does -// not throw an exception, but we should eventually have placement delete -// defined for class netReadNotifyIO when compilers support this so that -// there is no possibility of a leak if there was an exception in -// a future version of netReadNotifyIO::netReadNotifyIO() -#if ! defined ( NO_PLACEMENT_DELETE ) -inline void netReadNotifyIO::operator delete ( void *pCadaver, size_t size, - tsFreeList < class netReadNotifyIO, 1024, epicsMutexNOOP > &freeList ) { - freeList.release ( pCadaver, size ); -} -#endif - inline netWriteNotifyIO * netWriteNotifyIO::factory ( tsFreeList < class netWriteNotifyIO, 1024, epicsMutexNOOP > &freeList, nciu &chan, cacWriteNotify ¬ify ) @@ -241,17 +244,4 @@ inline void * netWriteNotifyIO::operator new ( size_t size, return freeList.allocate ( size ); } -// NOTE: The constructor for netWriteNotifyIO::netWriteNotifyIO() currently does -// not throw an exception, but we should eventually have placement delete -// defined for class netWriteNotifyIO when compilers support this so that -// there is no possibility of a leak if there was an exception in -// a future version of netWriteNotifyIO::netWriteNotifyIO() -#if ! defined ( NO_PLACEMENT_DELETE ) -inline void netWriteNotifyIO::operator delete ( void *pCadaver, size_t size, - tsFreeList < class netWriteNotifyIO, 1024, epicsMutexNOOP > &freeList ) -{ - freeList.release ( pCadaver, size ); -} -#endif - #endif // ifdef netIOh diff --git a/src/ca/netReadNotifyIO.cpp b/src/ca/netReadNotifyIO.cpp index ae9cd5a4b..c0effa05a 100644 --- a/src/ca/netReadNotifyIO.cpp +++ b/src/ca/netReadNotifyIO.cpp @@ -10,13 +10,15 @@ * Author: Jeff Hill */ +#include + #define epicsAssertAuthor "Jeff Hill johill@lanl.gov" #include "iocinf.h" #include "nciu.h" #include "cac.h" -netReadNotifyIO::netReadNotifyIO ( nciu &chan, cacReadNotify ¬ify ) : +netReadNotifyIO::netReadNotifyIO ( nciu & chan, cacReadNotify & notify ) : baseNMIU ( chan ), notify ( notify ) { } @@ -62,5 +64,24 @@ void netReadNotifyIO::completion ( unsigned type, this->notify.completion ( type, count, pData ); } +// NOTE: The constructor for netReadNotifyIO::netReadNotifyIO() currently does +// not throw an exception, but we should eventually have placement delete +// defined for class netReadNotifyIO when compilers support this so that +// there is no possibility of a leak if there was an exception in +// a future version of netReadNotifyIO::netReadNotifyIO() +#if defined ( NETIO_PLACEMENT_DELETE ) + void netReadNotifyIO::operator delete ( void *pCadaver, + tsFreeList < class netReadNotifyIO, 1024, epicsMutexNOOP > & freeList ) { + freeList.release ( pCadaver, sizeof ( netReadNotifyIO ) ); + } +#endif + +# if defined (_MSC_VER) && _MSC_VER == 1300 + void netReadNotifyIO::operator delete ( void * ) // avoid visual c++ 7 bug + { + throw std::logic_error ( "_MSC_VER == 1300 bogus stub called?" ); + } +# endif + diff --git a/src/ca/netSubscription.cpp b/src/ca/netSubscription.cpp index ca9e9e1d9..e9164d4ce 100644 --- a/src/ca/netSubscription.cpp +++ b/src/ca/netSubscription.cpp @@ -10,6 +10,8 @@ * Author: Jeff Hill */ +#include + #define epicsAssertAuthor "Jeff Hill johill@lanl.gov" #define epicsExportSharedSymbols @@ -80,5 +82,26 @@ void netSubscription::completion ( unsigned typeIn, this->notify.current ( typeIn, countIn, pDataIn ); } +// NOTE: The constructor for netSubscription::netSubscription() currently does +// not throw an exception, but we should eventually have placement delete +// defined for class netSubscription when compilers support this so that +// there is no possibility of a leak if there was an exception in +// a future version of netSubscription::netSubscription() +#if defined ( NETIO_PLACEMENT_DELETE ) + void netSubscription::operator delete ( void *pCadaver, + tsFreeList < class netSubscription, 1024, epicsMutexNOOP > &freeList ) + { + freeList.release ( pCadaver, sizeof ( netSubscription ) ); + } +#endif + +# if defined (_MSC_VER) && _MSC_VER == 1300 + void netSubscription::operator delete ( void * ) // avoid visual c++ 7 bug + { + throw std::logic_error ( "_MSC_VER == 1300 bogus stub called?" ); + } +# endif + + diff --git a/src/ca/netWriteNotifyIO.cpp b/src/ca/netWriteNotifyIO.cpp index b706be995..e557d1f0d 100644 --- a/src/ca/netWriteNotifyIO.cpp +++ b/src/ca/netWriteNotifyIO.cpp @@ -10,6 +10,8 @@ * Author: Jeff Hill */ +#include + #define epicsAssertAuthor "Jeff Hill johill@lanl.gov" #include "iocinf.h" @@ -63,5 +65,26 @@ void netWriteNotifyIO::completion ( unsigned /* type */, this->chan.getClient().printf ( "Write response with data ?\n" ); } +// NOTE: The constructor for netWriteNotifyIO::netWriteNotifyIO() currently does +// not throw an exception, but we should eventually have placement delete +// defined for class netWriteNotifyIO when compilers support this so that +// there is no possibility of a leak if there was an exception in +// a future version of netWriteNotifyIO::netWriteNotifyIO() +#if defined ( NETIO_PLACEMENT_DELETE ) + void netWriteNotifyIO::operator delete ( void *pCadaver, + tsFreeList < class netWriteNotifyIO, 1024, epicsMutexNOOP > &freeList ) + { + freeList.release ( pCadaver, sizeof ( netWriteNotifyIO ) ); + } +#endif + +# if defined (_MSC_VER) && _MSC_VER == 1300 + void netWriteNotifyIO::operator delete ( void * ) // avoid visual c++ 7 bug + { + throw std::logic_error ( "_MSC_VER == 1300 bogus stub called?" ); + } +# endif + +