summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Glacier2/Blobject.cpp22
-rw-r--r--cpp/src/Glacier2/RequestQueue.cpp11
-rw-r--r--cpp/src/Ice/.depend2
-rw-r--r--cpp/src/Ice/BasicStream.cpp36
-rw-r--r--cpp/src/Ice/StreamI.cpp10
-rw-r--r--cpp/src/Slice/CPlusPlusUtil.cpp142
-rw-r--r--cpp/src/Slice/CsUtil.cpp38
-rw-r--r--cpp/src/Slice/JavaUtil.cpp200
-rw-r--r--cpp/src/Slice/Preprocessor.cpp6
-rw-r--r--cpp/src/Slice/PythonUtil.cpp64
-rw-r--r--cpp/src/Slice/Util.cpp50
-rw-r--r--cpp/src/slice2cpp/Gen.cpp235
-rw-r--r--cpp/src/slice2cs/Gen.cpp23
-rw-r--r--cpp/src/slice2freeze/Main.cpp7
-rw-r--r--cpp/src/slice2java/Gen.cpp17
15 files changed, 729 insertions, 134 deletions
diff --git a/cpp/src/Glacier2/Blobject.cpp b/cpp/src/Glacier2/Blobject.cpp
index fee88f5780c..ae3ae5441b6 100644
--- a/cpp/src/Glacier2/Blobject.cpp
+++ b/cpp/src/Glacier2/Blobject.cpp
@@ -53,11 +53,9 @@ public:
//
if(_connection)
{
- try
- {
- ex.ice_throw();
- }
- catch(const Ice::ConnectionLostException&)
+ if(dynamic_cast<const Ice::SocketException*>(&ex) ||
+ dynamic_cast<const Ice::TimeoutException*>(&ex) ||
+ dynamic_cast<const Ice::ProtocolException*>(&ex))
{
try
{
@@ -67,9 +65,6 @@ public:
{
}
}
- catch(const Exception&)
- {
- }
}
_amdCB->ice_exception(ex);
@@ -115,11 +110,9 @@ public:
//
if(_connection)
{
- try
- {
- ex.ice_throw();
- }
- catch(const Ice::ConnectionLostException&)
+ if(dynamic_cast<const Ice::SocketException*>(&ex) ||
+ dynamic_cast<const Ice::TimeoutException*>(&ex) ||
+ dynamic_cast<const Ice::ProtocolException*>(&ex))
{
try
{
@@ -129,9 +122,6 @@ public:
{
}
}
- catch(const Exception&)
- {
- }
}
_amdCB->ice_exception(ex);
diff --git a/cpp/src/Glacier2/RequestQueue.cpp b/cpp/src/Glacier2/RequestQueue.cpp
index 3bccbc12ab9..8e21590d29c 100644
--- a/cpp/src/Glacier2/RequestQueue.cpp
+++ b/cpp/src/Glacier2/RequestQueue.cpp
@@ -51,11 +51,9 @@ public:
//
if(_connection)
{
- try
- {
- ex.ice_throw();
- }
- catch(const Ice::ConnectionLostException&)
+ if(dynamic_cast<const Ice::SocketException*>(&ex) ||
+ dynamic_cast<const Ice::TimeoutException*>(&ex) ||
+ dynamic_cast<const Ice::ProtocolException*>(&ex))
{
try
{
@@ -65,9 +63,6 @@ public:
{
}
}
- catch(const Exception&)
- {
- }
}
if(_amdCB)
diff --git a/cpp/src/Ice/.depend b/cpp/src/Ice/.depend
index 9aa34b48e2f..64786b613b3 100644
--- a/cpp/src/Ice/.depend
+++ b/cpp/src/Ice/.depend
@@ -74,7 +74,7 @@ Service$(OBJEXT): Service.cpp $(includedir)/IceUtil/DisableWarnings.h $(included
SliceChecksumDict$(OBJEXT): SliceChecksumDict.cpp $(includedir)/Ice/SliceChecksumDict.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/StringConverter.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/LoggerF.h $(includedir)/IceUtil/Unicode.h $(includedir)/Ice/Object.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/StreamF.h $(includedir)/IceUtil/Iterator.h $(includedir)/IceUtil/ScopedArray.h $(includedir)/IceUtil/DisableWarnings.h
SliceChecksums$(OBJEXT): SliceChecksums.cpp $(includedir)/Ice/SliceChecksums.h $(includedir)/Ice/SliceChecksumDict.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h
Stats$(OBJEXT): Stats.cpp $(includedir)/Ice/Stats.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/IceUtil/Iterator.h $(includedir)/IceUtil/ScopedArray.h $(includedir)/IceUtil/DisableWarnings.h
-StreamI$(OBJEXT): StreamI.cpp ../Ice/StreamI.h $(includedir)/Ice/Stream.h $(includedir)/Ice/StreamF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/LocalObjectF.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/Object.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/StringConverter.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/LoggerF.h $(includedir)/IceUtil/Unicode.h $(includedir)/Ice/Initialize.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/StatsF.h $(includedir)/Ice/BuiltinSequences.h
+StreamI$(OBJEXT): StreamI.cpp ../Ice/StreamI.h $(includedir)/Ice/Stream.h $(includedir)/Ice/StreamF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/LocalObjectF.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/Object.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/StringConverter.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/LoggerF.h $(includedir)/IceUtil/Unicode.h $(includedir)/Ice/Initialize.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/StatsF.h $(includedir)/Ice/BuiltinSequences.h $(includedir)/Ice/LocalException.h
Stream$(OBJEXT): Stream.cpp $(includedir)/Ice/Stream.h $(includedir)/Ice/StreamF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/LocalObjectF.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/Object.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h
StringConverter$(OBJEXT): StringConverter.cpp $(includedir)/Ice/StringConverter.h $(includedir)/Ice/Config.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/LoggerF.h $(includedir)/IceUtil/Unicode.h $(includedir)/IceUtil/IceUtil.h $(includedir)/IceUtil/AbstractMutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/Cache.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/CountDownLatch.h $(includedir)/IceUtil/Cond.h $(includedir)/IceUtil/CtrlCHandler.h $(includedir)/IceUtil/Functional.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/RWRecMutex.h $(includedir)/IceUtil/Thread.h $(includedir)/IceUtil/RecMutex.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/UUID.h $(includedir)/IceUtil/StringUtil.h $(includedir)/IceUtil/ScopedArray.h $(includedir)/Ice/Initialize.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/StatsF.h $(includedir)/Ice/BuiltinSequences.h ../Ice/Instance.h ../Ice/TraceLevelsF.h ../Ice/DefaultsAndOverridesF.h ../Ice/RouterInfoF.h ../Ice/LocatorInfoF.h ../Ice/ReferenceFactoryF.h ../Ice/ThreadPoolF.h ../Ice/SelectorThreadF.h $(includedir)/Ice/ConnectionFactoryF.h $(includedir)/Ice/ConnectionMonitorF.h ../Ice/ObjectFactoryManagerF.h $(includedir)/Ice/ObjectAdapterFactoryF.h ../Ice/EndpointFactoryManagerF.h ../Ice/RetryQueueF.h $(includedir)/Ice/DynamicLibraryF.h $(includedir)/Ice/PluginF.h ../Ice/SharedContext.h ../Ice/ImplicitContextI.h $(includedir)/Ice/ImplicitContext.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/FacetMap.h $(includedir)/Ice/Process.h $(includedir)/Ice/Outgoing.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/OutgoingAsync.h $(includedir)/Ice/Incoming.h $(includedir)/Ice/ServantLocatorF.h $(includedir)/Ice/ServantManagerF.h $(includedir)/Ice/Direct.h $(includedir)/Ice/LoggerUtil.h $(includedir)/Ice/Communicator.h $(includedir)/Ice/RouterF.h $(includedir)/Ice/LocatorF.h $(includedir)/Ice/ImplicitContextF.h $(includedir)/Ice/IconvStringConverter.h
SysLoggerI$(OBJEXT): SysLoggerI.cpp ../Ice/SysLoggerI.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/Time.h $(includedir)/Ice/Logger.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/UndefSysMacros.h
diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp
index 118b790f16a..c85e1d20b56 100644
--- a/cpp/src/Ice/BasicStream.cpp
+++ b/cpp/src/Ice/BasicStream.cpp
@@ -291,6 +291,26 @@ IceInternal::BasicStream::ReadEncaps::swap(ReadEncaps& other)
std::swap(previous, other.previous);
}
+void
+IceInternal::BasicStream::endWriteEncapsChecked()
+{
+ if(!_currentWriteEncaps)
+ {
+ throw EncapsulationException(__FILE__, __LINE__, "not in an encapsulation");
+ }
+ endWriteEncaps();
+}
+
+void
+IceInternal::BasicStream::endReadEncapsChecked()
+{
+ if(!_currentReadEncaps)
+ {
+ throw EncapsulationException(__FILE__, __LINE__, "not in an encapsulation");
+ }
+ endReadEncaps();
+}
+
Int
IceInternal::BasicStream::getReadEncapsSize()
{
@@ -377,6 +397,14 @@ IceInternal::BasicStream::skipSlice()
void
IceInternal::BasicStream::writeTypeId(const string& id)
{
+ if(!_currentWriteEncaps || !_currentWriteEncaps->typeIdMap)
+ {
+ //
+ // write(ObjectPtr) must be called first.
+ //
+ throw MarshalException(__FILE__, __LINE__, "type ids require an encapsulation");
+ }
+
TypeIdWriteMap::const_iterator k = _currentWriteEncaps->typeIdMap->find(id);
if(k != _currentWriteEncaps->typeIdMap->end())
{
@@ -394,6 +422,14 @@ IceInternal::BasicStream::writeTypeId(const string& id)
void
IceInternal::BasicStream::readTypeId(string& id)
{
+ if(!_currentReadEncaps || !_currentReadEncaps->typeIdMap)
+ {
+ //
+ // read(PatchFunc, void*) must be called first.
+ //
+ throw MarshalException(__FILE__, __LINE__, "type ids require an encapsulation");
+ }
+
bool isIndex;
read(isIndex);
if(isIndex)
diff --git a/cpp/src/Ice/StreamI.cpp b/cpp/src/Ice/StreamI.cpp
index f992b99b76f..c0006b817c0 100644
--- a/cpp/src/Ice/StreamI.cpp
+++ b/cpp/src/Ice/StreamI.cpp
@@ -9,6 +9,7 @@
#include <Ice/StreamI.h>
#include <Ice/Initialize.h>
+#include <Ice/LocalException.h>
using namespace std;
using namespace Ice;
@@ -305,7 +306,7 @@ Ice::InputStreamI::startEncapsulation()
void
Ice::InputStreamI::endEncapsulation()
{
- _is->endReadEncaps();
+ _is->endReadEncapsChecked();
}
void
@@ -562,6 +563,11 @@ Ice::OutputStreamI::writeWstringSeq(const vector<wstring>& v)
void
Ice::OutputStreamI::writeSize(Int sz)
{
+ if(sz < 0)
+ {
+ throw NegativeSizeException(__FILE__, __LINE__);
+ }
+
_os->writeSize(sz);
}
@@ -610,7 +616,7 @@ Ice::OutputStreamI::startEncapsulation()
void
Ice::OutputStreamI::endEncapsulation()
{
- _os->endWriteEncaps();
+ _os->endWriteEncapsChecked();
}
void
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp
index 6997b9b436c..e09e622ea41 100644
--- a/cpp/src/Slice/CPlusPlusUtil.cpp
+++ b/cpp/src/Slice/CPlusPlusUtil.cpp
@@ -215,6 +215,13 @@ Slice::typeToString(const TypePtr& type, bool useWstring, const StringList& meta
}
else
{
+ // Get the metadata associated at the point of definition.
+ bool protobuf;
+ seqType = findMetaData(seq, seq->getMetaData(), true, protobuf);
+ if(protobuf && !seqType.empty())
+ {
+ return seqType;
+ }
return fixKwd(seq->scoped());
}
}
@@ -348,6 +355,13 @@ Slice::inputTypeToString(const TypePtr& type, bool useWstring, const StringList&
}
else
{
+ // Get the metadata associated at the point of definition.
+ bool protobuf;
+ seqType = findMetaData(seq, seq->getMetaData(), true, protobuf);
+ if(protobuf && !seqType.empty())
+ {
+ return "const " + seqType + "&";
+ }
return "const " + fixKwd(seq->scoped()) + "&";
}
}
@@ -432,6 +446,12 @@ Slice::outputTypeToString(const TypePtr& type, bool useWstring, const StringList
}
else
{
+ bool protobuf;
+ seqType = findMetaData(seq, seq->getMetaData(), true, protobuf);
+ if(protobuf && !seqType.empty())
+ {
+ return seqType + "&";
+ }
return fixKwd(seq->scoped()) + "&";
}
}
@@ -679,6 +699,7 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string&
if(marshal)
{
string scope = fixKwd(seq->scope());
+
if(seqType == "array" || seqType == "range:array")
{
//
@@ -758,11 +779,13 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string&
else
{
//
- // No modifying metadata specified. Use appropriate write methods for type.
+ // No modifying metadata specified. Use appropriate
+ // write methods for type.
//
StringList l = seq->getMetaData();
- seqType = findMetaData(l, false);
- if(!seqType.empty())
+ bool protobuf;
+ seqType = findMetaData(seq, l, false, protobuf);
+ if(protobuf || !seqType.empty())
{
out << nl << scope << "__" << funcSeq << (pointer ? "" : "&") << stream << ", " << fixedParam
<< ");";
@@ -911,12 +934,14 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string&
else
{
//
- // No modifying metadata supplied. Just use appropriate read function.
+ // No modifying metadata supplied. Just use
+ // appropriate read function.
//
StringList l = seq->getMetaData();
- seqType = findMetaData(l, false);
- if(!seqType.empty() || !builtin || builtin->kind() == Builtin::KindObject ||
- builtin->kind() == Builtin::KindObjectProxy)
+ bool protobuf;
+ seqType = findMetaData(seq, l, false, protobuf);
+ if(protobuf || !seqType.empty() || !builtin || builtin->kind() == Builtin::KindObject ||
+ builtin->kind() == Builtin::KindObjectProxy)
{
out << nl << scope << "__" << funcSeq << (pointer ? "" : "&") << stream << ", "
<< fixedParam << ");";
@@ -1019,8 +1044,13 @@ writeRangeAllocateCode(Output& out, const TypePtr& type, const string& fixedName
SequencePtr seq = SequencePtr::dynamicCast(type);
if(seq)
{
- string seqType = findMetaData(metaData, true);
- if(seqType.find("range") == 0 && seqType != "range:array")
+ bool protobuf;
+ string seqType = findMetaData(seq, metaData, true, protobuf);
+ if(!protobuf && seqType.empty())
+ {
+ seqType = findMetaData(seq, seq->getMetaData(), true, protobuf);
+ }
+ if(!protobuf && seqType.find("range") == 0 && seqType != "range:array")
{
StringList md;
if(seqType.find("range:") == 0)
@@ -1305,9 +1335,10 @@ Slice::writeStreamMarshalUnmarshalCode(Output& out, const TypePtr& type, const s
}
else
{
- seqType = findMetaData(seq->getMetaData(), false);
+ bool protobuf;
+ seqType = findMetaData(seq, seq->getMetaData(), false, protobuf);
builtin = BuiltinPtr::dynamicCast(seq->type());
- if(!seqType.empty() || !builtin || (builtin->kind() == Builtin::KindObject ||
+ if(protobuf || !seqType.empty() || !builtin || (builtin->kind() == Builtin::KindObject ||
builtin->kind() == Builtin::KindObjectProxy))
{
string scope = fixKwd(seq->scope());
@@ -1501,6 +1532,95 @@ Slice::writeStreamMarshalUnmarshalCode(Output& out, const TypePtr& type, const s
assert(false);
}
+// Accepted metadata.
+//
+// cpp:type:<typename>
+// cpp:const
+// cpp:array
+// cpp:range:<typename>
+// cpp:protobuf<:typename>
+//
+
+// This form is for sequences definitions only.
+string
+Slice::findMetaData(const SequencePtr& seq, const StringList& metaData, bool inParam, bool& isProtobuf)
+{
+ isProtobuf = false;
+ static const string prefix = "cpp:";
+ for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); ++q)
+ {
+ string str = *q;
+ if(str.find(prefix) == 0)
+ {
+ string::size_type pos = str.find(':', prefix.size());
+ string ss;
+ if(pos == string::npos)
+ {
+ ss = str.substr(prefix.size());
+ }
+ else
+ {
+ ss = str.substr(prefix.size(), pos - prefix.size());
+ }
+ //
+ // If the form is cpp:type:<...> the data after cpp:type:
+ // is returned. If the form is cpp:range:<...> (and this
+ // is an inParam) the data after cpp: is returned.
+ //
+ if(ss == "protobuf" || pos != string::npos)
+ {
+ string ss = str.substr(prefix.size(), pos - prefix.size());
+ if(ss == "type")
+ {
+ return str.substr(pos + 1);
+ }
+ else if(ss == "protobuf")
+ {
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type());
+ if(!builtin || builtin->kind() != Builtin::KindByte)
+ {
+ continue;
+ }
+ isProtobuf = true;
+ if(pos != string::npos)
+ {
+ return str.substr(pos + 1);
+ }
+ return "";
+ }
+ else if(inParam && ss == "range")
+ {
+ return str.substr(prefix.size());
+ }
+ }
+ //
+ // If the data is an inParam and the metadata is cpp:array
+ // or cpp:range then array or range is returned.
+ //
+ else if(inParam)
+ {
+ if(ss == "array" || ss == "range")
+ {
+ return ss;
+ }
+ }
+ //
+ // Otherwise if the data is "class" it is returned.
+ //
+ else
+ {
+ if(ss == "class")
+ {
+ return ss;
+ }
+ }
+ }
+ }
+
+ return "";
+}
+
+// Does not handle cpp:protobuf
string
Slice::findMetaData(const StringList& metaData, bool inParam)
{
diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp
index a2f722b2dcb..58b41e7045c 100644
--- a/cpp/src/Slice/CsUtil.cpp
+++ b/cpp/src/Slice/CsUtil.cpp
@@ -214,6 +214,13 @@ Slice::CsGenerator::typeToString(const TypePtr& type)
}
}
+ prefix = "clr:serializable:";
+ if(seq->findMetaData(prefix, meta))
+ {
+ string type = meta.substr(prefix.size());
+ return global() + type;
+ }
+
return typeToString(seq->type()) + "[]";
}
@@ -888,6 +895,21 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
}
default:
{
+ string prefix = "clr:serializable:";
+ string meta;
+ if(seq->findMetaData(prefix, meta))
+ {
+ if(marshal)
+ {
+ out << nl << stream << ".writeSerializable(" << param << ");";
+ }
+ else
+ {
+ out << nl << param << " = (" << typeToString(seq) << ")" << stream << ".readSerializable();";
+ }
+ break;
+ }
+
typeS[0] = toupper(static_cast<unsigned char>(typeS[0]));
if(marshal)
{
@@ -1688,6 +1710,22 @@ Slice::CsGenerator::MetaDataVisitor::validate(const ContainedPtr& cont)
continue; // Custom type or List<T>
}
}
+ if(s.substr(prefix.size(), 13) == "serializable:")
+ {
+ string meta;
+ if(cont->findMetaData(prefix + "collection", meta)
+ || cont->findMetaData(prefix + "generic:", meta))
+ {
+ emitWarning(file, cont->line(), msg + " `" + meta + "':\n" +
+ "serialization can only be used with the array mapping for byte sequences");
+ }
+ string type = s.substr(prefix.size() + 13);
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type());
+ if(!type.empty() && builtin && builtin->kind() == Builtin::KindByte)
+ {
+ continue;
+ }
+ }
}
else if(StructPtr::dynamicCast(cont))
{
diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp
index 99b617e2146..5c4b2420f90 100644
--- a/cpp/src/Slice/JavaUtil.cpp
+++ b/cpp/src/Slice/JavaUtil.cpp
@@ -551,6 +551,22 @@ Slice::JavaGenerator::typeToString(const TypePtr& type,
}
else
{
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type());
+ if(builtin && builtin->kind() == Builtin::KindByte)
+ {
+ string prefix = "java:serializable:";
+ string meta;
+ if(seq->findMetaData(prefix, meta))
+ {
+ return string("Ice.Holder<") + meta.substr(prefix.size()) + " >";
+ }
+ prefix = "java:protobuf:";
+ if(seq->findMetaData(prefix, meta))
+ {
+ return string("Ice.Holder<") + meta.substr(prefix.size()) + " >";
+ }
+ }
+
//
// Only use the type's generated holder if the instance and
// formal types match.
@@ -595,6 +611,22 @@ Slice::JavaGenerator::typeToString(const TypePtr& type,
}
else
{
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type());
+ if(builtin && builtin->kind() == Builtin::KindByte)
+ {
+ string prefix = "java:serializable:";
+ string meta;
+ if(seq->findMetaData(prefix, meta))
+ {
+ return meta.substr(prefix.size());
+ }
+ prefix = "java:protobuf:";
+ if(seq->findMetaData(prefix, meta))
+ {
+ return meta.substr(prefix.size());
+ }
+ }
+
string instanceType, formalType;
getSequenceTypes(seq, package, metaData, instanceType, formalType);
return formal ? formalType : instanceType;
@@ -1241,15 +1273,64 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
{
string stream = marshal ? "__os" : "__is";
string v = param;
+ bool java2 = seq->definitionContext()->findMetaData(_java2MetaData) == _java2MetaData;
+
+ //
+ // If the sequence is a byte sequence, check if there's the serializable or protobuf metadata to
+ // get rid of these two easy cases first.
+ //
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type());
+ if(builtin && builtin->kind() == Builtin::KindByte)
+ {
+ string meta;
+ static const string protobuf = "java:protobuf:";
+ static const string serializable = "java:serializable:";
+ if(seq->findMetaData(serializable, meta))
+ {
+ if(marshal)
+ {
+ out << nl << stream << ".writeSerializable(" << v << ");";
+ }
+ else
+ {
+ string type = typeToString(seq, TypeModeIn, package);
+ out << nl << v << " = (" << type << ")" << stream << ".readSerializable();";
+ }
+ return;
+ }
+ else if(seq->findMetaData(protobuf, meta))
+ {
+ if(marshal)
+ {
+ out << nl << "if(!" << v << ".isInitialized())";
+ out << sb;
+ out << nl << "throw new Ice.MarshalException(\"type not fully initialized\");";
+ out << eb;
+ out << nl << stream << ".writeByteSeq(" << v << ".toByteArray());";
+ }
+ else
+ {
+ string type = typeToString(seq, TypeModeIn, package);
+ out << nl << "try";
+ out << sb;
+ out << nl << v << " = " << type << ".parseFrom(" << stream << ".readByteSeq());";
+ out << eb;
+ out << nl << "catch(com.google.protobuf.InvalidProtocolBufferException __ex)";
+ out << sb;
+ out << nl << "Ice.MarshalException __mex = new Ice.MarshalException();";
+ out << nl << "__mex.initCause(__ex);";
+ out << nl << "throw __mex;";
+ out << eb;
+ }
+ return;
+ }
+ }
- bool java2 = false;
bool customType = false;
string instanceType;
if(_featureProfile != Slice::IceE)
{
- java2 = seq->definitionContext()->findMetaData(_java2MetaData) == _java2MetaData;
-
//
// We have to determine whether it's possible to use the
// type's generated helper class for this marshal/unmarshal
@@ -1300,7 +1381,7 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
while(s)
{
//
- // Stop if the inner sequence type has a custom type.
+ // Stop if the inner sequence type has a custom, serializable or protobuf type.
//
if(hasTypeMetaData(s) && _featureProfile != Slice::IceE)
{
@@ -2496,10 +2577,60 @@ Slice::JavaGenerator::writeStreamSequenceMarshalUnmarshalCode(Output& out,
{
string stream = marshal ? "__outS" : "__inS";
string v = param;
-
bool java2 = seq->definitionContext()->findMetaData(_java2MetaData) == _java2MetaData;
//
+ // If the sequence is a byte sequence, check if there's the serializable or protobuf metadata to
+ // get rid of these two easy cases first.
+ //
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type());
+ if(builtin && builtin->kind() == Builtin::KindByte)
+ {
+ string meta;
+ static const string protobuf = "java:protobuf:";
+ static const string serializable = "java:serializable:";
+ if(seq->findMetaData(serializable, meta))
+ {
+ if(marshal)
+ {
+ out << nl << stream << ".writeSerializable(" << v << ");";
+ }
+ else
+ {
+ string type = typeToString(seq, TypeModeIn, package);
+ out << nl << v << " = (" << type << ")" << stream << ".readSerializable();";
+ }
+ return;
+ }
+ else if(seq->findMetaData(protobuf, meta))
+ {
+ if(marshal)
+ {
+ out << nl << "if(!" << v << ".isInitialized())";
+ out << sb;
+ out << nl << "throw new Ice.MarshalException(\"type not fully initialized\");";
+ out << eb;
+ out << nl << stream << ".writeByteSeq(" << v << ".toByteArray());";
+ }
+ else
+ {
+ string type = meta.substr(protobuf.size());
+ out << nl << "try";
+ out << sb;
+ out << nl << v << " = " << type << ".parseFrom(" << stream << ".readByteSeq());";
+ out << eb;
+ out << nl << "catch(com.google.protobuf.InvalidProtocolBufferException __ex)";
+ out << sb;
+ out << nl << "Ice.MarshalException __mex = new Ice.MarshalException();";
+ out << nl << "__mex.initCause(__ex);";
+ out << nl << "throw __mex;";
+ out << eb;
+ }
+ return;
+ }
+ }
+
+ //
// We have to determine whether it's possible to use the
// type's generated helper class for this marshal/unmarshal
// task. Since the user may have specified a custom type in
@@ -2548,7 +2679,7 @@ Slice::JavaGenerator::writeStreamSequenceMarshalUnmarshalCode(Output& out,
while(s)
{
//
- // Stop if the inner sequence type has a custom type.
+ // Stop if the inner sequence type has a custom, serializable or protobuf type.
//
if(hasTypeMetaData(s))
{
@@ -3145,6 +3276,18 @@ Slice::JavaGenerator::hasTypeMetaData(const TypePtr& type, const StringList& loc
{
return true;
}
+ else if(str.find("java:protobuf:") == 0 || str.find("java:serializable:") == 0)
+ {
+ SequencePtr seq = SequencePtr::dynamicCast(cont);
+ if(seq)
+ {
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type());
+ if(builtin && builtin->kind() == Builtin::KindByte)
+ {
+ return true;
+ }
+ }
+ }
}
}
@@ -3533,9 +3676,33 @@ Slice::JavaGenerator::MetaDataVisitor::visitDataMember(const DataMemberPtr& p)
void
Slice::JavaGenerator::MetaDataVisitor::visitSequence(const SequencePtr& p)
{
+ static const string protobuf = "java:protobuf:";
+ static const string serializable = "java:serializable:";
StringList metaData = getMetaData(p);
- validateType(p, metaData, p->definitionContext()->filename(), p->line());
- validateGetSet(p, metaData, p->definitionContext()->filename(), p->line());
+ const string file = p->definitionContext()->filename();
+ const string line = p->line();
+ for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); )
+ {
+ string s = *q++;
+ if(s.find(protobuf) == 0 || s.find(serializable) == 0)
+ {
+ //
+ // Remove from list so validateType does not try to handle as well.
+ //
+ metaData.remove(s);
+
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(p->type());
+ if(!builtin || builtin->kind() != Builtin::KindByte)
+ {
+ _history.insert(s);
+ emitWarning(file, line, "ignoring invalid metadata `" + s + "':\n" +
+ "this metadata can only be used with a byte sequence");
+ }
+ }
+ }
+
+ validateType(p, metaData, file, line);
+ validateGetSet(p, metaData, file, line);
}
void
@@ -3598,6 +3765,16 @@ Slice::JavaGenerator::MetaDataVisitor::getMetaData(const ContainedPtr& cont)
result.push_back(s);
continue;
}
+ else if(s.substr(prefix.size(), pos - prefix.size()) == "serializable")
+ {
+ result.push_back(s);
+ continue;
+ }
+ else if(s.substr(prefix.size(), pos - prefix.size()) == "protobuf")
+ {
+ result.push_back(s);
+ continue;
+ }
emitWarning(file, cont->line(), "ignoring invalid metadata `" + s + "'");
}
@@ -3634,6 +3811,13 @@ Slice::JavaGenerator::MetaDataVisitor::validateType(const SyntaxTreeBasePtr& p,
}
emitWarning(file, line, "invalid metadata for " + str);
}
+ else if(i->find("java:protobuf:") == 0 || i->find("java:serializable:") == 0)
+ {
+ //
+ // Only valid in sequence defintion which is checked in visitSequence
+ //
+ emitWarning(file, line, "ignoring invalid metadata `" + *i + "'");
+ }
}
}
diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp
index 6d47a0c689d..95432a9cee7 100644
--- a/cpp/src/Slice/Preprocessor.cpp
+++ b/cpp/src/Slice/Preprocessor.cpp
@@ -150,7 +150,11 @@ Slice::Preprocessor::preprocess(bool keepComments)
char* err = mcpp_get_mem_buffer(Err);
if(err)
{
- emitRaw(err);
+ vector<string> messages = filterMcppWarnings(err);
+ for(vector<string>::const_iterator i = messages.begin(); i != messages.end(); ++i)
+ {
+ emitRaw(i->c_str());
+ }
}
if(status == 0)
diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp
index c1c91b3f289..7dc251b25df 100644
--- a/cpp/src/Slice/PythonUtil.cpp
+++ b/cpp/src/Slice/PythonUtil.cpp
@@ -1204,17 +1204,46 @@ Slice::Python::CodeVisitor::visitStructStart(const StructPtr& p)
void
Slice::Python::CodeVisitor::visitSequence(const SequencePtr& p)
{
+ static const string protobuf = "python:protobuf:";
+ StringList metaData = p->getMetaData();
+ bool isCustom = false;
+ string customType;
+ for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); ++q)
+ {
+ if(q->find(protobuf) == 0)
+ {
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(p->type());
+ if(!builtin || builtin->kind() != Builtin::KindByte)
+ {
+ continue;
+ }
+ isCustom = true;
+ customType = q->substr(protobuf.size());
+ break;
+ }
+ }
+
//
// Emit the type information.
//
string scoped = p->scoped();
_out << sp << nl << "if not " << getDictLookup(p, "_t_") << ':';
_out.inc();
- _out << nl << "_M_" << getAbsolute(p, "_t_") << " = IcePy.defineSequence('" << scoped << "', ";
- writeMetaData(p->getMetaData());
- _out << ", ";
- writeType(p->type());
- _out << ")";
+ if(isCustom)
+ {
+ string package = customType.substr(0, customType.find('.'));
+ _out << nl << "import " << package;
+ _out << nl << "_M_" << getAbsolute(p, "_t_")
+ << " = IcePy.defineCustom('" << scoped << "', " << customType << ")";
+ }
+ else
+ {
+ _out << nl << "_M_" << getAbsolute(p, "_t_") << " = IcePy.defineSequence('" << scoped << "', ";
+ writeMetaData(metaData);
+ _out << ", ";
+ writeType(p->type());
+ _out << ")";
+ }
_out.dec();
}
@@ -2032,7 +2061,30 @@ Slice::Python::MetaDataVisitor::visitDataMember(const DataMemberPtr& p)
void
Slice::Python::MetaDataVisitor::visitSequence(const SequencePtr& p)
{
- validateSequence(p->definitionContext(), p->line(), p, p->getMetaData());
+ static const string protobuf = "python:protobuf:";
+ StringList metaData = p->getMetaData();
+ const string file = p->definitionContext()->filename();
+ const string line = p->line();
+ for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); )
+ {
+ string s = *q++;
+ if(s.find(protobuf) == 0)
+ {
+ //
+ // Remove from list so validateSequence does not try to handle as well.
+ //
+ metaData.remove(s);
+
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(p->type());
+ if(!builtin || builtin->kind() != Builtin::KindByte)
+ {
+ emitWarning(file, line, "ignoring invalid metadata `" + s + ":\n" +
+ "`protobuf' encoding must be a byte sequence");
+ }
+ }
+ }
+
+ validateSequence(p->definitionContext(), line, p, metaData);
}
void
diff --git a/cpp/src/Slice/Util.cpp b/cpp/src/Slice/Util.cpp
index 6a691df8fb3..106a14d989b 100644
--- a/cpp/src/Slice/Util.cpp
+++ b/cpp/src/Slice/Util.cpp
@@ -251,3 +251,53 @@ Slice::emitRaw(const char* message)
{
*errorStream << message << flush;
}
+
+vector<string>
+Slice::filterMcppWarnings(const string& message)
+{
+ static const int messagesSize = 2;
+ static const char* messages[messagesSize] = {"Converted [CR+LF] to [LF]", "End of input with no newline, supplemented newline"};
+
+ static const string delimiters = "\n";
+
+ // Skip delimiters at beginning.
+ string::size_type lastPos = message.find_first_not_of(delimiters, 0);
+ // Find first "non-delimiter".
+ string::size_type pos = message.find_first_of(delimiters, lastPos);
+
+ vector<string> tokens;
+ bool skiped;
+ while (string::npos != pos || string::npos != lastPos)
+ {
+ skiped = false;
+ string token = message.substr(lastPos, pos - lastPos);
+ static const string warningPrefix = "warning:";
+ if(token.find_first_of(warningPrefix) != string::npos)
+ {
+ for(int j = 0; j < messagesSize; ++j)
+ {
+ if(token.find_first_of(messages[j]) != string::npos)
+ {
+ skiped = true;
+ //Skip Next token.
+
+ // Skip delimiters. Note the "not_of"
+ lastPos = message.find_first_not_of(delimiters, pos);
+ // Find next "non-delimiter"
+ pos = message.find_first_of(delimiters, lastPos);
+ break;
+ }
+ }
+ }
+
+ if(!skiped)
+ {
+ tokens.push_back(token);
+ }
+ // Skip delimiters. Note the "not_of"
+ lastPos = message.find_first_not_of(delimiters, pos);
+ // Find next "non-delimiter"
+ pos = message.find_first_of(delimiters, lastPos);
+ }
+ return tokens;
+}
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 3ab5e21fcd4..513b9f684ee 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -1151,14 +1151,20 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p)
TypePtr type = p->type();
string s = typeToString(type, _useWstring, p->typeMetaData());
StringList metaData = p->getMetaData();
- string seqType = findMetaData(metaData, false);
- if(!seqType.empty())
- {
- H << sp << nl << "typedef " << seqType << ' ' << name << ';';
- }
- else
+
+ bool protobuf;
+ string seqType = findMetaData(p, metaData, false, protobuf);
+ H << sp;
+ if(!protobuf)
{
- H << sp << nl << "typedef ::std::vector<" << (s[0] == ':' ? " " : "") << s << "> " << name << ';';
+ if(!seqType.empty())
+ {
+ H << nl << "typedef " << seqType << ' ' << name << ';';
+ }
+ else
+ {
+ H << nl << "typedef ::std::vector<" << (s[0] == ':' ? " " : "") << s << "> " << name << ';';
+ }
}
BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
@@ -1167,100 +1173,163 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p)
string scoped = fixKwd(p->scoped());
string scope = fixKwd(p->scope());
- if(!seqType.empty())
+ if(protobuf || !seqType.empty())
{
- H << nl << _dllExport << "void __write" << name << "(::IceInternal::BasicStream*, const " << name << "&);";
- H << nl << _dllExport << "void __read" << name << "(::IceInternal::BasicStream*, " << name << "&);";
+ string typeName = name;
+ string scopedName = scoped;
+ if(protobuf && !seqType.empty())
+ {
+ typeName = seqType;
+ scopedName = seqType;
+ }
+ H << nl << _dllExport << "void __write" << name << "(::IceInternal::BasicStream*, const "
+ << typeName << "&);";
+ H << nl << _dllExport << "void __read" << name << "(::IceInternal::BasicStream*, "
+ << typeName << "&);";
if(_stream)
{
H << nl << _dllExport << "void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, const "
- << name << "&);";
- H << nl << _dllExport << "void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << name
+ << typeName << "&);";
+ H << nl << _dllExport << "void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << typeName
<< "&);";
}
C << sp << nl << "void" << nl << scope.substr(2) << "__write" << name <<
- "(::IceInternal::BasicStream* __os, const " << scoped << "& v)";
- C << sb;
- C << nl << "::Ice::Int size = static_cast< ::Ice::Int>(v.size());";
- C << nl << "__os->writeSize(size);";
- C << nl << "for(" << name << "::const_iterator p = v.begin(); p != v.end(); ++p)";
+ "(::IceInternal::BasicStream* __os, const " << scopedName << "& v)";
C << sb;
- writeMarshalUnmarshalCode(C, type, "(*p)", true);
- C << eb;
+ if(protobuf)
+ {
+ C << nl << "std::vector< ::Ice::Byte> data(v.ByteSize());";
+ C << nl << "if(!v.IsInitialized())";
+ C << sb;
+ C << nl << "throw ::Ice::MarshalException(__FILE__, __LINE__, \"type not fully initialized: \" + v.InitializationErrorString());";
+ C << eb;
+ C << nl << "if(!v.SerializeToArray(&data[0], data.size()))";
+ C << sb;
+ C << nl << "throw ::Ice::MarshalException(__FILE__, __LINE__, \"SerializeToArray failed\");";
+ C << eb;
+ C << nl << "__os->write(&data[0], &data[0] + data.size());";
+ }
+ else
+ {
+ C << nl << "::Ice::Int size = static_cast< ::Ice::Int>(v.size());";
+ C << nl << "__os->writeSize(size);";
+ C << nl << "for(" << name << "::const_iterator p = v.begin(); p != v.end(); ++p)";
+ C << sb;
+ writeMarshalUnmarshalCode(C, type, "(*p)", true);
+ C << eb;
+ }
C << eb;
C << sp << nl << "void" << nl << scope.substr(2) << "__read" << name
- << "(::IceInternal::BasicStream* __is, " << scoped << "& v)";
+ << "(::IceInternal::BasicStream* __is, " << scopedName << "& v)";
C << sb;
- C << nl << "::Ice::Int sz;";
- C << nl << "__is->readSize(sz);";
- C << nl << name << "(sz).swap(v);";
- if(type->isVariableLength())
+ if(protobuf)
{
- // Protect against bogus sequence sizes.
- C << nl << "__is->startSeq(sz, " << type->minWireSize() << ");";
+ C << nl << "::std::pair<const ::Ice::Byte*, const ::Ice::Byte*> data;";
+ C << nl << "__is->read(data);";
+ C << nl << "if(!v.ParseFromArray(data.first, data.second - data.first))";
+ C << sb;
+ C << nl << "throw ::Ice::MarshalException(__FILE__, __LINE__, \"ParseFromArray failed\");";
+ C << eb;
}
else
{
- C << nl << "__is->checkFixedSeq(sz, " << type->minWireSize() << ");";
- }
- C << nl << "for(" << name << "::iterator p = v.begin(); p != v.end(); ++p)";
- C << sb;
- writeMarshalUnmarshalCode(C, type, "(*p)", false);
+ C << nl << "::Ice::Int sz;";
+ C << nl << "__is->readSize(sz);";
+ C << nl << name << "(sz).swap(v);";
+ if(type->isVariableLength())
+ {
+ // Protect against bogus sequence sizes.
+ C << nl << "__is->startSeq(sz, " << type->minWireSize() << ");";
+ }
+ else
+ {
+ C << nl << "__is->checkFixedSeq(sz, " << type->minWireSize() << ");";
+ }
+ C << nl << "for(" << name << "::iterator p = v.begin(); p != v.end(); ++p)";
+ C << sb;
+ writeMarshalUnmarshalCode(C, type, "(*p)", false);
- //
- // After unmarshaling each element, check that there are still enough bytes left in the stream
- // to unmarshal the remainder of the sequence, and decrement the count of elements
- // yet to be unmarshaled for sequences with variable-length element type (that is, for sequences
- // of classes, structs, dictionaries, sequences, strings, or proxies). This allows us to
- // abort unmarshaling for bogus sequence sizes at the earliest possible moment.
- // (For fixed-length sequences, we don't need to do this because the prediction of how many
- // bytes will be taken up by the sequence is accurate.)
- //
- if(type->isVariableLength())
- {
- if(!SequencePtr::dynamicCast(type))
+ //
+ // After unmarshaling each element, check that there are still enough bytes left in the stream
+ // to unmarshal the remainder of the sequence, and decrement the count of elements
+ // yet to be unmarshaled for sequences with variable-length element type (that is, for sequences
+ // of classes, structs, dictionaries, sequences, strings, or proxies). This allows us to
+ // abort unmarshaling for bogus sequence sizes at the earliest possible moment.
+ // (For fixed-length sequences, we don't need to do this because the prediction of how many
+ // bytes will be taken up by the sequence is accurate.)
+ //
+ if(type->isVariableLength())
{
- //
- // No need to check for directly nested sequences because, at the start of each
- // sequence, we check anyway.
- //
- C << nl << "__is->checkSeq();";
+ if(!SequencePtr::dynamicCast(type))
+ {
+ //
+ // No need to check for directly nested sequences because, at the start of each
+ // sequence, we check anyway.
+ //
+ C << nl << "__is->checkSeq();";
+ }
+ C << nl << "__is->endElement();";
+ }
+ C << eb;
+ if(type->isVariableLength())
+ {
+ C << nl << "__is->endSeq(sz);";
}
- C << nl << "__is->endElement();";
- }
- C << eb;
- if(type->isVariableLength())
- {
- C << nl << "__is->endSeq(sz);";
}
C << eb;
if(_stream)
{
C << sp << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name()
- << "(const ::Ice::OutputStreamPtr& __outS, const " << scoped << "& v)";
- C << sb;
- C << nl << "__outS->writeSize(::Ice::Int(v.size()));";
- C << nl << scoped << "::const_iterator p;";
- C << nl << "for(p = v.begin(); p != v.end(); ++p)";
+ << "(const ::Ice::OutputStreamPtr& __outS, const " << scopedName << "& v)";
C << sb;
- writeStreamMarshalUnmarshalCode(C, type, "(*p)", true, "", _useWstring);
- C << eb;
+ if(protobuf)
+ {
+ C << nl << "std::vector< ::Ice::Byte> data(v.ByteSize());";
+ C << nl << "if(!v.IsInitialized())";
+ C << sb;
+ C << nl << "throw ::Ice::MarshalException(__FILE__, __LINE__, \"type not fully initialized: \" + v.InitializationErrorString());";
+ C << eb;
+ C << nl << "v.SerializeToArray(&data[0], data.size());";
+
+ C << nl << "__outS->writeByteSeq(data);";
+ }
+ else
+ {
+ C << nl << "__outS->writeSize(::Ice::Int(v.size()));";
+ C << nl << scopedName << "::const_iterator p;";
+ C << nl << "for(p = v.begin(); p != v.end(); ++p)";
+ C << sb;
+ writeStreamMarshalUnmarshalCode(C, type, "(*p)", true, "", _useWstring);
+ C << eb;
+ }
C << eb;
C << sp << nl << "void" << nl << scope.substr(2) << "ice_read" << p->name()
- << "(const ::Ice::InputStreamPtr& __inS, " << scoped << "& v)";
- C << sb;
- C << nl << "::Ice::Int sz = __inS->readSize();";
- C << nl << scoped << "(sz).swap(v);";
- C << nl << scoped << "::iterator p;";
- C << nl << "for(p = v.begin(); p != v.end(); ++p)";
+ << "(const ::Ice::InputStreamPtr& __inS, " << scopedName << "& v)";
C << sb;
- writeStreamMarshalUnmarshalCode(C, type, "(*p)", false, "", _useWstring);
- C << eb;
+ if(protobuf)
+ {
+ C << nl << "std::pair<const ::Ice::Byte*, const ::Ice::Byte*> data;";
+ C << nl << "__inS->readByteSeq(data);";
+ C << nl << "if(!v.ParseFromArray(data.first, data.second - data.first))";
+ C << sb;
+ C << nl << "throw ::Ice::MarshalException(__FILE__, __LINE__, \"ParseFromArray failed\");";
+ C << eb;
+ }
+ else
+ {
+ C << nl << "::Ice::Int sz = __inS->readSize();";
+ C << nl << scopedName << "(sz).swap(v);";
+ C << nl << scopedName << "::iterator p;";
+ C << nl << "for(p = v.begin(); p != v.end(); ++p)";
+ C << sb;
+ writeStreamMarshalUnmarshalCode(C, type, "(*p)", false, "", _useWstring);
+ C << eb;
+ }
C << eb;
}
}
@@ -5749,6 +5818,7 @@ Slice::Gen::MetaDataVisitor::visitStructEnd(const StructPtr&)
void
Slice::Gen::MetaDataVisitor::visitOperation(const OperationPtr& p)
{
+
bool ami = false;
ClassDefPtr cl = ClassDefPtr::dynamicCast(p->container());
if(cl->hasMetaData("ami") || p->hasMetaData("ami") || cl->hasMetaData("amd") || p->hasMetaData("amd"))
@@ -5814,7 +5884,31 @@ Slice::Gen::MetaDataVisitor::visitDataMember(const DataMemberPtr& p)
void
Slice::Gen::MetaDataVisitor::visitSequence(const SequencePtr& p)
{
- validate(p, p->getMetaData(), p->definitionContext()->filename(), p->line());
+ StringList metaData = p->getMetaData();
+ const string file = p->definitionContext()->filename();
+ const string line = p->line();
+ static const string prefix = "cpp:protobuf";
+ for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); )
+ {
+ string s = *q++;
+ if(s.find(prefix) == 0)
+ {
+ //
+ // Remove from list so validate does not try to handle as well.
+ //
+ metaData.remove(s);
+
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(p->type());
+ if(!builtin || builtin->kind() != Builtin::KindByte)
+ {
+ _history.insert(s);
+ emitWarning(file, line, "ignoring invalid metadata `" + s + "':\n"+
+ "`protobuf' encoding must be a byte sequence.");
+ }
+ }
+ }
+
+ validate(p, metaData, file, line);
}
void
@@ -5871,7 +5965,6 @@ Slice::Gen::MetaDataVisitor::validate(const SyntaxTreeBasePtr& cont, const Strin
{
continue;
}
-
emitWarning(file, line, "ignoring invalid metadata `" + s + "'");
}
_history.insert(s);
diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp
index 9a2a4ae2f08..a2420094869 100644
--- a/cpp/src/slice2cs/Gen.cpp
+++ b/cpp/src/slice2cs/Gen.cpp
@@ -1666,6 +1666,15 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p)
return;
}
+ //
+ // No need to generate anything for serializable sequences.
+ //
+ prefix = "clr:serializable:";
+ if(p->findMetaData(prefix, meta))
+ {
+ return;
+ }
+
string name = fixId(p->name());
string s = typeToString(p->type());
@@ -2732,9 +2741,10 @@ Slice::Gen::TypesVisitor::writeMemberHashCode(const DataMemberList& dataMembers,
SequencePtr seq = SequencePtr::dynamicCast(memberType);
if(seq)
{
- string genericType;
- bool isGeneric = seq->findMetaData("clr:generic:", genericType);
- bool isArray = !isGeneric && !seq->hasMetaData("clr:collection");
+ string meta;
+ bool isSerializable = seq->findMetaData("clr:serializable", meta);
+ bool isGeneric = seq->findMetaData("clr:generic:", meta);
+ bool isArray = !isSerializable && !isGeneric && !seq->hasMetaData("clr:collection");
if(isArray)
{
//
@@ -2811,9 +2821,10 @@ Slice::Gen::TypesVisitor::writeMemberEquals(const DataMemberList& dataMembers, i
SequencePtr seq = SequencePtr::dynamicCast(memberType);
if(seq)
{
- string genericType;
- bool isGeneric = seq->findMetaData("clr:generic:", genericType);
- bool isArray = !isGeneric && !seq->hasMetaData("clr:collection");
+ string meta;
+ bool isSerializable = seq->findMetaData("clr:serializable:", meta);
+ bool isGeneric = seq->findMetaData("clr:generic:", meta);
+ bool isArray = !isSerializable && !isGeneric && !seq->hasMetaData("clr:collection");
if(isArray)
{
//
diff --git a/cpp/src/slice2freeze/Main.cpp b/cpp/src/slice2freeze/Main.cpp
index c466a7edd62..3243dd7ee1f 100644
--- a/cpp/src/slice2freeze/Main.cpp
+++ b/cpp/src/slice2freeze/Main.cpp
@@ -702,8 +702,7 @@ writeDictWithIndicesC(const string& name, const string& absolute, const Dict& di
else
{
C << nl << typeToString(indexTypes[i].type, false, indexTypes[i].metaData)
- << " __lowerCaseIndex = __index;";
- C << nl << "std::transform(__lowerCaseIndex.begin(), __lowerCaseIndex.end(), __lowerCaseIndex.begin(), tolower);";
+ << " __lowerCaseIndex = IceUtilInternal::toLower(__index);";
valueS = "__lowerCaseIndex";
}
@@ -1235,8 +1234,7 @@ writeIndexC(const TypePtr& type, const TypePtr& memberType, const string& member
}
else
{
- C << nl << typeToString(memberType, false) << " __lowerCaseIndex = __index;";
- C << nl << "std::transform(__lowerCaseIndex.begin(), __lowerCaseIndex.end(), __lowerCaseIndex.begin(), tolower);";
+ C << nl << typeToString(memberType, false) << " __lowerCaseIndex = IceUtilInternal::toLower(__index);";
valueS = "__lowerCaseIndex";
}
@@ -1443,6 +1441,7 @@ gen(const string& name, const UnitPtr& u, const vector<string>& includePaths, co
}
CPP << "\n#include <Ice/BasicStream.h>";
+ CPP << "\n#include <IceUtil/StringUtil.h>";
CPP << "\n#include <";
if(include.size())
{
diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp
index 9142e4b6e05..4289a6ae5a9 100644
--- a/cpp/src/slice2java/Gen.cpp
+++ b/cpp/src/slice2java/Gen.cpp
@@ -3185,6 +3185,23 @@ Slice::Gen::HolderVisitor::visitStructStart(const StructPtr& p)
void
Slice::Gen::HolderVisitor::visitSequence(const SequencePtr& p)
{
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(p->type());
+ if(builtin && builtin->kind() == Builtin::KindByte)
+ {
+ string prefix = "java:serializable:";
+ string meta;
+ if(p->findMetaData(prefix, meta))
+ {
+ return; // No holders for serializable types.
+ }
+ prefix = "java:protobuf:";
+ if(p->findMetaData(prefix, meta))
+ {
+ return; // No holders for protobuf types.
+
+ }
+ }
+
writeHolder(p);
}