Fix compile error in gsl_typemaps.i
[Math-GSL.git] / gsl_typemaps.i
blob13f0361a3640cb4370a47022195527659db1a7a3
2 %typemap(in) double const [] {
3 AV *tempav;
4 I32 len;
5 int i;
6 SV **tv;
7 if (!SvROK($input))
8 croak("Math::GSL : $input is not a reference!");
9 if (SvTYPE(SvRV($input)) != SVt_PVAV)
10 croak("Math::GSL : $input is not an array ref!");
12 tempav = (AV*)SvRV($input);
13 len = av_len(tempav);
14 $1 = (double *) malloc((len+1)*sizeof(double));
15 for (i = 0; i <= len; i++) {
16 tv = av_fetch(tempav, i, 0);
17 $1[i] = (double) SvNV(*tv);
21 %apply double const [] { size_t *p };
23 %apply double const [] { double *data, double *dest, double *f_in, double *f_out, double data[], const double * src };
24 %apply double const [] { double x[], double a[], double b[] };
25 %apply double const [] { const double * x, const double * y, const double * w };
26 %apply double const [] { const double x_array[], const double xrange[], const double yrange[]};
27 %apply double const [] { double * base, const double * base};
28 %apply double const [] { const double xrange[], const double yrange[] };
29 %apply double const [] { const double * array };
30 %apply double const [] { const double data2[], const double w[] };
31 %apply double const [] { float const *A, float const *B, float const *C, float *C};
33 %apply double * OUTPUT { double *abserr, double *result };
35 static HV * Callbacks = (HV*)NULL;
36 /* this function returns the value
37 of evaluating the function pointer
38 stored in func
40 double callthis(double x , int func, void *params){
41 SV ** sv;
42 double y;
43 //fprintf(stderr, "LOOKUP CALLBACK\n");
44 sv = hv_fetch(Callbacks, (char*)func, sizeof(func), FALSE );
45 if (sv == (SV**)NULL)
46 croak("Math::GSL(callthis) : Missing callback!\n");
48 dSP;
49 PUSHMARK(SP);
50 XPUSHs(sv_2mortal(newSVnv((double)x)));
51 PUTBACK;
52 call_sv(*sv, G_SCALAR);
53 y = POPn;
54 //fprintf(stderr,"y=%f\n", y);
55 return y;
58 %typemap(in) gsl_function * {
59 gsl_function F;
60 int count;
61 F.params = &$input;
62 F.function = &callthis;
63 SV ** callback;
64 double x;
66 if (!SvROK($input)) {
67 croak("Math::GSL : $1_name is not a reference value!");
69 if (Callbacks == (HV*)NULL)
70 Callbacks = newHV();
71 //fprintf(stderr,"STORE CALLBACK\n");
72 hv_store( Callbacks, (char*)&$input, sizeof($input), newSVsv($input), 0 );
74 //Perl_sv_dump( $input );
75 $1 = &F;