thierry-martinez / pyml

OCaml bindings for Python
BSD 2-Clause "Simplified" License
187 stars 31 forks source link

Numpy.to_bigarray causes a segfault when passed a python object with the wrong type #61

Closed jonathan-laurent closed 3 years ago

jonathan-laurent commented 3 years ago

The following code causes a segfault:

let () =
  Py.initialize;
  Numpy.to_bigarray Float64 C_layout Py.none

Would it be possible for Numpy.to_bigarray to raise an exception instead (as is done byPy.Int.to_int for example)?

thierry-martinez commented 3 years ago

Thank you very much for reporting! This should be fixed now.

jonathan-laurent commented 3 years ago

Thanks for your answer!

However, your fix only applies to the case where None is passed and indeed, the code below still segfaults:

let () =
  Py.initialize;
  Numpy.to_bigarray Float64 C_layout (Py.Int.of_int 2)

Would there be a way for Numpy.to_bigarray to check whether the passed object is indeed a numpy array?

thierry-martinez commented 3 years ago

Oops! Sorry for that. Done!