aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sources/shiboken2/generator/shiboken2/shibokengenerator.cpp8
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py3
-rw-r--r--sources/shiboken2/tests/libsample/modifications.cpp16
-rw-r--r--sources/shiboken2/tests/libsample/modifications.h10
-rw-r--r--sources/shiboken2/tests/samplebinding/modifications_test.py10
-rw-r--r--sources/shiboken2/tests/samplebinding/typesystem_sample.xml6
6 files changed, 48 insertions, 5 deletions
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
index 34e43a4c7..2a8eefba6 100644
--- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
@@ -573,11 +573,11 @@ QString ShibokenGenerator::guessScopeForDefaultValue(const AbstractMetaFunction
{
QString value = getDefaultValue(func, arg);
- if (value.isEmpty())
- return QString();
-
- if (isPointer(arg->type()))
+ if (value.isEmpty()
+ || arg->hasModifiedDefaultValueExpression()
+ || isPointer(arg->type())) {
return value;
+ }
static const QRegularExpression enumValueRegEx(QStringLiteral("^([A-Za-z_]\\w*)?$"));
Q_ASSERT(enumValueRegEx.isValid());
diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py
index 3d14ec7b3..0081a07ba 100644
--- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py
@@ -106,7 +106,8 @@ def _parse_line(line):
$
"""
ret = SimpleNamespace(**re.match(line_re, line, re.VERBOSE).groupdict())
- argstr = ret.arglist
+ # PYSIDE-1095: Handle arbitrary default expressions
+ argstr = ret.arglist.replace("->", ".deref.")
arglist = _parse_arglist(argstr)
args = []
for arg in arglist:
diff --git a/sources/shiboken2/tests/libsample/modifications.cpp b/sources/shiboken2/tests/libsample/modifications.cpp
index 98b22f09b..56ba81875 100644
--- a/sources/shiboken2/tests/libsample/modifications.cpp
+++ b/sources/shiboken2/tests/libsample/modifications.cpp
@@ -149,3 +149,19 @@ Modifications::nonConversionRuleForArgumentWithDefaultValue(ObjectType** object)
*object = m_object;
return true;
}
+
+void Modifications::setEnumValue(TestEnum e)
+{
+ m_enumValue = e;
+}
+
+Modifications::TestEnum Modifications::enumValue() const
+{
+ return m_enumValue;
+}
+
+Modifications::TestEnum Modifications::defaultEnumValue() const
+{
+ return TestEnumValue2;
+}
+
diff --git a/sources/shiboken2/tests/libsample/modifications.h b/sources/shiboken2/tests/libsample/modifications.h
index fa32bdec3..674a05f27 100644
--- a/sources/shiboken2/tests/libsample/modifications.h
+++ b/sources/shiboken2/tests/libsample/modifications.h
@@ -51,6 +51,11 @@ public:
Overloaded_ibPP
};
+ enum TestEnum {
+ TestEnumValue1,
+ TestEnumValue2
+ };
+
// those overloaded methods should be heavily modified
// to push the overload decisor to its limits
inline OverloadedModFunc overloaded(int a0, bool b0, int c0, double d0) { return Overloaded_ibid; }
@@ -123,8 +128,13 @@ public:
// Inject code with a %CONVERTTOPYTHON that receives an user's primitive type.
static inline OddBool passOddBool(OddBool ob) { return ob; }
+ void setEnumValue(TestEnum e = TestEnumValue1);
+ TestEnum enumValue() const;
+ TestEnum defaultEnumValue() const;
+
private:
ObjectType* m_object;
+ TestEnum m_enumValue = TestEnumValue1;
};
class LIBSAMPLE_API AbstractModifications : public Modifications
diff --git a/sources/shiboken2/tests/samplebinding/modifications_test.py b/sources/shiboken2/tests/samplebinding/modifications_test.py
index 1dcd50359..e9a1eaf7f 100644
--- a/sources/shiboken2/tests/samplebinding/modifications_test.py
+++ b/sources/shiboken2/tests/samplebinding/modifications_test.py
@@ -220,5 +220,15 @@ class ModificationsTest(unittest.TestCase):
self.assertTrue(isinstance(res, float))
self.assertEqual(res, em.increment)
+ def testDefaultValueModifications(self):
+ # PSYIDE-1095: setEnumValue() has the default value modified to
+ # calling defaultEnumValue() which returns Modifications.TestEnumValue2.
+ # This used to generated broken code since defaultEnumValue() was
+ # qualified by the enum scope.
+ modifications = Modifications()
+ modifications.setEnumValue()
+ self.assertEqual(modifications.enumValue(), Modifications.TestEnumValue2)
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml
index 19b4948a1..4d624f952 100644
--- a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml
+++ b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml
@@ -956,6 +956,7 @@
<object-type name="Modifications">
<enum-type name="OverloadedModFunc"/>
+ <enum-type name="TestEnum"/>
<modify-function signature="overloaded(int, bool, int, double)">
<modify-argument index="2">
@@ -1287,6 +1288,11 @@
%PYARG_0 = %CONVERTTOPYTHON[OddBool](%0);
</inject-code>
</modify-function>
+ <modify-function signature="setEnumValue(Modifications::TestEnum)">
+ <modify-argument index="1">
+ <replace-default-expression with="cppSelf->defaultEnumValue()"/>
+ </modify-argument>
+ </modify-function>
</object-type>
<object-type name="AbstractModifications">