Help with xs: converting I32 to int ?

Help with xs: converting I32 to int ?

am 10.04.2006 01:49:54 von Peter Billam

Hi. Compiling my Math-WalshTransform-1.11 on a
Fedora5 with gcc 4.1.0 gives me (amongst other stuff which I can fix):

In file included from WalshTransform.xs:7:
ppport.h:231:1: warning: "PERL_UNUSED_DECL" redefined
In file included from WalshTransform.xs:5:
/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/perl.h:163 :1:
warning: this is the location of the previous definition
WalshTransform.xs: In function 'XS_Math__WalshTransform_xs_fht':
WalshTransform.xs:50: warning: format '%d' expects type 'int',
but argument 4 has type 'I32'
WalshTransform.xs: In function 'XS_Math__WalshTransform_xs_fhtinv':
WalshTransform.xs:90: warning: format '%d' expects type 'int',
but argument 4 has type 'I32'

Now the PERL_UNUSED_DECL bit comes from a
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include "math.h"
#ifdef __cplusplus
}
#endif
incantation at the beginning. Should I change this bit ?

The lines 50 and 90 are like
fprintf (stderr, "fhtinv: n should be a power of 2, but was %d\n", items);
How should I convert my I32 items builtin into an int ?

Regards, Peter

--
AUS/TAS/DPIWE/CIT/Servers hbt/lnd/l8 6233 3061 http://www.pjb.com.au
Pasaré, pasarémos dice el agua y canta la verdad contra la piedra
-- Pablo Neruda

Re: Help with xs: converting I32 to int ?

am 10.04.2006 07:33:04 von Sisyphus

"Peter Billam" wrote in message
news:slrne3jate.cu5.peter@localhost.localdomain...
> Hi. Compiling my Math-WalshTransform-1.11 on a
> Fedora5 with gcc 4.1.0 gives me (amongst other stuff which I can fix):
>
> In file included from WalshTransform.xs:7:
> ppport.h:231:1: warning: "PERL_UNUSED_DECL" redefined
> In file included from WalshTransform.xs:5:
> /usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/perl.h:163 :1:
> warning: this is the location of the previous definition
> WalshTransform.xs: In function 'XS_Math__WalshTransform_xs_fht':
> WalshTransform.xs:50: warning: format '%d' expects type 'int',
> but argument 4 has type 'I32'
> WalshTransform.xs: In function 'XS_Math__WalshTransform_xs_fhtinv':
> WalshTransform.xs:90: warning: format '%d' expects type 'int',
> but argument 4 has type 'I32'
>
..
..
> The lines 50 and 90 are like
> fprintf (stderr, "fhtinv: n should be a power of 2, but was %d\n",
items);
> How should I convert my I32 items builtin into an int ?
>

Not sure - '%d' is quite happy to accept an I32 for me. Does casting to an
'int' fix the problem :

fprintf (stderr, "fhtinv: n should be a power of 2, but was %d\n",
(int)items);

Cheers,
Rob

Re: Help with xs: converting I32 to int ?

am 10.04.2006 08:22:52 von Sisyphus

"Peter Billam"

> In file included from WalshTransform.xs:7:
> ppport.h:231:1: warning: "PERL_UNUSED_DECL" redefined
> In file included from WalshTransform.xs:5:
> /usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/perl.h:163 :1:
> warning: this is the location of the previous definition
..
..
>
> Now the PERL_UNUSED_DECL bit comes from a
> #ifdef __cplusplus
> extern "C" {
> #endif
> #include "EXTERN.h"
> #include "perl.h"
> #include "XSUB.h"
> #include "ppport.h"
> #include "math.h"
> #ifdef __cplusplus
> }
> #endif
> incantation at the beginning. Should I change this bit ?
>

Sorry - skipped this bit in my other reply. It's hard to answer -
search.cpan.org is still showing only version 1.10 (my mirror, at least) so
I can't get at a look at the actual ppport.h you've got.

There's a good chance the redefinition won't matter - but I doubt that it
should be happening. I would think the fact that PERL_UNUSED_DECL was
defined in perl.h should have been detected, and the definition omitted from
the generated ppport.h .... but I'm not really an expert on what ppport.h
should and should not do. (Come to think of it, I'm not an expert on
anything else, either.)

Do you need to include a ppport.h in the source ?

Cheers,
Rob

Re: Help with xs: converting I32 to int ?

am 10.04.2006 22:57:47 von Peter Billam

On 2006-04-10, Sisyphus wrote:
> > WalshTransform.xs:50: warning: format '%d' expects type 'int',
> > but argument 4 has type 'I32'
> Not sure - '%d' is quite happy to accept an I32 for me.
> Does casting to an 'int' fix the problem :
> fprintf (stderr, "fhtinv: n should be a power of 2, but was %d\n",
> (int)items);

Yes, it does fix the problem, thanks :-)

