diff options
author | Benoit Foucher <benoit@zeroc.com> | 2012-06-12 16:50:58 +0200 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2012-06-12 16:50:58 +0200 |
commit | b2c3f4fe51800183e78db500b1e91d0135689caf (patch) | |
tree | f515d08d95609db34b4a6b2c898a488e5fe6be4d /cpp/src | |
parent | demo fixes (diff) | |
download | ice-b2c3f4fe51800183e78db500b1e91d0135689caf.tar.bz2 ice-b2c3f4fe51800183e78db500b1e91d0135689caf.tar.xz ice-b2c3f4fe51800183e78db500b1e91d0135689caf.zip |
Fixed support unknown types in unknown optionals
Diffstat (limited to 'cpp/src')
-rwxr-xr-x | cpp/src/Ice/BasicStream.cpp | 58 | ||||
-rw-r--r-- | cpp/src/Ice/Exception.cpp | 14 | ||||
-rw-r--r-- | cpp/src/Ice/SlicedData.cpp | 64 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 3 |
4 files changed, 115 insertions, 24 deletions
diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp index e08d7ad9b49..ddd4dfa60ac 100755 --- a/cpp/src/Ice/BasicStream.cpp +++ b/cpp/src/Ice/BasicStream.cpp @@ -2312,12 +2312,19 @@ IceInternal::BasicStream::EncapsDecoder::throwException(const UserExceptionFacto traceSlicing("exception", _typeId, _slicingCat, _stream->instance()->initializationData().logger); } + // + // Slice off what we don't understand. + // + skipSlice(); + + // + // If this is the last slice, raise an exception and stop un-marshalling. + // if(_sliceFlags & FLAG_IS_LAST_SLICE) { throw NoExceptionFactoryException(__FILE__, __LINE__, "", "unknown exception type `" + mostDerivedId + "'"); } - skipSlice(); // Slice off what we don't understand. try { startSlice(); @@ -2654,12 +2661,10 @@ IceInternal::BasicStream::EncapsDecoder::readInstance() while(true) { // - // For the 1.0 encoding, the type ID for the base Object class marks - // the last slice. For later encodings, an empty type ID means the - // class was marshaled in the compact format and therefore cannot be - // sliced. + // For the 1.0 encoding, the type ID for the base Object class + // marks the last slice. // - if(_typeId.empty() || _typeId == Object::ice_staticId()) + if(_typeId == Object::ice_staticId()) { throw NoObjectFactoryException(__FILE__, __LINE__, "", mostDerivedId); } @@ -2709,32 +2714,41 @@ IceInternal::BasicStream::EncapsDecoder::readInstance() } // - // If object slicing is disabled, or if the flags indicate that this is the - // last slice (for encodings >= 1.1), we raise NoObjectFactoryException. + // Performance sensitive, so we use lazy initialization for tracing. // - if(!_sliceObjects) + if(_traceSlicing == -1) { - throw NoObjectFactoryException(__FILE__, __LINE__, "object slicing is disabled", _typeId); + _traceSlicing = _stream->instance()->traceLevels()->slicing; + _slicingCat = _stream->instance()->traceLevels()->slicingCat; } - else if(_sliceFlags & FLAG_IS_LAST_SLICE) + if(_traceSlicing > 0) { - throw NoObjectFactoryException(__FILE__, __LINE__, "", _typeId); + traceSlicing("class", _typeId, _slicingCat, _stream->instance()->initializationData().logger); } // - // Performance sensitive, so we use lazy initialization for tracing. + // If object slicing is disabled, stop un-marshalling. // - if(_traceSlicing == -1) + if(!_sliceObjects) { - _traceSlicing = _stream->instance()->traceLevels()->slicing; - _slicingCat = _stream->instance()->traceLevels()->slicingCat; + throw NoObjectFactoryException(__FILE__, __LINE__, "object slicing is disabled", _typeId); } - if(_traceSlicing > 0) + + // + // Slice off what we don't understand. + // + skipSlice(); + + // + // If this is the last slice, keep the object as an opaque + // UnknownSlicedData object. + // + if(_sliceFlags & FLAG_IS_LAST_SLICE) { - traceSlicing("class", _typeId, _slicingCat, _stream->instance()->initializationData().logger); + v = new UnknownSlicedObject(mostDerivedId); + break; } - skipSlice(); // Slice off what we don't understand. startSlice(); // Read next Slice header for next iteration. } @@ -2828,7 +2842,9 @@ IceInternal::BasicStream::EncapsDecoder::skipSlice() } else { - throw MarshalException(__FILE__, __LINE__, "compact format prevents slicing"); + throw MarshalException(__FILE__, + __LINE__, + "compact format prevents slicing (the sender should use the sliced format instead)"); } if(_encaps->encoding != Encoding_1_0) @@ -2899,7 +2915,7 @@ IceInternal::BasicStream::EncapsDecoder::readSlicedData() { throw MarshalException(__FILE__, __LINE__, "invalid id in object indirection table"); } - addPatchEntry(id, &patchHandle<Ice::Object>, &_slices[n]->objects[j++]); + addPatchEntry(id, &patchHandle<Object>, &_slices[n]->objects[j++]); } } diff --git a/cpp/src/Ice/Exception.cpp b/cpp/src/Ice/Exception.cpp index 002851f917d..a205af22a78 100644 --- a/cpp/src/Ice/Exception.cpp +++ b/cpp/src/Ice/Exception.cpp @@ -26,8 +26,20 @@ namespace Ex { void -throwUOE(const string& expectedType, const string& type) +throwUOE(const string& expectedType, const ObjectPtr& v) { + // + // If the object is an unknown sliced object, we didn't find an + // object factory, in this case raise a NoObjectFactoryException + // instead. + // + UnknownSlicedObject* uso = dynamic_cast<UnknownSlicedObject*>(v.get()); + if(uso) + { + throw NoObjectFactoryException(__FILE__, __LINE__, "", uso->getUnknownTypeId()); + } + + string type = v->ice_id(); throw Ice::UnexpectedObjectException(__FILE__, __LINE__, "expected element of type `" + expectedType + "' but received '" + type, type, expectedType); diff --git a/cpp/src/Ice/SlicedData.cpp b/cpp/src/Ice/SlicedData.cpp index 72409a2d79c..568c55a7585 100644 --- a/cpp/src/Ice/SlicedData.cpp +++ b/cpp/src/Ice/SlicedData.cpp @@ -9,6 +9,7 @@ #include <Ice/SlicedData.h> #include <Ice/Object.h> +#include <Ice/BasicStream.h> using namespace std; using namespace Ice; @@ -69,3 +70,66 @@ Ice::SlicedData::__addObject(IceInternal::GCCountMap& m) ++pos->second; } } + +Ice::UnknownSlicedObject::UnknownSlicedObject(const string& unknownTypeId) : _unknownTypeId(unknownTypeId) +{ +} + +const string& +Ice::UnknownSlicedObject::getUnknownTypeId() const +{ + return _unknownTypeId; +} + +void +Ice::UnknownSlicedObject::__addObject(IceInternal::GCCountMap& _c) +{ + IceInternal::GCCountMap::iterator pos = _c.find(this); + if(pos == _c.end()) + { + _c[this] = 1; + } + else + { + ++pos->second; + } +} + +bool +Ice::UnknownSlicedObject::__usesGC() +{ + return true; +} + +void +Ice::UnknownSlicedObject::__gcReachable(IceInternal::GCCountMap& _c) const +{ + if(_slicedData) + { + _slicedData->__addObject(_c); + } +} + +void +Ice::UnknownSlicedObject::__gcClear() +{ + if(_slicedData) + { + _slicedData->__decRefUnsafe(); + _slicedData.__clearHandleUnsafe(); + } +} + +void +Ice::UnknownSlicedObject::__write(IceInternal::BasicStream* __os) const +{ + __os->startWriteObject(_slicedData); + __os->endWriteObject(); +} + +void +Ice::UnknownSlicedObject::__read(IceInternal::BasicStream* __is) +{ + __is->startReadObject(); + _slicedData = __is->endReadObject(true); +} diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 54091b39450..fd34162a680 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -423,7 +423,6 @@ Slice::Gen::generate(const UnitPtr& p) if(p->hasContentsWithMetaData("preserve-slice")) { H << "\n#include <Ice/SlicedDataF.h>"; - C << "\n#include <Ice/SlicedData.h>"; } @@ -4165,7 +4164,7 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) C << nl << "handle = " << scope << p->name() << "Ptr::dynamicCast(v);"; C << nl << "if(v && !handle)"; C << sb; - C << nl << "IceInternal::Ex::throwUOE(" << scoped << "::ice_staticId(), v->ice_id());"; + C << nl << "IceInternal::Ex::throwUOE(" << scoped << "::ice_staticId(), v);"; C << eb; C << eb; |