Re: warning: cast to pointer from integer of different size
On Mon, Feb 06, 2012 at 09:51:54PM +0000, Nicholas Bamber wrote:
> We have a lot of packages with this build error.
> looks worrying to me. As far as I can see it would need to be fixed by
> changing the code generated by the XS layer. I imagine it would be
> concern on the newer 64 bit architectures. Or maybe it happens not to be
> a serious issue in XS Perl modules.
Looking at some of the packages and
these seem to be bugs in the modules rather than ExtUtils::ParseXS, and
mostly uncovered by our switch to -Duse64bitint from Perl 5.12 onwards.
It looks like most of the warnings result from typemap code like
$var = ($type)SvIV((SV*)SvRV( $arg ));
which should really be
$var = INT2PTR($type, SvIV((SV*)SvRV( $arg )));
In such cases the warnings should be harmless AFAICS, assuming $type is
a pointer at all. (The casts are a no-op on 64-bit architectures and a
lossless 32bit -> 64bit -> 32bit conversion on the 32-bit ones). However,
obviously some of the warnings could also indicate real problems. So
the false positives should really be fixed.
The big number of the warnings is probably because perlxs.pod recommended
the first form above for a long time, and although [perl #32660]
fixed much of that, there's still one example in the old style left.
(This seems to be a minor bug in perl.)
I had a look at a few of the offending modules, and they were all
trivially fixable with the above recipe and some corresponding PTR2IV
macros, either in the typemap file or (more rarely) in the XS code.
So I suppose the offenders should be fixed one by one and patches
Niko Tyni email@example.com