summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/BasicStream.cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2014-07-17 12:36:00 -0230
committerDwayne Boone <dwayne@zeroc.com>2014-07-17 12:36:00 -0230
commit93fdab6fa782511ef569acb17352853646aa66b5 (patch)
tree1e73a243303f1d9564499f0b7a036b4484cc1671 /cpp/src/Ice/BasicStream.cpp
parentC# transceiver fixes (diff)
downloadice-93fdab6fa782511ef569acb17352853646aa66b5.tar.bz2
ice-93fdab6fa782511ef569acb17352853646aa66b5.tar.xz
ice-93fdab6fa782511ef569acb17352853646aa66b5.zip
ICE-5481 startSize/endSize methods aren't designed to be "reentrant"
Diffstat (limited to 'cpp/src/Ice/BasicStream.cpp')
-rw-r--r--cpp/src/Ice/BasicStream.cpp112
1 files changed, 54 insertions, 58 deletions
diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp
index 2d19bd83d38..18192e118e9 100644
--- a/cpp/src/Ice/BasicStream.cpp
+++ b/cpp/src/Ice/BasicStream.cpp
@@ -37,12 +37,12 @@ namespace
class StreamUTF8BufferI : public IceUtil::UTF8Buffer
{
public:
-
- StreamUTF8BufferI(BasicStream& stream) :
+
+ StreamUTF8BufferI(BasicStream& stream) :
_stream(stream)
{
}
-
+
Ice::Byte*
getMoreBytes(size_t howMany, Ice::Byte* firstUnused)
{
@@ -100,8 +100,7 @@ IceInternal::BasicStream::BasicStream(Instance* instance, const EncodingVersion&
_unlimited(unlimited),
_stringConverter(instance->getStringConverter()),
_wstringConverter(instance->getWstringConverter()),
- _startSeq(-1),
- _sizePos(-1)
+ _startSeq(-1)
{
//
// Initialize the encoding members of our pre-allocated encapsulations, in case
@@ -111,7 +110,7 @@ IceInternal::BasicStream::BasicStream(Instance* instance, const EncodingVersion&
_preAllocatedWriteEncaps.encoding = encoding;
}
-IceInternal::BasicStream::BasicStream(Instance* instance, const EncodingVersion& encoding, const Byte* begin,
+IceInternal::BasicStream::BasicStream(Instance* instance, const EncodingVersion& encoding, const Byte* begin,
const Byte* end) :
IceInternal::Buffer(begin, end),
_instance(instance),
@@ -124,8 +123,7 @@ IceInternal::BasicStream::BasicStream(Instance* instance, const EncodingVersion&
_unlimited(false),
_stringConverter(instance->getStringConverter()),
_wstringConverter(instance->getWstringConverter()),
- _startSeq(-1),
- _sizePos(-1)
+ _startSeq(-1)
{
//
// Initialize the encoding members of our pre-allocated encapsulations, in case
@@ -153,7 +151,6 @@ IceInternal::BasicStream::clear()
}
_startSeq = -1;
- _sizePos = -1;
_sliceObjects = true;
}
@@ -191,7 +188,6 @@ IceInternal::BasicStream::swap(BasicStream& other)
std::swap(_unlimited, other._unlimited);
std::swap(_startSeq, other._startSeq);
std::swap(_minSeqSize, other._minSeqSize);
- std::swap(_sizePos, other._sizePos);
}
void
@@ -316,7 +312,7 @@ IceInternal::BasicStream::writePendingObjects()
// If using the 1.0 encoding and no objects were written, we
// still write an empty sequence for pending objects if
// requested (i.e.: if this is called).
- //
+ //
// This is required by the 1.0 encoding, even if no objects
// are written we do marshal an empty sequence if marshaled
// data types use classes.
@@ -339,8 +335,8 @@ IceInternal::BasicStream::readAndCheckSeqSize(int minSize)
// The _startSeq variable points to the start of the sequence for which
// we expect to read at least _minSeqSize bytes from the stream.
//
- // If not initialized or if we already read more data than _minSeqSize,
- // we reset _startSeq and _minSeqSize for this sequence (possibly a
+ // If not initialized or if we already read more data than _minSeqSize,
+ // we reset _startSeq and _minSeqSize for this sequence (possibly a
// top-level sequence or enclosed sequence it doesn't really matter).
//
// Otherwise, we are reading an enclosed sequence and we have to bump
@@ -349,7 +345,7 @@ IceInternal::BasicStream::readAndCheckSeqSize(int minSize)
//
// The goal of this check is to ensure that when we start un-marshalling
// a new sequence, we check the minimal size of this new sequence against
- // the estimated remaining buffer size. This estimatation is based on
+ // the estimated remaining buffer size. This estimatation is based on
// the minimum size of the enclosing sequences, it's _minSeqSize.
//
if(_startSeq == -1 || i > (b.begin() + _startSeq + _minSeqSize))
@@ -364,14 +360,14 @@ IceInternal::BasicStream::readAndCheckSeqSize(int minSize)
//
// If there isn't enough data to read on the stream for the sequence (and
- // possibly enclosed sequences), something is wrong with the marshalled
+ // possibly enclosed sequences), something is wrong with the marshalled
// data: it's claiming having more data that what is possible to read.
//
if(_startSeq + _minSeqSize > static_cast<int>(b.size()))
{
throw UnmarshalOutOfBoundsException(__FILE__, __LINE__);
}
-
+
return sz;
}
@@ -1361,19 +1357,19 @@ IceInternal::BasicStream::writeConverted(const char* vdata, size_t vsize)
{
Int guessedSize = static_cast<Int>(vsize);
writeSize(guessedSize); // writeSize() only writes the size; it does not reserve any buffer space.
-
+
size_t firstIndex = b.size();
StreamUTF8BufferI buffer(*this);
-
+
Byte* lastByte = _stringConverter->toUTF8(vdata, vdata + vsize, buffer);
if(lastByte != b.end())
{
b.resize(lastByte - b.begin());
}
size_t lastIndex = b.size();
-
+
Int actualSize = static_cast<Int>(lastIndex - firstIndex);
-
+
//
// Check against the guess
//
@@ -1396,7 +1392,7 @@ IceInternal::BasicStream::writeConverted(const char* vdata, size_t vsize)
memmove(b.begin() + firstIndex - 4, b.begin() + firstIndex, actualSize);
resize(b.size() - 4);
}
-
+
if(guessedSize <= 254)
{
rewriteSize(actualSize, b.begin() + firstIndex - 1);
@@ -1476,19 +1472,19 @@ IceInternal::BasicStream::write(const wstring& v)
{
Int guessedSize = static_cast<Int>(v.size());
writeSize(guessedSize); // writeSize() only writes the size; it does not reserve any buffer space.
-
+
size_t firstIndex = b.size();
StreamUTF8BufferI buffer(*this);
-
+
Byte* lastByte = _wstringConverter->toUTF8(v.data(), v.data() + v.size(), buffer);
if(lastByte != b.end())
{
b.resize(lastByte - b.begin());
}
size_t lastIndex = b.size();
-
+
Int actualSize = static_cast<Int>(lastIndex - firstIndex);
-
+
//
// Check against the guess
//
@@ -1511,7 +1507,7 @@ IceInternal::BasicStream::write(const wstring& v)
memmove(b.begin() + firstIndex - 4, b.begin() + firstIndex, actualSize);
resize(b.size() - 4);
}
-
+
if(guessedSize <= 254)
{
rewriteSize(actualSize, b.begin() + firstIndex - 1);
@@ -1616,7 +1612,7 @@ IceInternal::BasicStream::readEnum(Int maxValue)
read(value);
return value;
}
- else
+ else
{
Int value;
read(value);
@@ -1629,7 +1625,7 @@ IceInternal::BasicStream::readEnum(Int maxValue)
}
}
-void
+void
IceInternal::BasicStream::writeEnum(Int v, Int maxValue)
{
if(getWriteEncoding() == Encoding_1_0)
@@ -1642,7 +1638,7 @@ IceInternal::BasicStream::writeEnum(Int v, Int maxValue)
{
write(static_cast<Short>(v));
}
- else
+ else
{
write(v);
}
@@ -1695,7 +1691,7 @@ IceInternal::BasicStream::readOptImpl(Int readTag, OptionalFormat expectedFormat
--i; // Rewind
return false;
}
-
+
OptionalFormat format = static_cast<OptionalFormat>(v & 0x07); // First 3 bits.
Int tag = static_cast<Int>(v >> 3);
if(tag == 30)
@@ -1804,7 +1800,7 @@ BasicStream::skipOpts()
{
//
// Skip remaining un-read optional members.
- //
+ //
while(true)
{
if(i >= b.begin() + _currentReadEncaps->start + _currentReadEncaps->sz)
@@ -2003,7 +1999,7 @@ IceInternal::BasicStream::EncapsDecoder::unmarshal(Int index, const Ice::ObjectP
//
// Add the object to the map of un-marshalled objects, this must
// be done before reading the objects (for circular references).
- //
+ //
_unmarshaledMap.insert(make_pair(index, v));
//
@@ -2018,7 +2014,7 @@ IceInternal::BasicStream::EncapsDecoder::unmarshal(Int index, const Ice::ObjectP
if(patchPos != _patchMap.end())
{
assert(patchPos->second.size() > 0);
-
+
//
// Patch all pointers that refer to the instance.
//
@@ -2026,7 +2022,7 @@ IceInternal::BasicStream::EncapsDecoder::unmarshal(Int index, const Ice::ObjectP
{
(*k->patchFunc)(k->patchAddr, v);
}
-
+
//
// Clear out the patch map for that index -- there is nothing left
// to patch for that index for the time being.
@@ -2180,7 +2176,7 @@ IceInternal::BasicStream::EncapsDecoder10::throwException(const UserExceptionFac
readPendingObjects();
}
throw;
-
+
// Never reached.
}
}
@@ -2188,7 +2184,7 @@ IceInternal::BasicStream::EncapsDecoder10::throwException(const UserExceptionFac
//
// Slice off what we don't understand.
//
- skipSlice();
+ skipSlice();
try
{
startSlice();
@@ -2256,7 +2252,7 @@ IceInternal::BasicStream::EncapsDecoder10::startSlice()
//
// For objects, first read the type ID boolean which indicates
// whether or not the type ID is encoded as a string or as an
- // index. For exceptions, the type ID is always encoded as a
+ // index. For exceptions, the type ID is always encoded as a
// string.
//
if(_sliceType == ObjectSlice)
@@ -2264,7 +2260,7 @@ IceInternal::BasicStream::EncapsDecoder10::startSlice()
bool isIndex;
_stream->read(isIndex);
_typeId = readTypeId(isIndex);
- }
+ }
else
{
_stream->read(_typeId, false);
@@ -2281,7 +2277,7 @@ IceInternal::BasicStream::EncapsDecoder10::startSlice()
void
IceInternal::BasicStream::EncapsDecoder10::endSlice()
{
-}
+}
void
IceInternal::BasicStream::EncapsDecoder10::skipSlice()
@@ -2356,7 +2352,7 @@ IceInternal::BasicStream::EncapsDecoder10::readInstance()
{
throw NoObjectFactoryException(__FILE__, __LINE__, "", mostDerivedId);
}
-
+
v = newInstance(_typeId);
//
@@ -2477,7 +2473,7 @@ IceInternal::BasicStream::EncapsDecoder11::throwException(const UserExceptionFac
{
ex.__read(_stream);
throw;
-
+
// Never reached.
}
}
@@ -2485,7 +2481,7 @@ IceInternal::BasicStream::EncapsDecoder11::throwException(const UserExceptionFac
//
// Slice off what we don't understand.
//
- skipSlice();
+ skipSlice();
//
// If this is the last slice, raise an exception and stop un-marshalling.
@@ -2569,7 +2565,7 @@ IceInternal::BasicStream::EncapsDecoder11::startSlice()
_current->typeId.clear();
_current->compactId = -1;
}
- }
+ }
else
{
_stream->read(_current->typeId, false);
@@ -2611,7 +2607,7 @@ IceInternal::BasicStream::EncapsDecoder11::endSlice()
for(IndexList::iterator p = indirectionTable.begin(); p != indirectionTable.end(); ++p)
{
*p = readInstance(_stream->readSize(), 0, 0);
- }
+ }
//
// Sanity checks. If there are optional members, it's possible
@@ -2642,7 +2638,7 @@ IceInternal::BasicStream::EncapsDecoder11::endSlice()
}
_current->indirectPatchList.clear();
}
-}
+}
void
IceInternal::BasicStream::EncapsDecoder11::skipSlice()
@@ -2672,8 +2668,8 @@ IceInternal::BasicStream::EncapsDecoder11::skipSlice()
if(_current->sliceType == ObjectSlice)
{
throw NoObjectFactoryException(
- __FILE__, __LINE__,
- "compact format prevents slicing (the sender should use the sliced format instead)",
+ __FILE__, __LINE__,
+ "compact format prevents slicing (the sender should use the sliced format instead)",
_current->typeId);
}
else
@@ -2751,7 +2747,7 @@ Int
IceInternal::BasicStream::EncapsDecoder11::readInstance(Int index, PatchFunc patchFunc, void* patchAddr)
{
assert(index > 0);
-
+
if(index > 1)
{
if(patchFunc)
@@ -2864,7 +2860,7 @@ IceInternal::BasicStream::EncapsDecoder11::readInstance(Int index, PatchFunc pat
break;
}
-
+
startSlice(); // Read next Slice header for next iteration.
}
@@ -2889,7 +2885,7 @@ IceInternal::BasicStream::EncapsDecoder11::readInstance(Int index, PatchFunc pat
return index;
}
-SlicedDataPtr
+SlicedDataPtr
IceInternal::BasicStream::EncapsDecoder11::readSlicedData()
{
if(_current->slices.empty()) // No preserved slices.
@@ -2959,7 +2955,7 @@ IceInternal::BasicStream::EncapsEncoder10::write(const UserException& v)
//
// User exception with the 1.0 encoding start with a boolean
// flag that indicates whether or not the exception uses
- // classes.
+ // classes.
//
// This allows reading the pending objects even if some part of
// the exception was sliced.
@@ -3083,7 +3079,7 @@ IceInternal::BasicStream::EncapsEncoder10::writePendingObjects()
_stream->writeSize(0); // Zero marker indicates end of sequence of sequences of instances.
}
-Int
+Int
IceInternal::BasicStream::EncapsEncoder10::registerObject(const ObjectPtr& v)
{
assert(v);
@@ -3129,14 +3125,14 @@ IceInternal::BasicStream::EncapsEncoder11::write(const ObjectPtr& v)
// table. The indirect object table is encoded at the end of
// each slice and is always read (even if the Slice is
// unknown).
- //
+ //
PtrToIndexMap::const_iterator p = _current->indirectionMap.find(v);
if(p == _current->indirectionMap.end())
{
_current->indirectionTable.push_back(v);
Int idx = static_cast<Int>(_current->indirectionTable.size()); // Position + 1 (0 is reserved for nil)
_current->indirectionMap.insert(make_pair(v, idx));
- _stream->writeSize(idx);
+ _stream->writeSize(idx);
}
else
{
@@ -3210,7 +3206,7 @@ IceInternal::BasicStream::EncapsEncoder11::startSlice(const string& typeId, int
//
// Encode the type ID (only in the first slice for the compact
// encoding).
- //
+ //
if(_encaps->format == SlicedFormat || _current->firstSlice)
{
if(compactId >= 0)
@@ -3299,7 +3295,7 @@ IceInternal::BasicStream::EncapsEncoder11::endSlice()
*dest = _current->sliceFlags;
}
-bool
+bool
IceInternal::BasicStream::EncapsEncoder11::writeOpt(Ice::Int tag, Ice::OptionalFormat format)
{
if(!_current)
@@ -3339,12 +3335,12 @@ IceInternal::BasicStream::EncapsEncoder11::writeSlicedData(const SlicedDataPtr&
for(SliceInfoSeq::const_iterator p = slicedData->slices.begin(); p != slicedData->slices.end(); ++p)
{
startSlice((*p)->typeId, (*p)->compactId, (*p)->isLastSlice);
-
+
//
// Write the bytes associated with this slice.
//
_stream->writeBlob((*p)->bytes);
-
+
if((*p)->hasOptionalMembers)
{
_current->sliceFlags |= FLAG_HAS_OPTIONAL_MEMBERS;