Yannick Bergeron <[EMAIL PROTECTED]> writes:
>I'm trying to write a module for an AIX structure named procinfo. This 
>structure
>is different if we run AIX with a 32bit kernel or with a 64bit kernel
>
>the xs parser doesn't seem to like ifdef. How can I declarer the same 
>subroutine
>for 32 bits and 64 bits?

I suspect it isn't only the #if that is the problem but the blank line(s).
xsubpp processes things in "paragraphs".

#ifdef is ok in the C part (before the MODULE line)
so put the #if there:

-------------------------------
static IV my_pi_pid(struct procsinfo proc)
{
#ifdef __64BIT__
    return (IV) proc.pi_pid;
#else
    return (IV) proc.pi_pid;
#endif
}

MODULE AIX::Procinfo::procsinfo PACKAGE = AIX::Procinfo::procsinfo PREFIX = my_

IV pi_pid(struct procsinfo proc)

-------------------------------

That said as the only difference is the return type, and both are 
presumably going to end up as an IV anyway

-------------------------------
#define my_pi_pid(proc) ((IV)proc.pi_pid)

MODULE AIX::Procinfo::procsinfo PACKAGE = AIX::Procinfo::procsinfo PREFIX = my_

IV pi_pid(struct procsinfo proc)
-------------------------------

Should suffice.


>
>example:
>
>#include <procinfo.h>
>
>#include "EXTERN.h"
>#include "perl.h"
>#include "XSUB.h"
>
>MODULE = AIX::Procinfo::procsinfo       PACKAGE = AIX::Procinfo::procsinfo
>
>#ifdef __64BIT__
>pid_t
>pi_pid(struct procsinfo proc)
>        CODE:
>                /* process ID */
>                RETVAL = proc.pi_pid;
>
>        OUTPUT:
>                RETVAL
>#else /* __64BIT__ */
>unsigned long
>pi_pid(struct procsinfo proc)
>        CODE:
>                /* process ID */
>                RETVAL = proc.pi_pid;
>        OUTPUT:
>                RETVAL
>#endif /* __64BIT__ */

Reply via email to