Thanks Rob.  The missing Inline_Stack_Return() was the problem.  Well
that, and discovering I can't push a reference onto the list.  Calling
SvRV(message) before the push and newRV_noinc(*tmp) after the fetch
seems to have fixed that.  

Thanks,

Scott

-----Original Message-----
From: Sisyphus [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 16, 2006 6:14 PM
To: Mcmillan, Scott A; inline@perl.org
Subject: Re: inline_stack help


----- Original Message ----- 
From: "Mcmillan, Scott A" <[EMAIL PROTECTED]>
To: <inline@perl.org>
Sent: Friday, February 17, 2006 10:43 AM
Subject: inline_stack help


> Hi,
>
> I'm trying to convert the following Perl member functions into their
> Inline C equivalents:
>
> sub add_message {
>     my ($self, $message) = @ARG;
>
>     push @{$self->{MESSAGE}}, $message;
>
>     return;
> }
>
> sub messages {
>     my ($self) = @ARG;
>
>     if (defined $self->{MESSAGE}) {
> return @{$self->{MESSAGE}};
>     }
>
>     return;
> }
>
> I think I have the add_message() half working correctly, but I can't
> seem to get the list return in messages() quite right.
>
> void add_message(SV* obj, SV* message) {
>     Event* event = (Event*)SvIV(SvRV(obj));
>
>     av_push(event->messages, message);
> }
>
> void messages(SV* obj) {
>     Event* event = (Event*)SvIV(SvRV(obj));
>     SV** tmp;
>     int i, array_len;
>
>     Inline_Stack_Vars;
>
>     Inline_Stack_Reset;
>
>     array_len = av_len(event->messages) + 1;
>
>     if(array_len == 0) {
> Inline_Stack_Void;
>     }
>     else {
> for (i = 0 ; i < array_len ; i++) {
>     tmp = av_fetch(event->messages, i, 0);
>     Inline_Stack_Push(*tmp);
> }
>     }
>
>     Inline_Stack_Done;
> }
>
> Any advice?  In the array_len != 0 branch, the stack is coming back
> uninitialized.
>

Is that because you have failed to 'Inline_Stack_Return(i);' ?

Also (and this has no bearing on the problem) .... 'Inline_Stack_Void'
equates to 'Inline_Stack_Return(0)', so you shouldn't need to test for
the
condition 'array_len == 0'. In the event that array_len is zero,
'Inline_Stack_Return(i)' should still suffice (as 'i' will be zero).

If there are additional problems, I would probably need a *complete*
basic
script ... and the header file that defines the 'Event' type.

Cheers,
Rob

Reply via email to