This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patches for the allocators (malloc/debug).


Hello,

I don't know what the intention was in making malloc_allocator not throw
anything but that makes it non-compliant, and also the user is not
warned about any unsuccessful allocations, So I have added that check.

Also, I have added another check in debug_allocator for checking whether
a NULL pointer was passed.


-- 
	-Dhruv Matani.
http://www.geocities.com/dhruvbird/

Proud to be a Vegetarian.
http://www.vegetarianstarterkit.com/
http://www.vegkids.com/vegkids/index.html

Attachment: ChangeLog
Description: Text document

diff -rNcp ./cvs_libstdc++-v3/.cvsignore ./modified_cvs_libstdc++/.cvsignore
*** ./cvs_libstdc++-v3/.cvsignore	2004-02-06 04:49:53.000000000 +0530
--- ./modified_cvs_libstdc++/.cvsignore	1970-01-01 05:30:00.000000000 +0530
***************
*** 1 ****
- autom4te.cache
--- 0 ----
diff -rNcp ./cvs_libstdc++-v3/include/ext/debug_allocator.h ./modified_cvs_libstdc++/include/ext/debug_allocator.h
*** ./cvs_libstdc++-v3/include/ext/debug_allocator.h	2004-02-04 23:07:10.000000000 +0530
--- ./modified_cvs_libstdc++/include/ext/debug_allocator.h	2004-03-05 16:11:00.000000000 +0530
*************** namespace __gnu_cxx
*** 108,114 ****
        void
        deallocate(pointer __p, size_type __n)
        {
!         pointer __real_p = __p - _M_extra;
          if (*reinterpret_cast<size_type*>(__real_p) != __n)
            abort();
          _M_allocator.deallocate(__real_p, __n + _M_extra);
--- 108,116 ----
        void
        deallocate(pointer __p, size_type __n)
        {
! 	if (!__p)
! 	  abort();
! 	pointer __real_p = __p - _M_extra;
          if (*reinterpret_cast<size_type*>(__real_p) != __n)
            abort();
          _M_allocator.deallocate(__real_p, __n + _M_extra);
diff -rNcp ./cvs_libstdc++-v3/include/ext/malloc_allocator.h ./modified_cvs_libstdc++/include/ext/malloc_allocator.h
*** ./cvs_libstdc++-v3/include/ext/malloc_allocator.h	2004-02-23 21:11:43.000000000 +0530
--- ./modified_cvs_libstdc++/include/ext/malloc_allocator.h	2004-03-05 16:07:29.000000000 +0530
*************** namespace __gnu_cxx
*** 78,84 ****
        // about what the return value is when __n == 0.
        pointer
        allocate(size_type __n, const void* = 0)
!       { return static_cast<_Tp*>(malloc(__n * sizeof(_Tp))); }
  
        // __p is not permitted to be a null pointer.
        void
--- 78,89 ----
        // about what the return value is when __n == 0.
        pointer
        allocate(size_type __n, const void* = 0)
!       {
! 	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.
        void
*************** namespace __gnu_cxx
*** 93,99 ****
        // 402. wrong new expression in [some_] allocator::construct
        void 
        construct(pointer __p, const _Tp& __val) 
!       { *__p = __val; }
  
        void 
        destroy(pointer __p) { __p->~_Tp(); }
--- 98,104 ----
        // 402. wrong new expression in [some_] allocator::construct
        void 
        construct(pointer __p, const _Tp& __val) 
!       { ::new(__p) value_type(__val); }
  
        void 
        destroy(pointer __p) { __p->~_Tp(); }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]