Skip to content

Commit 3b7b400

Browse files
authored
Merge pull request #379 from Dekken/gcc8
GCC8 Werror changes
2 parents dcfe2d9 + 15e95af commit 3b7b400

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

lib/include/tick/array/abstractarray1d2d.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ ENABLE_WARNING(delete-non-virtual-dtor, delete-non-virtual-dtor, 42)
4949
#define INDICE_TYPE std::uint32_t
5050
#endif
5151

52+
namespace tick {
53+
template <typename T, typename K>
54+
class Allocator {
55+
public:
56+
template <typename Y = T, typename Z = K>
57+
static typename std::enable_if<std::is_base_of<std::atomic<Z>, Y>::value>::type memcopy(
58+
T *to, const T *from, size_t size) {
59+
for (size_t i = 0; i < size; i++) to[i].store(from[i]);
60+
}
61+
template <typename Y = T, typename Z = K>
62+
static typename std::enable_if<!std::is_base_of<std::atomic<Z>, Y>::value>::type memcopy(
63+
T *to, T *from, size_t size) {
64+
::memcpy(to, from, sizeof(T) * size);
65+
}
66+
};
67+
} // namespace tick
68+
5269
template <typename T>
5370
struct InnerType {};
5471

lib/include/tick/array/abstractarray1d2d/assignment.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ AbstractArray1d2d<T, MAJ>& AbstractArray1d2d<T, MAJ>::operator=(const AbstractAr
2020
_size_sparse = other._size_sparse;
2121
if (other.is_dense()) {
2222
TICK_PYTHON_MALLOC(_data, T, _size);
23-
memcpy(_data, other._data, sizeof(T) * _size);
23+
tick::Allocator<T, typename AbstractArray1d2d<T, MAJ>::K>
24+
::memcopy(_data, other._data, _size);
2425
_indices = nullptr;
2526
} else {
2627
if (_size_sparse > 0) {
2728
TICK_PYTHON_MALLOC(_data, T, _size_sparse);
28-
memcpy(_data, other._data, sizeof(T) * _size_sparse);
29+
tick::Allocator<T, typename AbstractArray1d2d<T, MAJ>::K>
30+
::memcopy(_data, other._data, _size_sparse);
2931
TICK_PYTHON_MALLOC(_indices, INDICE_TYPE, _size_sparse);
3032
memcpy(_indices, other._indices, sizeof(INDICE_TYPE) * _size_sparse);
3133
}

lib/include/tick/array/abstractarray1d2d/constructor.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ AbstractArray1d2d<T, MAJ>::AbstractArray1d2d(const AbstractArray1d2d<T, MAJ> &ot
4848
_data = nullptr;
4949
if (other.is_dense()) {
5050
TICK_PYTHON_MALLOC(_data, T, _size);
51-
memcpy(_data, other._data, sizeof(T) * _size);
51+
tick::Allocator<T, typename AbstractArray1d2d<T, MAJ>::K>
52+
::memcopy(_data, other._data, _size);
5253
_indices = nullptr;
5354
} else {
5455
TICK_PYTHON_MALLOC(_data, T, _size_sparse);
55-
memcpy(_data, other._data, sizeof(T) * _size_sparse);
56+
tick::Allocator<T, typename AbstractArray1d2d<T, MAJ>::K>
57+
::memcopy(_data, other._data, _size_sparse);
5658
TICK_PYTHON_MALLOC(_indices, INDICE_TYPE, _size_sparse);
5759
memcpy(_indices, other._indices, sizeof(INDICE_TYPE) * _size_sparse);
5860
}
@@ -80,6 +82,4 @@ AbstractArray1d2d<T, MAJ>::AbstractArray1d2d(AbstractArray1d2d<T, MAJ> &&other)
8082
other._size = 0;
8183
}
8284

83-
84-
8585
#endif // LIB_INCLUDE_TICK_ARRAY_ABSTRACTARRAY1D2D_CONSTRUCTOR_H_

0 commit comments

Comments
 (0)