23
23
// POSSIBILITY OF SUCH DAMAGE.
24
24
25
25
// A MemWord (memory word) is a type which is defined as having the size of a
26
- // char * and behaving as the union of a number of other types. If they are
26
+ // void * and behaving as the union of a number of other types. If they are
27
27
// small enough, they are actually stored in the MemWord. If not, they are
28
28
// stored as a pointer to external memory.
29
29
33
33
// The MWUAccessor provides the getters/setters for the MWUnion.
34
34
35
35
// The MWTest is an helper class to deal with types which are bigger than a
36
- // char *
36
+ // void *
37
37
38
38
39
39
#ifndef MOZART_MEMWORD_H
@@ -67,8 +67,8 @@ struct MWUAccessor {
67
67
}
68
68
};
69
69
70
- // The bottom case of the MWUnion contains just a char * as it can be cast to
71
- // any other pointer without fear of aliasing problems .
70
+ // The bottom case of the MWUnion contains just a void * as it can be cast to
71
+ // and from any other pointer.
72
72
template <>
73
73
union MWUnion<> {
74
74
template <typename Q>
@@ -86,7 +86,7 @@ union MWUnion<> {
86
86
return MWUAccessor<MWUnion, Q, Q>::requiresExternalMemory ();
87
87
}
88
88
89
- char * it;
89
+ void * it;
90
90
};
91
91
92
92
// The easy case of accessing what we have in the first member of the union.
@@ -129,7 +129,7 @@ struct MWUAccessor<MWUnion<>, T, T>{
129
129
}
130
130
131
131
static void alloc (VM vm, MWUnion<>* u) {
132
- u->it = reinterpret_cast < char *>( new (vm) T) ;
132
+ u->it = new (vm) T;
133
133
}
134
134
135
135
static constexpr bool requiresExternalMemory () {
@@ -141,8 +141,8 @@ struct MWUAccessor<MWUnion<>, T, T>{
141
141
// big, we reduce it.
142
142
template <typename T, typename ... Args>
143
143
union MWUnion<T, Args...> {
144
- typedef typename std::conditional<sizeof (T) <= sizeof (char *),
145
- T, char *>::type Tred;
144
+ typedef typename std::conditional<sizeof (T) <= sizeof (void *),
145
+ T, void *>::type Tred;
146
146
147
147
typedef MWUnion<Args...> Next;
148
148
@@ -180,12 +180,13 @@ typedef internal::MWUnion<nativeint, bool, double, unit_t, atom_t,
180
180
181
181
// Sanity tests
182
182
183
- static_assert (sizeof (MemWord) == sizeof (char *),
183
+ static_assert (sizeof (MemWord) == sizeof (void *),
184
184
" MemWord has not the size of a word" );
185
185
186
186
static_assert (!MemWord::requiresExternalMemory<nativeint>(), " MemWord bug" );
187
187
static_assert (!MemWord::requiresExternalMemory<unit_t >(), " MemWord bug" );
188
188
static_assert (!MemWord::requiresExternalMemory<char *>(), " MemWord bug" );
189
+ static_assert (!MemWord::requiresExternalMemory<void *>(), " MemWord bug" );
189
190
static_assert (!MemWord::requiresExternalMemory<StableNode*>(), " MemWord bug" );
190
191
191
192
static_assert (MemWord::requiresExternalMemory<float >(), " MemWord bug" );
0 commit comments