assume that new throws an exception

This commit is contained in:
Jeff Hill
2002-03-25 16:27:47 +00:00
parent 2c486479a8
commit 9e19d72cb1
11 changed files with 38 additions and 102 deletions
+21 -44
View File
@@ -169,10 +169,7 @@ cac::cac ( cacNotify & notifyIn, bool enablePreemptiveCallbackIn ) :
tmp[0] = '\0';
}
len = strlen ( tmp ) + 1;
this->pUserName = new ( std::nothrow ) char [ len ];
if ( ! this->pUserName ) {
throw std::bad_alloc ();
}
this->pUserName = new char [ len ];
strncpy ( this->pUserName, tmp, len );
}
@@ -673,12 +670,7 @@ cacChannel & cac::createChannel ( const char * pName,
}
epics_auto_ptr < cacChannel > pNetChan
( new nciu ( *this, limboIIU, chan, pName, pri ) );
if ( pNetChan.get() ) {
return *pNetChan.release ();
}
else {
throw std::bad_alloc ();
}
return *pNetChan.release ();
}
}
return *pIO;
@@ -1038,17 +1030,12 @@ cac::writeNotifyRequest ( nciu &chan, unsigned type, // X aCC 361
epicsGuard < epicsMutex > guard ( this->mutex );
autoPtrRecycle < netWriteNotifyIO > pIO ( this->ioTable, chan.cacPrivateListOfIO::eventq,
*this, netWriteNotifyIO::factory ( this->freeListWriteNotifyIO, chan, notifyIn ) );
if ( pIO.get() ) {
this->ioTable.add ( *pIO );
chan.cacPrivateListOfIO::eventq.add ( *pIO );
this->flushIfRequired ( guard, *chan.getPIIU() );
chan.getPIIU()->writeNotifyRequest (
chan, *pIO, type, nElem, pValue );
return pIO.release()->getId ();
}
else {
throw std::bad_alloc ();
}
this->ioTable.add ( *pIO );
chan.cacPrivateListOfIO::eventq.add ( *pIO );
this->flushIfRequired ( guard, *chan.getPIIU() );
chan.getPIIU()->writeNotifyRequest (
chan, *pIO, type, nElem, pValue );
return pIO.release()->getId ();
}
cacChannel::ioid
@@ -1059,16 +1046,11 @@ cac::readNotifyRequest ( nciu &chan, unsigned type, // X aCC 361
autoPtrRecycle < netReadNotifyIO > pIO ( this->ioTable,
chan.cacPrivateListOfIO::eventq, *this,
netReadNotifyIO::factory ( this->freeListReadNotifyIO, chan, notifyIn ) );
if ( pIO.get() ) {
this->ioTable.add ( *pIO );
chan.cacPrivateListOfIO::eventq.add ( *pIO );
this->flushIfRequired ( guard, *chan.getPIIU() );
chan.getPIIU()->readNotifyRequest ( chan, *pIO, type, nElem );
return pIO.release()->getId ();
}
else {
throw std::bad_alloc ();
}
this->ioTable.add ( *pIO );
chan.cacPrivateListOfIO::eventq.add ( *pIO );
this->flushIfRequired ( guard, *chan.getPIIU() );
chan.getPIIU()->readNotifyRequest ( chan, *pIO, type, nElem );
return pIO.release()->getId ();
}
void cac::ioCancel ( nciu &chan, const cacChannel::ioid &id )
@@ -1363,20 +1345,15 @@ cac::subscriptionRequest ( nciu &chan, unsigned type, // X aCC 361
chan.cacPrivateListOfIO::eventq, *this,
netSubscription::factory ( this->freeListSubscription,
chan, type, nElem, mask, notifyIn ) );
if ( pIO.get() ) {
this->ioTable.add ( *pIO );
chan.cacPrivateListOfIO::eventq.add ( *pIO );
if ( chan.connected () ) {
this->flushIfRequired ( guard, *chan.getPIIU() );
chan.getPIIU()->subscriptionRequest ( chan, *pIO );
}
cacChannel::ioid id = pIO->getId ();
pIO.release ();
return id;
}
else {
throw std::bad_alloc();
this->ioTable.add ( *pIO );
chan.cacPrivateListOfIO::eventq.add ( *pIO );
if ( chan.connected () ) {
this->flushIfRequired ( guard, *chan.getPIIU() );
chan.getPIIU()->subscriptionRequest ( chan, *pIO );
}
cacChannel::ioid id = pIO->getId ();
pIO.release ();
return id;
}
bool cac::noopAction ( epicsGuard < callbackMutex > &, tcpiiu &,
+2 -2
View File
@@ -67,7 +67,7 @@ public:
unsigned copyOutBytes ( void *pBuf, unsigned nBytes );
bool copyOutAllBytes ( void *pBuf, unsigned nBytes );
unsigned removeBytes ( unsigned nBytes );
void * operator new ( size_t size, const std::nothrow_t & );
void * operator new ( size_t size );
void operator delete ( void *pCadaver, size_t size );
bool flushToWire ( wireSendAdapter & );
unsigned fillFromWire ( wireRecvAdapter & );
@@ -116,7 +116,7 @@ inline void comBuf::clear ()
this->nextReadIndex = 0u;
}
inline void * comBuf::operator new ( size_t size, const std::nothrow_t & )
inline void * comBuf::operator new ( size_t size )
{
return comBuf::pFreeList->allocate ( size );
}
+2 -8
View File
@@ -79,10 +79,7 @@ private:
nCopied = 0u;
}
while ( nElem > nCopied ) {
comBuf * pComBuf = new ( std::nothrow ) comBuf;
if ( ! pComBuf ) {
throw std::bad_alloc ();
}
comBuf * pComBuf = new comBuf;
unsigned nNew = pComBuf->copyIn ( &pVal[nCopied], nElem - nCopied );
nCopied += nNew;
this->bufs.add ( *pComBuf );
@@ -105,10 +102,7 @@ private:
return;
}
}
pComBuf = new ( std::nothrow ) comBuf;
if ( ! pComBuf ) {
throw std::bad_alloc ();
}
pComBuf = new comBuf;
assert ( pComBuf->copyIn ( &val, 1u ) == 1u );
this->bufs.add ( *pComBuf );
if ( ! this->pFirstUncommited.valid() ) {
-3
View File
@@ -65,9 +65,6 @@ nciu::nciu ( cac & cacIn, netiiu & iiuIn, cacChannelNotify & chanIn,
this->nameLength = static_cast <unsigned short> ( nameLengthTmp );
this->pNameStr = new char [ this->nameLength ];
if ( ! this->pNameStr ) {
throw std::bad_alloc ();
}
strcpy ( this->pNameStr, pNameIn );
}
-3
View File
@@ -27,9 +27,6 @@ oldCAC::oldCAC ( bool enablePreemptiveCallback ) :
ca_exception_func ( 0 ), ca_exception_arg ( 0 ),
pVPrintfFunc ( errlogVprintf ), fdRegFunc ( 0 ), fdRegArg ( 0 )
{
if ( ! & this->clientCtx ) {
throw std::bad_alloc ();
}
}
oldCAC::~oldCAC ()
+2 -6
View File
@@ -91,12 +91,8 @@ void dbChannelIO::subscribe ( unsigned type, unsigned long count,
throw cacChannel::outOfBounds();
}
dbSubscriptionIO *pIO =
new dbSubscriptionIO ( this->serviceIO, *this,
this->addr, notify, type, count, mask, pId );
if ( ! pIO ) {
throw std::bad_alloc ();
}
new dbSubscriptionIO ( this->serviceIO, *this,
this->addr, notify, type, count, mask, pId );
}
void dbChannelIO::ioCancel ( const ioid & id )
+1 -10
View File
@@ -114,13 +114,7 @@ void dbServiceIO::callStateNotify ( struct dbAddr & addr,
// no need to lock this because state notify is
// called from only one event queue consumer thread
if ( this->stateNotifyCacheSize < size) {
char * pTmp = new ( std::nothrow ) char [size];
if ( ! pTmp ) {
notify.exception ( ECA_ALLOCMEM,
"unable to allocate callback cache",
type, count );
return;
}
char * pTmp = new char [size];
delete [] this->pStateNotifyCache;
this->pStateNotifyCache = pTmp;
this->stateNotifyCacheSize = size;
@@ -194,9 +188,6 @@ void dbServiceIO::initiatePutNotify (
epicsGuard < epicsMutex > locker ( this->mutex );
if ( ! chan.dbServicePrivateListOfIO::pBlocker ) {
chan.dbServicePrivateListOfIO::pBlocker = new dbPutNotifyBlocker ( chan );
if ( ! chan.dbServicePrivateListOfIO::pBlocker ) {
throw std::bad_alloc ();
}
this->ioTable.add ( *chan.dbServicePrivateListOfIO::pBlocker );
}
chan.dbServicePrivateListOfIO::pBlocker->initiatePutNotify (
-4
View File
@@ -41,10 +41,6 @@ dbSubscriptionIO::dbSubscriptionIO ( dbServiceIO &serviceIO, dbChannelIO &chanIO
type ( typeIn ), count ( countIn ), id ( 0u )
{
this->es = serviceIO.subscribe ( addr, chanIO, *this, maskIn );
if ( ! this->es ) {
throw std::bad_alloc ();
}
if ( pId ) {
*pId = this->getId ();
}
@@ -32,8 +32,5 @@ void epicsSingletonBase::lockedFactory ()
epicsGuard < epicsMutex > guard ( this->mutex );
if ( ! this->pSingleton ) {
this->pSingleton = this->factory ();
if ( ! this->pSingleton ) {
throw std::bad_alloc ();
}
}
}
+8 -11
View File
@@ -528,11 +528,14 @@ bool resTable<T,ID>::setTableSizePrivate ( unsigned logBaseTwoTableSizeIn )
# endif
const unsigned oldTableOccupiedSize = this->tableSize ();
tsSLList<T> * pNewTable = ( tsSLList<T> * )
operator new ( newTableSize * sizeof ( tsSLList<T> ), std::nothrow );
if ( ! pNewTable ) {
tsSLList<T> * pNewTable;
try {
pNewTable = ( tsSLList<T> * )
::operator new ( newTableSize * sizeof ( tsSLList<T> ) );
}
catch ( ... ){
if ( ! this->pTable ) {
throw std::bad_alloc();
throw;
}
return false;
}
@@ -899,14 +902,8 @@ stringId::stringId (const char * idIn, allocationType typeIn) :
{
if (typeIn==copyString) {
unsigned nChars = strlen (idIn) + 1u;
this->pStr = new char [nChars];
if (this->pStr!=0) {
memcpy ((void *)this->pStr, idIn, nChars);
}
else {
throw std::bad_alloc();
}
memcpy ( (void *) this->pStr, idIn, nChars );
}
else {
this->pStr = idIn;
+2 -8
View File
@@ -141,10 +141,7 @@ void * tsFreeList < T, N, MUTEX, DEBUG_LEVEL >::allocate ( size_t size )
}
if ( size != sizeof ( T ) || N == 0u || tsFreeListDebugBypass ) {
void *p = ::operator new ( size, std::nothrow );
if ( ! p ) {
throw std::bad_alloc ();
}
void *p = ::operator new ( size );
if ( tsFreeListDebugBypass ) {
memset ( p, 0xaa, size );
}
@@ -169,10 +166,7 @@ tsFreeListItem < T, DEBUG_LEVEL > *
tsFreeList < T, N, MUTEX, DEBUG_LEVEL >::allocateFromNewChunk ()
{
tsFreeListChunk < T, N, DEBUG_LEVEL > *pChunk =
new ( std::nothrow ) ( tsFreeListChunk < T, N, DEBUG_LEVEL > );
if ( ! pChunk ) {
throw std::bad_alloc ();
}
new tsFreeListChunk < T, N, DEBUG_LEVEL >;
for ( unsigned i=1u; i < N-1; i++ ) {
pChunk->items[i].pNext = &pChunk->items[i+1];