summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2009-01-27 17:33:50 -0800
committerMark Spruiell <mes@zeroc.com>2009-01-27 17:33:50 -0800
commit035d3f4040c37c78dcbad2b31a770c71e8b64c66 (patch)
treeb4a5b23a4943461cd6171cc62919f4efeed2c8cc /cpp
parentSquashed commit of the following: (diff)
downloadice-035d3f4040c37c78dcbad2b31a770c71e8b64c66.tar.bz2
ice-035d3f4040c37c78dcbad2b31a770c71e8b64c66.tar.xz
ice-035d3f4040c37c78dcbad2b31a770c71e8b64c66.zip
bug 3676 - bug in default value for structs
Diffstat (limited to 'cpp')
-rw-r--r--cpp/src/Slice/PythonUtil.cpp43
1 files changed, 39 insertions, 4 deletions
diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp
index cb9e024717a..1917192ae29 100644
--- a/cpp/src/Slice/PythonUtil.cpp
+++ b/cpp/src/Slice/PythonUtil.cpp
@@ -153,6 +153,11 @@ private:
};
typedef list<MemberInfo> MemberInfoList;
+ //
+ // Write a member assignment statement for a constructor.
+ //
+ void writeAssign(const MemberInfo&);
+
void collectClassMembers(const ClassDefPtr&, MemberInfoList&, bool);
void collectExceptionMembers(const ExceptionPtr&, MemberInfoList&, bool);
@@ -476,7 +481,7 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
{
if(!q->inherited)
{
- _out << nl << "self." << q->fixedName << " = " << q->fixedName;;
+ writeAssign(*q);
}
}
}
@@ -982,7 +987,7 @@ Slice::Python::CodeVisitor::visitExceptionStart(const ExceptionPtr& p)
{
if(!q->inherited)
{
- _out << nl << "self." << q->fixedName << " = " << q->fixedName;;
+ writeAssign(*q);
}
}
}
@@ -1101,7 +1106,7 @@ Slice::Python::CodeVisitor::visitStructStart(const StructPtr& p)
_out.inc();
for(r = memberList.begin(); r != memberList.end(); ++r)
{
- _out << nl << "self." << r->fixedName << " = " << r->fixedName;
+ writeAssign(*r);
}
_out.dec();
@@ -1629,7 +1634,13 @@ Slice::Python::CodeVisitor::writeDefaultValue(const TypePtr& p)
StructPtr st = StructPtr::dynamicCast(p);
if(st)
{
- _out << getSymbol(st) << "()";
+ //
+ // We cannot emit a call to the struct's constructor here because Python
+ // only evaluates this expression once (see bug 3676). Instead, we emit
+ // a marker that allows us to determine whether the application has
+ // supplied a value.
+ //
+ _out << "Ice._struct_marker";
return;
}
@@ -1701,6 +1712,30 @@ Slice::Python::CodeVisitor::writeMetaData(const StringList& meta)
_out << ')';
}
+void
+Slice::Python::CodeVisitor::writeAssign(const MemberInfo& info)
+{
+ //
+ // Structures are treated differently (see bug 3676).
+ //
+ StructPtr st = StructPtr::dynamicCast(info.type);
+ if(st)
+ {
+ _out << nl << "if " << info.fixedName << " is Ice._struct_marker:";
+ _out.inc();
+ _out << nl << "self." << info.fixedName << " = " << getSymbol(st) << "()";
+ _out.dec();
+ _out << nl << "else:";
+ _out.inc();
+ _out << nl << "self." << info.fixedName << " = " << info.fixedName;
+ _out.dec();
+ }
+ else
+ {
+ _out << nl << "self." << info.fixedName << " = " << info.fixedName;
+ }
+}
+
string
Slice::Python::CodeVisitor::getOperationMode(Slice::Operation::Mode mode)
{