Hi everbody,

I got into Perl yesterday for using a Perl extension for PVM, a parallel
computing environment, but found out that some newer functions were not
yet in it.

So, I added to the extension, but so far I couldn't figure out wrapping
a more complex function.


The C function pvm_getmboxinfo returns an array of structures, which
themselves contain some arrays (the indices of messages contained in a
cluster-wide message box).

So far, I get back:
- An array for each message box, OK
- The array is an array of hashes, OK
- Each hash's scalar values (integers, strings) are wrapped nicely, OK
- BUT ... the arrays contained in each hash don't come through.

When I print out those should-be arrays, it shows:

        ARRAY(0x816c1bc)

Even when I do a foreach over it, it prints out the same thing.

When I print a usual array, it prints as it should:

        @array = (1..5); print @array;

        1 2 3 4 5



Anyways, I av_push the various integers into the array (arr_tmp) and
then hv_store it into its hash. Then each hash (for each message box)
gets XPUSHs'ed, which results in the array of hashes received in Perl.
So far my theory, but I've obviously overlooked something ...

I've already tried XPUSHs'ing the array on its own, but then it shows up
in Perl on the same level as the hashes. I've also played around with
some newRV and newRV_noinc combinations, but ... well :-)


I'm grateful for your help, thanks an advance.



As a side note: Is it maybe easier to make a typedef and return an array
of real Perl objects?


Greetings,
Ernst Rohlicek jun.
<[EMAIL PROTECTED]>





---- Snippet from manpage ---------------------------------


int info = pvm_getmboxinfo(
        char *pattern,
        int *nclasses,
        struct pvmmboxinfo **classes )

struct pvmmboxinfo {
        char *mi_name;                /* class name */
        int   mi_nentries;            /* # of entries for this class */
        int  *mi_indices;             /* mbox entry indices */
        (int  *mi_owners;)            /* mbox entry owner tids */
        (int  *mi_flags;)             /* mbox entry flags */
};

---- Snippet from .xs file --------------------------------

01 void
02 getmboxinfo(pattern,nclasses=100)
03   char * pattern;
04   int nclasses;
05   PREINIT:
06   int n,m;
07
08   int info;
09   struct pvmmboxinfo *classes;
10
11   char mi_name[256];
12
13   HV * hv_tmp;
14   AV * arr_tmp;
15   PPCODE:
16   info = pvm_getmboxinfo(pattern,&nclasses,&classes);
17   XPUSHs(sv_2mortal(newSViv(info)));
18   for (n=0;n<nclasses;n++)
19     {
20     strcpy(mi_name,classes[n].mi_name);
21     hv_tmp = (HV *)sv_2mortal((SV *)newHV());
22     hv_store(hv_tmp,"mi_name",7,newSVpv(mi_name,0),0);
23     hv_store(hv_tmp,"mi_nentries",11,newSViv(classes[n].mi_nentries),0);
24     arr_tmp = (AV *)sv_2mortal((SV *)newAV());
25     for (m=0;m<classes[n].mi_nentries;m++)
26       {
27       av_push(arr_tmp,newSViv(classes[n].mi_indices[m]));
28       }
29     hv_store(hv_tmp,"mi_indices",10,newRV((SV *)arr_tmp),0);
30     hv_store(hv_tmp,"mi_flags",8,newSViv(*classes[n].mi_flags),0);
31     XPUSHs(sv_2mortal(newRV((SV *)hv_tmp)));
32     }


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to