Skip to content

Commit f44ee01

Browse files
committed
Fix compilation warning: include header file for malloc
1 parent ee9ab2f commit f44ee01

File tree

1 file changed

+30
-29
lines changed
  • src/Trinity.C/include/Trinity

1 file changed

+30
-29
lines changed

src/Trinity.C/include/Trinity/Array.h

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
44
//
55
#pragma once
6+
#include <cstdlib>
67
#include <cstring>
78
#include <vector>
89
#include <functional>
@@ -20,7 +21,7 @@ namespace Trinity
2021

2122
Array(size_t count)
2223
{
23-
allocate(count);
24+
allocate(count);
2425
initialize();
2526
}
2627

@@ -49,9 +50,9 @@ namespace Trinity
4950
_copy_from(il.begin(), il.size());
5051
}
5152

52-
Array(_Myt&& arr)
53-
{
54-
_move_from(std::forward<_Myt>(arr));
53+
Array(_Myt&& arr)
54+
{
55+
_move_from(std::forward<_Myt>(arr));
5556
}
5657

5758
~Array()
@@ -60,36 +61,36 @@ namespace Trinity
6061
deallocate();
6162
}
6263

63-
Array& operator = (const _Myt & arr)
64+
Array& operator = (const _Myt & arr)
6465
{
6566
destroy();
66-
deallocate();
67-
_copy_from(arr._array, arr._count);
68-
return *this;
67+
deallocate();
68+
_copy_from(arr._array, arr._count);
69+
return *this;
6970
}
7071

71-
template <class _VecAlloc> Array& operator = (const std::vector<T, _VecAlloc> & vec)
72-
{
72+
template <class _VecAlloc> Array& operator = (const std::vector<T, _VecAlloc> & vec)
73+
{
7374
destroy();
7475
deallocate();
7576
_copy_from(vec.data(), vec.size());
7677
return *this;
7778
}
7879

79-
Array& operator = (std::initializer_list<T> il)
80-
{
80+
Array& operator = (std::initializer_list<T> il)
81+
{
8182
destroy();
8283
deallocate();
83-
_copy_from(il.begin(), il.size());
84-
return *this;
84+
_copy_from(il.begin(), il.size());
85+
return *this;
8586
}
8687

87-
Array& operator = (_Myt && arr)
88+
Array& operator = (_Myt && arr)
8889
{
8990
destroy();
90-
deallocate();
91+
deallocate();
9192
_move_from(std::forward<_Myt>(arr));
92-
return *this;
93+
return *this;
9394
}
9495

9596
std::vector<T> ToList() const { std::vector<T> ret; ret.insert(ret.begin(), this->begin(), this->end()); return ret; }
@@ -111,17 +112,17 @@ namespace Trinity
111112
// As our primary usage is interop, it doesn't make sense
112113
// either to return std::unique_ptr.
113114
// Therefore the best thing to do is to malloc a new buffer, and move the elements
114-
// into the new buffer.
115-
T* detach_data()
116-
{
115+
// into the new buffer.
116+
T* detach_data()
117+
{
117118
auto len = _count * sizeof(T);
118119
auto ret = (T*)malloc(len);
119120

120121
std::move(_array, _array + _count, ret);
121122

122123
//! deallocate, not destroy
123124
deallocate();
124-
return ret;
125+
return ret;
125126
}
126127

127128
//since we're just simply arrays, we don't care much about the logic of iterator..
@@ -139,17 +140,17 @@ namespace Trinity
139140

140141
private:
141142

142-
inline void allocate(size_t count)
143-
{
144-
_array = _allocator.allocate(count);
143+
inline void allocate(size_t count)
144+
{
145+
_array = _allocator.allocate(count);
145146
_count = count;
146147
}
147148

148-
inline void deallocate()
149-
{
150-
_allocator.deallocate(_array, _count);
151-
_array = nullptr;
152-
_count = 0;
149+
inline void deallocate()
150+
{
151+
_allocator.deallocate(_array, _count);
152+
_array = nullptr;
153+
_count = 0;
153154
}
154155

155156
inline void initialize()

0 commit comments

Comments
 (0)