Prevent internal aligned_alloc clashing with libc version
If configure fails to detect aligned_alloc we will try to define our own in new_opa.cc but that could clash with the libcversion in <stdlib.h>. Use a namespace to keep them distinct. * libsupc++/new_opa.cc (aligned_alloc): Declare inside namespace to avoid clashing with an ::aligned_alloc function that was not detected by configure. From-SVN: r263409
This commit is contained in:
parent
8e09a12f01
commit
a801991954
@ -1,5 +1,9 @@
|
|||||||
2018-08-08 Jonathan Wakely <jwakely@redhat.com>
|
2018-08-08 Jonathan Wakely <jwakely@redhat.com>
|
||||||
|
|
||||||
|
* libsupc++/new_opa.cc (aligned_alloc): Declare inside namespace to
|
||||||
|
avoid clashing with an ::aligned_alloc function that was not detected
|
||||||
|
by configure.
|
||||||
|
|
||||||
* doc/xml/manual/using.xml: Fix markup for empty table entry.
|
* doc/xml/manual/using.xml: Fix markup for empty table entry.
|
||||||
* doc/html/*: Regenerate.
|
* doc/html/*: Regenerate.
|
||||||
|
|
||||||
|
@ -25,15 +25,30 @@
|
|||||||
|
|
||||||
#include <bits/c++config.h>
|
#include <bits/c++config.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <bits/exception_defines.h>
|
#include <bits/exception_defines.h>
|
||||||
#include "new"
|
#include "new"
|
||||||
|
|
||||||
|
#if !_GLIBCXX_HAVE_ALIGNED_ALLOC && !_GLIBCXX_HAVE__ALIGNED_MALLOC \
|
||||||
|
&& !_GLIBCXX_HAVE_POSIX_MEMALIGN && _GLIBCXX_HAVE_MEMALIGN
|
||||||
|
# if _GLIBCXX_HOSTED && __has_include(<malloc.h>)
|
||||||
|
// Some C libraries declare memalign in <malloc.h>
|
||||||
|
# include <malloc.h>
|
||||||
|
# else
|
||||||
|
extern "C" void *memalign(std::size_t boundary, std::size_t size);
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
using std::new_handler;
|
using std::new_handler;
|
||||||
using std::bad_alloc;
|
using std::bad_alloc;
|
||||||
|
|
||||||
#if !_GLIBCXX_HAVE_ALIGNED_ALLOC
|
namespace __gnu_cxx {
|
||||||
#if _GLIBCXX_HAVE__ALIGNED_MALLOC
|
#if _GLIBCXX_HAVE_ALIGNED_ALLOC
|
||||||
#define aligned_alloc(al,sz) _aligned_malloc(sz,al)
|
using ::aligned_alloc;
|
||||||
|
#elif _GLIBCXX_HAVE__ALIGNED_MALLOC
|
||||||
|
static inline void*
|
||||||
|
aligned_alloc (std::size_t al, std::size_t sz)
|
||||||
|
{ return _aligned_malloc(sz, al); }
|
||||||
#elif _GLIBCXX_HAVE_POSIX_MEMALIGN
|
#elif _GLIBCXX_HAVE_POSIX_MEMALIGN
|
||||||
static inline void*
|
static inline void*
|
||||||
aligned_alloc (std::size_t al, std::size_t sz)
|
aligned_alloc (std::size_t al, std::size_t sz)
|
||||||
@ -49,11 +64,6 @@ aligned_alloc (std::size_t al, std::size_t sz)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
#elif _GLIBCXX_HAVE_MEMALIGN
|
#elif _GLIBCXX_HAVE_MEMALIGN
|
||||||
#if _GLIBCXX_HOSTED
|
|
||||||
#include <malloc.h>
|
|
||||||
#else
|
|
||||||
extern "C" void *memalign(std::size_t boundary, std::size_t size);
|
|
||||||
#endif
|
|
||||||
static inline void*
|
static inline void*
|
||||||
aligned_alloc (std::size_t al, std::size_t sz)
|
aligned_alloc (std::size_t al, std::size_t sz)
|
||||||
{
|
{
|
||||||
@ -66,7 +76,6 @@ aligned_alloc (std::size_t al, std::size_t sz)
|
|||||||
return memalign (al, sz);
|
return memalign (al, sz);
|
||||||
}
|
}
|
||||||
#else // !HAVE__ALIGNED_MALLOC && !HAVE_POSIX_MEMALIGN && !HAVE_MEMALIGN
|
#else // !HAVE__ALIGNED_MALLOC && !HAVE_POSIX_MEMALIGN && !HAVE_MEMALIGN
|
||||||
#include <stdint.h>
|
|
||||||
// The C library doesn't provide any aligned allocation functions, define one.
|
// The C library doesn't provide any aligned allocation functions, define one.
|
||||||
// This is a modified version of code from gcc/config/i386/gmm_malloc.h
|
// This is a modified version of code from gcc/config/i386/gmm_malloc.h
|
||||||
static inline void*
|
static inline void*
|
||||||
@ -87,7 +96,7 @@ aligned_alloc (std::size_t al, std::size_t sz)
|
|||||||
return aligned_ptr;
|
return aligned_ptr;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
} // namespace __gnu_cxx
|
||||||
|
|
||||||
_GLIBCXX_WEAK_DEFINITION void *
|
_GLIBCXX_WEAK_DEFINITION void *
|
||||||
operator new (std::size_t sz, std::align_val_t al)
|
operator new (std::size_t sz, std::align_val_t al)
|
||||||
@ -116,6 +125,7 @@ operator new (std::size_t sz, std::align_val_t al)
|
|||||||
sz += align - rem;
|
sz += align - rem;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using __gnu_cxx::aligned_alloc;
|
||||||
while (__builtin_expect ((p = aligned_alloc (align, sz)) == 0, false))
|
while (__builtin_expect ((p = aligned_alloc (align, sz)) == 0, false))
|
||||||
{
|
{
|
||||||
new_handler handler = std::get_new_handler ();
|
new_handler handler = std::get_new_handler ();
|
||||||
|
Loading…
Reference in New Issue
Block a user