Parselmouth
Parselmouth copied to clipboard
Update pybind11 version to 2.13.1
This PR updates the pybind11
library to the latest v2.13.1 to resolve #125.
In doing so, the handling of Praat's array of strings has been modified (praat.cpp
).
The original
py::object autoSTRVECToArray(autoSTRVEC &&vector) {
if (!vector.elements)
return py::none();
auto v = vector.get();
return py::array_t<py::object>(py::cast(std::vector<char32 *>(v.begin(), v.end())));
throws compiler error:
In file included from /home/kesh/Parselmouth/src/parselmouth/praat.cpp:31:
/home/kesh/Parselmouth/pybind11/include/pybind11/numpy.h: In instantiation of ‘struct pybind11::detail::npy_format_descriptor<pybind11::object, void>’:
/home/kesh/Parselmouth/pybind11/include/pybind11/numpy.h:684:86: required from ‘static pybind11::dtype pybind11::dtype::of() [with T = pybind11::object]’
/home/kesh/Parselmouth/pybind11/include/pybind11/numpy.h:1297:68: required from ‘static PyObject* pybind11::array_t<T, ExtraFlags>::raw_array_t(PyObject*) [with T = pybind11::object; int ExtraFlags = 16; PyObject = _object]’
/home/kesh/Parselmouth/pybind11/include/pybind11/numpy.h:1186:49: required from ‘pybind11::array_t<T, ExtraFlags>::array_t(const pybind11::object&) [with T = pybind11::object; int ExtraFlags = 16]’
/home/kesh/Parselmouth/src/parselmouth/praat.cpp:103:84: required from here
/home/kesh/Parselmouth/pybind11/include/pybind11/numpy.h:1565:37: error: static assertion failed: Attempt to use a non-POD or unimplemented POD type as a numpy dtype
1565 | static_assert(is_pod_struct<T>::value,
| ^~~~~
/home/kesh/Parselmouth/pybind11/include/pybind11/numpy.h:1565:37: note: ‘std::integral_constant<bool, false>::value’ evaluates to false
This presumably happens now because numpy array elements must have a common fixed length. This perhaps wasn't imposed in pybind11<2.7
. Anyway, rather than fighting this, the changes in PR simply let py::array_t
constructor to convert a py::list
of py::str
s.
edit: Pushed another fix candidate. By instantiating py::array str_array(py::dtype('O'), {v.size}, {});
, we can populate its data straight from the source (with py::cast
).