Skip to content

Commit cd71f44

Browse files
committedJan 7, 2017
[libc++] Tolerate presence of __deallocate macro
Summary: On Windows the identifier `__deallocate` is defined as a macro by one of the Windows system headers. Previously libc++ worked around this by `#undef __deallocate` and generating a warning. However this causes the WIN32 version of `__threading_support` to always generate a warning on Windows. This is not OK. This patch renames all usages of `__deallocate` internally as to not conflict with the macro. Reviewers: mclow.lists, majnemer, rnk, rsmith, smeenai, compnerd Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D28426 llvm-svn: 291332
1 parent deaceef commit cd71f44

File tree

9 files changed

+21
-52
lines changed

9 files changed

+21
-52
lines changed
 

‎libcxx/include/__hash_table

+10-11
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <utility>
2121

2222
#include <__undef_min_max>
23-
#include <__undef___deallocate>
2423

2524
#include <__debug>
2625

@@ -1321,7 +1320,7 @@ private:
13211320
void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {}
13221321
#endif // _LIBCPP_CXX03_LANG
13231322

1324-
void __deallocate(__next_pointer __np) _NOEXCEPT;
1323+
void __deallocate_node(__next_pointer __np) _NOEXCEPT;
13251324
__next_pointer __detach() _NOEXCEPT;
13261325

13271326
template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
@@ -1454,7 +1453,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table()
14541453
"Predicate must be copy-constructible.");
14551454
static_assert((is_copy_constructible<hasher>::value),
14561455
"Hasher must be copy-constructible.");
1457-
__deallocate(__p1_.first().__next_);
1456+
__deallocate_node(__p1_.first().__next_);
14581457
#if _LIBCPP_DEBUG_LEVEL >= 2
14591458
__get_db()->__erase_c(this);
14601459
#endif
@@ -1492,7 +1491,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u)
14921491

14931492
template <class _Tp, class _Hash, class _Equal, class _Alloc>
14941493
void
1495-
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate(__next_pointer __np)
1494+
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate_node(__next_pointer __np)
14961495
_NOEXCEPT
14971496
{
14981497
__node_allocator& __na = __node_alloc();
@@ -1599,11 +1598,11 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
15991598
}
16001599
catch (...)
16011600
{
1602-
__deallocate(__cache);
1601+
__deallocate_node(__cache);
16031602
throw;
16041603
}
16051604
#endif // _LIBCPP_NO_EXCEPTIONS
1606-
__deallocate(__cache);
1605+
__deallocate_node(__cache);
16071606
}
16081607
const_iterator __i = __u.begin();
16091608
while (__u.size() != 0)
@@ -1661,11 +1660,11 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first
16611660
}
16621661
catch (...)
16631662
{
1664-
__deallocate(__cache);
1663+
__deallocate_node(__cache);
16651664
throw;
16661665
}
16671666
#endif // _LIBCPP_NO_EXCEPTIONS
1668-
__deallocate(__cache);
1667+
__deallocate_node(__cache);
16691668
}
16701669
for (; __first != __last; ++__first)
16711670
__insert_unique(*__first);
@@ -1701,11 +1700,11 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first,
17011700
}
17021701
catch (...)
17031702
{
1704-
__deallocate(__cache);
1703+
__deallocate_node(__cache);
17051704
throw;
17061705
}
17071706
#endif // _LIBCPP_NO_EXCEPTIONS
1708-
__deallocate(__cache);
1707+
__deallocate_node(__cache);
17091708
}
17101709
for (; __first != __last; ++__first)
17111710
__insert_multi(_NodeTypes::__get_value(*__first));
@@ -1765,7 +1764,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT
17651764
{
17661765
if (size() > 0)
17671766
{
1768-
__deallocate(__p1_.first().__next_);
1767+
__deallocate_node(__p1_.first().__next_);
17691768
__p1_.first().__next_ = nullptr;
17701769
size_type __bc = bucket_count();
17711770
for (size_type __i = 0; __i < __bc; ++__i)

‎libcxx/include/__sso_allocator

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include <type_traits>
1616
#include <new>
1717

18-
#include <__undef___deallocate>
19-
2018
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2119
#pragma GCC system_header
2220
#endif
@@ -64,7 +62,7 @@ public:
6462
if (__p == (pointer)&buf_)
6563
__allocated_ = false;
6664
else
67-
_VSTD::__deallocate(__p);
65+
_VSTD::__libcpp_deallocate(__p);
6866
}
6967
_LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);}
7068

‎libcxx/include/__undef___deallocate

-20
This file was deleted.

‎libcxx/include/experimental/dynarray

+5-8
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
#ifndef _LIBCPP_DYNARRAY
1212
#define _LIBCPP_DYNARRAY
1313

