[PyKDE] Sip problem with narrowed return types

Lőrentey Károly Karoly.Lorentey at cern.ch
Thu Aug 26 16:46:58 BST 2004


Hi,

(I'm sorry if this is a known issue, I could not find it mentioned in
the list archives.)

To try my hand on writing SIP specifications, I chose to write a
simple Python interface to Scott Wheeler's TagLib.  Unfortunately I
met an obstacle when I came across a situation similar to the
following:

        /* File test.h */

	#ifndef TEST_H
	#define TEST_H
	
	class Test 
	{
	public:
	  virtual Test *foo ();
	};
	
	class Child : public Test 
	{
	public:
	  virtual Child *foo ();  /* Note the return value! */
	};
	
	#endif /* TEST_H */

That is, Child::foo overrides Test::foo, but changes the type of the
returned value to a subclass of the original type.  (See TagLib's
TagLib::File::audioProperties vs. TagLib::MPEG::File::audioProperties.)

I tried to write a SIP specification for this class hierarchy, but the
narrowed return type of Child::foo seems to have confused sip.  Here
is my (simple-minded) attempt:

        /* File test.sip */
	%Module test 0
	
	class Test
	{
	
	%TypeHeaderCode
	#include "test.h"
	%End
	
	public:
	  virtual Test *foo ();
	};
	
	class Child : Test
	{
	
	%TypeHeaderCode
	#include "test.h"
	%End
	
	public:
	  virtual Child *foo ();
	};

Running `sip -c . test.sip' produces the following code in
siptestChild.h:

        ...
	class sipChild : public Child
	{
	public:
                ...
		/*
		 * There is a public method for every virtual method visible from
		 * this class.
		 */
		Test * foo();               /* <---- Invalid */
		Child * foo();
                ...
	};
        ...

That is, sip fails to recognize that Child::foo overrides Test::foo,
and tries to produce code for both.  Unfortunately, this is not valid
C++ code.  The `Test * foo ()' declaration has the same signature as
`Child * foo ()', therefore the C++ compiler signals an error.  

Is this a bug in sip, or is there something obvious missing from my
specification?

-- 
Károly
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20040826/9c3e8818/attachment.bin


More information about the PyQt mailing list