[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] The long way to build XSUBs (LONG EMAIL)



This is how I've been building XSUBs for PPC. I'm just putting it out 
there for sake of discussion. I'm not a trained CompSci type; it's all OJT 
(my background is physics). So if you see something bizarre, please 
chastise me gently. :-)

I originally started to write my own XSUB, and took it all the way through 
the process.  But my "perlguts" comprehension isn't quite there yet, so 
while the subroutine got recognized and called, it wasn't receiving the 
argument inside the XSUB function that it expected.

In an effort to figure out what was going on, I ended up building 
Devel::Peek, which strikes me as being a pretty good example in itself.
:-)

*IF* I had been building from scratch, I'd be running Codewarrior MPW and 
the current directory would be MACPERL_SRC:perl:lib:ext. Reminder: to be 
doing this stuff you do need the source distribution. On the MPW cmd line 
run 'perl h2xs.PL' tp produce "h2xs", if necessary. (Note: you'll also 
have downloaded and set up the Perl MPW tool. h2xs.PL is located in 
perl:utils).

h2xs -A -n NewModule

then creates folder NewModule, and populates it with a number of files 
that you'll want to have for a proper module. We're interested mostly in 
the .pm and .xs files.

We'll now return to module Devel::Peek, by Ilya Zakharevitch. I take the 
.pm and .xs files and put them in folder MACPERL_SRC:perl:lib:ext:Devel. I 
also get "typemap" and "xsubpp" from lib:ExtUtils and throw them in here, 
too (I like having everything right there).

Since it's the next step in "perlxstut", go ahead and run 'perl 
Makefile.PL': you'll get Makefile.mk which is very handy to look at. 
(Modifying this method, look in here to see what to do for other targets).
This is where I part ways with the easy way to do it - I don't have dmake, for 
starters.

If folder Obj doesn't exist yet, make it (the object file and shared lib 
get parked in it).

Without further ado, this is what I ended up doing for Peek (The 
line-ending D's are MPW option-d line continuations):

*** MPW Worksheet ***

perl -I:::lib: xsubpp -prototypes -typemap typemap Peek.xs

Set PerlIncludes "Tallinn:MacPerl_SRC:perl"
Set SFIOIncludes "Tallinn:MacPerl_Src:sfio:include"
Set GUSIIncludes "Tallinn:MacPerl_Src:GUSI:include"

MWCPPC -nosyspath -sym on -d MULTIPLICITY -w nounusedarg D
-i- -i : -i "{MWCIncludes}" -i "{PerlIncludes}" D
-i "{GUSIIncludes}" D
-i "{SFIOIncludes}" -traceback -opt all -t D
-ext PPC.o Peek.c -o :Obj:

*** MY NOTE: following all on one line (space between
Codewarrior and MPW ) ***
Set MWPPCLibraries "Tallinn:Metrowerks:CodeWarrior 
MPW:Interfaces&Libraries:Libraries:MWPPCLibraries:"

MWLinkPPC -xm sharedlibrary -sym on -msg nodup D
-export boot_Devel__Peek,XS_Devel__Peek_DeadCode,D
XS_Devel__Peek_SvREFCNT_dec,XS_Devel__Peek_SvREFCNT_inc,D
XS_Devel__Peek_SvREFCNT,XS_Devel__Peek_DumpProg,D
XS_Devel__Peek_DumpArray,XS_Devel__Peek_Dump,XS_Devel__Peek_mstat D
-name Peek -o Peek.shlb.PPC  :Obj:Peek.ppc.o D
:::PerlStub D
"{MWPPCLibraries}InterfaceLib" D
"{MWPPCLibraries}MathLib" D
"{MWPPCLibraries}MSL ShLibRuntime.Lib" D
"{MWPPCLibraries}MSL C.PPC.Lib"

*** END of Worksheet ***

DISCLAIMER: I'm using CW Pro 3 with IDE 3.1. These libraries work for *ME* 
with Devel::Peek. At other times I've found that -@export NewModule.exp 
works fine instead of diving into the .c file and looking at what symbols 
to export specifically.

Once this is done, I copy the Peek.pm to MacPerl:lib:Devel:, and copy the 
shared lib to MacPerl:lib:MacPPC:auto:Devel:Peek:, and call it Peek.

Having done all this, the following .plx script works just fine: :-)

*****

#!perl5 -w

use Devel::Peek qw(:DEFAULT SvREFCNT);

# DeadCode();

print "\n";
$a = -1;
$b = 'aabbccdd';
$c = \&test1;

$Devel::Peek::pv_limit = 6;
Dump $b;
DumpArray( 3, $a, $b, $c );

$a_rcnt = Devel::Peek::SvREFCNT( $a );
print "Ref count for \$a = $a_rcnt\n";

sub test1 {
	my ($thing) = @_;

	ref $thing;
}

*****

Comments, suggestions and particularly advice/corrections are welcome.

Arved



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch