Hi,

First of all, thank you Brian for the inline. It's wonderful. And easy
to use for a stubborn perl-coder :-). This also betrays that I know only
a little about C, so please bear with me asking the following question.

I'm plagued by a segfault that only occurs when I create to use a
somewhat larger stack. The list is created by reading from an int array.
The segfaults, funny enough, is triggered _after_ 'perl' returned from
the inline sub.

Here is the (apparently) offending perl code:

....
  @max = _max_indici( $ndim, $dimwidth, $$matrix, $neighbours, $n_size,
     $ndim, 0, $max );
  print "Ready with c-code\n";
  print join ":", @max;
  print "\n";
  [sort {$b <=> $a} @max];
}

_max_indici is one of the inline functions. The segfault occurs when
reading from @max in the print statement.

arggl. I just ran another check, by resetting @max to 1..5 => lead to a
postponement of the segfault, this time it occurred after the sub had
returned to the main script. When I removed the @max=1..5 line no
segfault anymore, but a 
    index out of range at ### line 73
where line 73 is the @max = _max_indici line. There is no single index
in that line, so what's happening here?

The inline function is probably important as well, so here it goes:

-------------------
void _max_indici( int ndim, int dimwidth, char* matrix_in,
            char* neighbours_in, int n_size, int localdim, int
localindex, char* max_in ){
    float* matrix = (float*) matrix_in;
    int* neighbours = (int*) neighbours_in;
    int* max = (int*) max_in;
    int i;
    int matrix_size = pow( dimwidth, ndim);
    Inline_Stack_Vars;
 
    __iterate_max_indici( ndim, dimwidth, matrix, neighbours, n_size,
localdim, localindex, max, matrix_size);
 
    Inline_Stack_Reset;
 
    for( i=1; i < max[0]; i++){
      Inline_Stack_Push(sv_2mortal(newSViv(max[i])));
      printf("%06d -> %06d\n",i, max[i]);
    }
    Inline_Stack_Done;
    printf("Ready with catting\n");
}
--------------------
The __iterate function is a void recursive c function. Some remarks:

If I put the Inline_Stack_Vars below the __iterate function, I'll get
myself some compiler errors, complaining about 'extern', 'sp', etc.. the
stuff in INLINE.h. This seems to be strange behaviour.

I also tried other scemes: returning a char* string of int bytes, and a
pointer to the last record in the string. Doesn't work (of course), the
string gets truncated at the first \000. Also tried the same with a SV*,
sv_catpvf'ing the numbers with a delimiter, splitting the result in perl
=> segfaults as well. Moreover, the catting produced sometimes irregular
large integers in the int* array!

In some cases (particular combinations of different sizes of matrici),
the segfault occurs in the main script.

I would be very thankful for any help in solving this segfault!

Jeroen

-- 
J. Elassaiss-Schaap 
Dept. Physiology  
Leiden University Medical Centre
Postbus 9604
2300 RC Leiden 
The Netherlands

tel: 071-5276513 
fax: 071-5276782 
E-mail: [EMAIL PROTECTED]

Reply via email to