> > In file included from WalshTransform.xs:7:
> > ppport.h:231:1: warning: "PERL_UNUSED_DECL" redefined
> search.cpan.org is still showing only version 1.10 (my mirror, at
> least) so I can't get at a look at the actual ppport.h you've got.
>
Ah, er, sorry, 1.11 is the _next_ release. But 1.10 behaves the same
for me under Fedora5 gcc4.1.0 ...

> I'm not really an expert on what ppport.h should and should not do.
> ... Do you need to include a ppport.h in the source ?

Well, apparently not; it compiles perfectly without #include "ppport.h",
so the question remains open of what ppport.h does, and when it's
needed.

Thanks for your help, expect Math::WalshTransform-1.11 sometime soon.

Regards, Peter

--
AUS/TAS/DPIW/CIT/Servers hbt/lnd/l8 6233 3061 http://www.pjb.com.au
Pasaré, pasarémos dice el agua y canta la verdad contra la piedra
-- Pablo Neruda

Re: Help with xs: converting I32 to int ?

am 11.04.2006 02:02:47 von Sisyphus

"Peter Billam" wrote in message
..
..
> > fprintf (stderr, "fhtinv: n should be a power of 2, but was %d\n",
> > (int)items);

It's probably worth pointing out that if you ever declare dXSARGS in a
function, then 'items' becomes a keyword (within that function) and any
attempt to use 'items' as a variable name (within that function) will
produce fatal redefinition errors - error messages that don't really make it
clear just what the problem is. For that reason I always avoid using 'items'
as a variable name .... even though it's often the logical name to bestow
upon the variable.

>
> > I'm not really an expert on what ppport.h should and should not do.
> > ... Do you need to include a ppport.h in the source ?
>
> Well, apparently not; it compiles perfectly without #include "ppport.h",
> so the question remains open of what ppport.h does, and when it's
> needed.
>

Probably a good question for another post - unless someone else comes
forward here and answers it. I don't think I've ever seen any advocacy for
using it, or indeed any discussion about it. All I know is that it's a part
of a small percentage of source tarballs, and that its own documentation
says it's useful.

I've no doubt there are people perusing this list who know a good deal about
it, but if I were going to ask about the usage of ppport.h I'd probably post
to a higher volume list (like, say, PerlMonks) where there's a wider range
of respondents.

Cheers,
Rob

Re: Help with xs: converting I32 to int ?

am 11.04.2006 03:12:39 von Peter Billam

On 2006-04-11, Sisyphus wrote:
> It's probably worth pointing out that if you ever declare dXSARGS
> in a function, then 'items' becomes a keyword (within that function)
> and any attempt to use 'items' as a variable name (within that
> function) will produce fatal redefinition errors - error messages
> that don't really make it clear just what the problem is. For that
> reason I always avoid using 'items' as a variable name .... even
> though it's often the logical name to bestow upon the variable.

I got my "items" from perldoc perlxs where it says:
XSUBs can have variable-length parameter lists by specifying an
ellipsis "(...)" in the parameter list. This use of the ellipsis
is similar to that found in ANSI C. The programmer is able to
determine the number of arguments passed to the XSUB by examining
the "items" variable which the xsubpp compiler supplies for all <==
XSUBs. By using this mechanism one can create an XSUB which
accepts a list of parameters of unknown length.

What's dXSARGS and when would I need to declare it ?
It's mentioned once in perldoc perlxstut, but not in perldoc perlxs.

Regards, Peter

--
AUS/TAS/DPIW/CIT/Servers hbt/lnd/l8 6233 3061 http://www.pjb.com.au
Pasaré, pasarémos dice el agua y canta la verdad contra la piedra
-- Pablo Neruda

Re: Help with xs: converting I32 to int ?

am 11.04.2006 05:57:43 von Sisyphus

"Peter Billam" wrote in message
news:slrne3m44i.n18.peter@localhost.localdomain...
> On 2006-04-11, Sisyphus wrote:
> > It's probably worth pointing out that if you ever declare dXSARGS
> > in a function, then 'items' becomes a keyword (within that function)
> > and any attempt to use 'items' as a variable name (within that
> > function) will produce fatal redefinition errors - error messages
> > that don't really make it clear just what the problem is. For that
> > reason I always avoid using 'items' as a variable name .... even
> > though it's often the logical name to bestow upon the variable.
>
> I got my "items" from perldoc perlxs where it says:
> XSUBs can have variable-length parameter lists by specifying an
> ellipsis "(...)" in the parameter list. This use of the ellipsis
> is similar to that found in ANSI C. The programmer is able to
> determine the number of arguments passed to the XSUB by examining
> the "items" variable which the xsubpp compiler supplies for all <==
> XSUBs. By using this mechanism one can create an XSUB which
> accepts a list of parameters of unknown length.
>

Aaaahh .... sorry - I thought you had declared and were using a variable
named 'items' - but you're obviously not. In fact, you're using 'items' as
that very same reserved variable I was talking about. My mistake.

Cheers,
Rob