14-
#include <__config>
15-
#if _LIBCPP_STD_VER > 11
16-
1714
/*
1815
dynarray synopsis
1916
@@ -96,6 +93,8 @@ public:
9693
}} // std::experimental
9794
9895
*/
96+
#include <__config>
97+
#if _LIBCPP_STD_VER > 11
9998

10099
#include <__functional_base>
101100
#include <iterator>
@@ -104,8 +103,6 @@ public:
104103
#include <new>
105104
#include <algorithm>
106105

107-
#include <__undef___deallocate>
108-
109106
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
110107
#pragma GCC system_header
111108
#endif
@@ -143,9 +140,9 @@ private:
143140
return static_cast<value_type *> (_VSTD::__allocate (sizeof(value_type) * count));
144141
}
145142

146-
static inline _LIBCPP_INLINE_VISIBILITY void __deallocate ( value_type* __ptr ) noexcept
143+
static inline _LIBCPP_INLINE_VISIBILITY void __deallocate_value( value_type* __ptr ) noexcept
147144
{
148-
_VSTD::__deallocate (static_cast<void *> (__ptr));
145+
_VSTD::__libcpp_deallocate (static_cast<void *> (__ptr));
149146
}
150147

151148
public:
@@ -265,7 +262,7 @@ dynarray<_Tp>::~dynarray()
265262
value_type *__data = data () + __size_;
266263
for ( size_t i = 0; i < __size_; ++i )
267264
(--__data)->value_type::~value_type();
268-
__deallocate ( __base_ );
265+
__deallocate_value( __base_ );
269266
}
270267

271268
template <class _Tp>

‎libcxx/include/memory

+2-3
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,6 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
644644
#endif
645645

646646
#include <__undef_min_max>
647-
#include <__undef___deallocate>
648647

649648
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
650649
#pragma GCC system_header
@@ -1772,7 +1771,7 @@ public:
17721771
return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
17731772
}
17741773
_LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1775-
{_VSTD::__deallocate((void*)__p);}
1774+
{_VSTD::__libcpp_deallocate((void*)__p);}
17761775
_LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
17771776
{return size_type(~0) / sizeof(_Tp);}
17781777
#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
@@ -1868,7 +1867,7 @@ public:
18681867
return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
18691868
}
18701869
_LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1871-
{_VSTD::__deallocate((void*)__p);}
1870+
{_VSTD::__libcpp_deallocate((void*)__p);}
18721871
_LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
18731872
{return size_type(~0) / sizeof(_Tp);}
18741873
#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)

‎libcxx/include/module.modulemap

-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ module std [system] {
485485
module __tree { header "__tree" export * }
486486
module __tuple { header "__tuple" export * }
487487
module __undef_min_max { header "__undef_min_max" export * }
488-
module __undef___deallocate { header "__undef___deallocate" export * }
489488

490489
module experimental {
491490
requires cplusplus11

‎libcxx/include/new

+1-3
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ void operator delete[](void* ptr, void*) noexcept;
9292
#include <cstdlib>
9393
#endif
9494

95-
#include <__undef___deallocate>
96-
9795
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
9896
#pragma GCC system_header
9997
#endif
@@ -217,7 +215,7 @@ inline _LIBCPP_INLINE_VISIBILITY void *__allocate(size_t __size) {
217215
#endif
218216
}
219217

220-
inline _LIBCPP_INLINE_VISIBILITY void __deallocate(void *__ptr) {
218+
inline _LIBCPP_INLINE_VISIBILITY void __libcpp_deallocate(void *__ptr) {
221219
#ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
222220
::operator delete(__ptr);
223221
#else

‎libcxx/include/valarray

+1-2
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ template <class T> unspecified2 end(const valarray<T>& v);
348348
#include <new>
349349

350350
#include <__undef_min_max>
351-
#include <__undef___deallocate>
352351

353352
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
354353
#pragma GCC system_header
@@ -3697,7 +3696,7 @@ valarray<_Tp>::resize(size_t __n, value_type __x)
36973696
{
36983697
while (__end_ != __begin_)
36993698
(--__end_)->~value_type();
3700-
_VSTD::__deallocate(__begin_);
3699+
_VSTD::__libcpp_deallocate(__begin_);
37013700
__begin_ = __end_ = nullptr;
37023701
}
37033702
if (__n)

‎libcxx/src/experimental/memory_resource.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class _LIBCPP_TYPE_VIS __new_delete_memory_resource_imp
3434
{ return __allocate(__size); }
3535

3636
virtual void do_deallocate(void * __p, size_t, size_t)
37-
{ __deallocate(__p); }
37+
{ _VSTD::__libcpp_deallocate(__p); }
3838

3939
virtual bool do_is_equal(memory_resource const & __other) const _NOEXCEPT
4040
{ return &__other == this; }

0 commit comments

Comments
 (0)
Please sign in to comment.