Markus Mottl avatar Markus Mottl committed fdb285e

Added Olivier's patch for improved bigarray allocation

Comments (0)

Files changed (1)

 double gsl_multimin_callback(const gsl_vector *x, void *params)
+  int barr_flags = BIGARRAY_FLOAT64 | BIGARRAY_C_LAYOUT;
   struct callback_params *p=params;
   value x_barr;
-  int len = x->size;
-/* CR mmottl: Stack allocation may segfault with large lengths, hence
-   malloc.  Note that the OCaml callbacks may put the bigarrays into
-   references.  This is evil, and these bindings should really get fixed
-   to avoid problems of that sort. */
-  double *x_arr = malloc(sizeof(double) * len);
-#if 0
-  LOCALARRAY(double, x_arr, len);
+  intnat len = x->size;
+  double *x_arr;
   gsl_vector_view x_v;
   value res;
-  x_v = gsl_vector_view_array(x_arr, len);
+  x_barr = alloc_bigarray_dims(barr_flags, 1, NULL, len);
+  x_v = gsl_vector_view_array(Data_bigarray_val(x_barr), len);
   gsl_vector_memcpy(&x_v.vector, x);
-  x_barr = alloc_bigarray_dims(barr_flags, 1, x_arr, len);
   res=callback_exn(p->closure, x_barr);
-  /* CR mmottl: need to free malloced memory now */
-  free(x_arr);
   if(Is_exception_result(res)) {
     return GSL_NAN;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.