[Bf-python] 64-bit and void*/int hackery

Ken Hughes khughes at pacific.edu
Tue Feb 5 01:46:32 CET 2008


Throwing this out for general comments:

Back when I started adding tp_getset goodness to the API, there were 
many places where I wrapped a common handler function (for example, for 
bitmasks) by using a void* to hold a constant:

    {"useAlpha",
     (getter)Texture_getImageFlags, (setter)Texture_setImageFlags,
     "Use of image's alpha channel enabled ('ImageFlags')",
     (void *)TEX_USEALPHA},

and then cast to an integer inside the function to get the value.  Of 
course, gcc complains about this on 64-bit platforms:

    warning: cast from pointer to integer of different size

In some places I later coded around this by first casting to a long, 
then masking the result:
 
 switch ( (int)((long)type & UINT_MAX) ):

This seems really hackish to me, plus I don't know if it fixes warnings 
on other platforms.  An alternative would be to actually pass pointers 
to real data; the overhead in terms of wasted memory is probably minimal.

Is this a problem we should try to fix in the code, or is it just me 
that's bothered by this?

Ken



More information about the Bf-python mailing list