summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2015-02-20 15:48:50 +0100
committerBenoit Foucher <benoit@zeroc.com>2015-02-20 15:48:50 +0100
commit6912a3e2c742e0243130d989f558131f0c73b54e (patch)
tree708610eaf0d52e0d35fde0661a4ded595efe424a
parentbuild fix (diff)
downloadice-6912a3e2c742e0243130d989f558131f0c73b54e.tar.bz2
ice-6912a3e2c742e0243130d989f558131f0c73b54e.tar.xz
ice-6912a3e2c742e0243130d989f558131f0c73b54e.zip
Additional fix for ICE-6268, fixed struct un-marshalling to not re-create the struct
-rw-r--r--cpp/src/Slice/CsUtil.cpp4
-rw-r--r--cpp/src/Slice/ObjCUtil.cpp21
-rw-r--r--cpp/src/slice2cs/Gen.cpp14
-rw-r--r--objc/include/objc/Ice/Stream.h12
-rw-r--r--objc/src/Ice/Stream.mm85
-rw-r--r--objc/test/Ice/objects/AllTests.m4
6 files changed, 88 insertions, 52 deletions
diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp
index be424b7b67b..c72137ae53c 100644
--- a/cpp/src/Slice/CsUtil.cpp
+++ b/cpp/src/Slice/CsUtil.cpp
@@ -643,8 +643,8 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out,
{
if(!isValueType(st))
{
- const string read = streamingAPI ? "ice_readNew" : "readNew__";
- out << nl << param << " = " << typeToString(type) << "." << read << "(" << stream << ");";
+ const string r = streamingAPI ? "ice_read" : "read__";
+ out << nl << param << " = " << typeToString(type) << "." << r << "(" << stream << ", " << param << ");";
}
else
{
diff --git a/cpp/src/Slice/ObjCUtil.cpp b/cpp/src/Slice/ObjCUtil.cpp
index e449ea87539..77a2d627ece 100644
--- a/cpp/src/Slice/ObjCUtil.cpp
+++ b/cpp/src/Slice/ObjCUtil.cpp
@@ -848,13 +848,27 @@ Slice::ObjCGenerator::writeMarshalUnmarshalCode(Output &out, const TypePtr& type
}
else
{
- if(autoreleased)
+ if(StructPtr::dynamicCast(type))
{
- out << nl << param << " = [" << name << " read:" << stream << "];";
+ if(autoreleased)
+ {
+ out << nl << param << " = [" << name << " read:" << stream << " value:" << param << "];";
+ }
+ else
+ {
+ out << nl << param << " = [" << name << " readRetained:" << stream << " value:" << param << "];";
+ }
}
else
{
- out << nl << param << " = [" << name << " readRetained:" << stream << "];";
+ if(autoreleased)
+ {
+ out << nl << param << " = [" << name << " read:" << stream << "];";
+ }
+ else
+ {
+ out << nl << param << " = [" << name << " readRetained:" << stream << "];";
+ }
}
}
}
@@ -1294,4 +1308,3 @@ Slice::ObjCGenerator::MetaDataVisitor::modulePrefixError(const ModulePtr& m, con
os << " as `" << mp.name << "'" << endl;
emitWarning(file, line, os.str());
}
-
diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp
index 6693a6fdc9f..e4d6460a81d 100644
--- a/cpp/src/slice2cs/Gen.cpp
+++ b/cpp/src/slice2cs/Gen.cpp
@@ -4374,9 +4374,12 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p)
_out << sp;
emitGeneratedCodeAttribute();
- _out << nl << "public static " << name << " readNew__(IceInternal.BasicStream is__)";
+ _out << nl << "public static " << name << " read__(IceInternal.BasicStream is__, " << name << " v__)";
_out << sb;
- _out << nl << name << " v__ = new " << name << "();";
+ _out << nl << "if(v__ == null)";
+ _out << sb;
+ _out << nl << "v__ = new " << name << "();";
+ _out << eb;
_out << nl << "v__.read__(is__);";
_out << nl << "return v__;";
_out << eb;
@@ -4423,9 +4426,12 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p)
_out << sp;
emitGeneratedCodeAttribute();
- _out << nl << "public static " << name << " ice_readNew(Ice.InputStream inS__)";
+ _out << nl << "public static " << name << " ice_read(Ice.InputStream inS__, " << name << " v__)";
_out << sb;
- _out << nl << name << " v__ = new " << name << "();";
+ _out << nl << "if(v__ == null)";
+ _out << sb;
+ _out << nl << "v__ = new " << name << "();";
+ _out << eb;
_out << nl << "v__.ice_read(inS__);";
_out << nl << "return v__;";
_out << eb;
diff --git a/objc/include/objc/Ice/Stream.h b/objc/include/objc/Ice/Stream.h
index a2a9a3b5635..71dd4c87b2b 100644
--- a/objc/include/objc/Ice/Stream.h
+++ b/objc/include/objc/Ice/Stream.h
@@ -27,9 +27,9 @@ ICE_API @interface ICEInternalPrefixTable : NSObject
typedef enum
{
- ICEOptionalFormatF1 = 0,
+ ICEOptionalFormatF1 = 0,
ICEOptionalFormatF2 = 1,
- ICEOptionalFormatF4 = 2,
+ ICEOptionalFormatF4 = 2,
ICEOptionalFormatF8 = 3,
ICEOptionalFormatSize = 4,
ICEOptionalFormatVSize = 5,
@@ -113,7 +113,7 @@ ICE_API @protocol ICEInputStream <NSObject>
-(NSMutableDictionary*) newDictionary:(ICEKeyValueTypeHelper)type;
-(NSMutableDictionary*) readDictionary:(ICEKeyValueTypeHelper)type;
--(BOOL) readOptional:(ICEInt)tag format:(ICEOptionalFormat)format;
+-(BOOL) readOptional:(ICEInt)tag format:(ICEOptionalFormat)format;
-(ICEInt) readSize;
-(ICEInt) readAndCheckSeqSize:(ICEInt)minSize;
@@ -184,7 +184,7 @@ ICE_API @protocol ICEOutputStream <NSObject>
-(void) writeSequence:(NSArray*)arr helper:(Class)helper;
-(void) writeDictionary:(NSDictionary*)dictionary helper:(ICEKeyValueTypeHelper)helper;
--(BOOL) writeOptional:(ICEInt)tag format:(ICEOptionalFormat)format;
+-(BOOL) writeOptional:(ICEInt)tag format:(ICEOptionalFormat)format;
-(void) writeSize:(ICEInt)v;
@@ -271,6 +271,8 @@ ICE_API @interface ICEEnumHelper : ICEStreamHelper
@end
ICE_API @interface ICEStructHelper : ICEStreamHelper
++(id) readRetained:(id<ICEInputStream>)stream value:(id)v NS_RETURNS_RETAINED;
++(id) read:(id<ICEInputStream>)stream value:(id)v;
+(Class) getOptionalHelper;
@end
@@ -353,7 +355,7 @@ ICE_API @interface ICEFixedSize1SequenceOptionalHelper : NSObject<ICEOptionalStr
ICE_API @interface ICEFixedDictionaryOptionalHelper : NSObject<ICEOptionalStreamHelper>
@end
-
+
ICE_API @interface CompactIdMapHelper : NSObject
+(void) initialize;
+(void) registerClass:(NSString*)type value:(ICEInt)value;
diff --git a/objc/src/Ice/Stream.mm b/objc/src/Ice/Stream.mm
index 4abb3350ad5..ef7752b36b1 100644
--- a/objc/src/Ice/Stream.mm
+++ b/objc/src/Ice/Stream.mm
@@ -31,7 +31,7 @@ namespace IceObjC
class ObjectWriter : public Ice::ObjectWriter
{
public:
-
+
ObjectWriter(ICEObject* obj, ICEOutputStream* stream) : _obj(obj), _stream(stream)
{
}
@@ -63,7 +63,7 @@ private:
class ObjectReader : public Ice::ObjectReader
{
public:
-
+
// We must explicitely CFRetain/CFRelease so that the garbage
// collector does not trash the _obj.
ObjectReader(ICEObject* obj) : _obj(obj)
@@ -114,15 +114,15 @@ typedef IceUtil::Handle<ObjectReader> ObjectReaderPtr;
class ReadObjectBase : public Ice::ReadObjectCallback
{
public:
-
+
ReadObjectBase(Class expectedType) : _expectedType(expectedType)
{
}
-
+
void checkType(ICEObject*);
private:
-
+
Class _expectedType;
};
@@ -135,7 +135,7 @@ ReadObjectBase::checkType(ICEObject* o)
NSString* expectedType = [_expectedType ice_staticId];
NSString* reason = [NSString stringWithFormat:@"expected element of type `%@' but received `%@'",
expectedType, actualType];
-
+
@throw [ICEUnexpectedObjectException unexpectedObjectException:__FILE__
line:__LINE__
reason:reason
@@ -147,8 +147,8 @@ ReadObjectBase::checkType(ICEObject* o)
class ReadObject : public ReadObjectBase
{
public:
-
- ReadObject(ICEObject** addr, Class expectedType, bool autorelease) :
+
+ ReadObject(ICEObject** addr, Class expectedType, bool autorelease) :
ReadObjectBase(expectedType), _addr(addr), _autorelease(autorelease)
{
}
@@ -188,8 +188,8 @@ private:
class ReadObjectAtIndex : public ReadObjectBase
{
public:
-
- ReadObjectAtIndex(NSMutableArray* array, ICEInt index, Class expectedType) :
+
+ ReadObjectAtIndex(NSMutableArray* array, ICEInt index, Class expectedType) :
ReadObjectBase(expectedType), _array(array), _index(index)
{
}
@@ -221,10 +221,10 @@ private:
class ReadObjectForKey : public ReadObjectBase
{
public:
-
+
// We must explicitely CFRetain/CFRelease so that the garbage
// collector does not trash the _key.
- ReadObjectForKey(NSMutableDictionary* dict, id key, Class expectedType) :
+ ReadObjectForKey(NSMutableDictionary* dict, id key, Class expectedType) :
ReadObjectBase(expectedType), _dict(dict), _key(key)
{
CFRetain(_key);
@@ -234,7 +234,7 @@ public:
{
CFRelease(_key);
}
-
+
virtual void
invoke(const Ice::ObjectPtr& obj)
{
@@ -267,7 +267,7 @@ class ExceptionWriter : public Ice::UserExceptionWriter
{
public:
- ExceptionWriter(const Ice::CommunicatorPtr& communicator, ICEOutputStream* stream, ICEUserException* ex) :
+ ExceptionWriter(const Ice::CommunicatorPtr& communicator, ICEOutputStream* stream, ICEUserException* ex) :
Ice::UserExceptionWriter(communicator),
_stream(stream),
_ex(ex)
@@ -377,7 +377,7 @@ public:
virtual void createAndThrow(const std::string& typeId) const
{
ICEUserException* ex = nil;
- std::string objcId = toObjCSliceId(typeId,
+ std::string objcId = toObjCSliceId(typeId,
[[ICECommunicator localObjectWithCxxObject:_communicator.get()] getPrefixTable]);
Class c = objc_lookUpClass(objcId.c_str());
if(c != nil)
@@ -406,22 +406,22 @@ private:
{
ICENone = [[ICEInternalNone alloc] init];
}
--(id) copyWithZone:(NSZone *)zone
+-(id) copyWithZone:(NSZone *)zone
{
return self;
}
--(id) retain
+-(id) retain
{
return self;
}
--(NSUInteger) retainCount
+-(NSUInteger) retainCount
{
return NSUIntegerMax;
}
--(oneway void) release
+-(oneway void) release
{
}
--(id) autorelease
+-(id) autorelease
{
return self;
}
@@ -543,7 +543,7 @@ private:
std::pair<const Ice::Byte*, const Ice::Byte*> seq;
is_->read(seq);
return [[NSMutableData alloc] initWithBytes:seq.first length:(seq.second - seq.first)];
- }
+ }
catch(const std::exception& ex)
{
nsex = toObjCException(ex);
@@ -558,9 +558,9 @@ private:
{
std::pair<const Ice::Byte*, const Ice::Byte*> seq;
is_->read(seq);
- return [NSData dataWithBytesNoCopy:const_cast<Ice::Byte*>(seq.first)
+ return [NSData dataWithBytesNoCopy:const_cast<Ice::Byte*>(seq.first)
length:(seq.second - seq.first) freeWhenDone:NO];
- }
+ }
catch(const std::exception& ex)
{
nsex = toObjCException(ex);
@@ -855,7 +855,7 @@ private:
}
//
-// Size of an enum. Slice enum underling type is specified as ICEInt so
+// Size of an enum. Slice enum underling type is specified as ICEInt so
// all Slice enums have the same size as an ICEInt.
//
#define ENUM_SIZE sizeof(ICEInt)
@@ -1213,9 +1213,9 @@ private:
NSException* nsex = nil;
try
{
- Ice::UserExceptionReaderFactoryPtr factory =
+ Ice::UserExceptionReaderFactoryPtr factory =
new IceObjC::UserExceptionReaderFactoryI(is_->communicator().get(), self);
- is_->throwException(factory);
+ is_->throwException(factory);
}
catch(const IceObjC::ExceptionReader& reader)
{
@@ -1576,7 +1576,7 @@ private:
}
-(void) writeByteSeq:(NSData*)v
-{
+{
NSException* nsex = nil;
try
{
@@ -2375,7 +2375,6 @@ private:
+(id) read:(id<ICEInputStream>)stream
{
return [[self readRetained:stream] autorelease];
- return nil;
}
+(void) write:(id)obj stream:(id<ICEOutputStream>)stream
{
@@ -2671,7 +2670,7 @@ private:
+(void) writeOpt:(id)v stream:(id<ICEOutputStream>)stream tag:(ICEInt)tag
{
NSString* value;
- if([ICEOptionalGetter get:v value:&value type:[NSString class]] &&
+ if([ICEOptionalGetter get:v value:&value type:[NSString class]] &&
[stream writeOptional:tag format:ICEOptionalFormatVSize])
{
[stream writeString:v];
@@ -2762,7 +2761,7 @@ private:
+(void) writeOpt:(id)v stream:(id<ICEOutputStream>)stream tag:(ICEInt)tag
{
ICEObject* value;
- if([ICEOptionalGetter get:v value:&value type:[ICEObject class]] &&
+ if([ICEOptionalGetter get:v value:&value type:[ICEObject class]] &&
[stream writeOptional:tag format:ICEOptionalFormatClass])
{
[self write:value stream:stream];
@@ -2816,7 +2815,7 @@ private:
+(void) writeOpt:(id)v stream:(id<ICEOutputStream>)stream tag:(ICEInt)tag
{
ICEObjectPrx* value;
- if([ICEOptionalGetter get:v value:&value type:[ICEObjectPrx class]] &&
+ if([ICEOptionalGetter get:v value:&value type:[ICEObjectPrx class]] &&
[stream writeOptional:tag format:ICEOptionalFormatFSize])
{
[ICEVarLengthOptionalHelper write:v stream:stream helper:self];
@@ -2831,7 +2830,19 @@ private:
@implementation ICEStructHelper
+(id) readRetained:(id<ICEInputStream>)stream
{
- id p = [[self getType] new];
+ return [self readRetained:stream value:nil];
+}
++(id) readRetained:(id<ICEInputStream>)stream value:(id)p
+{
+ if(p == nil)
+ {
+ p = [[self getType] new];
+ }
+ else
+ {
+ [p retain];
+ }
+
@try
{
[p read__:stream];
@@ -2843,6 +2854,10 @@ private:
}
return p;
}
++(id) read:(id<ICEInputStream>)stream value:(id)p
+{
+ return [[self readRetained:stream value:p] autorelease];
+}
+(void) write:(id)obj stream:(id<ICEOutputStream>)stream
{
if(obj == nil)
@@ -2965,7 +2980,7 @@ private:
+(void) writeOpt:(id)v stream:(id<ICEOutputStream>)stream tag:(ICEInt)tag
{
NSData* a;
- if([ICEOptionalGetter get:v value:&a type:[NSData class]] &&
+ if([ICEOptionalGetter get:v value:&a type:[NSData class]] &&
[stream writeOptional:tag format:ICEOptionalFormatVSize])
{
[ICEFixedSequenceOptionalHelper write:a stream:stream helper:self];
@@ -3005,7 +3020,7 @@ private:
+(void) writeOpt:(id)v stream:(id<ICEOutputStream>)stream tag:(ICEInt)tag
{
NSData* a;
- if([ICEOptionalGetter get:v value:&a type:[NSData class]] &&
+ if([ICEOptionalGetter get:v value:&a type:[NSData class]] &&
[stream writeOptional:tag format:ICEOptionalFormatVSize])
{
[stream writeBoolSeq:a];
@@ -3037,7 +3052,7 @@ private:
+(void) writeOpt:(id)v stream:(id<ICEOutputStream>)stream tag:(ICEInt)tag
{
NSData* a;
- if([ICEOptionalGetter get:v value:&a type:[NSData class]] &&
+ if([ICEOptionalGetter get:v value:&a type:[NSData class]] &&
[stream writeOptional:tag format:ICEOptionalFormatVSize])
{
[stream writeByteSeq:a];
diff --git a/objc/test/Ice/objects/AllTests.m b/objc/test/Ice/objects/AllTests.m
index 4689ce85ce6..47c9e574d91 100644
--- a/objc/test/Ice/objects/AllTests.m
+++ b/objc/test/Ice/objects/AllTests.m
@@ -65,8 +65,8 @@ objectsAllTests(id<ICECommunicator> communicator, BOOL collocated)
TestObjectsBase* ba1 = [TestObjectsBase base];
- test(ba1.theS.str == nil);
- test(ba1.str == nil);
+ test([ba1.theS.str isEqual:@""]);
+ test([ba1.str isEqual:@""]);
ba1.theS = nil;
TestObjectsS* s = [TestObjectsS s];