1
0
Fork 0

(svn r14935) -Fix [FS#2498]: the new operator may not return NULL, so don't.

release/0.7
rubidium 2009-01-09 15:01:15 +00:00
parent 07c5fb2a02
commit 0464e9f864
2 changed files with 11 additions and 5 deletions

View File

@ -211,6 +211,7 @@ struct PoolItem {
/** /**
* An overriden version of new that allocates memory on the pool. * An overriden version of new that allocates memory on the pool.
* @param size the size of the variable (unused) * @param size the size of the variable (unused)
* @pre CanAllocateItem()
* @return the memory that is 'allocated' * @return the memory that is 'allocated'
*/ */
void *operator new(size_t size) void *operator new(size_t size)
@ -282,7 +283,8 @@ private:
protected: protected:
/** /**
* Allocate a pool item; possibly allocate a new block in the pool. * Allocate a pool item; possibly allocate a new block in the pool.
* @return the allocated pool item (or NULL when the pool is full). * @pre CanAllocateItem()
* @return the allocated pool item.
*/ */
static inline T *AllocateRaw() static inline T *AllocateRaw()
{ {
@ -292,7 +294,8 @@ protected:
/** /**
* Allocate a pool item; possibly allocate a new block in the pool. * Allocate a pool item; possibly allocate a new block in the pool.
* @param first the first pool item to start searching * @param first the first pool item to start searching
* @return the allocated pool item (or NULL when the pool is full). * @pre CanAllocateItem()
* @return the allocated pool item.
*/ */
static inline T *AllocateRaw(uint &first) static inline T *AllocateRaw(uint &first)
{ {
@ -342,7 +345,8 @@ public:
OldMemoryPool<type> _##name##_pool( \ OldMemoryPool<type> _##name##_pool( \
#name, name##_POOL_MAX_BLOCKS, name##_POOL_BLOCK_SIZE_BITS, sizeof(type), \ #name, name##_POOL_MAX_BLOCKS, name##_POOL_BLOCK_SIZE_BITS, sizeof(type), \
PoolNewBlock<type, &_##name##_pool>, PoolCleanBlock<type, &_##name##_pool>); \ PoolNewBlock<type, &_##name##_pool>, PoolCleanBlock<type, &_##name##_pool>); \
template type *PoolItem<type, type##ID, &_##name##_pool>::AllocateSafeRaw(uint &first); template type *PoolItem<type, type##ID, &_##name##_pool>::AllocateSafeRaw(uint &first); \
template bool PoolItem<type, type##ID, &_##name##_pool>::CanAllocateItem(uint count);
#define STATIC_OLD_POOL(name, type, block_size_bits, max_blocks, new_block_proc, clean_block_proc) \ #define STATIC_OLD_POOL(name, type, block_size_bits, max_blocks, new_block_proc, clean_block_proc) \

View File

@ -11,7 +11,8 @@
* Allocate a pool item; possibly allocate a new block in the pool. * Allocate a pool item; possibly allocate a new block in the pool.
* @param first the first pool item to start searching * @param first the first pool item to start searching
* @pre first <= Tpool->GetSize() * @pre first <= Tpool->GetSize()
* @return the allocated pool item (or NULL when the pool is full). * @pre CanAllocateItem()
* @return the allocated pool item
*/ */
template<typename T, typename Tid, OldMemoryPool<T> *Tpool> T *PoolItem<T, Tid, Tpool>::AllocateSafeRaw(uint &first) template<typename T, typename Tid, OldMemoryPool<T> *Tpool> T *PoolItem<T, Tid, Tpool>::AllocateSafeRaw(uint &first)
{ {
@ -31,7 +32,8 @@ template<typename T, typename Tid, OldMemoryPool<T> *Tpool> T *PoolItem<T, Tid,
/* Check if we can add a block to the pool */ /* Check if we can add a block to the pool */
if (Tpool->AddBlockToPool()) return AllocateRaw(first); if (Tpool->AddBlockToPool()) return AllocateRaw(first);
return NULL; /* One should *ALWAYS* be sure to have enough space before making vehicles! */
NOT_REACHED();
} }
/** /**