[Qgis-developer] QgsRasterBlock.setColor(size_t, QRgb) in SIP

Radim Blazek radim.blazek at gmail.com
Thu Oct 24 07:40:58 PDT 2013


On Thu, Oct 24, 2013 at 3:46 AM, Martin Dobias <wonder.sk at gmail.com> wrote:
> On Thu, Oct 24, 2013 at 1:32 AM, Radim Blazek <radim.blazek at gmail.com> wrote:
>> On Wed, Oct 23, 2013 at 7:07 PM, Martin Dobias <wonder.sk at gmail.com> wrote:
>>> When I enter those two lines into QGIS python console, it work fine
>>> (no debug output, result of setColor() call is True). Tested on linux
>>> 64bit, QGIS master (debug), SIP v4.15.2.
>>
>> could you also test if you get the right value from block back
>>    block.color( index )
>> and with indexes > 0
>
> Yes, I get correct values.
>
>>> Otherwise I do not really have an idea what goes wrong there (btw. the
>>> index is an interesting number - in hex it is 0x7ff800000000
>>
>> it does not seem to be really correct
>>
>>> - maybe it is not handling size_t type correctly?
>>
>> yes, size_t seems to be the problem, it is not defined in qgsrasterblock.sip,
>> probably the definition from qgsgeometry.sip is used:
>>   %If (WS_MACX)
>>   typedef unsigned long size_t;
>>   %End
>>   %If (WS_X11 || WS_WIN)
>>   typedef unsigned int size_t;
>>   %End
>> which does not seem to be very robust.
>
> Indeed, the definition does not look robust. Will it help if you
> change size_t definition for your platform to "unsigned long long" ?
> (assuming you are on 64bit OS)

Then I get

>>> block.setColor( 0, QColor ().rgb() )
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: arguments did not match any overloaded call:
  QgsRasterBlock.setColor(int, int, int): not enough arguments
  QgsRasterBlock.setColor(int, int): argument 1 has unexpected type 'int'

works with "unsigned long". In C++ I have size_t defined as "long
unsigned int" (gives compilation error if used in sip file) which
should be the same as "unsigned long" I believe.

The problem is wrong definition of size_t in sip file. It should not
work for you as well, right? If you are on Linux you get "typedef
unsigned int size_t" in sip which is not the same as size_t in C++. I
guess that it accidentally works because by chance the memory used by
wider type is zeroed.

> There was a thread on size_t in PyQt some time ago:
> http://www.riverbankcomputing.com/pipermail/pyqt/2006-March/012753.html

Yes, I saw, quite old and no solution. If I look into stddef.h
(/usr/lib/gcc/x86_64-linux-gnu/4.6/include/stddef.h) the typedef of
size_t is quite complex.

So how can we reliably define size_t in sip file?

>> BTW, how to define such things
>> correctly, in each sip file or globally in another sip file for all?
>
> You need to define these things just once in one of the .sip files.
> The order is not important (unlike c/c++).

I mean what is the best practice to do that in QGIS. Would not it be
better to have shared definitions separated into some common.sip?

Radim

> Martin


More information about the Qgis-developer mailing list