Glenn MacGregor [31/07/01 16:46 +0000]:
> Hi All,
> 
> I got my test to run (somewhat), thanks to all for your help.  I have a
> c function in a static lib file which takes and int and a char **
> 
> int
> Init(int, char **);
> 
> I have made a wrapper around it in my perl test in the __C__ section
> 
> int
> PInit(int argc, char **argv) {
>     return Init(argc, argv);
> }
> 
> I have also put in that library the XS_unpack_CharPtrPtr;  The compile
> works fine.  When It runs I always get the Usage message:
> 
> Usage  main::PInit(int argc, char ** argv)
> 
> Now Calling PInit:
> 
> $test = PInit($#ARGV, @ARGV);
> 
> Looking into the build directory I see where it is happening in the c
> file:
> 
> if (item != 2) ...
> 
> I don't see where item gets set though.
> 
>     Any clues?

It's set in a macro. Here's how to see it expanded (unfortunately MakeMaker
doesn't put a rule for this automatically). This is a little cryptic because
the command lines are so long. Try to follow along:

0) First, we need to get a couple of commands that aren't provided in the
   Makefile for us (stupid MakeMaker :)

   In pseudo-shell (adapt to your shell as necessary)

   SH> A=`perl -MConfig -e 'print $Config{cpprun}'`
   SH> B=`perl -MExtUtils::Embed -e ccopts`

1) Create the build directory and preserve it:

   SH> perl -MInline=info,force,noclean script.pl

2) Go to the build dir (I'm making up the md5 key here)

   SH> cd _Inline/build/script_pl_0abc/

3) Generate the preprocessed output:

   SH> $A $B script_pl_0abc.c > out.i

4) You should see a something like this in out.i. It's quite far down in my
   case: line 31155, actually. I never said this was fun...

----8<----
    extern int Perl___notused  ; register SV **sp =
(*Perl_Tstack_sp_ptr(((PerlInterpreter
*)pthread_getspecific((*Perl_Gthr_key_ptr(((void *)0) )) ) )   ))   ;
register SV **mark = (*Perl_Tstack_base_ptr(((PerlInterpreter
*)pthread_getspecific((*Perl_Gthr_key_ptr(((void *)0) )) ) )   ))  + (*
(*Perl_Tmarkstack_ptr_ptr(((PerlInterpreter
*)pthread_getspecific((*Perl_Gthr_key_ptr(((void *)0) )) ) )   )) --)  ;
I32 ax = mark - (*Perl_Tstack_base_ptr(((PerlInterpreter
*)pthread_getspecific((*Perl_Gthr_key_ptr(((void *)0) )) ) )   ))  + 1;
I32 items = sp - mark ;
---->8----

That's the expansion of the initialization macros XS generates for you. I
wish MakeMaker inserted the following lines automatically:

CPPFLAG = -E
CPP = $(CC) $(CPPFLAG)
CPPCMD = $(CPP) $(INC) $(CCFLAGS) $(OPTIMIZE) \
        $(PERLTYPE) $(LARGE) $(SPLIT) $(MPOLLUTE) $(DEFINE_VERSION) \
        $(XS_DEFINE_VERSION)
.c.i: 
        $(CPPCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.c > $*.i

Then you could just type 'make script_pl_0abc.i' and have done with it.

Later,
Neil

Reply via email to