diff --git a/cpp/src/slice2objc/Gen.cpp b/cpp/src/slice2objc/Gen.cpp index 492bd9e..149a43b 100644 --- a/cpp/src/slice2objc/Gen.cpp +++ b/cpp/src/slice2objc/Gen.cpp @@ -1008,6 +1008,7 @@ Slice::Gen::generate(const UnitPtr& p) _M << nl << "\n#import "; _M << nl << "#import "; + _M << nl << "#import "; _M << nl << "#import <"; if(!_include.empty()) @@ -2189,7 +2190,26 @@ Slice::Gen::TypesVisitor::writeMemberHashCode(const DataMemberList& dataMembers, _M << nl << "h_ = (h_ << 1) ^ "; if(isValueType(type)) { - _M << name << ";"; + BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); + if(builtin) + { + if(builtin->kind() == Builtin::KindFloat) + { + _M << "ICEInternalHashFloat(" << name << ");"; + } + else if(builtin->kind() == Builtin::KindDouble) + { + _M << "ICEInternalHashDouble(" << name << ");"; + } + else + { + _M << name << ";"; + } + } + else + { + _M << name << ";"; + } } else { diff --git a/objc/include/Ice/Internal.h b/objc/include/Ice/Internal.h new file mode 100644 index 0000000..ce1e1b9 --- /dev/null +++ b/objc/include/Ice/Internal.h @@ -0,0 +1,27 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_TOUCH_LICENSE file included in this distribution. +// +// ********************************************************************** + +// +// Compute hash value for float/double values. +// +static inline NSUInteger +ICEInternalHashFloat(float f) +{ + return *(unsigned int*)&f; +} + +static inline NSUInteger +ICEInternalHashDouble(double d) +{ +#ifdef __LP64__ + return *(unsigned long*)&d; +#else + return (*(unsigned int*)&d << 1) ^ *((unsigned int*)&d + 1); +#endif +} diff --git a/objc/test/Ice/operations/Test.ice b/objc/test/Ice/operations/Test.ice index b13fb27..f13d244 100644 --- a/objc/test/Ice/operations/Test.ice +++ b/objc/test/Ice/operations/Test.ice @@ -69,6 +69,20 @@ dictionary StringMyEnumD; sequence StructS; // Used by Objective-C test only. +struct Struct2 // Ensures the generated code for this struct compiles +{ + bool b; + int i; + float f; + double d; + byte by; + short sh; + long l; + StructS ss; + ByteBoolD dict; + MyEnumSS seq; +}; + class A // Used Objective-C test only. { int i;