From e2774ff5350fa94352858672aa165a8ff22aa3b1 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 2 Oct 2019 14:05:57 +0200 Subject: shiboken: Fix handling of modified default expressions - Do not try to resolve modified default expressions (add enumeration scopes or similar) - Fix the signature parser to handle arbitrary expressions Fixes: PYSIDE-1095 Change-Id: I059c3a1f066687d7c2f0dad9ea7f0d93e292b1b5 Reviewed-by: Christian Tismer --- .../shiboken2/generator/shiboken2/shibokengenerator.cpp | 8 ++++---- .../files.dir/shibokensupport/signature/parser.py | 3 ++- sources/shiboken2/tests/libsample/modifications.cpp | 16 ++++++++++++++++ sources/shiboken2/tests/libsample/modifications.h | 10 ++++++++++ .../shiboken2/tests/samplebinding/modifications_test.py | 10 ++++++++++ .../shiboken2/tests/samplebinding/typesystem_sample.xml | 6 ++++++ 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 @@ + @@ -1287,6 +1288,11 @@ %PYARG_0 = %CONVERTTOPYTHON[OddBool](%0); + + + + + -- cgit v1.2.3