diff options
49 files changed, 898 insertions, 531 deletions
diff --git a/cpp/include/Ice/BasicStream.h b/cpp/include/Ice/BasicStream.h index d9da7b77dcb..f54f9a181fb 100644 --- a/cpp/include/Ice/BasicStream.h +++ b/cpp/include/Ice/BasicStream.h @@ -251,7 +251,21 @@ public: assert(_currentReadEncaps); Container::size_type start = _currentReadEncaps->start; Ice::Int sz = _currentReadEncaps->sz; - i = b.begin() + start + sz; + if(i != b.begin() + start + sz) + { + if(i + 1 != b.begin() + start + sz) + { + throwEncapsulationException(__FILE__, __LINE__); + } + + // + // Ice version < 3.3 had a bug where user exceptions with + // class members could be encoded with a trailing byte + // when dispatched with AMD. So we tolerate an extra byte + // in the encapsulation. + // + ++i; + } ReadEncaps* oldEncaps = _currentReadEncaps; _currentReadEncaps = _currentReadEncaps->previous; @@ -264,7 +278,27 @@ public: delete oldEncaps; } } - void checkReadEncaps(); + void skipEmptyEncaps() + { + Ice::Int sz; + read(sz); + if(sz < 0) + { + throwNegativeSizeException(__FILE__, __LINE__); + } + + if(sz != static_cast<Ice::Int>(sizeof(Ice::Int)) + 2) + { + throwEncapsulationException(__FILE__, __LINE__); + } + + if(i + 2 > b.end()) + { + throwUnmarshalOutOfBoundsException(__FILE__, __LINE__); + } + i += 2; + } + Ice::Int getReadEncapsSize(); void skipEncaps(); @@ -596,6 +630,7 @@ private: void throwMemoryLimitException(const char*, int); void throwNegativeSizeException(const char*, int); void throwUnsupportedEncodingException(const char*, int, Ice::Byte, Ice::Byte); + void throwEncapsulationException(const char*, int); // // Optimization. The instance may not be deleted while a diff --git a/cpp/include/Ice/Outgoing.h b/cpp/include/Ice/Outgoing.h index 10f3db806e0..403a042a6f1 100644 --- a/cpp/include/Ice/Outgoing.h +++ b/cpp/include/Ice/Outgoing.h @@ -87,6 +87,8 @@ public: BasicStream* is() { return &_is; } BasicStream* os() { return &_os; } + void throwUserException(); + private: // diff --git a/cpp/include/Ice/OutgoingAsync.h b/cpp/include/Ice/OutgoingAsync.h index e72fef15768..12014055e1e 100644 --- a/cpp/include/Ice/OutgoingAsync.h +++ b/cpp/include/Ice/OutgoingAsync.h @@ -85,6 +85,7 @@ protected: void __send(); virtual void __response(bool) = 0; + void __throwUserException(); private: diff --git a/cpp/include/Ice/Stream.h b/cpp/include/Ice/Stream.h index 526df7e11ad..0fa7926ff5e 100644 --- a/cpp/include/Ice/Stream.h +++ b/cpp/include/Ice/Stream.h @@ -85,6 +85,7 @@ public: virtual void startEncapsulation() = 0; virtual void endEncapsulation() = 0; + virtual void skipEncapsulation() = 0; virtual void readPendingObjects() = 0; }; diff --git a/cpp/src/Glacier2/SessionRouterI.cpp b/cpp/src/Glacier2/SessionRouterI.cpp index 830bb978243..28944c97701 100644 --- a/cpp/src/Glacier2/SessionRouterI.cpp +++ b/cpp/src/Glacier2/SessionRouterI.cpp @@ -634,22 +634,30 @@ Glacier2::SessionRouterI::SessionRouterI(const InstancePtr& instance, Identity routerId; routerId.category = _instance->properties()->getPropertyWithDefault("Glacier2.InstanceName", "Glacier2"); routerId.name = "router"; - _instance->clientObjectAdapter()->add(this, routerId); - // - // All other calls on the client object adapter are dispatched to - // a router servant based on connection information. - // - _instance->clientObjectAdapter()->addServantLocator(new ClientLocator(this), ""); - - // - // If there is a server object adapter, all calls on this adapter - // are dispatched to a router servant based on the category field - // of the identity. - // - if(_instance->serverObjectAdapter()) + try + { + _instance->clientObjectAdapter()->add(this, routerId); + + // + // All other calls on the client object adapter are dispatched to + // a router servant based on connection information. + // + _instance->clientObjectAdapter()->addServantLocator(new ClientLocator(this), ""); + + // + // If there is a server object adapter, all calls on this adapter + // are dispatched to a router servant based on the category field + // of the identity. + // + if(_instance->serverObjectAdapter()) + { + _instance->serverObjectAdapter()->addServantLocator(new ServerLocator(this), ""); + } + } + catch(const Ice::ObjectAdapterDeactivatedException&) { - _instance->serverObjectAdapter()->addServantLocator(new ServerLocator(this), ""); + // Ignore. } if(_sessionThread) diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp index e636c0d952d..6c710bd5ab5 100644 --- a/cpp/src/Ice/BasicStream.cpp +++ b/cpp/src/Ice/BasicStream.cpp @@ -291,18 +291,6 @@ IceInternal::BasicStream::ReadEncaps::swap(ReadEncaps& other) std::swap(previous, other.previous); } -void -IceInternal::BasicStream::checkReadEncaps() -{ - assert(_currentReadEncaps); - Container::size_type start = _currentReadEncaps->start; - Int sz = _currentReadEncaps->sz; - if(i != b.begin() + start + sz) - { - throw EncapsulationException(__FILE__, __LINE__); - } -} - Int IceInternal::BasicStream::getReadEncapsSize() { @@ -2017,6 +2005,12 @@ IceInternal::BasicStream::throwUnsupportedEncodingException(const char* file, in } void +IceInternal::BasicStream::throwEncapsulationException(const char* file, int line) +{ + throw EncapsulationException(file, line); +} + +void IceInternal::BasicStream::writeInstance(const ObjectPtr& v, Int index) { write(index); diff --git a/cpp/src/Ice/ConnectRequestHandler.cpp b/cpp/src/Ice/ConnectRequestHandler.cpp index 20d326061dc..d334c1b6c3f 100644 --- a/cpp/src/Ice/ConnectRequestHandler.cpp +++ b/cpp/src/Ice/ConnectRequestHandler.cpp @@ -79,7 +79,6 @@ ConnectRequestHandler::ConnectRequestHandler(const ReferencePtr& ref, RequestHandler(ref), _proxy(proxy), _delegate(delegate), - _response(ref->getMode() == Reference::ModeTwoway), _batchAutoFlush( ref->getInstance()->initializationData().properties->getPropertyAsIntWithDefault("Ice.BatchAutoFlush", 1) > 0), _initialized(false), diff --git a/cpp/src/Ice/ConnectRequestHandler.h b/cpp/src/Ice/ConnectRequestHandler.h index b05a33fdfec..a94505003db 100644 --- a/cpp/src/Ice/ConnectRequestHandler.h +++ b/cpp/src/Ice/ConnectRequestHandler.h @@ -71,7 +71,6 @@ private: Ice::ObjectPrx _proxy; Handle< ::IceDelegate::Ice::Object> _delegate; - const bool _response; const bool _batchAutoFlush; Ice::ConnectionIPtr _connection; diff --git a/cpp/src/Ice/ConnectionRequestHandler.cpp b/cpp/src/Ice/ConnectionRequestHandler.cpp index 736e1cdbc0c..35eb67a6c5a 100644 --- a/cpp/src/Ice/ConnectionRequestHandler.cpp +++ b/cpp/src/Ice/ConnectionRequestHandler.cpp @@ -19,8 +19,7 @@ using namespace std; using namespace IceInternal; ConnectionRequestHandler::ConnectionRequestHandler(const ReferencePtr& reference, const Ice::ObjectPrx& proxy) : - RequestHandler(reference), - _response(reference->getMode() == Reference::ModeTwoway) + RequestHandler(reference) { _connection = _reference->getConnection(_compress); RouterInfoPtr ri = reference->getRouterInfo(); @@ -34,7 +33,6 @@ ConnectionRequestHandler::ConnectionRequestHandler(const ReferencePtr& reference const Ice::ConnectionIPtr& connection, bool compress) : RequestHandler(reference), - _response(reference->getMode() == Reference::ModeTwoway), _connection(connection), _compress(compress) { diff --git a/cpp/src/Ice/ConnectionRequestHandler.h b/cpp/src/Ice/ConnectionRequestHandler.h index 785cda3b5b6..68daba81e31 100644 --- a/cpp/src/Ice/ConnectionRequestHandler.h +++ b/cpp/src/Ice/ConnectionRequestHandler.h @@ -38,7 +38,6 @@ public: private: - const bool _response; Ice::ConnectionIPtr _connection; bool _compress; }; diff --git a/cpp/src/Ice/Incoming.cpp b/cpp/src/Ice/Incoming.cpp index d7d4bd253b0..cddef9f98e4 100644 --- a/cpp/src/Ice/Incoming.cpp +++ b/cpp/src/Ice/Incoming.cpp @@ -296,7 +296,7 @@ IceInternal::Incoming::startOver() // // That's the first startOver, so almost nothing to do // - _inParamPos = _is.i - 6; // 6 bytes for the start of the encaps + _inParamPos = _is.i; } else { @@ -305,9 +305,7 @@ IceInternal::Incoming::startOver() // // Let's rewind _is and clean-up _os // - _is.endReadEncaps(); _is.i = _inParamPos; - _is.startReadEncaps(); if(_response) { @@ -384,8 +382,6 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) _current.ctx.insert(_current.ctx.end(), pr); } - _is.startReadEncaps(); - if(_response) { assert(_os.b.size() == headerSize + 4); // Reply status position. @@ -508,13 +504,11 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) } catch(const std::exception& ex) { - _is.endReadEncaps(); __handleException(ex); return; } catch(...) { - _is.endReadEncaps(); __handleException(); return; } @@ -524,8 +518,6 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) // in the code below are considered fatal, and must propagate to // the caller of this operation. // - - _is.endReadEncaps(); // // DispatchAsync is "pseudo dispatch status", used internally only diff --git a/cpp/src/Ice/Network.cpp b/cpp/src/Ice/Network.cpp index 002ea18b780..70940b2e7c3 100644 --- a/cpp/src/Ice/Network.cpp +++ b/cpp/src/Ice/Network.cpp @@ -878,6 +878,11 @@ IceInternal::doBind(SOCKET fd, struct sockaddr_storage& addr) { size = sizeof(sockaddr_in6); } + else + { + assert(false); + size = 0; // Keep the compiler happy. + } if(bind(fd, reinterpret_cast<struct sockaddr*>(&addr), size) == SOCKET_ERROR) { @@ -927,6 +932,11 @@ repeatConnect: { size = sizeof(sockaddr_in6); } + else + { + assert(false); + size = 0; // Keep the compiler happy. + } if(::connect(fd, reinterpret_cast<struct sockaddr*>(&addr), size) == SOCKET_ERROR) { diff --git a/cpp/src/Ice/Object.cpp b/cpp/src/Ice/Object.cpp index 9c7d05b87f4..7fddcb7f57c 100644 --- a/cpp/src/Ice/Object.cpp +++ b/cpp/src/Ice/Object.cpp @@ -95,17 +95,20 @@ DispatchStatus Ice::Object::___ice_isA(Incoming& __inS, const Current& __current) { BasicStream* __is = __inS.is(); - BasicStream* __os = __inS.os(); + __is->startReadEncaps(); string __id; __is->read(__id, false); + __is->endReadEncaps(); bool __ret = ice_isA(__id, __current); + BasicStream* __os = __inS.os(); __os->write(__ret); return DispatchOK; } DispatchStatus -Ice::Object::___ice_ping(Incoming&, const Current& __current) +Ice::Object::___ice_ping(Incoming& __inS, const Current& __current) { + __inS.is()->skipEmptyEncaps(); ice_ping(__current); return DispatchOK; } @@ -113,8 +116,9 @@ Ice::Object::___ice_ping(Incoming&, const Current& __current) DispatchStatus Ice::Object::___ice_ids(Incoming& __inS, const Current& __current) { - BasicStream* __os = __inS.os(); + __inS.is()->skipEmptyEncaps(); vector<string> __ret = ice_ids(__current); + BasicStream* __os = __inS.os(); __os->write(&__ret[0], &__ret[0] + __ret.size(), false); return DispatchOK; } @@ -122,8 +126,9 @@ Ice::Object::___ice_ids(Incoming& __inS, const Current& __current) DispatchStatus Ice::Object::___ice_id(Incoming& __inS, const Current& __current) { - BasicStream* __os = __inS.os(); + __inS.is()->skipEmptyEncaps(); string __ret = ice_id(__current); + BasicStream* __os = __inS.os(); __os->write(__ret, false); return DispatchOK; } @@ -350,9 +355,12 @@ DispatchStatus Ice::Blobject::__dispatch(Incoming& in, const Current& current) { vector<Byte> inParams; + BasicStream* is = in.is(); + is->startReadEncaps(); + Int sz = is->getReadEncapsSize(); + is->readBlob(inParams, sz); + is->endReadEncaps(); vector<Byte> outParams; - Int sz = in.is()->getReadEncapsSize(); - in.is()->readBlob(inParams, sz); bool ok = ice_invoke(inParams, outParams, current); in.os()->writeBlob(outParams); if(ok) @@ -369,10 +377,13 @@ DispatchStatus Ice::BlobjectArray::__dispatch(Incoming& in, const Current& current) { pair<const Byte*, const Byte*> inParams; - vector<Byte> outParams; - Int sz = in.is()->getReadEncapsSize(); - in.is()->readBlob(inParams.first, sz); + BasicStream* is = in.is(); + is->startReadEncaps(); + Int sz = is->getReadEncapsSize(); + is->readBlob(inParams.first, sz); inParams.second = inParams.first + sz; + is->endReadEncaps(); + vector<Byte> outParams; bool ok = ice_invoke(inParams, outParams, current); in.os()->writeBlob(outParams); if(ok) @@ -389,8 +400,11 @@ DispatchStatus Ice::BlobjectAsync::__dispatch(Incoming& in, const Current& current) { vector<Byte> inParams; - Int sz = in.is()->getReadEncapsSize(); - in.is()->readBlob(inParams, sz); + BasicStream* is = in.is(); + is->startReadEncaps(); + Int sz = is->getReadEncapsSize(); + is->readBlob(inParams, sz); + is->endReadEncaps(); AMD_Object_ice_invokePtr cb = new ::IceAsync::Ice::AMD_Object_ice_invoke(in); try { @@ -411,9 +425,12 @@ DispatchStatus Ice::BlobjectArrayAsync::__dispatch(Incoming& in, const Current& current) { pair<const Byte*, const Byte*> inParams; - Int sz = in.is()->getReadEncapsSize(); - in.is()->readBlob(inParams.first, sz); + BasicStream* is = in.is(); + is->startReadEncaps(); + Int sz = is->getReadEncapsSize(); + is->readBlob(inParams.first, sz); inParams.second = inParams.first + sz; + is->endReadEncaps(); AMD_Array_Object_ice_invokePtr cb = new ::IceAsync::Ice::AMD_Array_Object_ice_invoke(in); try { diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index dbc65756136..7d6028a75c8 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -686,9 +686,13 @@ Ice::ObjectAdapterI::isLocal(const ObjectPrx& proxy) const { for(p = endpoints.begin(); p != endpoints.end(); ++p) { - if(binary_search(_routerEndpoints.begin(), _routerEndpoints.end(), *p)) // _routerEndpoints is sorted. + vector<EndpointIPtr>::const_iterator r; + for(r = _routerEndpoints.begin(); r != _routerEndpoints.end(); ++r) { - return true; + if((*p)->equivalent(*r)) + { + return true; + } } } } diff --git a/cpp/src/Ice/Outgoing.cpp b/cpp/src/Ice/Outgoing.cpp index 24d6263ac2d..8f9b716e52c 100644 --- a/cpp/src/Ice/Outgoing.cpp +++ b/cpp/src/Ice/Outgoing.cpp @@ -374,24 +374,12 @@ IceInternal::Outgoing::finished(BasicStream& is) { case replyOK: { - // - // Input and output parameters are always sent in an - // encapsulation, which makes it possible to forward - // oneway requests as blobs. - // - _is.startReadEncaps(); _state = StateOK; // The state must be set last, in case there is an exception. break; } case replyUserException: { - // - // Input and output parameters are always sent in an - // encapsulation, which makes it possible to forward - // oneway requests as blobs. - // - _is.startReadEncaps(); _state = StateUserException; // The state must be set last, in case there is an exception. break; } @@ -534,6 +522,21 @@ IceInternal::Outgoing::finished(const LocalException& ex) _monitor.notify(); } +void +IceInternal::Outgoing::throwUserException() +{ + try + { + _is.startReadEncaps(); + _is.throwException(); + } + catch(const Ice::UserException&) + { + _is.endReadEncaps(); + throw; + } +} + IceInternal::BatchOutgoing::BatchOutgoing(RequestHandler* handler) : _handler(handler), _connection(0), diff --git a/cpp/src/Ice/OutgoingAsync.cpp b/cpp/src/Ice/OutgoingAsync.cpp index f215964e4d9..51887688b6a 100644 --- a/cpp/src/Ice/OutgoingAsync.cpp +++ b/cpp/src/Ice/OutgoingAsync.cpp @@ -241,7 +241,6 @@ IceInternal::OutgoingAsync::__finished(BasicStream& is) case replyOK: case replyUserException: { - __is->startReadEncaps(); break; } @@ -521,6 +520,21 @@ IceInternal::OutgoingAsync::__send() } void +IceInternal::OutgoingAsync::__throwUserException() +{ + try + { + __is->startReadEncaps(); + __is->throwException(); + } + catch(const Ice::UserException&) + { + __is->endReadEncaps(); + throw; + } +} + +void IceInternal::OutgoingAsync::handleException(const LocalExceptionWrapper& ex) { if(_mode == Nonmutating || _mode == Idempotent) @@ -637,8 +651,10 @@ Ice::AMI_Object_ice_invoke::__response(bool ok) // ok == true means no user exce vector<Byte> outParams; try { + __is->startReadEncaps(); Int sz = __is->getReadEncapsSize(); __is->readBlob(outParams, sz); + __is->endReadEncaps(); } catch(const LocalException& ex) { @@ -673,9 +689,11 @@ Ice::AMI_Array_Object_ice_invoke::__response(bool ok) // ok == true means no use pair<const Byte*, const Byte*> outParams; try { + __is->startReadEncaps(); Int sz = __is->getReadEncapsSize(); __is->readBlob(outParams.first, sz); outParams.second = outParams.first + sz; + __is->endReadEncaps(); } catch(const LocalException& ex) { diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index 1191532eda2..124ae11f4bb 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -1170,19 +1170,21 @@ IceDelegateM::Ice::Object::ice_isA(const string& __id, const Context* context) bool __ok = __og.invoke(); try { - BasicStream* __is = __og.is(); if(!__ok) { try { - __is->throwException(); + __og.throwUserException(); } catch(const ::Ice::UserException& __ex) { throw ::Ice::UnknownUserException(__FILE__, __LINE__, __ex.ice_name()); } } + BasicStream* __is = __og.is(); + __is->startReadEncaps(); __is->read(__ret); + __is->endReadEncaps(); } catch(const ::Ice::LocalException& __ex) { @@ -1197,24 +1199,27 @@ IceDelegateM::Ice::Object::ice_ping(const Context* context) static const string __operation("ice_ping"); Outgoing __og(__handler.get(), __operation, ::Ice::Nonmutating, context); bool __ok = __og.invoke(); - try + if(!__og.is()->b.empty()) { - BasicStream* __is = __og.is(); - if(!__ok) + try { - try - { - __is->throwException(); - } - catch(const ::Ice::UserException& __ex) + if(!__ok) { - throw ::Ice::UnknownUserException(__FILE__, __LINE__, __ex.ice_name()); + try + { + __og.throwUserException(); + } + catch(const ::Ice::UserException& __ex) + { + throw ::Ice::UnknownUserException(__FILE__, __LINE__, __ex.ice_name()); + } } + __og.is()->skipEmptyEncaps(); + } + catch(const ::Ice::LocalException& __ex) + { + throw ::IceInternal::LocalExceptionWrapper(__ex, false); } - } - catch(const ::Ice::LocalException& __ex) - { - throw ::IceInternal::LocalExceptionWrapper(__ex, false); } } @@ -1227,19 +1232,21 @@ IceDelegateM::Ice::Object::ice_ids(const Context* context) bool __ok = __og.invoke(); try { - BasicStream* __is = __og.is(); if(!__ok) { try { - __is->throwException(); + __og.throwUserException(); } catch(const ::Ice::UserException& __ex) { throw ::Ice::UnknownUserException(__FILE__, __LINE__, __ex.ice_name()); } } + BasicStream* __is = __og.is(); + __is->startReadEncaps(); __is->read(__ret, false); + __is->endReadEncaps(); } catch(const ::Ice::LocalException& __ex) { @@ -1257,19 +1264,21 @@ IceDelegateM::Ice::Object::ice_id(const Context* context) bool __ok = __og.invoke(); try { - BasicStream* __is = __og.is(); if(!__ok) { try { - __is->throwException(); + __og.throwUserException(); } catch(const ::Ice::UserException& __ex) { throw ::Ice::UnknownUserException(__FILE__, __LINE__, __ex.ice_name()); } } + BasicStream* __is = __og.is(); + __is->startReadEncaps(); __is->read(__ret, false); + __is->endReadEncaps(); } catch(const ::Ice::LocalException& __ex) { @@ -1301,8 +1310,10 @@ IceDelegateM::Ice::Object::ice_invoke(const string& operation, try { BasicStream* __is = __og.is(); + __is->startReadEncaps(); Int sz = __is->getReadEncapsSize(); __is->readBlob(outParams, sz); + __is->endReadEncaps(); } catch(const ::Ice::LocalException& __ex) { diff --git a/cpp/src/Ice/RequestHandler.cpp b/cpp/src/Ice/RequestHandler.cpp index cf2845c77ae..f1937fda7f7 100644 --- a/cpp/src/Ice/RequestHandler.cpp +++ b/cpp/src/Ice/RequestHandler.cpp @@ -8,6 +8,7 @@ // ********************************************************************** #include <Ice/RequestHandler.h> +#include <Ice/Reference.h> using namespace std; using namespace IceInternal; @@ -18,6 +19,8 @@ RequestHandler::~RequestHandler() { } -RequestHandler::RequestHandler(const ReferencePtr& reference) : _reference(reference) +RequestHandler::RequestHandler(const ReferencePtr& reference) : + _reference(reference), + _response(reference->getMode() == Reference::ModeTwoway) { } diff --git a/cpp/src/Ice/RequestHandler.h b/cpp/src/Ice/RequestHandler.h index 1b22794930c..7a5b585e0ee 100644 --- a/cpp/src/Ice/RequestHandler.h +++ b/cpp/src/Ice/RequestHandler.h @@ -48,6 +48,7 @@ protected: RequestHandler(const ReferencePtr&); const ReferencePtr _reference; + const bool _response; }; } diff --git a/cpp/src/Ice/StreamI.cpp b/cpp/src/Ice/StreamI.cpp index b0458637dfe..7f2ee26dadf 100644 --- a/cpp/src/Ice/StreamI.cpp +++ b/cpp/src/Ice/StreamI.cpp @@ -309,6 +309,12 @@ Ice::InputStreamI::endEncapsulation() } void +Ice::InputStreamI::skipEncapsulation() +{ + _is->skipEncaps(); +} + +void Ice::InputStreamI::skipSlice() { _is->skipSlice(); diff --git a/cpp/src/Ice/StreamI.h b/cpp/src/Ice/StreamI.h index 1f00533612d..22c9bd8079d 100644 --- a/cpp/src/Ice/StreamI.h +++ b/cpp/src/Ice/StreamI.h @@ -80,6 +80,7 @@ public: virtual void skipSlice(); virtual void startEncapsulation(); + virtual void skipEncapsulation(); virtual void endEncapsulation(); virtual void readPendingObjects(); diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index bb88118354c..d68c2f4d8c2 100755 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -2622,17 +2622,22 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p) C << nl << "__og.abort(__ex);"; C << eb; } + C << nl << "bool __ok = __og.invoke();"; + if(!p->returnsData()) + { + C << nl << "if(!__og.is()->b.empty())"; + C << sb; + } C << nl << "try"; C << sb; - C << nl << "::IceInternal::BasicStream* __is = __og.is();"; C << nl << "if(!__ok)"; C << sb; C << nl << "try"; C << sb; - C << nl << "__is->throwException();"; + C << nl << "__og.throwUserException();"; C << eb; - + // // Generate a catch block for each legal user exception. This is necessary // to prevent an "impossible" user exception to be thrown if client and @@ -2686,11 +2691,23 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p) C << nl << fixKwd((*opi)->name()) << " = new " << fixKwd(st->scoped()) << ";"; } } - writeUnmarshalCode(C, outParams, ret, p->getMetaData()); - if(p->returnsClasses()) + + if(p->returnsData()) + { + C << nl << "::IceInternal::BasicStream* __is = __og.is();"; + C << nl << "__is->startReadEncaps();"; + writeUnmarshalCode(C, outParams, ret, p->getMetaData()); + if(p->returnsClasses()) + { + C << nl << "__is->readPendingObjects();"; + } + C << nl << "__is->endReadEncaps();"; + } + else { - C << nl << "__is->readPendingObjects();"; + C << nl << "__og.is()->skipEmptyEncaps();"; } + if(ret) { C << nl << "return __ret;"; @@ -2700,6 +2717,10 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p) C << sb; C << nl << "throw ::IceInternal::LocalExceptionWrapper(__ex, false);"; C << eb; + if(!p->returnsData()) + { + C << eb; + } C << eb; } @@ -3991,11 +4012,7 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) C << sp; C << nl << "::Ice::DispatchStatus" << nl << scope.substr(2) << "___" << name - << "(::IceInternal::Incoming&"; - if(!paramList.empty() || !p->throws().empty() || ret || amd) - { - C << "__inS"; - } + << "(::IceInternal::Incoming& __inS"; C << ", const ::Ice::Current& __current)" << (isConst ? " const" : ""); C << sb; if(!amd) @@ -4022,16 +4039,23 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) if(!inParams.empty()) { C << nl << "::IceInternal::BasicStream* __is = __inS.is();"; + C << nl << "__is->startReadEncaps();"; + writeAllocateCode(C, inParams, 0, StringList(), _useWstring, true); + writeUnmarshalCode(C, inParams, 0, StringList(), true); + if(p->sendsClasses()) + { + C << nl << "__is->readPendingObjects();"; + } + C << nl << "__is->endReadEncaps();"; } - if(ret || !outParams.empty() || !throws.empty()) + else { - C << nl << "::IceInternal::BasicStream* __os = __inS.os();"; + C << nl << "__inS.is()->skipEmptyEncaps();"; } - writeAllocateCode(C, inParams, 0, StringList(), _useWstring, true); - writeUnmarshalCode(C, inParams, 0, StringList(), true); - if(p->sendsClasses()) + + if(ret || !outParams.empty() || !throws.empty()) { - C << nl << "__is->readPendingObjects();"; + C << nl << "::IceInternal::BasicStream* __os = __inS.os();"; } writeAllocateCode(C, outParams, 0, StringList(), _useWstring); if(!throws.empty()) @@ -4063,6 +4087,7 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) C << eb; } } + C << nl << "return ::Ice::DispatchOK;"; } else @@ -4072,13 +4097,20 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) if(!inParams.empty()) { C << nl << "::IceInternal::BasicStream* __is = __inS.is();"; + C << nl << "__is->startReadEncaps();"; + writeAllocateCode(C, inParams, 0, StringList(), _useWstring, true); + writeUnmarshalCode(C, inParams, 0, StringList(), true); + if(p->sendsClasses()) + { + C << nl << "__is->readPendingObjects();"; + } + C << nl << "__is->endReadEncaps();"; } - writeAllocateCode(C, inParams, 0, StringList(), _useWstring, true); - writeUnmarshalCode(C, inParams, 0, StringList(), true); - if(p->sendsClasses()) + else { - C << nl << "__is->readPendingObjects();"; + C << nl << "__inS.is()->skipEmptyEncaps();"; } + C << nl << classScopedAMD << '_' << name << "Ptr __cb = new IceAsync" << classScopedAMD << '_' << name << "(__inS);"; C << nl << "try"; @@ -5247,7 +5279,7 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) C << sb; C << nl << "try"; C << sb; - C << nl << "__is->throwException();"; + C << nl << "__throwUserException();"; C << eb; // // Generate a catch block for each legal user exception. @@ -5276,14 +5308,23 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) C << nl << "return;"; C << eb; - writeUnmarshalCode(C, outParams, 0, StringList(), true); - if(ret) + if(p->returnsData()) { - writeMarshalUnmarshalCode(C, ret, "__ret", false, "", true, p->getMetaData(), true); + C << nl << "__is->startReadEncaps();"; + writeUnmarshalCode(C, outParams, 0, StringList(), true); + if(ret) + { + writeMarshalUnmarshalCode(C, ret, "__ret", false, "", true, p->getMetaData(), true); + } + if(p->returnsClasses()) + { + C << nl << "__is->readPendingObjects();"; + } + C << nl << "__is->endReadEncaps();"; } - if(p->returnsClasses()) + else { - C << nl << "__is->readPendingObjects();"; + C << nl << "__is->skipEmptyEncaps();"; } C << eb; C << nl << "catch(const ::Ice::LocalException& __ex)"; diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 3ac77fe0918..6921360f09c 100755 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -305,51 +305,57 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) _out << nl << "checkMode__(" << sliceModeToIceMode(op->mode()) << ", current__.mode);"; if(!inParams.empty()) { + // + // Unmarshal 'in' parameters. + // _out << nl << "IceInternal.BasicStream is__ = inS__.istr();"; - } - if(!outParams.empty() || ret || !throws.empty()) - { - _out << nl << "IceInternal.BasicStream os__ = inS__.ostr();"; - } - - // - // Unmarshal 'in' parameters. - // - for(q = inParams.begin(); q != inParams.end(); ++q) - { - string param = fixId(q->second); - string typeS = typeToString(q->first); - BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); - bool isClass = (builtin && builtin->kind() == Builtin::KindObject) - || ClassDeclPtr::dynamicCast(q->first); - if(!isClass) + _out << nl << "is__.startReadEncaps();"; + for(q = inParams.begin(); q != inParams.end(); ++q) { - _out << nl << typeS << ' ' << param << ';'; - StructPtr st = StructPtr::dynamicCast(q->first); - if(st) + string param = fixId(q->second); + string typeS = typeToString(q->first); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); + bool isClass = (builtin && builtin->kind() == Builtin::KindObject) + || ClassDeclPtr::dynamicCast(q->first); + if(!isClass) { - if(isValueType(q->first)) + _out << nl << typeS << ' ' << param << ';'; + StructPtr st = StructPtr::dynamicCast(q->first); + if(st) { - _out << nl << param << " = new " << typeS << "();"; - } - else - { - _out << nl << param << " = null;"; + if(isValueType(q->first)) + { + _out << nl << param << " = new " << typeS << "();"; + } + else + { + _out << nl << param << " = null;"; + } } } + writeMarshalUnmarshalCode(_out, q->first, param, false, false, true); + } + if(op->sendsClasses()) + { + _out << nl << "is__.readPendingObjects();"; } - writeMarshalUnmarshalCode(_out, q->first, param, false, false, true); + _out << nl << "is__.endReadEncaps();"; } - if(op->sendsClasses()) + else { - _out << nl << "is__.readPendingObjects();"; + _out << nl << "inS__.istr().skipEmptyEncaps();"; } - + for(q = outParams.begin(); q != outParams.end(); ++q) { string typeS = typeToString(q->first); _out << nl << typeS << ' ' << fixId(q->second) << ";"; } + + if(!outParams.empty() || ret || !throws.empty()) + { + _out << nl << "IceInternal.BasicStream os__ = inS__.ostr();"; + } // // Call on the servant. @@ -444,42 +450,47 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) if(!inParams.empty()) { + // + // Unmarshal 'in' parameters. + // _out << nl << "IceInternal.BasicStream is__ = inS__.istr();"; - } - - // - // Unmarshal 'in' parameters. - // - for(q = inParams.begin(); q != inParams.end(); ++q) - { - string param = fixId(q->second); - string typeS = typeToString(q->first); - BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); - bool isClass = (builtin && builtin->kind() == Builtin::KindObject) - || ClassDeclPtr::dynamicCast(q->first); - if(!isClass) + _out << nl << "is__.startReadEncaps();"; + for(q = inParams.begin(); q != inParams.end(); ++q) { - _out << nl << typeS << ' ' << param << ';'; - StructPtr st = StructPtr::dynamicCast(q->first); - if(st) + string param = fixId(q->second); + string typeS = typeToString(q->first); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); + bool isClass = (builtin && builtin->kind() == Builtin::KindObject) + || ClassDeclPtr::dynamicCast(q->first); + if(!isClass) { - if(isValueType(q->first)) - { - _out << nl << param << " = new " << typeS << "();"; - } - else + _out << nl << typeS << ' ' << param << ';'; + StructPtr st = StructPtr::dynamicCast(q->first); + if(st) { - _out << nl << param << " = null;"; + if(isValueType(q->first)) + { + _out << nl << param << " = new " << typeS << "();"; + } + else + { + _out << nl << param << " = null;"; + } } } + writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, false, true); } - writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, false, true); + if(op->sendsClasses()) + { + _out << nl << "is__.readPendingObjects();"; + } + _out << nl << "is__.endReadEncaps();"; } - if(op->sendsClasses()) + else { - _out << nl << "is__.readPendingObjects();"; + _out << nl << "inS__.istr().skipEmptyEncaps();"; } - + // // Call on the servant. // @@ -3856,9 +3867,13 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) _out << eb; } _out << nl << "bool ok__ = og__.invoke();"; + if(!op->returnsData()) + { + _out << nl << "if(!og__.istr().isEmpty())"; + _out << sb; + } _out << nl << "try"; _out << sb; - _out << nl << "IceInternal.BasicStream is__ = og__.istr();"; _out << nl << "if(!ok__)"; _out << sb; // @@ -3867,7 +3882,7 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) // _out << nl << "try"; _out << sb; - _out << nl << "is__.throwException();"; + _out << nl << "og__.throwUserException();"; _out << eb; for(ExceptionList::const_iterator t = throws.begin(); t != throws.end(); ++t) { @@ -3881,76 +3896,87 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) _out << nl << "throw new Ice.UnknownUserException(ex.ice_name(), ex);"; _out << eb; _out << eb; - for(q = outParams.begin(); q != outParams.end(); ++q) + if(op->returnsData()) { - string param = fixId(q->second); - StructPtr st = StructPtr::dynamicCast(q->first); - if(st) + _out << nl << "IceInternal.BasicStream is__ = og__.istr();"; + _out << nl << "is__.startReadEncaps();"; + for(q = outParams.begin(); q != outParams.end(); ++q) + { + string param = fixId(q->second); + StructPtr st = StructPtr::dynamicCast(q->first); + if(st) + { + if(isValueType(q->first)) + { + _out << nl << param << " = new " << typeToString(q->first) << "();"; + } + else + { + _out << nl << param << " = null;"; + } + } + writeMarshalUnmarshalCode(_out, q->first, param, false, false, true, ""); + } + if(ret) { - if(isValueType(q->first)) + BuiltinPtr builtin = BuiltinPtr::dynamicCast(ret); + if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(ret)) { - _out << nl << param << " = new " << typeToString(q->first) << "();"; + _out << nl << retS << " ret__;"; + ContainedPtr contained = ContainedPtr::dynamicCast(ret); + string sliceId = contained ? contained->scoped() : "::Ice::Object"; + _out << nl << "IceInternal.ParamPatcher<" << retS << "> ret___PP = new IceInternal.ParamPatcher<" + << retS << ">(\"" << sliceId << "\");"; + _out << nl << "is__.readObject(ret___PP);"; } else { - _out << nl << param << " = null;"; + _out << nl << retS << " ret__;"; + StructPtr st = StructPtr::dynamicCast(ret); + if(st) + { + if(isValueType(st)) + { + _out << nl << "ret__ = new " << retS << "();"; + } + else + { + _out << nl << "ret__ = null;"; + } + } + writeMarshalUnmarshalCode(_out, ret, "ret__", false, false, true, ""); } } - writeMarshalUnmarshalCode(_out, q->first, param, false, false, true, ""); - } - if(ret) - { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(ret); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(ret)) - { - _out << nl << retS << " ret__;"; - ContainedPtr contained = ContainedPtr::dynamicCast(ret); - string sliceId = contained ? contained->scoped() : "::Ice::Object"; - _out << nl << "IceInternal.ParamPatcher<" << retS << "> ret___PP = new IceInternal.ParamPatcher<" - << retS << ">(\"" << sliceId << "\");"; - _out << nl << "is__.readObject(ret___PP);"; - } - else + if(op->returnsClasses()) { - _out << nl << retS << " ret__;"; - StructPtr st = StructPtr::dynamicCast(ret); - if(st) + _out << nl << "is__.readPendingObjects();"; + for(q = outParams.begin(); q != outParams.end(); ++q) { - if(isValueType(st)) - { - _out << nl << "ret__ = new " << retS << "();"; - } - else - { - _out << nl << "ret__ = null;"; + string param = fixId(q->second); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); + if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(q->first)) + { + string type = typeToString(q->first); + _out << nl << "try"; + _out << sb; + _out << nl << param << " = (" << type << ")" << param << "_PP.value;"; + _out << eb; + _out << nl << "catch(System.InvalidCastException)"; + _out << sb; + _out << nl << param << " = null;"; + _out << nl << "IceInternal.Ex.throwUOE(" << param << "_PP.type(), " + << param << "_PP.value.ice_id());"; + _out << eb; } } - writeMarshalUnmarshalCode(_out, ret, "ret__", false, false, true, ""); } + _out << nl << "is__.endReadEncaps();"; } - if(op->returnsClasses()) + else { - _out << nl << "is__.readPendingObjects();"; - for(q = outParams.begin(); q != outParams.end(); ++q) - { - string param = fixId(q->second); - BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(q->first)) - { - string type = typeToString(q->first); - _out << nl << "try"; - _out << sb; - _out << nl << param << " = (" << type << ")" << param << "_PP.value;"; - _out << eb; - _out << nl << "catch(System.InvalidCastException)"; - _out << sb; - _out << nl << param << " = null;"; - _out << nl << "IceInternal.Ex.throwUOE(" << param << "_PP.type(), " - << param << "_PP.value.ice_id());"; - _out << eb; - } - } + _out << nl << "og__.istr().skipEmptyEncaps();"; } + if(ret) { BuiltinPtr builtin = BuiltinPtr::dynamicCast(ret); @@ -3973,6 +3999,10 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) _out << sb; _out << nl << "throw new IceInternal.LocalExceptionWrapper(ex__, false);"; _out << eb; + if(!op->returnsData()) + { + _out << eb; + } _out << eb; _out << nl << "finally"; _out << sb; @@ -4450,7 +4480,7 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) _out << sb; _out << nl << "try"; _out << sb; - _out << nl << "is__.throwException();"; + _out << nl << "throwUserException__();"; _out << eb; for(ExceptionList::const_iterator r = throws.begin(); r != throws.end(); ++r) { @@ -4465,59 +4495,68 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) _out << eb; _out << "return;"; _out << eb; - for(q = outParams.begin(); q != outParams.end(); ++q) + if(p->returnsData()) { - string param = fixId(q->second); - StructPtr st = StructPtr::dynamicCast(q->first); - if(st) - if(isValueType(st)) - { - _out << nl << param << " = new " << typeToString(q->first) << "();"; - } - else + _out << nl << "is__.startReadEncaps();"; + for(q = outParams.begin(); q != outParams.end(); ++q) { - _out << nl << param << " = null;"; + string param = fixId(q->second); + StructPtr st = StructPtr::dynamicCast(q->first); + if(st) + if(isValueType(st)) + { + _out << nl << param << " = new " << typeToString(q->first) << "();"; + } + else + { + _out << nl << param << " = null;"; + } + writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, false, true); } - writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, false, true); - } - if(ret) - { - StructPtr st = StructPtr::dynamicCast(ret); - if(st) + if(ret) { - if(isValueType(ret)) + StructPtr st = StructPtr::dynamicCast(ret); + if(st) { - _out << nl << "ret__ = new " << retS << "();"; + if(isValueType(ret)) + { + _out << nl << "ret__ = new " << retS << "();"; + } + else + { + _out << nl << "ret__ = null;"; + } } - else + writeMarshalUnmarshalCode(_out, ret, "ret__", false, false, true); + } + if(p->returnsClasses()) + { + _out << nl << "is__.readPendingObjects();"; + } + _out << nl << "is__.endReadEncaps();"; + for(q = outParams.begin(); q != outParams.end(); ++q) + { + string param = fixId(q->second); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); + if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(q->first)) { - _out << nl << "ret__ = null;"; + string type = typeToString(q->first); + _out << nl << param << " = (" << type << ")" << param << "_PP.value;"; } } - writeMarshalUnmarshalCode(_out, ret, "ret__", false, false, true); - } - if(p->returnsClasses()) - { - _out << nl << "is__.readPendingObjects();"; - } - for(q = outParams.begin(); q != outParams.end(); ++q) - { - string param = fixId(q->second); - BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(q->first)) + if(ret) { - string type = typeToString(q->first); - _out << nl << param << " = (" << type << ")" << param << "_PP.value;"; + BuiltinPtr builtin = BuiltinPtr::dynamicCast(ret); + if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(ret)) + { + string type = typeToString(ret); + _out << nl << "ret__ = (" << retS << ")ret___PP.value;"; + } } } - if(ret) + else { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(ret); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(ret)) - { - string type = typeToString(ret); - _out << nl << "ret__ = (" << retS << ")ret___PP.value;"; - } + _out << nl << "is__.skipEmptyEncaps();"; } _out << eb; _out << nl << "catch(Ice.LocalException ex__)"; diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp index 6990c90618c..ddf80905a61 100644 --- a/cpp/src/slice2java/Gen.cpp +++ b/cpp/src/slice2java/Gen.cpp @@ -634,41 +634,42 @@ Slice::JavaVisitor::writeDispatchAndMarshalling(Output& out, const ClassDefPtr& if(!inParams.empty()) { + // + // Unmarshal 'in' parameters. + // out << nl << "IceInternal.BasicStream __is = __inS.is();"; - } - if(!outParams.empty() || ret || !throws.empty()) - { - out << nl << "IceInternal.BasicStream __os = __inS.os();"; - } - - // - // Unmarshal 'in' parameters. - // - iter = 0; - for(pli = inParams.begin(); pli != inParams.end(); ++pli) - { - StringList metaData = (*pli)->getMetaData(); - TypePtr paramType = (*pli)->type(); - string paramName = fixKwd((*pli)->name()); - string typeS = typeToString(paramType, TypeModeIn, package, metaData); - BuiltinPtr builtin = BuiltinPtr::dynamicCast(paramType); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(paramType)) + out << nl << "__is.startReadEncaps();"; + iter = 0; + for(pli = inParams.begin(); pli != inParams.end(); ++pli) { - out << nl << typeS << "Holder " << paramName << " = new " << typeS << "Holder();"; - writeMarshalUnmarshalCode(out, package, paramType, paramName, false, iter, true, - metaData, string()); + StringList metaData = (*pli)->getMetaData(); + TypePtr paramType = (*pli)->type(); + string paramName = fixKwd((*pli)->name()); + string typeS = typeToString(paramType, TypeModeIn, package, metaData); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(paramType); + if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(paramType)) + { + out << nl << typeS << "Holder " << paramName << " = new " << typeS << "Holder();"; + writeMarshalUnmarshalCode(out, package, paramType, paramName, false, iter, true, + metaData, string()); + } + else + { + out << nl << typeS << ' ' << paramName << ';'; + writeMarshalUnmarshalCode(out, package, paramType, paramName, false, iter, false, metaData); + } } - else + if(op->sendsClasses()) { - out << nl << typeS << ' ' << paramName << ';'; - writeMarshalUnmarshalCode(out, package, paramType, paramName, false, iter, false, metaData); + out << nl << "__is.readPendingObjects();"; } + out << nl << "__is.endReadEncaps();"; } - if(op->sendsClasses()) + else { - out << nl << "__is.readPendingObjects();"; + out << nl << "__inS.is().skipEmptyEncaps();"; } - + // // Create holders for 'out' parameters. // @@ -678,6 +679,11 @@ Slice::JavaVisitor::writeDispatchAndMarshalling(Output& out, const ClassDefPtr& out << nl << typeS << ' ' << fixKwd((*pli)->name()) << " = new " << typeS << "();"; } + if(!outParams.empty() || ret || !throws.empty()) + { + out << nl << "IceInternal.BasicStream __os = __inS.os();"; + } + // // Call on the servant. // @@ -764,40 +770,45 @@ Slice::JavaVisitor::writeDispatchAndMarshalling(Output& out, const ClassDefPtr& int iter; out << nl << "__checkMode(" << sliceModeToIceMode(op->mode()) << ", __current.mode);"; - + if(!inParams.empty()) { + // + // Unmarshal 'in' parameters. + // out << nl << "IceInternal.BasicStream __is = __inS.is();"; - } - - // - // Unmarshal 'in' parameters. - // - iter = 0; - for(pli = inParams.begin(); pli != inParams.end(); ++pli) - { - StringList metaData = (*pli)->getMetaData(); - TypePtr paramType = (*pli)->type(); - string paramName = fixKwd((*pli)->name()); - string typeS = typeToString(paramType, TypeModeIn, package, metaData); - BuiltinPtr builtin = BuiltinPtr::dynamicCast(paramType); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(paramType)) + out << nl << "__is.startReadEncaps();"; + iter = 0; + for(pli = inParams.begin(); pli != inParams.end(); ++pli) { - out << nl << typeS << "Holder " << paramName << " = new " << typeS << "Holder();"; - writeMarshalUnmarshalCode(out, package, paramType, paramName, false, iter, true, metaData, - string()); + StringList metaData = (*pli)->getMetaData(); + TypePtr paramType = (*pli)->type(); + string paramName = fixKwd((*pli)->name()); + string typeS = typeToString(paramType, TypeModeIn, package, metaData); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(paramType); + if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(paramType)) + { + out << nl << typeS << "Holder " << paramName << " = new " << typeS << "Holder();"; + writeMarshalUnmarshalCode(out, package, paramType, paramName, false, iter, true, metaData, + string()); + } + else + { + out << nl << typeS << ' ' << paramName << ';'; + writeMarshalUnmarshalCode(out, package, paramType, paramName, false, iter, false, metaData); + } } - else + if(op->sendsClasses()) { - out << nl << typeS << ' ' << paramName << ';'; - writeMarshalUnmarshalCode(out, package, paramType, paramName, false, iter, false, metaData); + out << nl << "__is.readPendingObjects();"; } + out << nl << "__is.endReadEncaps();"; } - if(op->sendsClasses()) + else { - out << nl << "__is.readPendingObjects();"; + out << nl << "__inS.is().skipEmptyEncaps();"; } - + // // Call on the servant. // @@ -4225,15 +4236,21 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) out << nl << "__og.abort(__ex);"; out << eb; } + out << nl << "boolean __ok = __og.invoke();"; + if(!op->returnsData()) + { + out << nl << "if(!__og.is().isEmpty())"; + out << sb; + } + out << nl << "try"; out << sb; - out << nl << "IceInternal.BasicStream __is = __og.is();"; out << nl << "if(!__ok)"; out << sb; out << nl << "try"; out << sb; - out << nl << "__is.throwException();"; + out << nl << "__og.throwUserException();"; out << eb; for(ExceptionList::const_iterator t = throws.begin(); t != throws.end(); ++t) { @@ -4247,29 +4264,40 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) out << nl << "throw new Ice.UnknownUserException(__ex.ice_name());"; out << eb; out << eb; - for(pli = outParams.begin(); pli != outParams.end(); ++pli) - { - writeMarshalUnmarshalCode(out, package, (*pli)->type(), fixKwd((*pli)->name()), false, iter, true, - (*pli)->getMetaData()); - } - if(ret) + if(op->returnsData()) { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(ret); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(ret)) + out << nl << "IceInternal.BasicStream __is = __og.is();"; + out << nl << "__is.startReadEncaps();"; + for(pli = outParams.begin(); pli != outParams.end(); ++pli) { - out << nl << retS << "Holder __ret = new " << retS << "Holder();"; - out << nl << "__is.readObject(__ret.getPatcher());"; + writeMarshalUnmarshalCode(out, package, (*pli)->type(), fixKwd((*pli)->name()), false, iter, true, + (*pli)->getMetaData()); } - else + if(ret) { - out << nl << retS << " __ret;"; - writeMarshalUnmarshalCode(out, package, ret, "__ret", false, iter, false, opMetaData); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(ret); + if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(ret)) + { + out << nl << retS << "Holder __ret = new " << retS << "Holder();"; + out << nl << "__is.readObject(__ret.getPatcher());"; + } + else + { + out << nl << retS << " __ret;"; + writeMarshalUnmarshalCode(out, package, ret, "__ret", false, iter, false, opMetaData); + } + } + if(op->returnsClasses()) + { + out << nl << "__is.readPendingObjects();"; } + out << nl << "__is.endReadEncaps();"; } - if(op->returnsClasses()) + else { - out << nl << "__is.readPendingObjects();"; + out << nl << "__og.is().skipEmptyEncaps();"; } + if(ret) { BuiltinPtr builtin = BuiltinPtr::dynamicCast(ret); @@ -4287,6 +4315,11 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) out << sb; out << nl << "throw new IceInternal.LocalExceptionWrapper(__ex, false);"; out << eb; + if(!op->returnsData()) + { + out << eb; + } + out << eb; out << nl << "finally"; out << sb; @@ -5096,7 +5129,7 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) out << sb; out << nl << "try"; out << sb; - out << nl << "__is.throwException();"; + out << nl << "__throwUserException();"; out << eb; for(ExceptionList::const_iterator r = throws.begin(); r != throws.end(); ++r) { @@ -5110,38 +5143,48 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) out << nl << "throw new Ice.UnknownUserException(__ex.ice_name());"; out << eb; out << eb; - for(pli = outParams.begin(); pli != outParams.end(); ++pli) + if(p->returnsData()) { - TypePtr paramType = (*pli)->type(); - string paramName = fixKwd((*pli)->name()); - BuiltinPtr builtin = BuiltinPtr::dynamicCast(paramType); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(paramType)) - { - out << nl << "__is.readObject(" << paramName << ".getPatcher());"; - } - else + out << nl << "__is.startReadEncaps();"; + for(pli = outParams.begin(); pli != outParams.end(); ++pli) { - writeMarshalUnmarshalCode(out, classPkg, paramType, paramName, false, iter, false, - (*pli)->getMetaData()); + TypePtr paramType = (*pli)->type(); + string paramName = fixKwd((*pli)->name()); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(paramType); + if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(paramType)) + { + out << nl << "__is.readObject(" << paramName << ".getPatcher());"; + } + else + { + writeMarshalUnmarshalCode(out, classPkg, paramType, paramName, false, iter, false, + (*pli)->getMetaData()); + } } - } - if(ret) - { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(ret); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(ret)) + if(ret) { - out << nl << "__is.readObject(__ret.getPatcher());"; + BuiltinPtr builtin = BuiltinPtr::dynamicCast(ret); + if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(ret)) + { + out << nl << "__is.readObject(__ret.getPatcher());"; + } + else + { + writeMarshalUnmarshalCode(out, classPkg, ret, "__ret", false, iter, false, opMetaData); + } } - else + if(p->returnsClasses()) { - writeMarshalUnmarshalCode(out, classPkg, ret, "__ret", false, iter, false, opMetaData); + out << nl << "__is.readPendingObjects();"; } + out << nl << "__is.endReadEncaps();"; } - if(p->returnsClasses()) + else { - out << nl << "__is.readPendingObjects();"; + out << nl << "__is.skipEmptyEncaps();"; } out << eb; + if(!throws.empty()) { out << nl << "catch(Ice.UserException __ex)"; diff --git a/cs/src/Ice/BasicStream.cs b/cs/src/Ice/BasicStream.cs index e5749b8c4d6..a8aaf8a2659 100644 --- a/cs/src/Ice/BasicStream.cs +++ b/cs/src/Ice/BasicStream.cs @@ -437,15 +437,27 @@ namespace IceInternal public virtual void endReadEncaps() { Debug.Assert(_readEncapsStack != null); - int start = _readEncapsStack.start; - int sz = _readEncapsStack.sz; - try - { - _buf.b.position(start + sz); - } - catch(ArgumentOutOfRangeException ex) + if(_buf.b.position() != _readEncapsStack.start + _readEncapsStack.sz) { - throw new Ice.UnmarshalOutOfBoundsException(ex); + if(_buf.b.position() + 1 != _readEncapsStack.start + _readEncapsStack.sz) + { + throw new Ice.EncapsulationException(); + } + + // + // Ice version < 3.3 had a bug where user exceptions with + // class members could be encoded with a trailing byte + // when dispatched with AMD. So we tolerate an extra byte + // in the encapsulation. + // + try + { + _buf.b.get(); + } + catch(InvalidOperationException ex) + { + throw new Ice.UnmarshalOutOfBoundsException(ex); + } } ReadEncaps curr = _readEncapsStack; @@ -455,15 +467,27 @@ namespace IceInternal _readEncapsCache.reset(); } - public virtual void checkReadEncaps() + public virtual void skipEmptyEncaps() { - Debug.Assert(_readEncapsStack != null); - int start = _readEncapsStack.start; - int sz = _readEncapsStack.sz; - if(_buf.b.position() != start + sz) + int sz = readInt(); + if(sz < 0) + { + throw new Ice.NegativeSizeException(); + } + + if(sz != 6) { throw new Ice.EncapsulationException(); } + + try + { + _buf.b.position(_buf.b.position() + 2); + } + catch(ArgumentOutOfRangeException ex) + { + throw new Ice.UnmarshalOutOfBoundsException(ex); + } } public virtual int getReadEncapsSize() @@ -2515,7 +2539,7 @@ namespace IceInternal return _buf.size(); } - virtual internal bool isEmpty() + public virtual bool isEmpty() { return _buf.empty(); } diff --git a/cs/src/Ice/Incoming.cs b/cs/src/Ice/Incoming.cs index caae6674a79..17df2c59ef2 100644 --- a/cs/src/Ice/Incoming.cs +++ b/cs/src/Ice/Incoming.cs @@ -460,8 +460,6 @@ namespace IceInternal current_.ctx[first] = second; } - _is.startReadEncaps(); - if(response_) { Debug.Assert(os_.size() == Protocol.headerSize + 4); // Reply status position. @@ -553,7 +551,6 @@ namespace IceInternal } catch(System.Exception ex) { - _is.endReadEncaps(); handleException__(ex); return; } @@ -564,8 +561,6 @@ namespace IceInternal // the caller of this operation. // - _is.endReadEncaps(); - // // Async dispatch // @@ -660,7 +655,7 @@ namespace IceInternal // // That's the first startOver, so almost nothing to do // - _inParamPos = _is.pos() - 6; // 6 bytes for the start of the encaps + _inParamPos = _is.pos(); } else { @@ -669,9 +664,7 @@ namespace IceInternal // // Let's rewind _is and clean-up os_ // - _is.endReadEncaps(); _is.pos(_inParamPos); - _is.startReadEncaps(); if(response_) { diff --git a/cs/src/Ice/Object.cs b/cs/src/Ice/Object.cs index c44dbd4b3d6..445545ac579 100644 --- a/cs/src/Ice/Object.cs +++ b/cs/src/Ice/Object.cs @@ -95,9 +95,11 @@ namespace Ice Current __current) { IceInternal.BasicStream is__ = inS__.istr(); - IceInternal.BasicStream os__ = inS__.ostr(); + is__.startReadEncaps(); string __id = is__.readString(); + is__.endReadEncaps(); bool __ret = __obj.ice_isA(__id, __current); + IceInternal.BasicStream os__ = inS__.ostr(); os__.writeBool(__ret); return DispatchStatus.DispatchOK; } @@ -115,6 +117,7 @@ namespace Ice public static DispatchStatus ice_ping___(Ice.Object __obj, IceInternal.Incoming inS__, Current __current) { + inS__.istr().skipEmptyEncaps(); __obj.ice_ping(__current); return DispatchStatus.DispatchOK; } @@ -132,8 +135,10 @@ namespace Ice public static DispatchStatus ice_ids___(Ice.Object __obj, IceInternal.Incoming inS__, Current __current) { + inS__.istr().skipEmptyEncaps(); + string[] ret__ = __obj.ice_ids(__current); IceInternal.BasicStream os__ = inS__.ostr(); - os__.writeStringSeq(__obj.ice_ids(__current)); + os__.writeStringSeq(ret__); return DispatchStatus.DispatchOK; } @@ -150,8 +155,9 @@ namespace Ice public static DispatchStatus ice_id___(Ice.Object __obj, IceInternal.Incoming inS__, Current __current) { - IceInternal.BasicStream os__ = inS__.ostr(); + inS__.istr().skipEmptyEncaps(); string __ret = __obj.ice_id(__current); + IceInternal.BasicStream os__ = inS__.ostr(); os__.writeString(__ret); return DispatchStatus.DispatchOK; } @@ -350,8 +356,11 @@ namespace Ice { byte[] inParams; byte[] outParams; - int sz = inc.istr().getReadEncapsSize(); - inParams = inc.istr().readBlob(sz); + IceInternal.BasicStream is__ = inc.istr(); + is__.startReadEncaps(); + int sz = is__.getReadEncapsSize(); + inParams = is__.readBlob(sz); + is__.endReadEncaps(); bool ok = ice_invoke(inParams, out outParams, current); if(outParams != null) { @@ -375,8 +384,11 @@ namespace Ice public override DispatchStatus dispatch__(IceInternal.Incoming inc, Current current) { byte[] inParams; - int sz = inc.istr().getReadEncapsSize(); - inParams = inc.istr().readBlob(sz); + IceInternal.BasicStream is__ = inc.istr(); + is__.startReadEncaps(); + int sz = is__.getReadEncapsSize(); + inParams = is__.readBlob(sz); + is__.endReadEncaps(); AMD_Object_ice_invoke cb = new _AMD_Object_ice_invoke(inc); try { diff --git a/cs/src/Ice/ObjectAdapterI.cs b/cs/src/Ice/ObjectAdapterI.cs index 9c4379a331b..9c995aabf02 100644 --- a/cs/src/Ice/ObjectAdapterI.cs +++ b/cs/src/Ice/ObjectAdapterI.cs @@ -676,9 +676,12 @@ namespace Ice { for(int i = 0; i < endpoints.Length; ++i) { - if(_routerEndpoints.BinarySearch(endpoints[i]) >= 0) // _routerEndpoints is sorted. + foreach(IceInternal.EndpointI endpoint in _routerEndpoints) { - return true; + if(endpoints[i].equivalent(endpoint)) + { + return true; + } } } } diff --git a/cs/src/Ice/Outgoing.cs b/cs/src/Ice/Outgoing.cs index 3eab3675542..f6cdd4d987e 100644 --- a/cs/src/Ice/Outgoing.cs +++ b/cs/src/Ice/Outgoing.cs @@ -268,24 +268,12 @@ namespace IceInternal { case ReplyStatus.replyOK: { - // - // Input and output parameters are always sent in an - // encapsulation, which makes it possible to forward - // oneway requests as blobs. - // - _is.startReadEncaps(); _state = StateOK; // The state must be set last, in case there is an exception. break; } case ReplyStatus.replyUserException: { - // - // Input and output parameters are always sent in an - // encapsulation, which makes it possible to forward - // oneway requests as blobs. - // - _is.startReadEncaps(); _state = StateUserException; // The state must be set last, in case there is an exception. break; } @@ -421,6 +409,20 @@ namespace IceInternal return _os; } + public void throwUserException() + { + try + { + _is.startReadEncaps(); + _is.throwException(); + } + catch(Ice.UserException) + { + _is.endReadEncaps(); + throw; + } + } + private void writeHeader(string operation, Ice.OperationMode mode, Dictionary<string, string> context) { switch(_handler.getReference().getMode()) diff --git a/cs/src/Ice/OutgoingAsync.cs b/cs/src/Ice/OutgoingAsync.cs index 7020f8f9f22..7a0115cd33f 100644 --- a/cs/src/Ice/OutgoingAsync.cs +++ b/cs/src/Ice/OutgoingAsync.cs @@ -194,7 +194,6 @@ namespace IceInternal case ReplyStatus.replyOK: case ReplyStatus.replyUserException: { - is__.startReadEncaps(); break; } @@ -463,6 +462,20 @@ namespace IceInternal protected abstract void response__(bool ok); + protected void throwUserException__() + { + try + { + is__.startReadEncaps(); + is__.throwException(); + } + catch(Ice.UserException) + { + is__.endReadEncaps(); + throw; + } + } + private void handleException(LocalExceptionWrapper ex) { if(_mode == Ice.OperationMode.Nonmutating || _mode == Ice.OperationMode.Idempotent) @@ -593,8 +606,10 @@ namespace Ice byte[] outParams; try { + is__.startReadEncaps(); int sz = is__.getReadEncapsSize(); outParams = is__.readBlob(sz); + is__.endReadEncaps(); } catch(LocalException ex) { diff --git a/cs/src/Ice/Proxy.cs b/cs/src/Ice/Proxy.cs index 724995c84a8..754ac968975 100644 --- a/cs/src/Ice/Proxy.cs +++ b/cs/src/Ice/Proxy.cs @@ -1490,19 +1490,22 @@ namespace Ice bool ok__ = og__.invoke(); try { - IceInternal.BasicStream is__ = og__.istr(); if(!ok__) { try { - is__.throwException(); + og__.throwUserException(); } catch(UserException ex) { throw new UnknownUserException(ex.ice_name(), ex); } } - return is__.readBool(); + IceInternal.BasicStream is__ = og__.istr(); + is__.startReadEncaps(); + bool ret__ = is__.readBool(); + is__.endReadEncaps(); + return ret__; } catch(LocalException ex__) { @@ -1521,24 +1524,27 @@ namespace Ice try { bool ok__ = og__.invoke(); - try + if(!og__.istr().isEmpty()) { - IceInternal.BasicStream is__ = og__.istr(); - if(!ok__) + try { - try - { - is__.throwException(); - } - catch(UserException ex) + if(!ok__) { - throw new UnknownUserException(ex.ice_name(), ex); + try + { + og__.throwUserException(); + } + catch(UserException ex) + { + throw new UnknownUserException(ex.ice_name(), ex); + } } + og__.istr().skipEmptyEncaps(); + } + catch(LocalException ex__) + { + throw new IceInternal.LocalExceptionWrapper(ex__, false); } - } - catch(LocalException ex__) - { - throw new IceInternal.LocalExceptionWrapper(ex__, false); } } finally @@ -1555,19 +1561,22 @@ namespace Ice bool ok__ = og__.invoke(); try { - IceInternal.BasicStream is__ = og__.istr(); if(!ok__) { try { - is__.throwException(); + og__.throwUserException(); } catch(UserException ex) { throw new UnknownUserException(ex.ice_name(), ex); } } - return is__.readStringSeq(); + IceInternal.BasicStream is__ = og__.istr(); + is__.startReadEncaps(); + string[] ret__ = is__.readStringSeq(); + is__.endReadEncaps(); + return ret__; } catch(LocalException ex__) { @@ -1588,19 +1597,22 @@ namespace Ice bool ok__ = og__.invoke(); try { - IceInternal.BasicStream is__ = og__.istr(); if(!ok__) { try { - is__.throwException(); + og__.throwUserException(); } catch(UserException ex) { throw new UnknownUserException(ex.ice_name(), ex); } } - return is__.readString(); + IceInternal.BasicStream is__ = og__.istr(); + is__.startReadEncaps(); + string ret__ = is__.readString(); + is__.endReadEncaps(); + return ret__; } catch(LocalException ex__) { @@ -1635,8 +1647,10 @@ namespace Ice try { IceInternal.BasicStream is__ = og__.istr(); + is__.startReadEncaps(); int sz = is__.getReadEncapsSize(); outParams = is__.readBlob(sz); + is__.endReadEncaps(); } catch(LocalException ex__) { diff --git a/cs/src/Ice/Stream.cs b/cs/src/Ice/Stream.cs index f52317b212a..b3d3ac5790b 100644 --- a/cs/src/Ice/Stream.cs +++ b/cs/src/Ice/Stream.cs @@ -62,6 +62,7 @@ namespace Ice void startEncapsulation(); void endEncapsulation(); + void skipEncapsulation(); int getEncapsulationSize(); byte[] readBlob(int size); diff --git a/cs/src/Ice/StreamI.cs b/cs/src/Ice/StreamI.cs index 1770e32a7e9..96f1ab2ae79 100644 --- a/cs/src/Ice/StreamI.cs +++ b/cs/src/Ice/StreamI.cs @@ -179,6 +179,11 @@ namespace Ice _is.endReadEncaps(); } + public void skipEncapsulation() + { + _is.skipEncaps(); + } + public int getEncapsulationSize() { return _is.getReadEncapsSize(); diff --git a/cs/test/Ice/operations/MyDerivedClassAMDI.cs b/cs/test/Ice/operations/MyDerivedClassAMDI.cs index cda8925cb3b..7eae3b84e94 100755 --- a/cs/test/Ice/operations/MyDerivedClassAMDI.cs +++ b/cs/test/Ice/operations/MyDerivedClassAMDI.cs @@ -130,11 +130,11 @@ public sealed class MyDerivedClassI : Test.MyDerivedClass Dictionary<byte, bool> r = new Dictionary<byte, bool>(); foreach(KeyValuePair<byte, bool> e in p1) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } foreach(KeyValuePair<byte, bool> e in p2) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } cb.ice_response(r, p3); } @@ -214,11 +214,11 @@ public sealed class MyDerivedClassI : Test.MyDerivedClass Dictionary<long, float> r = new Dictionary<long, float>(); foreach(KeyValuePair<long, float> e in p1) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } foreach(KeyValuePair<long, float> e in p2) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } cb.ice_response(r, p3); } @@ -243,11 +243,11 @@ public sealed class MyDerivedClassI : Test.MyDerivedClass Dictionary<short, int> r = new Dictionary<short, int>(); foreach(KeyValuePair<short, int> e in p1) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } foreach(KeyValuePair<short, int> e in p2) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } cb.ice_response(r, p3); } @@ -300,11 +300,11 @@ public sealed class MyDerivedClassI : Test.MyDerivedClass Dictionary<string, Test.MyEnum> r = new Dictionary<string, Test.MyEnum>(); foreach(KeyValuePair<string, Test.MyEnum> e in p1) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } foreach(KeyValuePair<string, Test.MyEnum> e in p2) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } cb.ice_response(r, p3); } @@ -393,11 +393,11 @@ public sealed class MyDerivedClassI : Test.MyDerivedClass Dictionary<string, string> r = new Dictionary<string, string>(); foreach(KeyValuePair<string, string> e in p1) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } foreach(KeyValuePair<string, string> e in p2) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } cb.ice_response(r, p3); } diff --git a/cs/test/Ice/operations/MyDerivedClassI.cs b/cs/test/Ice/operations/MyDerivedClassI.cs index 1b5a6792133..eb4fd2f2944 100755 --- a/cs/test/Ice/operations/MyDerivedClassI.cs +++ b/cs/test/Ice/operations/MyDerivedClassI.cs @@ -75,11 +75,11 @@ public sealed class MyDerivedClassI : Test.MyDerivedClass Dictionary<byte, bool> r = new Dictionary<byte, bool>(); foreach(KeyValuePair<byte, bool> e in p1) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } foreach(KeyValuePair<byte, bool> e in p2) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } return r; } @@ -161,11 +161,11 @@ public sealed class MyDerivedClassI : Test.MyDerivedClass Dictionary<long, float> r = new Dictionary<long, float>(); foreach(KeyValuePair<long, float> e in p1) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } foreach(KeyValuePair<long, float> e in p2) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } return r; } @@ -192,11 +192,11 @@ public sealed class MyDerivedClassI : Test.MyDerivedClass Dictionary<short, int> r = new Dictionary<short, int>(); foreach(KeyValuePair<short, int> e in p1) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } foreach(KeyValuePair<short, int> e in p2) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } return r; } @@ -257,11 +257,11 @@ public sealed class MyDerivedClassI : Test.MyDerivedClass Dictionary<string, Test.MyEnum> r = new Dictionary<string, Test.MyEnum>(); foreach(KeyValuePair<string, Test.MyEnum> e in p1) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } foreach(KeyValuePair<string, Test.MyEnum> e in p2) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } return r; } @@ -348,11 +348,11 @@ public sealed class MyDerivedClassI : Test.MyDerivedClass Dictionary<string, string> r = new Dictionary<string, string>(); foreach(KeyValuePair<string, string> e in p1) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } foreach(KeyValuePair<string, string> e in p2) { - r.Add(e.Key, e.Value); + r[e.Key] = e.Value; } return r; } diff --git a/cs/test/Ice/operations/Twoways.cs b/cs/test/Ice/operations/Twoways.cs index 97cab80209e..c649b5450ad 100755 --- a/cs/test/Ice/operations/Twoways.cs +++ b/cs/test/Ice/operations/Twoways.cs @@ -460,7 +460,7 @@ class Twoways di1[10] = true; di1[100] = false; Dictionary<byte, bool> di2 = new Dictionary<byte, bool>(); - // di2[10] = true; // Disabled since new dictionary mapping. + di2[10] = true; di2[11] = false; di2[101] = true; @@ -480,7 +480,7 @@ class Twoways di1[110] = -1; di1[1100] = 123123; Dictionary<short, int> di2 = new Dictionary<short, int>(); - //di2[110] = 1; // Disabled since new dictionary mapping. + di2[110] = -1; di2[111] = -100; di2[1101] = 0; @@ -500,7 +500,7 @@ class Twoways di1[999999110L] = -1.1f; di1[999999111L] = 123123.2f; Dictionary<long, float> di2 = new Dictionary<long, float>(); - //di2[999999110L] = -1.1f; // Disabled since new dictionary mapping. + di2[999999110L] = -1.1f; di2[999999120L] = -100.4f; di2[999999130L] = 0.5f; @@ -520,7 +520,7 @@ class Twoways di1["foo"] = "abc -1.1"; di1["bar"] = "abc 123123.2"; Dictionary<string, string> di2 = new Dictionary<string, string>(); - // di2["foo"] = "abc -1.1"; // Disabled since new dictionary mapping. + di2["foo"] = "abc -1.1"; di2["FOO"] = "abc -100.4"; di2["BAR"] = "abc 0.5"; @@ -540,7 +540,7 @@ class Twoways di1["abc"] = Test.MyEnum.enum1; di1[""] = Test.MyEnum.enum2; Dictionary<string, Test.MyEnum> di2 = new Dictionary<string, Test.MyEnum>(); - // di2["abc"] = Test.MyEnum.enum1; // Disabled since new dictionary mapping. + di2["abc"] = Test.MyEnum.enum1; di2["qwerty"] = Test.MyEnum.enum3; di2["Hello!!"] = Test.MyEnum.enum2; diff --git a/java/src/Ice/AMI_Object_ice_invoke.java b/java/src/Ice/AMI_Object_ice_invoke.java index b891e74375a..7a4f0074c0a 100644 --- a/java/src/Ice/AMI_Object_ice_invoke.java +++ b/java/src/Ice/AMI_Object_ice_invoke.java @@ -38,6 +38,7 @@ public abstract class AMI_Object_ice_invoke extends IceInternal.OutgoingAsync { int sz = __is.getReadEncapsSize(); outParams = __is.readBlob(sz); + __is.endReadEncaps(); } catch(LocalException ex) { diff --git a/java/src/Ice/Blobject.java b/java/src/Ice/Blobject.java index daadab0654c..c5b348e39ce 100644 --- a/java/src/Ice/Blobject.java +++ b/java/src/Ice/Blobject.java @@ -20,8 +20,11 @@ public abstract class Blobject extends Ice.ObjectImpl { byte[] inParams; ByteSeqHolder outParams = new ByteSeqHolder(); - int sz = in.is().getReadEncapsSize(); - inParams = in.is().readBlob(sz); + IceInternal.BasicStream is = in.is(); + is.startReadEncaps(); + int sz = is.getReadEncapsSize(); + inParams = is.readBlob(sz); + is.endReadEncaps(); boolean ok = ice_invoke(inParams, outParams, current); if(outParams.value != null) { diff --git a/java/src/Ice/BlobjectAsync.java b/java/src/Ice/BlobjectAsync.java index 50288c12a50..e8679631ef6 100644 --- a/java/src/Ice/BlobjectAsync.java +++ b/java/src/Ice/BlobjectAsync.java @@ -18,8 +18,11 @@ public abstract class BlobjectAsync extends Ice.ObjectImpl __dispatch(IceInternal.Incoming in, Current current) { byte[] inParams; - int sz = in.is().getReadEncapsSize(); - inParams = in.is().readBlob(sz); + IceInternal.BasicStream is = in.is(); + is.startReadEncaps(); + int sz = is.getReadEncapsSize(); + inParams = is.readBlob(sz); + is.endReadEncaps(); AMD_Object_ice_invoke cb = new _AMD_Object_ice_invoke(in); try { diff --git a/java/src/Ice/InputStream.java b/java/src/Ice/InputStream.java index 60d7aab5615..8d882fec59f 100644 --- a/java/src/Ice/InputStream.java +++ b/java/src/Ice/InputStream.java @@ -54,6 +54,7 @@ public interface InputStream void skipSlice(); void startEncapsulation(); + void skipEncapsulation(); void endEncapsulation(); void readPendingObjects(); diff --git a/java/src/Ice/InputStreamI.java b/java/src/Ice/InputStreamI.java index eaa75550cf9..2024c8c99bc 100644 --- a/java/src/Ice/InputStreamI.java +++ b/java/src/Ice/InputStreamI.java @@ -211,6 +211,12 @@ public class InputStreamI implements InputStream } public void + skipEncapsulation() + { + _is.skipEncaps(); + } + + public void endEncapsulation() { _is.endReadEncaps(); diff --git a/java/src/Ice/ObjectAdapterI.java b/java/src/Ice/ObjectAdapterI.java index 7ca631d61d5..38bcab3e208 100644 --- a/java/src/Ice/ObjectAdapterI.java +++ b/java/src/Ice/ObjectAdapterI.java @@ -680,10 +680,14 @@ public final class ObjectAdapterI implements ObjectAdapter { for(int i = 0; i < endpoints.length; ++i) { - // _routerEndpoints is sorted. - if(java.util.Collections.binarySearch(_routerEndpoints, endpoints[i]) >= 0) + java.util.Iterator p; + p = _routerEndpoints.iterator(); + while(p.hasNext()) { - return true; + if(endpoints[i].equivalent((IceInternal.EndpointI)p.next())) + { + return true; + } } } } diff --git a/java/src/Ice/ObjectImpl.java b/java/src/Ice/ObjectImpl.java index dfca5d6b3f3..af589d40da7 100644 --- a/java/src/Ice/ObjectImpl.java +++ b/java/src/Ice/ObjectImpl.java @@ -58,9 +58,11 @@ public abstract class ObjectImpl implements Object, java.lang.Cloneable ___ice_isA(Ice.Object __obj, IceInternal.Incoming __inS, Current __current) { IceInternal.BasicStream __is = __inS.is(); - IceInternal.BasicStream __os = __inS.os(); + __is.startReadEncaps(); String __id = __is.readString(); + __is.endReadEncaps(); boolean __ret = __obj.ice_isA(__id, __current); + IceInternal.BasicStream __os = __inS.os(); __os.writeBool(__ret); return DispatchStatus.DispatchOK; } @@ -80,6 +82,7 @@ public abstract class ObjectImpl implements Object, java.lang.Cloneable public static DispatchStatus ___ice_ping(Ice.Object __obj, IceInternal.Incoming __inS, Current __current) { + __inS.is().skipEmptyEncaps(); __obj.ice_ping(__current); return DispatchStatus.DispatchOK; } @@ -99,8 +102,9 @@ public abstract class ObjectImpl implements Object, java.lang.Cloneable public static DispatchStatus ___ice_ids(Ice.Object __obj, IceInternal.Incoming __inS, Current __current) { - IceInternal.BasicStream __os = __inS.os(); + __inS.is().skipEmptyEncaps(); String[] __ret = __obj.ice_ids(__current); + IceInternal.BasicStream __os = __inS.os(); __os.writeStringSeq(__ret); return DispatchStatus.DispatchOK; } @@ -120,8 +124,9 @@ public abstract class ObjectImpl implements Object, java.lang.Cloneable public static DispatchStatus ___ice_id(Ice.Object __obj, IceInternal.Incoming __inS, Current __current) { - IceInternal.BasicStream __os = __inS.os(); + __inS.is().skipEmptyEncaps(); String __ret = __obj.ice_id(__current); + IceInternal.BasicStream __os = __inS.os(); __os.writeString(__ret); return DispatchStatus.DispatchOK; } diff --git a/java/src/Ice/_ObjectDelM.java b/java/src/Ice/_ObjectDelM.java index a060df4fae3..297cfd8ac63 100644 --- a/java/src/Ice/_ObjectDelM.java +++ b/java/src/Ice/_ObjectDelM.java @@ -30,19 +30,22 @@ public class _ObjectDelM implements _ObjectDel boolean __ok = __og.invoke(); try { - IceInternal.BasicStream __is = __og.is(); if(!__ok) { try { - __is.throwException(); + __og.throwUserException(); } catch(UserException __ex) { throw new UnknownUserException(__ex.ice_name()); } } - return __is.readBool(); + IceInternal.BasicStream __is = __og.is(); + __is.startReadEncaps(); + boolean __ret = __is.readBool(); + __is.endReadEncaps(); + return __ret; } catch(LocalException __ex) { @@ -63,24 +66,27 @@ public class _ObjectDelM implements _ObjectDel try { boolean __ok = __og.invoke(); - try + if(!__og.is().isEmpty()) { - IceInternal.BasicStream __is = __og.is(); - if(!__ok) + try { - try - { - __is.throwException(); - } - catch(UserException __ex) + if(!__ok) { - throw new UnknownUserException(__ex.ice_name()); + try + { + __og.throwUserException(); + } + catch(UserException __ex) + { + throw new UnknownUserException(__ex.ice_name()); + } } + __og.is().skipEmptyEncaps(); + } + catch(LocalException __ex) + { + throw new IceInternal.LocalExceptionWrapper(__ex, false); } - } - catch(LocalException __ex) - { - throw new IceInternal.LocalExceptionWrapper(__ex, false); } } finally @@ -99,19 +105,22 @@ public class _ObjectDelM implements _ObjectDel boolean __ok = __og.invoke(); try { - IceInternal.BasicStream __is = __og.is(); if(!__ok) { try { - __is.throwException(); + __og.throwUserException(); } catch(UserException __ex) { throw new UnknownUserException(__ex.ice_name()); } } - return __is.readStringSeq(); + IceInternal.BasicStream __is = __og.is(); + __is.startReadEncaps(); + String[] __ret = __is.readStringSeq(); + __is.endReadEncaps(); + return __ret; } catch(LocalException __ex) { @@ -134,19 +143,22 @@ public class _ObjectDelM implements _ObjectDel boolean __ok = __og.invoke(); try { - IceInternal.BasicStream __is = __og.is(); if(!__ok) { try { - __is.throwException(); + __og.throwUserException(); } catch(UserException __ex) { throw new UnknownUserException(__ex.ice_name()); } } - return __is.readString(); + IceInternal.BasicStream __is = __og.is(); + __is.startReadEncaps(); + String __ret = __is.readString(); + __is.endReadEncaps(); + return __ret; } catch(LocalException __ex) { @@ -184,11 +196,13 @@ public class _ObjectDelM implements _ObjectDel try { IceInternal.BasicStream __is = __og.is(); + __is.startReadEncaps(); int sz = __is.getReadEncapsSize(); if(outParams != null) { outParams.value = __is.readBlob(sz); } + __is.endReadEncaps(); } catch(LocalException __ex) { diff --git a/java/src/IceInternal/BasicStream.java b/java/src/IceInternal/BasicStream.java index 16409506b80..f55c45b7669 100644 --- a/java/src/IceInternal/BasicStream.java +++ b/java/src/IceInternal/BasicStream.java @@ -422,15 +422,27 @@ public class BasicStream endReadEncaps() { assert(_readEncapsStack != null); - int start = _readEncapsStack.start; - int sz = _readEncapsStack.sz; - try - { - _buf.b.position(start + sz); - } - catch(IllegalArgumentException ex) + if(_buf.b.position() != _readEncapsStack.start + _readEncapsStack.sz) { - throw new Ice.UnmarshalOutOfBoundsException(); + if(_buf.b.position() + 1 != _readEncapsStack.start + _readEncapsStack.sz) + { + throw new Ice.EncapsulationException(); + } + + // + // Ice version < 3.3 had a bug where user exceptions with + // class members could be encoded with a trailing byte + // when dispatched with AMD. So we tolerate an extra byte + // in the encapsulation. + // + try + { + _buf.b.get(); + } + catch(java.nio.BufferUnderflowException ex) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } } ReadEncaps curr = _readEncapsStack; @@ -441,15 +453,27 @@ public class BasicStream } public void - checkReadEncaps() + skipEmptyEncaps() { - assert(_readEncapsStack != null); - int start = _readEncapsStack.start; - int sz = _readEncapsStack.sz; - if(_buf.b.position() != start + sz) + int sz = readInt(); + if(sz < 0) + { + throw new Ice.NegativeSizeException(); + } + + if(sz != 6) { throw new Ice.EncapsulationException(); } + + try + { + _buf.b.position(_buf.b.position() + 2); + } + catch(IllegalArgumentException ex) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } } public int diff --git a/java/src/IceInternal/Incoming.java b/java/src/IceInternal/Incoming.java index f55af36735b..30b149fa707 100644 --- a/java/src/IceInternal/Incoming.java +++ b/java/src/IceInternal/Incoming.java @@ -103,8 +103,6 @@ final public class Incoming extends IncomingBase implements Ice.Request _current.ctx.put(first, second); } - _is.startReadEncaps(); - if(_response) { assert(_os.size() == Protocol.headerSize + 4); // Reply status position. @@ -197,7 +195,6 @@ final public class Incoming extends IncomingBase implements Ice.Request } catch(java.lang.Exception ex) { - _is.endReadEncaps(); __handleException(ex); return; } @@ -208,8 +205,6 @@ final public class Incoming extends IncomingBase implements Ice.Request // the caller of this operation. // - _is.endReadEncaps(); - // // DispatchAsync is "pseudo dispatch status", used internally // only to indicate async dispatch. @@ -306,7 +301,7 @@ final public class Incoming extends IncomingBase implements Ice.Request // // That's the first startOver, so almost nothing to do // - _inParamPos = _is.pos() - 6; // 6 bytes for the start of the encaps + _inParamPos = _is.pos(); } else { @@ -315,9 +310,7 @@ final public class Incoming extends IncomingBase implements Ice.Request // // Let's rewind _is and clean-up _os // - _is.endReadEncaps(); _is.pos(_inParamPos); - _is.startReadEncaps(); if(_response) { diff --git a/java/src/IceInternal/Outgoing.java b/java/src/IceInternal/Outgoing.java index d5288310ebe..97a00eb0597 100644 --- a/java/src/IceInternal/Outgoing.java +++ b/java/src/IceInternal/Outgoing.java @@ -292,24 +292,12 @@ public final class Outgoing implements OutgoingMessageCallback { case ReplyStatus.replyOK: { - // - // Input and output parameters are always sent in an - // encapsulation, which makes it possible to forward - // oneway requests as blobs. - // - _is.startReadEncaps(); _state = StateOK; // The state must be set last, in case there is an exception. break; } case ReplyStatus.replyUserException: { - // - // Input and output parameters are always sent in an - // encapsulation, which makes it possible to forward - // oneway requests as blobs. - // - _is.startReadEncaps(); _state = StateUserException; // The state must be set last, in case there is an exception. break; } @@ -444,6 +432,22 @@ public final class Outgoing implements OutgoingMessageCallback return _os; } + public void + throwUserException() + throws Ice.UserException + { + try + { + _is.startReadEncaps(); + _is.throwException(); + } + catch(Ice.UserException ex) + { + _is.endReadEncaps(); + throw ex; + } + } + private void writeHeader(String operation, Ice.OperationMode mode, java.util.Map context) throws LocalExceptionWrapper diff --git a/java/src/IceInternal/OutgoingAsync.java b/java/src/IceInternal/OutgoingAsync.java index 29ce96039af..6d354f23885 100644 --- a/java/src/IceInternal/OutgoingAsync.java +++ b/java/src/IceInternal/OutgoingAsync.java @@ -79,7 +79,6 @@ public abstract class OutgoingAsync extends OutgoingAsyncMessageCallback case ReplyStatus.replyOK: case ReplyStatus.replyUserException: { - __is.startReadEncaps(); break; } @@ -368,6 +367,22 @@ public abstract class OutgoingAsync extends OutgoingAsyncMessageCallback protected abstract void __response(boolean ok); + protected void + __throwUserException() + throws Ice.UserException + { + try + { + __is.startReadEncaps(); + __is.throwException(); + } + catch(Ice.UserException ex) + { + __is.endReadEncaps(); + throw ex; + } + } + private void handleException(LocalExceptionWrapper ex) { diff --git a/slice/Glacier2/PermissionsVerifierF.ice b/slice/Glacier2/PermissionsVerifierF.ice index ac7f559e9f9..578e07823fa 100755 --- a/slice/Glacier2/PermissionsVerifierF.ice +++ b/slice/Glacier2/PermissionsVerifierF.ice @@ -6,16 +6,16 @@ // ICE_LICENSE file included in this distribution. // // ********************************************************************** -
-#ifndef GLACIER2_PERMISSIONS_VERIFIER_F_ICE
-#define GLACIER2_PERMISSIONS_VERIFIER_F_ICE
-
-module Glacier2
-{
-
-interface PermissionsVerifier;
-interface SSLPermissionsVerifier;
-
-};
-
-#endif
+ +#ifndef GLACIER2_PERMISSIONS_VERIFIER_F_ICE +#define GLACIER2_PERMISSIONS_VERIFIER_F_ICE + +module Glacier2 +{ + +interface PermissionsVerifier; +interface SSLPermissionsVerifier; + +}; + +#endif |