Mailing List Archive

Re: Perl5 Extensions
In <Pine.3.89.9508311047.B20776-0100000@lafcol>
On Thu, 31 Aug 1995 10:54:00 -0400 (EDT)
Andy Dougherty <doughera@lafcol.lafayette.edu> writes:
>On Thu, 31 Aug 1995 m1klk99@FRB.GOV wrote:
>
>[. I've forwarded this to the <perl5-porters@africa.nicoh.com> list where
>someone may have a ready-made example they can share. ]
>
>> Hi-
>>
>> I am trying to add functions to my perl-C extension that pass back arrays
>> of doubles, floats or ints. I am having a bit of trouble with this, getting
>> either garbage values or segmentation faults. Is
>> there an easy way to pass a C array to a perl array in an XSUB? Thanks
>> so much.

I don't have canned example of passing a C array back to perl, but perl/Tk
does return lists of values (sometimes mixed types) so if you send
code that does not work I can probably correct it.

Are you trying to put values into an existing array as in :

xsub(\@array_to_fill);

Or the more normal way :

@array_to_fill = xsub();


Outline of latter in an XSUB is :

double data[count];
int i;
if (count > items)
{
EXTEND(sp, count-items);
}
for (i=0; i < count; i++)
{
ST(i) = sv_2mortal(newSVnv(data[i]));
}
XSRETURN(count);

For 'float' still use newSVnv