summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2004-10-27 03:23:42 +0000
committerMichi Henning <michi@zeroc.com>2004-10-27 03:23:42 +0000
commit0770a34e5ae37938a6dce437a112784867d747b7 (patch)
treeb109a0851f148d6beaa5e8411e80e17f15045beb /cpp/src
parentfixes for glacier2 change (diff)
downloadice-0770a34e5ae37938a6dce437a112784867d747b7.tar.bz2
ice-0770a34e5ae37938a6dce437a112784867d747b7.tar.xz
ice-0770a34e5ae37938a6dce437a112784867d747b7.zip
- Fixed a bug in slice2cs: the generated code was incorrect for
dictionaries with sequence value types, if that sequence value type was mapped to an array.
Diffstat (limited to 'cpp/src')
-rwxr-xr-xcpp/src/Slice/CsUtil.cpp36
-rwxr-xr-xcpp/src/slice2cs/Gen.cpp21
2 files changed, 37 insertions, 20 deletions
diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp
index 2156728494d..ddd87d8a4c3 100755
--- a/cpp/src/Slice/CsUtil.cpp
+++ b/cpp/src/Slice/CsUtil.cpp
@@ -179,23 +179,6 @@ Slice::CsGenerator::typeToString(const TypePtr& type)
return "???";
}
-static string
-toArrayAlloc(const string& decl, const string& sz)
-{
- int count = 0;
- string::size_type pos = decl.size();
- while(pos > 1 && decl.substr(pos - 2, 2) == "[]")
- {
- ++count;
- pos -= 2;
- }
- assert(count > 0);
-
- ostringstream o;
- o << decl.substr(0, pos) << '[' << sz << ']' << decl.substr(pos + 2);
- return o.str();
-}
-
bool
Slice::CsGenerator::isValueType(const TypePtr& type)
{
@@ -618,7 +601,7 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
out << nl << param << " = new ";
if(isArray)
{
- out << toArrayAlloc(typeS + "[]", "sz");
+ out << toArrayAlloc(typeS + "[]", "sz");
}
else
{
@@ -775,6 +758,23 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
return;
}
+string
+Slice::CsGenerator::toArrayAlloc(const string& decl, const string& sz)
+{
+ int count = 0;
+ string::size_type pos = decl.size();
+ while(pos > 1 && decl.substr(pos - 2, 2) == "[]")
+ {
+ ++count;
+ pos -= 2;
+ }
+ assert(count > 0);
+
+ ostringstream o;
+ o << decl.substr(0, pos) << '[' << sz << ']' << decl.substr(pos + 2);
+ return o.str();
+}
+
void
Slice::CsGenerator::validateMetaData(const UnitPtr& unit)
{
diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp
index 2d66c7d9103..b2554371d41 100755
--- a/cpp/src/slice2cs/Gen.cpp
+++ b/cpp/src/slice2cs/Gen.cpp
@@ -2292,10 +2292,27 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
_out << nl << "return false;";
_out << eb;
_out << eb;
- _out << nl << vs << "[] __vlhs = new " << vs << "[Count];";
+ SequencePtr seq = SequencePtr::dynamicCast(p->valueType());
+ bool valueIsArray = seq && !seq->hasMetaData("cs:collection");
+ if(valueIsArray)
+ {
+ _out << nl << vs << "[] __vlhs = new " << toArrayAlloc(vs + "[]", "Count") << ';';
+ }
+ else
+ {
+ _out << nl << vs << "[] __vlhs = new " << vs << "[Count];";
+ }
_out << nl << "Values.CopyTo(__vlhs, 0);";
_out << nl << "_System.Array.Sort(__vlhs);";
- _out << nl << vs << "[] __vrhs = new " << vs << "[((" << name << ")other).Count];";
+ string vrhsCount = "((" + name + ")other).Count";
+ if(valueIsArray)
+ {
+ _out << nl << vs << "[] __vrhs = new " << toArrayAlloc(vs + "[]", vrhsCount) << ';';
+ }
+ else
+ {
+ _out << nl << vs << "[] __vrhs = new " << vs << '[' << vrhsCount << "];";
+ }
_out << nl << "((" << name << ")other).Values.CopyTo(__vrhs, 0);";
_out << nl << "_System.Array.Sort(__vrhs);";
_out << nl << "for(int i = 0; i < Count; ++i)";