[reportlab-users] Re: FutureWarnings in ttfonts.py with Python 2.3

Marc Stober reportlab-users@reportlab.com
Fri, 2 Apr 2004 14:58:07 -0500


Robin wrote:
> .... I don't get that with the latest pyd's and the CVS code. It's an
> utter pain that they did the unification without introducing 
> an unsigned
> 32 bit int so the bit twiddling can continue. The fix seems 
> to be to use
> 
> def _L2U32(L):
>         return unpack('l',pack('L',L))[0]
> .....
>
> _L2U32((hi << 16L) | (lo & 0xFFFF))

Hi Robin,
I worked out a solution. The function above helps, but it's a little more
complicated. The future warning is still raised when the hi << 16L is
evaluated, before being passed to the function. 

I think that I now understand this warning is trying to say, "warning,
bit-shifting is an ugly hack for modulo multiplication." So, I was able to
use modulo multiplication directly, such as:
_L2U32((hi * (2**16) % (2**32)) ... etc.
The _L2U32 function is still needed to convert the result back to regular
(non-long) int.

I've uploaded a revised version of ttfonts.py to the SourceForge Patches
area and tested it under Python 2.2 and 2.3. (A simple test it to generate
the ReportLab userguide.)

Also, I don't think you'd get these warnings if you have the _rl_accel dll
installed, as the bit-shifting part will be executed in the dll.

Hope this helps!

Thanks,
Marc