Aaron,
It is not kosher to use the stack macros when setting up the stack to call
back into Perl. Read the perlcall manpage and the perlapi manpage for the
proper howto. I know that I do this in the Cookbook, but I was wrong. A
future version of Inline may have better macros to fix this.
Cheers, Brian
On 10/07/02 09:13 -0400, Aaron J Mackey wrote:
>
> Since I didn't get a response, I've compiled a small test case that
> exhibits the behavior: here are two files, "test.pl" and "Foo.pm"; the
> interesting bit is in Foo.pm's call_C function, where we attempt to call
> call_Perl twice - the first time is successful, the second time is not.
> Thanks (again) for any help! -Aaron
>
> test.pl:
> #!/usr/bin/perl -w
> use strict; use Foo;
> my $one = new Foo; my $two = new Foo;
> $one->bar($two, 'a', 'b', 'c');
>
> Foo.pm:
> package Foo;
>
> use strict;
> use Inline C => 'DATA';
>
> sub new { return bless {}, shift; }
> sub bar {
> my ($self, $other, $a, $b, $c) = @_;
> print "In bar: $a $b $c\n";
> $self->call_C($other, $b, $c, 'd');
> }
> sub call_Perl {
> my ($self, $c, $d, $e) = @_;
> print "In call_Perl: $c $d $e\n";
> }
> 1;
> __DATA__
> __C__
> void call_C(SV* self, SV* other, char b, char c, char d) {
> Inline_Stack_Vars;
>
> PerlIO_stdoutf("In call_C: %c %c %c\n", b, c, d);
>
> ENTER; SAVETMPS;
> Inline_Stack_Reset;
> Inline_Stack_Push(other);
> Inline_Stack_Push(sv_2mortal(newSVpvf("%c1", c)));
> Inline_Stack_Push(sv_2mortal(newSVpvf("%c1", d)));
> Inline_Stack_Push(sv_2mortal(newSVpvf("e1")));
> Inline_Stack_Done;
> call_method("call_Perl", G_SCALAR); SPAGAIN; Inline_Stack_Done;
> FREETMPS; LEAVE;
>
> ENTER; SAVETMPS;
> Inline_Stack_Reset;
> Inline_Stack_Push(other);
> Inline_Stack_Push(sv_2mortal(newSVpvf("%c2", c)));
> Inline_Stack_Push(sv_2mortal(newSVpvf("%c2", d)));
> Inline_Stack_Push(sv_2mortal(newSVpvf("e2")));
> Inline_Stack_Done;
> call_method("call_Perl", G_SCALAR); SPAGAIN; Inline_Stack_Done;
> FREETMPS; LEAVE;
> }
>
>
> On Tue, 9 Jul 2002, Aaron J Mackey wrote:
>
> >
> > Ok, in the middle of a C function I have this:
> >
> > /* $n = $seq->length() */
> > Inline_Stack_Reset; Inline_Stack_Push(seq); Inline_Stack_Done;
> > call_method("length", G_SCALAR);
> > if (SvIOK(Inline_Stack_Item(0))) {
> > n = SvIV(Inline_Stack_Item(0));
> > }
> >
> > This works fine. But then a few lines later:
> >
> > /* read.base = $seq->seq() */
> > Inline_Stack_Reset; Inline_Stack_Push(seq); Inline_Stack_Done;
> > call_method("seq", G_SCALAR);
> > if (SvPOK(Inline_Stack_Item(0))) {
> > strncpy(read->base, SvPV_nolen(Inline_Stack_Item(0)), n + 1);
> > }
> >
> > And I get:
> > Can't locate object method "seq" via package "pln" (perhaps you forgot to
> > load "pln"?) at blib/lib/Bio/SeqIO/staden/read.pm line 132
> >
> > Now my blessed ref "seq" is not the scalar string "pln", it's a real live
> > blessed object (sv_isa(seq, "The::Right::Package") is true). This smells
> > more like the Inline_Stack_Reset and friends not really repositioning the
> > stack correctly (translated as: how do I get these to correctly reposition
> > the stack for multiple call_method()'s). Or maybe it's something else?
> > Do I need to use ENTER; LEAVE; stuff?
> >
> > Thanks for any help, or "gotchyas".
> >
> > -Aaron
> >
> >
>
> --
> Aaron J Mackey
> Pearson Laboratory
> University of Virginia
> (434) 924-2821
> [EMAIL PROTECTED]
>