diff mbox

Make the 2 versions of delete more similar

Message ID alpine.DEB.2.02.1310021043470.13176@stedding.saclay.inria.fr
State New
Headers show

Commit Message

Marc Glisse Oct. 2, 2013, 12:28 p.m. UTC
Hello,

I don't understand why those 2 files differ by more than 1 extra argument, 
so I am changing that.

Bootstrap and testsuite on x86_64.

2013-10-03  Marc Glisse  <marc.glisse@inria.fr>

 	* libsupc++/del_op.cc (operator delete): Don't test for 0 before free.
 	* libsupc++/del_opnt.cc (free): Only declare if freestanding.
 	(operator delete): Qualify free with std::.

Comments

Christopher Jefferson Oct. 2, 2013, 12:42 p.m. UTC | #1
On 2 October 2013 13:28, Marc Glisse <marc.glisse@inria.fr> wrote:
> Hello,
>
> I don't understand why those 2 files differ by more than 1 extra argument,
> so I am changing that.
>
> Bootstrap and testsuite on x86_64.
>
> 2013-10-03  Marc Glisse  <marc.glisse@inria.fr>
>
>         * libsupc++/del_op.cc (operator delete): Don't test for 0 before
> free.

Just checking, for the nervous:

Is the plan that this change will not effect any code behaviour (as
correct implementations of free are happy to take a NULL pointer, and
not do anything)?

Chris


>  _GLIBCXX_WEAK_DEFINITION void
>  operator delete(void* ptr) _GLIBCXX_USE_NOEXCEPT
>  {
> -  if (ptr)
> -    std::free(ptr);
> +  std::free(ptr);
>  }
Marc Glisse Oct. 2, 2013, 12:59 p.m. UTC | #2
On Wed, 2 Oct 2013, Christopher Jefferson wrote:

> On 2 October 2013 13:28, Marc Glisse <marc.glisse@inria.fr> wrote:
>> Hello,
>>
>> I don't understand why those 2 files differ by more than 1 extra argument,
>> so I am changing that.
>>
>> Bootstrap and testsuite on x86_64.
>>
>> 2013-10-03  Marc Glisse  <marc.glisse@inria.fr>
>>
>>         * libsupc++/del_op.cc (operator delete): Don't test for 0 before
>> free.
>
> Just checking, for the nervous:
>
> Is the plan that this change will not effect any code behaviour (as
> correct implementations of free are happy to take a NULL pointer, and
> not do anything)?

Yes. As far as I can tell from the logs, there was a massive change from 
if(p)free(p) to just free(p) that missed this file, while the patch on how 
to declare free missed the other.
Jonathan Wakely Oct. 2, 2013, 1:23 p.m. UTC | #3
On 2 October 2013 13:28, Marc Glisse wrote:
> Hello,
>
> I don't understand why those 2 files differ by more than 1 extra argument,
> so I am changing that.
>
> Bootstrap and testsuite on x86_64.
>
> 2013-10-03  Marc Glisse  <marc.glisse@inria.fr>
>
>         * libsupc++/del_op.cc (operator delete): Don't test for 0 before
> free.
>         * libsupc++/del_opnt.cc (free): Only declare if freestanding.
>         (operator delete): Qualify free with std::.

Looks good to me, thanks.
diff mbox

Patch

Index: libsupc++/del_op.cc
===================================================================
--- libsupc++/del_op.cc	(revision 203101)
+++ libsupc++/del_op.cc	(working copy)
@@ -36,13 +36,12 @@  _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
 #else
 # include <cstdlib>
 #endif
 
 #include "new"
 
 _GLIBCXX_WEAK_DEFINITION void
 operator delete(void* ptr) _GLIBCXX_USE_NOEXCEPT
 {
-  if (ptr)
-    std::free(ptr);
+  std::free(ptr);
 }
Index: libsupc++/del_opnt.cc
===================================================================
--- libsupc++/del_opnt.cc	(revision 203101)
+++ libsupc++/del_opnt.cc	(working copy)
@@ -17,19 +17,31 @@ 
 // Under Section 7 of GPL version 3, you are granted additional
 // permissions described in the GCC Runtime Library Exception, version
 // 3.1, as published by the Free Software Foundation.
 
 // You should have received a copy of the GNU General Public License and
 // a copy of the GCC Runtime Library Exception along with this program;
 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 // <http://www.gnu.org/licenses/>.
 
 #include <bits/c++config.h>
-#include "new"
 
-extern "C" void free (void *);
+#if !_GLIBCXX_HOSTED
+// A freestanding C runtime may not provide "free" -- but there is no
+// other reasonable way to implement "operator delete".
+namespace std
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+  extern "C" void free(void*);
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace
+#else
+# include <cstdlib>
+#endif
+
+#include "new"
 
 _GLIBCXX_WEAK_DEFINITION void
 operator delete (void *ptr, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
 {
-  free (ptr);
+  std::free(ptr);
 }