Hi,

I think i have found a SegFault bug and its correction. I don't have a "global vision" of the Ocaml-R code, so i don't know if this correction will have side effects...

With Ocaml toplevel, you can see the bug with the following code:
>#use "topfind";;
>#require "R.interpreter";;
>let q=R.eval_string "rep(1,200000)";;
>let e=R.floats_of_t q;;
The last line rises a "stack overflow". The natively compiled code rises a Segmentation Fault.

The origin of this issue might be in "conversion.ml", in the "list_of_vecsxp" function : > let list_of_vecsxp (access: 'a vecsxp -> int -> 'a) (s: 'a vecsxp) : 'a list =
>     let lngth = length_of_vecsxp s in
>     let rec aux n s = match n with | 0 -> [] | _ ->
>         let x = access s (lngth - n) in x::(aux (n - 1) s)
>     in aux lngth s
The "aux" function  is not tail recursive.

I have corrected this with:
> let list_of_vecsxp (access: 'a vecsxp -> int -> 'a) (s: 'a vecsxp) : 'a list =
>     let lngth = length_of_vecsxp s in
>     let rec aux n s acc=
>       match n with
>        | 0 -> acc
>        | _ ->
>            let x = access s (lngth - n) in
>            aux (n - 1) s (x::acc)
>      in List.rev (aux lngth s [])
The "aux" function  is now tail recursive.

This correction seems to work but i'm concerned about possible side effects due to this modification.

Regards,
Richard


_______________________________________________
Ocaml-r-devel mailing list
[email protected]
https://mail.gna.org/listinfo/ocaml-r-devel

Reply via email to