Skip to content

Commit fc8307b

Browse files
committed
Add some explicit type casts to the hxcpp header files.
1 parent bfcfb9b commit fc8307b

File tree

11 files changed

+39
-38
lines changed

11 files changed

+39
-38
lines changed

include/Dynamic.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
168168
bool operator op (const ::String &inRHS) const { return mPtr && ((::String)(*this) op inRHS); } \
169169
bool operator op (double inRHS) const { return IsNumeric() && ((double)(*this) op inRHS); } \
170170
bool operator op (::cpp::Int64 inRHS) const { return IsNumeric() && ((::cpp::Int64)(*this) op inRHS); } \
171-
bool operator op (::cpp::UInt64 inRHS) const { return IsNumeric() && ((::cpp::Int64)(*this) op inRHS); } \
171+
bool operator op (::cpp::UInt64 inRHS) const { return IsNumeric() && ((::cpp::UInt64)(*this) op inRHS); } \
172172
bool operator op (float inRHS) const { return IsNumeric() && ((double)(*this) op inRHS); } \
173173
bool operator op (int inRHS) const { return IsNumeric() && ((double)(*this) op (double)inRHS); } \
174174
bool operator op (unsigned int inRHS) const { return IsNumeric() && ((double)(*this) op (double)inRHS); } \
@@ -183,7 +183,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
183183
bool operator != (const String &inRHS) const { return !mPtr || ((String)(*this) != inRHS); }
184184
bool operator != (double inRHS) const { return !IsNumeric() || ((double)(*this) != inRHS); }
185185
bool operator != (cpp::Int64 inRHS) const { return !IsNumeric() || ((cpp::Int64)(*this) != inRHS); }
186-
bool operator != (cpp::UInt64 inRHS) const { return !IsNumeric() || ((cpp::Int64)(*this) != inRHS); }
186+
bool operator != (cpp::UInt64 inRHS) const { return !IsNumeric() || ((cpp::UInt64)(*this) != inRHS); }
187187
bool operator != (float inRHS) const { return !IsNumeric() || ((double)(*this) != inRHS); }
188188
bool operator != (int inRHS) const { return !IsNumeric() || ((double)(*this) != (double)inRHS); }
189189
bool operator != (unsigned int inRHS) const { return !IsNumeric() || ((double)(*this) != (double)inRHS); }
@@ -381,9 +381,9 @@ inline int Dynamic::Cast<int>() const { return mPtr ? mPtr->__ToInt() : 0; }
381381
template<>
382382
inline bool Dynamic::Cast<bool>() const { return mPtr ? mPtr->__ToInt() : 0; }
383383
template<>
384-
inline double Dynamic::Cast<double>() const { return mPtr ? mPtr->__ToDouble() : 0; }
384+
inline double Dynamic::Cast<double>() const { return mPtr ? mPtr->__ToDouble() : 0.0; }
385385
template<>
386-
inline float Dynamic::Cast<float>() const { return mPtr ? mPtr->__ToDouble() : 0; }
386+
inline float Dynamic::Cast<float>() const { return (float)(mPtr ? mPtr->__ToDouble() : 0.0f); }
387387
template<>
388388
inline String Dynamic::Cast<String>() const { return mPtr ? mPtr->toString() : String(null()); }
389389

@@ -466,8 +466,8 @@ COMPARE_DYNAMIC_OP( > )
466466

467467

468468
#define ARITH_DYNAMIC( op ) \
469-
inline double operator op (const ::cpp::Int64 &inLHS,const ::Dynamic &inRHS) { return inLHS op (::cpp::Int64)inRHS;} \
470-
inline double operator op (const ::cpp::UInt64 &inLHS,const ::Dynamic &inRHS) { return inLHS op (::cpp::UInt64)inRHS;} \
469+
inline double operator op (const ::cpp::Int64 &inLHS,const ::Dynamic &inRHS) { return (double)( inLHS op (::cpp::Int64)inRHS );} \
470+
inline double operator op (const ::cpp::UInt64 &inLHS,const ::Dynamic &inRHS) { return (double)( inLHS op (::cpp::UInt64)inRHS );} \
471471
inline double operator op (const double &inLHS,const ::Dynamic &inRHS) { return inLHS op (double)inRHS;} \
472472
inline double operator op (const float &inLHS,const ::Dynamic &inRHS) { return inLHS op (double)inRHS;} \
473473
inline double operator op (const int &inLHS,const ::Dynamic &inRHS) { return inLHS op (double)inRHS; } \

