aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauro Neto <lauro.neto@openbossa.org>2010-02-23 12:45:14 -0300
committerLauro Neto <lauro.neto@openbossa.org>2010-02-23 20:10:28 -0300
commit506a97bad2ab5cf9b09f735a59f9dcea68bbd276 (patch)
tree8b3a216259607c8f789a68db7163c529daf8e0d3
parent742eba6e0898f08c5ca04c1eb8292fc3d7b60a43 (diff)
Adding default value for enum/flag constructor
-rw-r--r--cppgenerator.cpp8
-rwxr-xr-xtests/samplebinding/enum_test.py5
2 files changed, 9 insertions, 4 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp
index 7ef7a4b09..ddf347581 100644
--- a/cppgenerator.cpp
+++ b/cppgenerator.cpp
@@ -2271,8 +2271,8 @@ void CppGenerator::writeFlagsNewMethod(QTextStream& s, const FlagsTypeEntry* cpp
s << '{' << endl;
s << INDENT << "if (!PyType_IsSubtype(type, &" << cpythonName << "_Type))" << endl;
s << INDENT << INDENT << "return 0;" << endl << endl;
- s << INDENT << "int item_value;" << endl;
- s << INDENT << "if (!PyArg_ParseTuple(args, \"i:__new__\", &item_value))" << endl;
+ s << INDENT << "int item_value = 0;" << endl;
+ s << INDENT << "if (!PyArg_ParseTuple(args, \"|i:__new__\", &item_value))" << endl;
{
Indentation indent(INDENT);
s << INDENT << "return 0;" << endl;
@@ -2292,8 +2292,8 @@ void CppGenerator::writeEnumNewMethod(QTextStream& s, const AbstractMetaEnum* cp
s << "static PyObject*" << endl;
s << cpythonName << "_New(PyTypeObject* type, PyObject* args, PyObject* kwds)" << endl;
s << '{' << endl;
- s << INDENT << "int item_value;" << endl;
- s << INDENT << "if (!PyArg_ParseTuple(args, \"i:__new__\", &item_value))" << endl;
+ s << INDENT << "int item_value = 0;" << endl;
+ s << INDENT << "if (!PyArg_ParseTuple(args, \"|i:__new__\", &item_value))" << endl;
{
Indentation indent(INDENT);
s << INDENT << "return 0;" << endl;
diff --git a/tests/samplebinding/enum_test.py b/tests/samplebinding/enum_test.py
index 53b4a9b3a..a6c2e0421 100755
--- a/tests/samplebinding/enum_test.py
+++ b/tests/samplebinding/enum_test.py
@@ -48,6 +48,11 @@ class EnumTest(unittest.TestCase):
'''Tries to build the proper enum using an integer.'''
SampleNamespace.getNumber(SampleNamespace.Option(1))
+ def testBuildingEnumWithDefaultValue(self):
+ '''Enum constructor with default value'''
+ enum = SampleNamespace.Option()
+ self.assertEqual(enum, SampleNamespace.None)
+
def testEnumConversionToAndFromPython(self):
'''Conversion of enum objects from Python to C++ back again.'''
enumout = SampleNamespace.enumInEnumOut(SampleNamespace.TwoIn)