This patch makes -fsized-delete define a macro __GXX_DELETE_WITH_SIZE__. If this macro is defined, the deallocate ...
13 years, 1 month ago
(2012-03-13 01:03:49 UTC)
#1
This patch makes -fsized-delete define a macro __GXX_DELETE_WITH_SIZE__. If
this macro is defined, the deallocate function in new_allocator.h invokes
the two parameter delete operator with the size of the object. Tested by
bootstrapping the compiler and ensuring no tests are broken. Also verified
that compiling a C++ program that uses std::vector with -fsized-delete invokes
the two parameter version of operator delete.
OK for google/main and google/4_6 branches?
c-family/ChangeLog.google-main:
2012-03-12 Easwaran Raman <eraman@google.com>
* c-cppbuiltin.c (c_cpp_builtins): Define __GXX_DELETE_WITH_SIZE__ for
C++ files compiled with -fsized-delete.
libstdc++-v3/ChangeLog.google-main:
2012-03-12 Easwaran Raman <eraman@google.com>
* include/ext/new_allocator.h (deallocate): Call delete with size if
__GXX_DELETE_WITH_SIZE__ is defined.
diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index ccf57fd..3c9a96b 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -970,6 +970,8 @@ c_cpp_builtins (cpp_reader *pfile)
format. */
if (ENABLE_DECIMAL_FLOAT && ENABLE_DECIMAL_BID_FORMAT)
cpp_define (pfile, "__DECIMAL_BID_FORMAT__");
+ if (c_dialect_cxx () && flag_sized_delete)
+ cpp_define (pfile, "__GXX_DELETE_WITH_SIZE__");
}
/* Pass an object-like macro. If it doesn't lie in the user's
diff --git a/libstdc++-v3/include/ext/new_allocator.h
b/libstdc++-v3/include/ext/new_allocator.h
index 0c82bd0..c972c1e 100644
--- a/libstdc++-v3/include/ext/new_allocator.h
+++ b/libstdc++-v3/include/ext/new_allocator.h
@@ -94,10 +94,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
}
+#ifdef __GXX_DELETE_WITH_SIZE__
+ // __p is not permitted to be a null pointer.
+ void
+ deallocate(pointer __p, size_type __t)
+ { ::operator delete(__p, __t * sizeof(_Tp)); }
+#else
// __p is not permitted to be a null pointer.
void
deallocate(pointer __p, size_type)
{ ::operator delete(__p); }
+#endif
size_type
max_size() const _GLIBCXX_USE_NOEXCEPT
--
This patch is available for review at http://codereview.appspot.com/5794070
On Mon, Mar 12, 2012 at 8:03 PM, Easwaran Raman <eraman@google.com> wrote: > > OK ...
13 years, 1 month ago
(2012-03-13 01:14:50 UTC)
#2
On Mon, Mar 12, 2012 at 8:03 PM, Easwaran Raman <eraman@google.com> wrote:
>
> OK for google/main and google/4_6 branches?
You will need to check this into google/gcc-4_7 as well.
Ollie
ok. As Ollie said, it needs to be in google/gcc-4_7 as well. David On Mon, ...
13 years, 1 month ago
(2012-03-13 04:59:05 UTC)
#3
ok. As Ollie said, it needs to be in google/gcc-4_7 as well.
David
On Mon, Mar 12, 2012 at 6:03 PM, Easwaran Raman <eraman@google.com> wrote:
> This patch makes -fsized-delete define a macro __GXX_DELETE_WITH_SIZE__. If
> this macro is defined, the deallocate function in new_allocator.h invokes
> the two parameter delete operator with the size of the object. Tested by
> bootstrapping the compiler and ensuring no tests are broken. Also verified
> that compiling a C++ program that uses std::vector with -fsized-delete invokes
> the two parameter version of operator delete.
>
> OK for google/main and google/4_6 branches?
>
> c-family/ChangeLog.google-main:
> 2012-03-12 Easwaran Raman <eraman@google.com>
>
> * c-cppbuiltin.c (c_cpp_builtins): Define __GXX_DELETE_WITH_SIZE__ for
> C++ files compiled with -fsized-delete.
>
> libstdc++-v3/ChangeLog.google-main:
> 2012-03-12 Easwaran Raman <eraman@google.com>
> * include/ext/new_allocator.h (deallocate): Call delete with size if
> __GXX_DELETE_WITH_SIZE__ is defined.
>
>
> diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
> index ccf57fd..3c9a96b 100644
> --- a/gcc/c-family/c-cppbuiltin.c
> +++ b/gcc/c-family/c-cppbuiltin.c
> @@ -970,6 +970,8 @@ c_cpp_builtins (cpp_reader *pfile)
> format. */
> if (ENABLE_DECIMAL_FLOAT && ENABLE_DECIMAL_BID_FORMAT)
> cpp_define (pfile, "__DECIMAL_BID_FORMAT__");
> + if (c_dialect_cxx () && flag_sized_delete)
> + cpp_define (pfile, "__GXX_DELETE_WITH_SIZE__");
> }
>
> /* Pass an object-like macro. If it doesn't lie in the user's
> diff --git a/libstdc++-v3/include/ext/new_allocator.h
b/libstdc++-v3/include/ext/new_allocator.h
> index 0c82bd0..c972c1e 100644
> --- a/libstdc++-v3/include/ext/new_allocator.h
> +++ b/libstdc++-v3/include/ext/new_allocator.h
> @@ -94,10 +94,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
> }
>
> +#ifdef __GXX_DELETE_WITH_SIZE__
> + // __p is not permitted to be a null pointer.
> + void
> + deallocate(pointer __p, size_type __t)
> + { ::operator delete(__p, __t * sizeof(_Tp)); }
> +#else
> // __p is not permitted to be a null pointer.
> void
> deallocate(pointer __p, size_type)
> { ::operator delete(__p); }
> +#endif
>
> size_type
> max_size() const _GLIBCXX_USE_NOEXCEPT
>
> --
> This patch is available for review at http://codereview.appspot.com/5794070
Issue 5794070: [google] Use delete with size parameter in STL deallocate
Created 13 years, 1 month ago by eraman
Modified 10 years, 4 months ago
Reviewers: davidxl, Ollie Wild
Base URL:
Comments: 0