include/cpp/Variant.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace cpp
102102
inline operator double() const { return asDouble(); }
103103
inline operator int() const { return asInt(); }
104104
inline operator bool() const { return asInt(); }
105-
inline operator float () const { return asDouble(); }
105+
inline operator float () const { return (float)asDouble(); }
106106
inline operator unsigned int () const { return asInt(); }
107107
inline operator short () const { return asInt(); }
108108
inline operator unsigned short () const { return asInt(); }
@@ -345,7 +345,7 @@ namespace cpp
345345

346346
switch(type)
347347
{
348-
case typeDouble: return valDouble;
348+
case typeDouble: return (int)valDouble;
349349
case typeInt64: return (int)valInt64;
350350
case typeBool: return valBool;
351351
case typeObject: return valObject ? valObject->__ToInt() : 0;
@@ -363,7 +363,7 @@ namespace cpp
363363

364364
switch(type)
365365
{
366-
case typeDouble: return valDouble;
366+
case typeDouble: return (cpp::Int64)valDouble;
367367
case typeInt: return valInt;
368368
case typeBool: return valBool;
369369
case typeObject: return valObject ? valObject->__ToInt64() : 0;
@@ -381,7 +381,7 @@ namespace cpp
381381
else if (type==typeBool)
382382
return valBool ? 1.0 : 0.0;
383383
else if (type==typeInt64)
384-
return valInt64;
384+
return (double)valInt64;
385385
else if (type==typeObject)
386386
return valObject ? valObject->__ToDouble() : 0.0;
387387
return 0.0;

include/cpp/marshal/Marshal.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,9 @@ inline void cpp::marshal::Marshal::writeLittleEndianUInt32(const View<uint8_t>&
414414
inline void cpp::marshal::Marshal::writeLittleEndianUInt64(const View<uint8_t>& view, const uint64_t& value)
415415
{
416416
#ifdef HXCPP_BIG_ENDIAN
417-
writeUInt16(view, reverse(value));
417+
writeUInt64(view, reverse(value));
418418
#else
419-
writeUInt16(view, value);
419+
writeUInt64(view, value);
420420
#endif
421421
}
422422

@@ -496,9 +496,9 @@ inline void cpp::marshal::Marshal::writeBigEndianUInt32(const View<uint8_t>& vie
496496
inline void cpp::marshal::Marshal::writeBigEndianUInt64(const View<uint8_t>& view, const uint64_t& value)
497497
{
498498
#ifndef HXCPP_BIG_ENDIAN
499-
writeUInt16(view, reverse(value));
499+
writeUInt64(view, reverse(value));
500500
#else
501-
writeUInt16(view, value);
501+
writeUInt64(view, value);
502502
#endif
503503
}
504504

include/hx/GC.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ namespace hx
329329

330330

331331

332-
class StackContext;
332+
struct StackContext;
333333

334334
EXTERN_FAST_TLS_DATA(StackContext, tlsStackContext);
335335

@@ -360,7 +360,7 @@ class ImmixAllocator
360360

361361

362362

363-
// These allocate the function using the garbage-colleced malloc
363+
// These allocate the function using the garbage-collected malloc
364364
inline static void *alloc(ImmixAllocator *alloc, size_t inSize, bool inContainer, const char *inName )
365365
{
366366
#ifdef HXCPP_GC_NURSERY
@@ -406,7 +406,7 @@ class ImmixAllocator
406406
// Ensure odd alignment in 8 bytes
407407
start += 4 - (start & 4);
408408
#endif
409-
int end = start + sizeof(int) + inSize;
409+
int end = start + (int)(sizeof(int) + inSize);
410410

411411
if ( end <= alloc->spaceEnd )
412412
{
@@ -420,11 +420,11 @@ class ImmixAllocator
420420

421421
if (inContainer)
422422
*buffer++ = (( (end+(IMMIX_LINE_LEN-1))>>IMMIX_LINE_BITS) -startRow) |
423-
(inSize<<IMMIX_ALLOC_SIZE_SHIFT) |
423+
((int)inSize<<IMMIX_ALLOC_SIZE_SHIFT) |
424424
hx::gMarkIDWithContainer;
425425
else
426426
*buffer++ = (( (end+(IMMIX_LINE_LEN-1))>>IMMIX_LINE_BITS) -startRow) |
427-
(inSize<<IMMIX_ALLOC_SIZE_SHIFT) |
427+
((int)inSize<<IMMIX_ALLOC_SIZE_SHIFT) |
428428
hx::gMarkID;
429429

430430
#if defined(HXCPP_GC_CHECK_POINTER) && defined(HXCPP_GC_DEBUG_ALWAYS_MOVE)
@@ -439,7 +439,7 @@ class ImmixAllocator
439439
}
440440

441441
// Fall back to external method
442-
void *result = alloc->CallAlloc(inSize, inContainer ? IMMIX_ALLOC_IS_CONTAINER : 0);
442+
void *result = alloc->CallAlloc((int)inSize, inContainer ? IMMIX_ALLOC_IS_CONTAINER : 0);
443443

444444
#ifdef HXCPP_TELEMETRY
445445
__hxt_gc_new((hx::StackContext *)alloc,result, inSize, inName);

include/hx/LessThanEq.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ struct CompareTraits<double>
103103
{
104104
enum { type = (int)CompareAsDouble };
105105

106-
inline static int toInt(double inValue) { return inValue; }
106+
inline static int toInt(double inValue) { return (int)inValue; }
107107
inline static double toDouble(double inValue) { return inValue; }
108-
inline static cpp::Int64 toInt64(double inValue) { return inValue; }
108+
inline static cpp::Int64 toInt64(double inValue) { return (cpp::Int64)inValue; }
109109
inline static String toString(double inValue) { return String(); }
110110
inline static hx::Object *toObject(double inValue) { return 0; }
111111

@@ -122,7 +122,7 @@ struct CompareTraits<cpp::Int64>
122122
enum { type = (int)CompareAsInt64 };
123123

124124
inline static int toInt(cpp::Int64 inValue) { return (int)inValue; }
125-
inline static double toDouble(cpp::Int64 inValue) { return inValue; }
125+
inline static double toDouble(cpp::Int64 inValue) { return (double)inValue; }
126126
inline static cpp::Int64 toInt64(cpp::Int64 inValue) { return inValue; }
127127
inline static String toString(cpp::Int64 inValue) { return String(); }
128128
inline static hx::Object *toObject(cpp::Int64 inValue) { return 0; }
@@ -137,7 +137,7 @@ struct CompareTraits<cpp::UInt64>
137137
enum { type = (int)CompareAsInt64 };
138138

139139
inline static int toInt(cpp::UInt64 inValue) { return (int)inValue; }
140-
inline static double toDouble(cpp::UInt64 inValue) { return inValue; }
140+
inline static double toDouble(cpp::UInt64 inValue) { return (double)inValue; }
141141
// Return value is unsigned ...
142142
inline static cpp::UInt64 toInt64(cpp::UInt64 inValue) { return inValue; }
143143
inline static String toString(cpp::UInt64 inValue) { return String(); }

include/hx/Operators.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ template<> inline double ToDouble(double inValue) { return inValue; }
8282
template<> inline double ToDouble(int inValue) { return inValue; }
8383
template<> inline double ToDouble(bool inValue) { return inValue; }
8484
template<> inline double ToDouble(float inValue) { return inValue; }
85-
template<> inline double ToDouble(cpp::UInt64 inValue) { return inValue; }
86-
template<> inline double ToDouble(cpp::Int64 inValue) { return inValue; }
85+
template<> inline double ToDouble(cpp::UInt64 inValue) { return (double)inValue; }
86+
template<> inline double ToDouble(cpp::Int64 inValue) { return (double)inValue; }
8787
template<> inline double ToDouble(null inValue) { return 0; }
8888

8989

@@ -261,7 +261,7 @@ template<> inline float TCastObject<float>(hx::Object *inObj)
261261
{
262262
if (!inObj || (inObj->__GetType()!=::vtFloat && inObj->__GetType()!=::vtInt64 && inObj->__GetType()!=::vtInt))
263263
return hx::BadCast();
264-
return inObj->__ToDouble();
264+
return (float)inObj->__ToDouble();
265265
}
266266

267267
template<> inline String TCastObject<String>(hx::Object *inObj)

include/hxString.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES String
331331

332332
inline int cca(int inPos) const
333333
{
334-
if ((unsigned)inPos>=length) return 0;
334+
if ( (inPos>=length) || (inPos<0) ) return 0;
335335
#ifdef HX_SMART_STRINGS
336336
if (isUTF16Encoded())
337337
return __w[inPos];

include/hxcpp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ namespace hx { class Object; }
249249
namespace hx { class FieldRef; }
250250
namespace hx { class IndexRef; }
251251
namespace hx { class NativeInterface; }
252-
namespace hx { class StackContext; }
252+
namespace hx { struct StackContext; }
253253
namespace hx { template<typename T> class Native; }
254254
namespace hx { template<typename O> class ObjectPtr; }
255255
namespace cpp { template<typename S,typename H> class Struct; }
@@ -261,7 +261,7 @@ namespace cpp { namespace marshal { template<class T> class ValueType; } }
261261
namespace cpp { namespace marshal { template<class T> class ValueReference; } }
262262
namespace cpp { namespace marshal { template<class T> class PointerType; } }
263263
namespace cpp { namespace marshal { template<class T> class PointerReference; } }
264-
namespace cpp { namespace marshal { template<class T> class View; } }
264+
namespace cpp { namespace marshal { template<class T> struct View; } }
265265
template<typename ELEM_> class Array_obj;
266266
template<typename ELEM_> class Array;
267267
namespace hx {

src/Dynamic.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class DoubleData : public hx::Object
123123
String __ToString() const { return String(mValue); }
124124
double __ToDouble() const { return mValue; }
125125
int __ToInt() const { return (int)mValue; }
126-
cpp::Int64 __ToInt64() const { return mValue; }
126+
cpp::Int64 __ToInt64() const { return (cpp::Int64)mValue; }
127127

128128
int __Compare(const hx::Object *inRHS) const
129129
{
@@ -153,7 +153,7 @@ class Int64Data : public hx::Object
153153
virtual int __GetType() const { return vtInt64; }
154154
String toString() { return String(mValue); }
155155
String __ToString() const { return String(mValue); }
156-
double __ToDouble() const { return mValue; }
156+
double __ToDouble() const { return (double)mValue; }
157157
int __ToInt() const { return (int)mValue; }
158158
cpp::Int64 __ToInt64() const { return mValue; }
159159
void __GetFields(Array<String> &outFields)
@@ -414,7 +414,7 @@ Dynamic::Dynamic(double inVal)
414414
int idx = inVal+1;
415415
mPtr = sConstDynamicInts[idx].mPtr;
416416
if (!mPtr)
417-
mPtr = sConstDynamicInts[idx].mPtr = new (hx::NewObjConst)IntData(inVal);
417+
mPtr = sConstDynamicInts[idx].mPtr = new (hx::NewObjConst)IntData((int)inVal);
418418
}
419419
else
420420
mPtr = (hx::Object *)new DoubleData(inVal);
@@ -423,12 +423,13 @@ Dynamic::Dynamic(double inVal)
423423

424424
Dynamic::Dynamic(cpp::Int64 inVal)
425425
{
426-
if ( (int)inVal==inVal && inVal>=-1 && inVal<256 )
426+
int ival = (int)inVal;
427+
if ( ival==inVal && ival>=-1 && ival<256 )
427428
{
428-
int idx = inVal+1;
429+
int idx = ival+1;
429430
mPtr = sConstDynamicInts[idx].mPtr;
430431
if (!mPtr)
431-
mPtr = sConstDynamicInts[idx].mPtr = new (hx::NewObjConst)IntData(inVal);
432+
mPtr = sConstDynamicInts[idx].mPtr = new (hx::NewObjConst)IntData(ival);
432433
}
433434
else
434435
mPtr = (hx::Object *)new Int64Data(inVal);

src/hx/Hash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ inline void CopyValue(String &outValue, Float inValue) { }
243243
inline void CopyValue(String &outValue, const Dynamic &inValue) { outValue = inValue; }
244244
inline void CopyValue(int &outValue, int inValue) { outValue = inValue; }
245245
inline void CopyValue(int &outValue, cpp::Int64 inValue) { }
246-
inline void CopyValue(int &outValue, Float inValue) { outValue = inValue; }
246+
inline void CopyValue(int &outValue, Float inValue) { outValue = (int)inValue; }
247247
inline void CopyValue(int &outValue, const Dynamic &inValue) { outValue = inValue; }
248248
inline void CopyValue(int &outValue, const String &inValue) { }
249249
inline void CopyValue(Float &outValue, Float inValue) { outValue = inValue; }

0 commit comments

Comments
 (0)