Skip to content
Snippets Groups Projects
Commit 99c98f02 authored by Manuel Günther's avatar Manuel Günther
Browse files

Switched to new API of FilenameConverter

parent 0d17208f
No related branches found
No related tags found
1 merge request!7Switched to new API of FilenameConverter
Pipeline #
...@@ -28,19 +28,11 @@ Returns the list of variable names stored in the given Matlab(R) file.\n\ ...@@ -28,19 +28,11 @@ Returns the list of variable names stored in the given Matlab(R) file.\n\
PyObject* PyBobIoMatlab_ReadVarNames(PyObject*, PyObject* o) { PyObject* PyBobIoMatlab_ReadVarNames(PyObject*, PyObject* o) {
PyObject* filename = 0; const char* filename;
if (!PyBobIo_FilenameConverter(o, &filename)) return 0; if (!PyBobIo_FilenameConverter(o, &filename)) return 0;
auto filename_ = make_safe(filename); auto list = list_variables(filename);
#if PY_VERSION_HEX >= 0x03000000
const char* c_filename = PyBytes_AS_STRING(filename);
#else
const char* c_filename = PyString_AS_STRING(filename);
#endif
auto list = list_variables(c_filename);
PyObject* retval = PyTuple_New(list->size()); PyObject* retval = PyTuple_New(list->size());
if (!retval) return 0; if (!retval) return 0;
auto retval_ = make_safe(retval); auto retval_ = make_safe(retval);
...@@ -81,33 +73,25 @@ PyObject* PyBobIoMatlab_ReadMatrix(PyObject*, PyObject* args, PyObject* kwds) { ...@@ -81,33 +73,25 @@ PyObject* PyBobIoMatlab_ReadMatrix(PyObject*, PyObject* args, PyObject* kwds) {
static const char* const_kwlist[] = {"path", "varname", 0}; static const char* const_kwlist[] = {"path", "varname", 0};
static char** kwlist = const_cast<char**>(const_kwlist); static char** kwlist = const_cast<char**>(const_kwlist);
PyObject* filename = 0; const char* filename;
const char* varname = 0; const char* varname = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|s", kwlist, if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|s", kwlist,
&PyBobIo_FilenameConverter, &filename, &varname)) return 0; &PyBobIo_FilenameConverter, &filename, &varname)) return 0;
auto filename_ = make_safe(filename);
#if PY_VERSION_HEX >= 0x03000000
const char* c_filename = PyBytes_AS_STRING(filename);
#else
const char* c_filename = PyString_AS_STRING(filename);
#endif
// open matlab file // open matlab file
auto matfile = make_matfile(c_filename, MAT_ACC_RDONLY); auto matfile = make_matfile(filename, MAT_ACC_RDONLY);
if (!matfile) { if (!matfile) {
PyErr_Format(PyExc_RuntimeError, PyErr_Format(PyExc_RuntimeError,
"Could open the matlab file `%s'", c_filename); "Could open the matlab file `%s'", filename);
return 0; return 0;
} }
try { try {
// get type of data // get type of data
bob::io::base::array::typeinfo info; bob::io::base::array::typeinfo info;
mat_peek(c_filename, info, varname); mat_peek(filename, info, varname);
npy_intp shape[NPY_MAXDIMS]; npy_intp shape[NPY_MAXDIMS];
for (size_t k=0; k<info.nd; ++k) shape[k] = info.shape[k]; for (size_t k=0; k<info.nd; ++k) shape[k] = info.shape[k];
...@@ -129,7 +113,7 @@ PyObject* PyBobIoMatlab_ReadMatrix(PyObject*, PyObject* args, PyObject* kwds) { ...@@ -129,7 +113,7 @@ PyObject* PyBobIoMatlab_ReadMatrix(PyObject*, PyObject* args, PyObject* kwds) {
return 0; return 0;
} }
catch (...) { catch (...) {
PyErr_Format(PyExc_RuntimeError, "cannot read contents of variable `%s' at matlab file `%s'", varname, c_filename); PyErr_Format(PyExc_RuntimeError, "cannot read contents of variable `%s' at matlab file `%s'", varname, filename);
return 0; return 0;
} }
......
...@@ -2,4 +2,4 @@ setuptools ...@@ -2,4 +2,4 @@ setuptools
bob.extension bob.extension
bob.blitz bob.blitz
bob.core bob.core
bob.io.base bob.io.base > 2.1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment