Commit 58c95921 by Dhruv Matani Committed by Benjamin Kosnik

malloc_allocator.h: Fixed the construct function to call global placement new…

malloc_allocator.h: Fixed the construct function to call global placement new instead of assignment.


2004-03-24  Dhruv Matani  <dhruvbird@gmx.net>

	* ext/malloc_allocator.h: Fixed the construct function to call
	global placement new instead of assignment. Added a check after
	the return from malloc to check whether returned pointer is NULL,
	and if so, throw std::bad_alloc().
	* ext/debug_allocator.h: Added a check in the deallocate function
	to check whether the user has passed a NULL pointer or not.

From-SVN: r79934
parent 8367b9c1
2004-03-24 Dhruv Matani <dhruvbird@gmx.net>
* ext/malloc_allocator.h: Fixed the construct function to call
global placement new instead of assignment. Added a check after
the return from malloc to check whether returned pointer is NULL,
and if so, throw std::bad_alloc().
* ext/debug_allocator.h: Added a check in the deallocate function
to check whether the user has passed a NULL pointer or not.
2004-03-24 Benjamin Kosnik <bkoz@redhat.com> 2004-03-24 Benjamin Kosnik <bkoz@redhat.com>
* docs/html/20_util/allocator.html: Add bitmap_allocator links. * docs/html/20_util/allocator.html: Add bitmap_allocator links.
......
...@@ -108,7 +108,9 @@ namespace __gnu_cxx ...@@ -108,7 +108,9 @@ namespace __gnu_cxx
void void
deallocate(pointer __p, size_type __n) deallocate(pointer __p, size_type __n)
{ {
pointer __real_p = __p - _M_extra; if (!__p)
abort();
pointer __real_p = __p - _M_extra;
if (*reinterpret_cast<size_type*>(__real_p) != __n) if (*reinterpret_cast<size_type*>(__real_p) != __n)
abort(); abort();
_M_allocator.deallocate(__real_p, __n + _M_extra); _M_allocator.deallocate(__real_p, __n + _M_extra);
......
...@@ -78,7 +78,12 @@ namespace __gnu_cxx ...@@ -78,7 +78,12 @@ namespace __gnu_cxx
// about what the return value is when __n == 0. // about what the return value is when __n == 0.
pointer pointer
allocate(size_type __n, const void* = 0) allocate(size_type __n, const void* = 0)
{ return static_cast<_Tp*>(malloc(__n * sizeof(_Tp))); } {
pointer __ret = static_cast<_Tp*>(malloc(__n * sizeof(_Tp)));
if (!__ret)
throw std::bad_alloc();
return __ret;
}
// __p is not permitted to be a null pointer. // __p is not permitted to be a null pointer.
void void
...@@ -93,7 +98,7 @@ namespace __gnu_cxx ...@@ -93,7 +98,7 @@ namespace __gnu_cxx
// 402. wrong new expression in [some_] allocator::construct // 402. wrong new expression in [some_] allocator::construct
void void
construct(pointer __p, const _Tp& __val) construct(pointer __p, const _Tp& __val)
{ *__p = __val; } { ::new(__p) value_type(__val); }
void void
destroy(pointer __p) { __p->~_Tp(); } destroy(pointer __p) { __p->~_Tp(); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment