summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/CHANGES4
-rw-r--r--cpp/include/Slice/Parser.h4
-rw-r--r--cpp/src/Slice/Parser.cpp78
-rw-r--r--cpp/test/Slice/errorDetection/IllegalDictionary.err1
-rw-r--r--cpp/test/Slice/errorDetection/IllegalDictionary.ice2
5 files changed, 39 insertions, 50 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES
index 8b4104e9f05..50eca43583c 100644
--- a/cpp/CHANGES
+++ b/cpp/CHANGES
@@ -1,6 +1,10 @@
Changes since version 1.0.1
---------------------------
+- Structs and sequences which hold other structs or sequences are now
+ legal dictionary key types, as long as such nested structs or
+ sequences are (recursively) legal.
+
- The connection timeout is now also used when connections are
closed. This avoid hanging processes if the peer misbehaves.
diff --git a/cpp/include/Slice/Parser.h b/cpp/include/Slice/Parser.h
index 79d31010086..858a4efdbc3 100644
--- a/cpp/include/Slice/Parser.h
+++ b/cpp/include/Slice/Parser.h
@@ -678,10 +678,6 @@ protected:
TypePtr _keyType;
TypePtr _valueType;
-
-private:
-
- static bool legalSimpleKeyType(const TypePtr&);
};
// ----------------------------------------------------------------------
diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp
index 7853bab5e56..aa48414bbec 100644
--- a/cpp/src/Slice/Parser.cpp
+++ b/cpp/src/Slice/Parser.cpp
@@ -2732,54 +2732,13 @@ Slice::Dictionary::recDependencies(set<ConstructedPtr>& dependencies)
}
//
-// Check that the key type of a dictionary is legal. Legal types are integral types, string, and sequences and
-// structs containing only integral types or strings.
+// Check that the key type of a dictionary is legal. Legal types are
+// integral types, string, and sequences and structs containing only
+// other legal key types.
//
bool
Slice::Dictionary::legalKeyType(const TypePtr& type)
{
- if(legalSimpleKeyType(type))
- {
- return true;
- }
-
- SequencePtr seqp = SequencePtr::dynamicCast(type);
- if(seqp && legalSimpleKeyType(seqp->type()))
- {
- return true;
- }
-
- StructPtr strp = StructPtr::dynamicCast(type);
- if(strp)
- {
- DataMemberList dml = strp->dataMembers();
- for(DataMemberList::const_iterator mem = dml.begin(); mem != dml.end(); ++mem)
- {
- if(!legalSimpleKeyType((*mem)->type()))
- {
- return false;
- }
- }
- return true;
- }
-
- return false;
-}
-
-Slice::Dictionary::Dictionary(const ContainerPtr& container, const string& name, const TypePtr& keyType,
- const TypePtr& valueType, bool local) :
- Constructed(container, name, local),
- Type(container->unit()),
- Contained(container, name),
- SyntaxTreeBase(container->unit()),
- _keyType(keyType),
- _valueType(valueType)
-{
-}
-
-bool
-Slice::Dictionary::legalSimpleKeyType(const TypePtr& type)
-{
BuiltinPtr bp = BuiltinPtr::dynamicCast(type);
if(bp)
{
@@ -2814,9 +2773,40 @@ Slice::Dictionary::legalSimpleKeyType(const TypePtr& type)
return true;
}
+ SequencePtr seqp = SequencePtr::dynamicCast(type);
+ if(seqp && legalKeyType(seqp->type()))
+ {
+ return true;
+ }
+
+ StructPtr strp = StructPtr::dynamicCast(type);
+ if(strp)
+ {
+ DataMemberList dml = strp->dataMembers();
+ for(DataMemberList::const_iterator mem = dml.begin(); mem != dml.end(); ++mem)
+ {
+ if(!legalKeyType((*mem)->type()))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
return false;
}
+Slice::Dictionary::Dictionary(const ContainerPtr& container, const string& name, const TypePtr& keyType,
+ const TypePtr& valueType, bool local) :
+ Constructed(container, name, local),
+ Type(container->unit()),
+ Contained(container, name),
+ SyntaxTreeBase(container->unit()),
+ _keyType(keyType),
+ _valueType(valueType)
+{
+}
+
// ----------------------------------------------------------------------
// Enum
// ----------------------------------------------------------------------
diff --git a/cpp/test/Slice/errorDetection/IllegalDictionary.err b/cpp/test/Slice/errorDetection/IllegalDictionary.err
index 5f43c053467..33863b470f8 100644
--- a/cpp/test/Slice/errorDetection/IllegalDictionary.err
+++ b/cpp/test/Slice/errorDetection/IllegalDictionary.err
@@ -4,6 +4,5 @@ IllegalDictionary.ice:24: dictionary `b3' uses an illegal key type
IllegalDictionary.ice:25: dictionary `b4' uses an illegal key type
IllegalDictionary.ice:26: dictionary `b5' uses an illegal key type
IllegalDictionary.ice:32: dictionary `b6' uses an illegal key type
-IllegalDictionary.ice:35: dictionary `b7' uses an illegal key type
IllegalDictionary.ice:49: dictionary `b8' uses an illegal key type
IllegalDictionary.ice:57: dictionary `b9' uses an illegal key type
diff --git a/cpp/test/Slice/errorDetection/IllegalDictionary.ice b/cpp/test/Slice/errorDetection/IllegalDictionary.ice
index 305390093fe..9e8190c90ee 100644
--- a/cpp/test/Slice/errorDetection/IllegalDictionary.ice
+++ b/cpp/test/Slice/errorDetection/IllegalDictionary.ice
@@ -32,7 +32,7 @@ sequence<float> s2;
dictionary<s2, long> b6; // Bad
sequence<s1> s3;
-dictionary<s3, long> b7; // Bad
+dictionary<s3, long> b7; // OK
struct st1
{