diff options
Diffstat (limited to 'cpp/src/Ice/BasicStream.cpp')
-rw-r--r-- | cpp/src/Ice/BasicStream.cpp | 113 |
1 files changed, 91 insertions, 22 deletions
diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp index c5c53947751..e1a475f8ee1 100644 --- a/cpp/src/Ice/BasicStream.cpp +++ b/cpp/src/Ice/BasicStream.cpp @@ -291,6 +291,26 @@ IceInternal::BasicStream::ReadEncaps::swap(ReadEncaps& other) std::swap(previous, other.previous); } +void +IceInternal::BasicStream::endWriteEncapsChecked() +{ + if(!_currentWriteEncaps) + { + throw EncapsulationException(__FILE__, __LINE__, "not in an encapsulation"); + } + endWriteEncaps(); +} + +void +IceInternal::BasicStream::endReadEncapsChecked() +{ + if(!_currentReadEncaps) + { + throw EncapsulationException(__FILE__, __LINE__, "not in an encapsulation"); + } + endReadEncaps(); +} + Int IceInternal::BasicStream::getReadEncapsSize() { @@ -377,6 +397,14 @@ IceInternal::BasicStream::skipSlice() void IceInternal::BasicStream::writeTypeId(const string& id) { + if(!_currentWriteEncaps || !_currentWriteEncaps->typeIdMap) + { + // + // write(ObjectPtr) must be called first. + // + throw MarshalException(__FILE__, __LINE__, "type ids require an encapsulation"); + } + TypeIdWriteMap::const_iterator k = _currentWriteEncaps->typeIdMap->find(id); if(k != _currentWriteEncaps->typeIdMap->end()) { @@ -394,6 +422,14 @@ IceInternal::BasicStream::writeTypeId(const string& id) void IceInternal::BasicStream::readTypeId(string& id) { + if(!_currentReadEncaps || !_currentReadEncaps->typeIdMap) + { + // + // read(PatchFunc, void*) must be called first. + // + throw MarshalException(__FILE__, __LINE__, "type ids require an encapsulation"); + } + bool isIndex; read(isIndex); if(isIndex) @@ -1743,34 +1779,42 @@ IceInternal::BasicStream::read(PatchFunc patchFunc, void* patchAddr) Int index; read(index); - if(index == 0) + if(patchAddr) { - patchFunc(patchAddr, v); // Null Ptr. - return; - } + if(index == 0) + { + // Calling the patch function for null instances is necessary for correct functioning of Ice for + // Python and Ruby. + patchFunc(patchAddr, v); // Null Ptr. + return; + } - if(index < 0 && patchAddr) - { - PatchMap::iterator p = _currentReadEncaps->patchMap->find(-index); - if(p == _currentReadEncaps->patchMap->end()) + if(index < 0) { + PatchMap::iterator p = _currentReadEncaps->patchMap->find(-index); + if(p == _currentReadEncaps->patchMap->end()) + { + // + // We have no outstanding instances to be patched for this + // index, so make a new entry in the patch map. + // + p = _currentReadEncaps->patchMap->insert(make_pair(-index, PatchList())).first; + } // - // We have no outstanding instances to be patched for this - // index, so make a new entry in the patch map. + // Append a patch entry for this instance. // - p = _currentReadEncaps->patchMap->insert(make_pair(-index, PatchList())).first; + PatchEntry e; + e.patchFunc = patchFunc; + e.patchAddr = patchAddr; + p->second.push_back(e); + patchPointers(-index, _currentReadEncaps->unmarshaledMap->end(), p); + return; } - // - // Append a patch entry for this instance. - // - PatchEntry e; - e.patchFunc = patchFunc; - e.patchAddr = patchAddr; - p->second.push_back(e); - patchPointers(-index, _currentReadEncaps->unmarshaledMap->end(), p); - return; } - assert(index > 0); + if(index <= 0) + { + throw MarshalException(__FILE__, __LINE__, "Invalid class instance index"); + } string mostDerivedId; readTypeId(mostDerivedId); @@ -1896,6 +1940,8 @@ IceInternal::BasicStream::throwException() string id; read(id, false); + const string origId = id; + for(;;) { // @@ -1938,8 +1984,22 @@ IceInternal::BasicStream::throwException() { traceSlicing("exception", id, _slicingCat, _instance->initializationData().logger); } + skipSlice(); // Slice off what we don't understand. - read(id, false); // Read type id for next slice. + + try + { + read(id, false); // Read type id for next slice. + } + catch(UnmarshalOutOfBoundsException& ex) + { + // + // When read() raises this exception it means we've seen the last slice, + // so we set the reason member to a more helpful message. + // + ex.reason = "unknown exception type `" + origId + "'"; + throw; + } } } @@ -2004,6 +2064,15 @@ IceInternal::BasicStream::readPendingObjects() } while(num); + if(_currentReadEncaps && _currentReadEncaps->patchMap && _currentReadEncaps->patchMap->size() != 0) + { + // + // If any entries remain in the patch map, the sender has sent an index for an object, but failed + // to supply the object. + // + throw MarshalException(__FILE__, __LINE__, "Index for class received, but no instance"); + } + // // Iterate over the object list and invoke ice_postUnmarshal on // each object. We must do this after all objects have been |