pike.git / src / modules / Math / transforms.cmod

version» Context lines:

pike.git/src/modules/Math/transforms.cmod:8:      #include "interpret.h"   #include "svalue.h"   #include "array.h"   #include "pike_macros.h"   #include "program.h"   #include "stralloc.h"   #include "object.h"   #include "pike_types.h"   #include "threads.h" - #include "dynamic_buffer.h" +    #include "builtin_functions.h"   #include "config.h"      #if defined(HAVE_FFTW_H) && defined(HAVE_LIBFFTW) && defined(HAVE_RFFTW_H) && defined(HAVE_LIBRFFTW)   #define HAVE_RFFTW   #endif      #ifdef HAVE_RFFTW      #ifdef HAVE_FFTW_H
pike.git/src/modules/Math/transforms.cmod:67:    *! rIFFT(rFFT()) returns the input array scaled by n=sizeof(input array).    *! This is due to the nature of the DFT algorithm.    *!    *! @seealso    *! @[rIFFT()]    */    PIKEFUN array rFFT(array myarray)    {    int i, j;    -  if (args<1) -  SIMPLE_TOO_FEW_ARGS_ERROR("rFFT", 1); +  if (args!=1) +  SIMPLE_WRONG_NUM_ARGS_ERROR("rFFT", 1);       if (TYPEOF(Pike_sp[-args]) == PIKE_T_ARRAY)    {    struct array *a = Pike_sp[-args].u.array;    int n = a->size; -  THIS->r_in = malloc(sizeof(fftw_real)*n); +  THIS->r_in = calloc(n, sizeof(fftw_real));       for(i=0; i<n; i++)    {    if (TYPEOF(a->item[i]) == PIKE_T_INT)    THIS->r_in[i] = (fftw_real)a->item[i].u.integer;       if (TYPEOF(a->item[i]) == PIKE_T_FLOAT)    THIS->r_in[i] = (fftw_real)a->item[i].u.float_number;    };    -  THIS->r_out = malloc(sizeof(fftw_real)*n); +  THIS->r_out = calloc(n, sizeof(fftw_real));       if (THIS->r_rc_plan_size != n)    {    if (THIS->r_rc_plan_size > 0)    rfftw_destroy_plan(THIS->r_rc_plan);    THIS->r_rc_plan =    rfftw_create_plan(n, FFTW_REAL_TO_COMPLEX, FFTW_ESTIMATE);    THIS->r_rc_plan_size = n;    };    rfftw_one(THIS->r_rc_plan, THIS->r_in, THIS->r_out);
pike.git/src/modules/Math/transforms.cmod:170:       if (TYPEOF(myarray->item[0]) != PIKE_T_ARRAY ||    TYPEOF(myarray->item[1]) != PIKE_T_ARRAY ||    myarray->item[0].u.array->size != myarray->item[1].u.array->size)    Pike_error("Argument error!\n");       r = myarray->item[0].u.array;    p = myarray->item[1].u.array;    n = r->size;    -  THIS->r_in = malloc(sizeof(fftw_real)*n); -  memset(THIS->r_in,0,sizeof(fftw_real)*n); +  free(THIS->r_in); +  THIS->r_in = NULL; /* Needs to be NULL if xcalloc throws */ +  THIS->r_in = xcalloc(sizeof(fftw_real), n);       for(i=0; i<=n/2; i++)    {    if (TYPEOF(r->item[i]) == PIKE_T_INT)    THIS->r_in[i] = (fftw_real)r->item[i].u.integer;    else if (TYPEOF(r->item[i]) == PIKE_T_FLOAT)    THIS->r_in[i] = (fftw_real)r->item[i].u.float_number;    else Pike_error("Invalid type in array!\n");    }       for(;i<n;i++, j++)    {    if (TYPEOF(p->item[j]) == PIKE_T_INT)    THIS->r_in[n-j] = (fftw_real)p->item[j].u.integer;    else if (TYPEOF(p->item[j]) == PIKE_T_FLOAT)    THIS->r_in[n-j] = (fftw_real)p->item[j].u.float_number;    else Pike_error("Invalid type in array!\n");    }    -  +  free(THIS->r_out); +  THIS->r_out = NULL; /* Needs to be NULL if xcalloc throws */ +  THIS->r_out = xcalloc(sizeof(fftw_real), n);    -  THIS->r_out = malloc(sizeof(fftw_real)*n); -  memset(THIS->r_out,0,sizeof(fftw_real)*n); -  +     if (THIS->r_cr_plan_size!=n)    {    if (THIS->r_cr_plan_size > 0)    rfftw_destroy_plan(THIS->r_cr_plan);    THIS->r_cr_plan =    rfftw_create_plan(n, FFTW_COMPLEX_TO_REAL, FFTW_ESTIMATE);    THIS->r_cr_plan_size = n;    }       rfftw_one(THIS->r_cr_plan, THIS->r_in, THIS->r_out);
pike.git/src/modules/Math/transforms.cmod:260:    Pike_error("Invalid number of arguments\n");    }       THIS->r_rc_plan_size = n;    THIS->r_cr_plan_size = n;    if (n>0)    {    THIS->r_rc_plan = rfftw_create_plan(n, FFTW_REAL_TO_COMPLEX, t);    THIS->r_cr_plan = rfftw_create_plan(n, FFTW_COMPLEX_TO_REAL, t);    } -  pop_n_elems(args); +     }       INIT    {    THIS->r_in=NULL;    THIS->r_out=NULL;    }       EXIT    gc_trivial;    {    if (THIS->r_cr_plan_size>0)    rfftw_destroy_plan(THIS->r_cr_plan);    if (THIS->r_rc_plan_size>0)    rfftw_destroy_plan(THIS->r_rc_plan); -  if (THIS->r_out!=NULL) +     free(THIS->r_out); -  if (THIS->r_in!=NULL) +     free(THIS->r_in);    }   }      /*! @endclass    */      /*! @endmodule    */