Re: XS to return Perl Arrays - and NetWare Select()

[email protected] (NormW)
Newsgroups perl.xs
Message-ID <[email protected]>
G/Morning,
On 10/06/2011 2:46 AM, Brandon McCaig wrote:
> On Wed, Jun 8, 2011 at 7:11 PM, NormW<[email protected]>  wrote:
>> AFAICT, I want to implement the following Perl call to XS code:
>>
>> my (@ro,@wo,@eo) = nw_select(\@ri,\@wi,\@ei,$wait);
>
> Perhaps you meant:
>
> my ($ro, $wo, $eo) = nw_select(\@ri, \@wi, \@ei, $wait);
>
> That is, instead of getting three arrays returned, getting three array
> /references/ returned. The first is valid Perl, but it probably
> doesn't do what you intended since the first array would get all of
> the values returned by nw_select and the second two arrays would
> always be empty.
select() takes 3 NULL pointers or pointers to FD_SET structs and returns 
int arrays for any array actually passed in. So you always get 3 data 
pointers back, and for arrays not passed in you get the original NULL 
pointer back. Which is why if you pass into the XS a non-valid Perl 
array pointer I try to return an 'undefined' array. Granted, it is 
likely possible to return array pointers to arrays created in the XS 
space, but the implications of doing that are even less clear.

Norm
>
> bash $ perl -e<<'EOF'
> use strict;
> use warnings;
>
> use Data::Dumper;
>
> sub example
> {
>      my @first = (1..3);
>      my @second = (4..6);
>      my @third = (7..9);
>
>      return @first, @second, @third;
> }
>
> my (@first, @second, @third) = example;
>
> print Dumper \@first, \@second, \@third;
> EOF
> $VAR1 = [
>            1,
>            2,
>            3,
>            4,
>            5,
>            6,
>            7,
>            8,
>            9
>          ];
> $VAR2 = [];
> $VAR3 = [];
> bash $
>
> See `perldoc perlsub` for details.
>
> I'm afraid that I'm lurking here to try to learn XS by example so I
> can't help with the XS implementation. :) Good luck.
Almost certainly will need it.
Norm
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.