[PyQt] Sip generates wrong argument parsing code
Phil Thompson
phil at riverbankcomputing.com
Thu Jun 12 10:09:54 BST 2008
On Wednesday 11 June 2008 6:13:21 pm Olaf Schumann wrote:
> Hello, I have a problem with sip 4.7.6 under both linux and windows
>
> I wrap a self-written C++-library for Python.
> For a Matrix-Object I implement a __getitem__ and __setitem__ method in
> the sip-file with two integer arguments. While the __setitem__ function
> is working from python, the __get__item__ generates the following error:
>
> argument 1 of Mat3D.__getitem__() has an invalid type
>
>
> the corresponding code in the sip-file is:
>
> [...]
> void __setitem__(int i, int j, double d);
> %MethodCode
> Py_BEGIN_ALLOW_THREADS
> *(*sipCpp).at(a0,a1)=a2;
> Py_END_ALLOW_THREADS
> %End
>
> double __getitem__(int i, int j);
> %MethodCode
> Py_BEGIN_ALLOW_THREADS
> sipRes = *((*sipCpp).at(a0, a1));
> Py_END_ALLOW_THREADS
> %End
>
> [...]
>
>
> The argument parsing in the __getitem__ function looks like:
>
>
>
> if (sipParseArgs(&sipArgsParsed,sipArg,"1ii",&a0,&a1))
> {
> double sipRes = 0;
>
> Here, i would not expect the "1" before the "i"s? Is this my fault or a
> bug in sip?
Neither, it's supposed to be there.
> The complete generated __getitem__ function is below, if necessary I
> could send the complete source code (sip-files, cpp files etc).
The sequence protocol only supports one dimension. If you are accessing a 2-D
object then you can't use __setitem__ and __getitem__ unless your index is
something like a tuple and your handwritten code unpacks the tuple to get the
i and j values.
There is a bug in SIP that, for some reason I don't understand (or can't
remember), is only checking that __getitem__ is being given a minimum of one
argument instead of exactly one argument. __delitem__ and __setitem__ have a
similar problem.
Without that bug SIP would have given errors with your code.
Phil
More information about the PyQt
mailing list