diff --git a/bob/learn/libsvm/file.cpp b/bob/learn/libsvm/file.cpp index a6720d2832551f8da61707f991cd42303dca57a4..212fe94e53fbe57f55cd13ccdeac1ada2e1c7b31 100644 --- a/bob/learn/libsvm/file.cpp +++ b/bob/learn/libsvm/file.cpp @@ -56,22 +56,14 @@ static int PyBobLearnLibsvmFile_init static const char* const_kwlist[] = {"path", 0}; static char** kwlist = const_cast<char**>(const_kwlist); - PyObject* filename = 0; + const char* filename = 0; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kwlist, &PyBobIo_FilenameConverter, &filename)) return -1; - 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 - try { - self->cxx = new bob::learn::libsvm::File(c_filename); + self->cxx = new bob::learn::libsvm::File(filename); } catch (std::exception& ex) { PyErr_SetString(PyExc_RuntimeError, ex.what()); @@ -488,10 +480,10 @@ static PyObject* PyBobLearnLibsvmFile_read_all auto bzval = PyBlitzArrayCxx_AsBlitz<double,2>(values); blitz::Range all = blitz::Range::all(); int k = 0; - + while ((self->cxx->good()) && ((size_t)k < self->cxx->samples())) { blitz::Array<double,1> v_ = (*bzval)(k, all); - + int label = 0; bool ok = self->cxx->read_(label, v_); if (ok) (*bzlab)(k) = label; diff --git a/bob/learn/libsvm/machine.cpp b/bob/learn/libsvm/machine.cpp index 5dfb98cead32ac3939bcb1c83ae7e5a252895f9e..80c9b88264d739502f248fca1211ed8bd42afdf2 100644 --- a/bob/learn/libsvm/machine.cpp +++ b/bob/learn/libsvm/machine.cpp @@ -69,22 +69,14 @@ static int PyBobLearnLibsvmMachine_init_svmfile static const char* const_kwlist[] = {"filename", 0}; static char** kwlist = const_cast<char**>(const_kwlist); - PyObject* filename = 0; + const char* filename = 0; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kwlist, &PyBobIo_FilenameConverter, &filename)) return -1; - 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 - try { - self->cxx = new bob::learn::libsvm::Machine(c_filename); + self->cxx = new bob::learn::libsvm::Machine(filename); } catch (std::exception& ex) { PyErr_SetString(PyExc_RuntimeError, ex.what()); @@ -985,31 +977,22 @@ static PyObject* PyBobLearnLibsvmMachine_Save } // try a filename conversion and use libsvm's original file format - PyObject* filename = 0; + const char* filename = 0; int ok = PyBobIo_FilenameConverter(f, &filename); if (!ok) { PyErr_Format(PyExc_TypeError, "cannot convert `%s' into a valid string for a file path - objects of type `%s' can only save to HDF5 files or text files using LIBSVM's original file format (pass a string referring to a valid filesystem path in this case)", Py_TYPE(f)->tp_name, Py_TYPE(self)->tp_name); return 0; } - // at this point we know we have a valid file system string - 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 - try { - self->cxx->save(c_filename); + self->cxx->save(filename); } catch (std::exception& ex) { PyErr_SetString(PyExc_RuntimeError, ex.what()); return 0; } catch (...) { - PyErr_Format(PyExc_RuntimeError, "`%s' cannot write data to file `%s' (using LIBSVM's original text format): unknown exception caught", Py_TYPE(self)->tp_name, c_filename); + PyErr_Format(PyExc_RuntimeError, "`%s' cannot write data to file `%s' (using LIBSVM's original text format): unknown exception caught", Py_TYPE(self)->tp_name, filename); return 0; } diff --git a/requirements.txt b/requirements.txt index 6d514b193654ed2d2c35ac6cdda95e945ba869be..7c4a7ee6d75f696b8a7a6b1be1ea7691b0b7e13a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ setuptools bob.extension bob.blitz bob.core -bob.io.base +bob.io.base > 2.1