PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 616 - error compiling when public and private methods differ by the const-ness
: error compiling when public and private methods differ by the const-ness
Status: CLOSED FIXED
Product: PySide
Classification: Unclassified
Component: Shiboken
: HEAD
: All Linux
: P3 normal
Assigned To: Hugo Parente Lima
:
:
:
  Show dependency treegraph
 
Reported: 2011-01-17 13:34 EET by John Cummings
Modified: 2011-02-23 18:57 EET (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Cummings 2011-01-17 13:34:30 EET
When both and public private method have the same name and differ by their
const-ness, a compilation error may result.

For example, adding to the binding tutorial:

http://developer.qt.nokia.com/wiki/PySide_Binding_Generation_Tutorial%3A_Binding_libfoo_using_Shiboken

Let me add two very similar methods:

class Math : public QObject
{
    Q_OBJECT
public:
    Math() {}
    virtual ~Math() {}
    int squared(int x);

    const Math* ptr() const { return this; }
private:
    Math* ptr() { return this; }
};

That is, I have added two ptr() methods, one public that is const and one
private that is not const. Leaving everything else the same with the tutorial,
results in the following compilation errors:

../libfoo/foo.h: In function ‘PyObject* Sbk_MathFunc_ptr(PyObject*)’:
../libfoo/foo.h:16:11: error: ‘Math* Math::ptr()’ is private
foo/foo/math_wrapper.cpp:292:55: error: within this contex

The generated code may be summarized as:

Math* cppSelf = 0;
...
const Math * cppResult = cppSelf->ptr();

Note that since cppSelf is a non-const pointer, the compiler chooses to call
the non-const method, namely the private version. That call, of course, results
in a compilation error. However, if I manually change cppSelf to be a const
pointer, everything compiles just fine.

So, I believe when a method is declared const, a const pointer should be used
for invoking all methods to avoid inadvertently calling a non-const method,
which can lead to compile errors.

The obvious workaround in the meantime, is to change the name of the private
method and to change the source code appropriately. However, sometime one does
not have access to the underlying source code.

One final note, this bug may be very distantly related to bug 42, which has
been closed. At the very least, a unit test could be added in the same place.
Comment 1 Matti Airas 2011-01-17 13:46:13 EET
Thanks for the bug - prioritizing P3. Should be taken care of during our next
two-week sprint (starting next week).
Comment 2 Hugo Parente Lima 2011-02-02 11:43:30 EET
Fixed in commit:

shiboken/81b6d4a6489e8b958418c7db3cccc2b480571af6

I added some tests to shiboken, can you test the patch with your own binding
just to check if I missed some use case?
Comment 3 renato filho 2011-02-02 15:46:09 EET
released on beta 5
Comment 4 John Cummings 2011-02-23 18:57:12 EET
(In reply to comment #2)
> Fixed in commit:
> 
> shiboken/81b6d4a6489e8b958418c7db3cccc2b480571af6
> 
> I added some tests to shiboken, can you test the patch with your own binding
> just to check if I missed some use case?

For what it is worth, this patch fixed my issue.

I am sorry for the very slow response. My email has not been right, so I never
received a notice of the fix. Thankful you moved on without me.