summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/CHANGES4
-rw-r--r--cpp/include/Slice/CsUtil.h6
-rwxr-xr-xcpp/src/Slice/CsUtil.cpp36
-rwxr-xr-xcpp/src/slice2cs/Gen.cpp21
4 files changed, 47 insertions, 20 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES
index 55378efd947..2a284536018 100644
--- a/cpp/CHANGES
+++ b/cpp/CHANGES
@@ -1,6 +1,10 @@
Changes since version 1.5.1
---------------------------
+- 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.
+
- Fixed bug in IcePack that would prevent dynamically added adapters
to be used again after the IcePack registry was restarted.
diff --git a/cpp/include/Slice/CsUtil.h b/cpp/include/Slice/CsUtil.h
index 259080b2d20..e527d8d140a 100644
--- a/cpp/include/Slice/CsUtil.h
+++ b/cpp/include/Slice/CsUtil.h
@@ -23,6 +23,11 @@ public:
virtual ~CsGenerator() {};
//
+ // Convert a dimension-less array declaration to one with a dimension.
+ //
+ static std::string toArrayAlloc(const std::string& decl, const std::string& sz);
+
+ //
// Validate all metadata in the unit with a "cs:" prefix.
//
static void validateMetaData(const UnitPtr&);
@@ -31,6 +36,7 @@ protected:
static std::string fixId(const std::string&, int = 0, bool = false);
static std::string typeToString(const TypePtr&);
static bool isValueType(const TypePtr&);
+
//
// Generate code to marshal or unmarshal a type
//
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)";