diff --git a/buildout.cfg b/buildout.cfg index 685e6b4f249748959146e3a1fb04c01d4190f658..003fdb526d24eeac1862741b0cbd143a226f15cd 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -8,7 +8,7 @@ eggs = xbob.io ipdb extensions = mr.developer auto-checkout = * -prefixes = /Users/andre/work/bob/b/dbg +prefixes = /idiap/group/torch5spro/nightlies/last/install/linux-x86_64-release debug = true verbose = true diff --git a/setup.py b/setup.py index e314346a39f228f49e58747623cf4e367ce06488..e20f5b3665e1543588efd27c2f042a9aa89ecf57 100644 --- a/setup.py +++ b/setup.py @@ -47,6 +47,7 @@ setup( packages = packages, include_dirs = include_dirs, version = version, + define_macros = [('__STDC_CONSTANT_MACROS', None)], ), Extension("xbob.io._library", [ @@ -60,6 +61,7 @@ setup( packages = packages, include_dirs = include_dirs, version = version, + define_macros = [('__STDC_CONSTANT_MACROS', None)], ), ], diff --git a/xbob/io/bobskin.cpp b/xbob/io/bobskin.cpp index 603df51a8de4c49ef7d35af28a3c3a6ec48dde77..c1bc9caa9b0dbea69e84c0d2f4b1320c2b9684ed 100644 --- a/xbob/io/bobskin.cpp +++ b/xbob/io/bobskin.cpp @@ -5,8 +5,8 @@ * @brief Implementation of our bobskin class */ -#include <stdexcept> #include "bobskin.h" +#include <stdexcept> bobskin::bobskin(PyObject* array, bob::core::array::ElementType eltype) { @@ -15,7 +15,7 @@ bobskin::bobskin(PyObject* array, bob::core::array::ElementType eltype) { throw std::runtime_error("error is already set"); } - m_type.set<npy_intp>(eltype, PyArray_NDIM((PyArrayObject*)array), + m_type.set<npy_intp>(eltype, PyArray_NDIM((PyArrayObject*)array), PyArray_DIMS((PyArrayObject*)array), PyArray_STRIDES((PyArrayObject*)array)); @@ -25,7 +25,7 @@ bobskin::bobskin(PyObject* array, bob::core::array::ElementType eltype) { bobskin::bobskin(PyArrayObject* array, bob::core::array::ElementType eltype) { - m_type.set<npy_intp>(eltype, PyArray_NDIM((PyArrayObject*)array), + m_type.set<npy_intp>(eltype, PyArray_NDIM((PyArrayObject*)array), PyArray_DIMS((PyArrayObject*)array), PyArray_STRIDES((PyArrayObject*)array)); diff --git a/xbob/io/bobskin.h b/xbob/io/bobskin.h index bdae7b62d145c4906127bfa81bec4284a97afd0f..c60e754f4ab72755401545d835b7cba7e9647676 100644 --- a/xbob/io/bobskin.h +++ b/xbob/io/bobskin.h @@ -1,15 +1,16 @@ /** * @author Andre Anjos <andre.anjos@idiap.ch> - * @date Tue 5 Nov 22:09:07 2013 + * @date Tue 5 Nov 22:09:07 2013 * * @brief A pythonic version of bob::core::array::interface, with minimal * functionality. */ +#include <Python.h> + #include <bob/core/array.h> extern "C" { -#include <Python.h> #include <xbob.blitz/capi.h> } @@ -37,7 +38,7 @@ class bobskin: public bob::core::array::interface { bobskin(PyBlitzArrayObject* array); /** - * @brief By default, the interface is never freed. You must override + * @brief By default, the interface is never freed. You must override * this method to do something special for your class type. */ virtual ~bobskin(); @@ -64,9 +65,9 @@ class bobskin: public bob::core::array::interface { virtual const bob::core::array::typeinfo& type() const { return m_type; } /** - * @brief Borrows a reference from the underlying memory. This means - * this object continues to be responsible for deleting the memory and - * you should make sure that it outlives the usage of the returned + * @brief Borrows a reference from the underlying memory. This means + * this object continues to be responsible for deleting the memory and + * you should make sure that it outlives the usage of the returned * pointer. */ virtual void* ptr() { return m_ptr; } diff --git a/xbob/io/externals.cpp b/xbob/io/externals.cpp index ce61bc07ce28d3c6897faa98b0f616c8b1dff8c1..5a4bec510f237ba4b60e605369b7a0e5310d03ea 100644 --- a/xbob/io/externals.cpp +++ b/xbob/io/externals.cpp @@ -5,6 +5,8 @@ * @brief Binds configuration information available from bob */ +#include <Python.h> + #define XBOB_IO_MODULE #include <xbob.io/config.h> @@ -21,8 +23,6 @@ extern "C" { -#include <Python.h> - #ifdef NO_IMPORT_ARRAY #undef NO_IMPORT_ARRAY #endif @@ -34,7 +34,7 @@ extern "C" { #define PNG_SKIP_SETJMP_CHECK // #define requires because of the problematic pngconf.h. -// Look at the thread here: +// Look at the thread here: // https://bugs.launchpad.net/ubuntu/+source/libpng/+bug/218409 #include <png.h> @@ -45,7 +45,10 @@ extern "C" { # include <libswscale/swscale.h> # include <libavutil/opt.h> # include <libavutil/pixdesc.h> -#endif +# if !HAVE_FFMPEG_AVCODEC_AVCODECID +# define AVCodecID CodecID +# endif +#endif #include <gif_lib.h> @@ -231,12 +234,12 @@ static PyObject* libtiff_version() { // Remove first part if it starts with "LIBTIFF, Version " if(vtiff.compare(0, beg_len, beg_str) == 0) - vtiff = vtiff.substr(beg_len); + vtiff = vtiff.substr(beg_len); // Remove multiple (copyright) lines if any size_t end_line = vtiff.find("\n"); if(end_line != std::string::npos) - vtiff = vtiff.substr(0,end_line); + vtiff = vtiff.substr(0,end_line); return Py_BuildValue("s", vtiff.c_str()); @@ -358,7 +361,7 @@ static PyObject* describe_codec(const AVCodec* codec) { unsigned int i=0; while(codec->pix_fmts[i] != -1) { - if (!list_append(pixfmt.get(), + if (!list_append(pixfmt.get(), #if LIBAVUTIL_VERSION_INT >= 0x320f01 //50.15.1 @ ffmpeg-0.6 av_get_pix_fmt_name #else @@ -386,7 +389,7 @@ static PyObject* describe_codec(const AVCodec* codec) { } rates.reset(PySequence_Tuple(rates.get()), &pyobject_deleter); if (!rates) return 0; - + if (!dict_set_string(retval, "specific_framerates_hz", rates.get())) return 0; /* Other codec capabilities */ @@ -429,7 +432,7 @@ static PyObject* PyBobIo_DescribeEncoder(PyObject*, PyObject *args, PyObject* kw } if (PyNumber_Check(key)) { - + /* If you get to this point, the user passed a number - re-parse */ int id = 0; if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &id)) return 0; @@ -488,7 +491,7 @@ static PyObject* PyBobIo_DescribeDecoder(PyObject*, PyObject *args, PyObject* kw } if (PyNumber_Check(key)) { - + /* If you get to this point, the user passed a number - re-parse */ int id = 0; if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &id)) return 0; @@ -530,10 +533,10 @@ the given decoder.\n\ "); static PyObject* get_video_codecs(void (*f)(std::map<std::string, const AVCodec*>&)) { - + std::map<std::string, const AVCodec*> m; f(m); - + PyObject* retval = PyDict_New(); if (!retval) return 0; @@ -588,7 +591,7 @@ static PyObject* get_video_iformats(void (*f)(std::map<std::string, AVInputForma std::map<std::string, AVInputFormat*> m; f(m); - + PyObject* retval = PyDict_New(); if (!retval) return 0; @@ -605,7 +608,7 @@ static PyObject* get_video_iformats(void (*f)(std::map<std::string, AVInputForma Py_DECREF(retval); return 0; } - + if (!dict_set(property, "long_name", k->second->long_name)) { Py_DECREF(property); Py_DECREF(retval); @@ -615,7 +618,7 @@ static PyObject* get_video_iformats(void (*f)(std::map<std::string, AVInputForma // get extensions std::vector<std::string> exts; bob::io::detail::ffmpeg::tokenize_csv(k->second->extensions, exts); - + PyObject* ext_list = PyList_New(0); if (!ext_list) { Py_DECREF(property); @@ -650,11 +653,11 @@ static PyObject* get_video_iformats(void (*f)(std::map<std::string, AVInputForma } static PyObject* PyBobIo_SupportedInputFormats(PyObject*) { - return get_video_iformats(&bob::io::detail::ffmpeg::iformats_supported); + return get_video_iformats(&bob::io::detail::ffmpeg::iformats_supported); } static PyObject* PyBobIo_AvailableInputFormats(PyObject*) { - return get_video_iformats(&bob::io::detail::ffmpeg::iformats_installed); + return get_video_iformats(&bob::io::detail::ffmpeg::iformats_installed); } PyDoc_STRVAR(s_supported_iformats_str, "supported_videoreader_formats"); @@ -683,7 +686,7 @@ static PyObject* get_video_oformats(bool supported) { std::map<std::string, AVOutputFormat*> m; if (supported) bob::io::detail::ffmpeg::oformats_supported(m); else bob::io::detail::ffmpeg::oformats_installed(m); - + PyObject* retval = PyDict_New(); if (!retval) return 0; @@ -700,7 +703,7 @@ static PyObject* get_video_oformats(bool supported) { Py_DECREF(retval); return 0; } - + if (!dict_set(property, "long_name", k->second->long_name)) { Py_DECREF(property); Py_DECREF(retval); @@ -716,7 +719,7 @@ static PyObject* get_video_oformats(bool supported) { // get extensions std::vector<std::string> exts; bob::io::detail::ffmpeg::tokenize_csv(k->second->extensions, exts); - + PyObject* ext_list = PyList_New(0); if (!ext_list) { Py_DECREF(property); @@ -809,7 +812,7 @@ static PyObject* get_video_oformats(bool supported) { return retval; } - + static PyObject* PyBobIo_SupportedOutputFormats(PyObject*) { return get_video_oformats(true); } diff --git a/xbob/io/file.cpp b/xbob/io/file.cpp index 6320bb882ddb9ec539e4d6f32b0e20ae44bb92a7..8edb42dc4c6478f31c236196cfaf98fe8ba5f61e 100644 --- a/xbob/io/file.cpp +++ b/xbob/io/file.cpp @@ -6,13 +6,13 @@ */ #define XBOB_IO_MODULE +#include "bobskin.h" #include <xbob.io/api.h> #include <bob/io/CodecRegistry.h> #include <bob/io/utils.h> #include <numpy/arrayobject.h> #include <xbob.blitz/capi.h> #include <stdexcept> -#include "bobskin.h" #define FILETYPE_NAME "File" PyDoc_STRVAR(s_file_str, XBOB_EXT_MODULE_PREFIX "." FILETYPE_NAME); @@ -133,14 +133,14 @@ library." static PyGetSetDef PyBobIoFile_getseters[] = { { - s_filename_str, + s_filename_str, (getter)PyBobIoFile_Filename, 0, s_filename_doc, 0, }, { - s_codec_name_str, + s_codec_name_str, (getter)PyBobIoFile_CodecName, 0, s_codec_name_doc, @@ -203,7 +203,7 @@ static PyObject* PyBobIoFile_GetIndex (PyBobIoFileObject* self, Py_ssize_t i) { if (i < 0) i += self->f->size(); ///< adjust for negative indexing - if (i < 0 || i >= self->f->size()) { + if (i < 0 || (size_t)i >= self->f->size()) { PyErr_Format(PyExc_IndexError, "file index out of range - `%s' only contains %" PY_FORMAT_SIZE_T "d object(s)", self->f->filename().c_str(), self->f->size()); return 0; } @@ -211,7 +211,7 @@ static PyObject* PyBobIoFile_GetIndex (PyBobIoFileObject* self, Py_ssize_t i) { const bob::core::array::typeinfo& info = self->f->type(); npy_intp shape[NPY_MAXDIMS]; - for (int 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]; int type_num = PyBobIo_AsTypenum(info.dtype); if (type_num == NPY_NOTYPE) return 0; ///< failure @@ -254,7 +254,7 @@ static PyObject* PyBobIoFile_GetSlice (PyBobIoFileObject* self, PySliceObject* s npy_intp shape[NPY_MAXDIMS]; shape[0] = slicelength; - for (int k=0; k<info.nd; ++k) shape[k+1] = info.shape[k]; + for (size_t k=0; k<info.nd; ++k) shape[k+1] = info.shape[k]; PyObject* retval = PyArray_SimpleNew(info.nd+1, shape, type_num); if (!retval) return 0; @@ -336,7 +336,7 @@ static PyObject* PyBobIoFile_Read(PyBobIoFileObject* self, PyObject *args, PyObj if (i < 0) i += self->f->size(); - if (i < 0 || i >= self->f->size()) { + if (i < 0 || (size_t)i >= self->f->size()) { PyErr_Format(PyExc_IndexError, "file index out of range - `%s' only contains %" PY_FORMAT_SIZE_T "d object(s)", self->f->filename().c_str(), self->f->size()); return 0; } @@ -350,7 +350,7 @@ static PyObject* PyBobIoFile_Read(PyBobIoFileObject* self, PyObject *args, PyObj const bob::core::array::typeinfo& info = self->f->type_all(); npy_intp shape[NPY_MAXDIMS]; - for (int 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]; int type_num = PyBobIo_AsTypenum(info.dtype); if (type_num == NPY_NOTYPE) return 0; ///< failure @@ -404,7 +404,7 @@ not specified, reads the whole contents of the file into a\n\ ); static PyObject* PyBobIoFile_Write(PyBobIoFileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"array", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -456,7 +456,7 @@ this method.\n\ ); static PyObject* PyBobIoFile_Append(PyBobIoFileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"array", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -514,7 +514,7 @@ PyObject* PyBobIo_TypeInfoAsTuple (const bob::core::array::typeinfo& ti) { int type_num = PyBobIo_AsTypenum(ti.dtype); if (type_num == NPY_NOTYPE) return 0; - PyObject* retval = Py_BuildValue("NNN", + PyObject* retval = Py_BuildValue("NNN", reinterpret_cast<PyObject*>(PyArray_DescrFromType(type_num)), PyTuple_New(ti.nd), //shape PyTuple_New(ti.nd) //strides @@ -523,7 +523,7 @@ PyObject* PyBobIo_TypeInfoAsTuple (const bob::core::array::typeinfo& ti) { PyObject* shape = PyTuple_GET_ITEM(retval, 1); PyObject* stride = PyTuple_GET_ITEM(retval, 2); - for (Py_ssize_t i=0; i<ti.nd; ++i) { + for (Py_ssize_t i=0; (size_t)i<ti.nd; ++i) { PyTuple_SET_ITEM(shape, i, Py_BuildValue("n", ti.shape[i])); PyTuple_SET_ITEM(stride, i, Py_BuildValue("n", ti.stride[i])); } @@ -533,7 +533,7 @@ PyObject* PyBobIo_TypeInfoAsTuple (const bob::core::array::typeinfo& ti) { } static PyObject* PyBobIoFile_Describe(PyBobIoFileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"all", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -613,7 +613,7 @@ static PyObject* PyBobIoFileIterator_Iter (PyBobIoFileIteratorObject* self) { } static PyObject* PyBobIoFileIterator_Next (PyBobIoFileIteratorObject* self) { - if (self->curpos >= self->pyfile->f->size()) { + if ((size_t)self->curpos >= self->pyfile->f->size()) { Py_XDECREF((PyObject*)self->pyfile); self->pyfile = 0; return 0; diff --git a/xbob/io/hdf5.cpp b/xbob/io/hdf5.cpp index 62b68ec653587741a13a7df15c9094817b2b3b9d..2ff54113af822fdacf0cf6ccfd5e3a1341a44260 100644 --- a/xbob/io/hdf5.cpp +++ b/xbob/io/hdf5.cpp @@ -75,7 +75,7 @@ static void PyBobIoHDF5File_Delete (PyBobIoHDF5FileObject* o) { } /* The __init__(self) method */ -static int PyBobIoHDF5File_Init(PyBobIoHDF5FileObject* self, +static int PyBobIoHDF5File_Init(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { /* Parses input arguments in a single shot */ @@ -118,7 +118,7 @@ static PyObject* PyBobIoHDF5File_Repr(PyBobIoHDF5FileObject* self) { } static PyObject* PyBobIoHDF5File_ChangeDirectory(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"path", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -166,7 +166,7 @@ defined by the ``cwd`` property of this object.\n\ "); static PyObject* PyBobIoHDF5File_HasGroup(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"path", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -207,7 +207,7 @@ to the current working directory.\n\ "); static PyObject* PyBobIoHDF5File_CreateGroup(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"path", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -248,7 +248,7 @@ directory. If the directory already exists (check it with\n\ "); static PyObject* PyBobIoHDF5File_HasDataset(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"key", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -383,7 +383,7 @@ static PyObject* PyBobIo_HDF5TypeAsTuple (const bob::io::HDF5Type& t) { } PyObject* shape = PyTuple_GET_ITEM(retval, 1); - for (Py_ssize_t i=0; i<ndim; ++i) { + for (Py_ssize_t i=0; i<(Py_ssize_t)ndim; ++i) { PyTuple_SET_ITEM(shape, i, Py_BuildValue("n", shptr[i])); } @@ -404,7 +404,7 @@ static PyObject* PyBobIo_HDF5DescriptorAsTuple (const bob::io::HDF5Descriptor& d } static PyObject* PyBobIoHDF5File_Describe(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"key", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -456,7 +456,7 @@ formats.\n\ "); static PyObject* PyBobIoHDF5File_Unlink(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"key", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -498,7 +498,7 @@ object using copy(), for example.\n\ "); static PyObject* PyBobIoHDF5File_Rename(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"from", "to", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -539,7 +539,7 @@ to\n\ "); static PyObject* PyBobIoHDF5File_Paths(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"relative", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -593,7 +593,7 @@ otherwise they are absolute.\n\ "); static PyObject* PyBobIoHDF5File_SubGroups(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"relative", "recursive", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -649,7 +649,7 @@ recursive\n\ \n\ "); -static PyObject* PyBobIoHDF5File_Xread(PyBobIoHDF5FileObject* self, +static PyObject* PyBobIoHDF5File_Xread(PyBobIoHDF5FileObject* self, const char* p, int descriptor, int pos) { const std::vector<bob::io::HDF5Descriptor>* D = 0; @@ -724,7 +724,7 @@ static PyObject* PyBobIoHDF5File_Xread(PyBobIoHDF5FileObject* self, if (type_num == NPY_NOTYPE) return 0; ///< failure npy_intp pyshape[NPY_MAXDIMS]; - for (int k=0; k<shape.n(); ++k) pyshape[k] = shape.get()[k]; + for (size_t k=0; k<shape.n(); ++k) pyshape[k] = shape.get()[k]; PyObject* retval = PyArray_SimpleNew(shape.n(), pyshape, type_num); if (!retval) return 0; @@ -747,7 +747,7 @@ static PyObject* PyBobIoHDF5File_Xread(PyBobIoHDF5FileObject* self, } static PyObject* PyBobIoHDF5File_Read(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"key", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -775,7 +775,7 @@ key\n\ "); static PyObject* PyBobIoHDF5File_ListRead(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"key", "pos", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -930,55 +930,55 @@ static int PyBobIoHDF5File_GetObjectType(PyObject* o, bob::io::HDF5Type& t, else if (PyLong_Check(o)) return PyBobIoHDF5File_SetType<int64_t>(t); - else if (PyFloat_Check(o)) + else if (PyFloat_Check(o)) return PyBobIoHDF5File_SetType<double>(t); - else if (PyComplex_Check(o)) + else if (PyComplex_Check(o)) return PyBobIoHDF5File_SetType<std::complex<double> >(t); - else if (PyArray_IsScalar(o, Bool)) + else if (PyArray_IsScalar(o, Bool)) return PyBobIoHDF5File_SetType<bool>(t); - else if (PyArray_IsScalar(o, Int8)) + else if (PyArray_IsScalar(o, Int8)) return PyBobIoHDF5File_SetType<int8_t>(t); - else if (PyArray_IsScalar(o, UInt8)) + else if (PyArray_IsScalar(o, UInt8)) return PyBobIoHDF5File_SetType<uint8_t>(t); - else if (PyArray_IsScalar(o, Int16)) + else if (PyArray_IsScalar(o, Int16)) return PyBobIoHDF5File_SetType<int16_t>(t); - else if (PyArray_IsScalar(o, UInt16)) + else if (PyArray_IsScalar(o, UInt16)) return PyBobIoHDF5File_SetType<uint16_t>(t); - else if (PyArray_IsScalar(o, Int32)) + else if (PyArray_IsScalar(o, Int32)) return PyBobIoHDF5File_SetType<int32_t>(t); else if (PyArray_IsScalar(o, UInt32)) return PyBobIoHDF5File_SetType<uint32_t>(t); - else if (PyArray_IsScalar(o, Int64)) + else if (PyArray_IsScalar(o, Int64)) return PyBobIoHDF5File_SetType<int64_t>(t); - else if (PyArray_IsScalar(o, UInt64)) + else if (PyArray_IsScalar(o, UInt64)) return PyBobIoHDF5File_SetType<uint64_t>(t); else if (PyArray_IsScalar(o, Float)) return PyBobIoHDF5File_SetType<float>(t); - else if (PyArray_IsScalar(o, Double)) + else if (PyArray_IsScalar(o, Double)) return PyBobIoHDF5File_SetType<double>(t); - else if (PyArray_IsScalar(o, LongDouble)) + else if (PyArray_IsScalar(o, LongDouble)) return PyBobIoHDF5File_SetType<long double>(t); - else if (PyArray_IsScalar(o, CFloat)) + else if (PyArray_IsScalar(o, CFloat)) return PyBobIoHDF5File_SetType<std::complex<float> >(t); - else if (PyArray_IsScalar(o, CDouble)) + else if (PyArray_IsScalar(o, CDouble)) return PyBobIoHDF5File_SetType<std::complex<double> >(t); - else if (PyArray_IsScalar(o, CLongDouble)) + else if (PyArray_IsScalar(o, CLongDouble)) return PyBobIoHDF5File_SetType<std::complex<long double> >(t); //if you get to this, point, it is an unsupported scalar @@ -1010,11 +1010,11 @@ static int PyBobIoHDF5File_GetObjectType(PyObject* o, bob::io::HDF5Type& t, else if (converted) { - *converted = PyArray_FromAny(o, 0, 1, 0, + *converted = PyArray_FromAny(o, 0, 1, 0, #if NPY_FEATURE_VERSION >= NUMPY17_API /* NumPy C-API version >= 1.7 */ - NPY_ARRAY_CARRAY_RO, + NPY_ARRAY_CARRAY_RO, # else - NPY_CARRAY_RO, + NPY_CARRAY_RO, # endif 0); if (!*converted) return -1; ///< error condition @@ -1049,7 +1049,7 @@ static PyObject* PyBobIoHDF5File_ReplaceScalar(PyBobIoHDF5FileObject* self, } static PyObject* PyBobIoHDF5File_Replace(PyBobIoHDF5FileObject* self, PyObject* args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"path", "pos", "data", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -1066,7 +1066,7 @@ static PyObject* PyBobIoHDF5File_Replace(PyBobIoHDF5FileObject* self, PyObject* PyErr_Format(PyExc_TypeError, "error replacing position %" PY_FORMAT_SIZE_T "d of dataset `%s' at HDF5 file `%s': no support for storing objects of type `%s' on HDF5 files", pos, path, self->f->filename().c_str(), data->ob_type->tp_name); return 0; } - + try { if (!is_array) { //write as a scalar @@ -1200,7 +1200,7 @@ static int PyBobIoHDF5File_InnerAppend(PyBobIoHDF5FileObject* self, const char* PyErr_Format(PyExc_TypeError, "error appending to object `%s' of HDF5 file `%s': no support for storing objects of type `%s' on HDF5 files", path, self->f->filename().c_str(), data->ob_type->tp_name); return 0; } - + try { if (!is_array) { //write as a scalar @@ -1290,7 +1290,7 @@ static int PyBobIoHDF5File_InnerAppend(PyBobIoHDF5FileObject* self, const char* } static PyObject* PyBobIoHDF5File_Append(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"path", "data", "compression", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -1370,7 +1370,7 @@ static PyObject* PyBobIoHDF5File_SetScalar(PyBobIoHDF5FileObject* self, } static PyObject* PyBobIoHDF5File_Set(PyBobIoHDF5FileObject* self, PyObject* args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"path", "data", "compression", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -1392,7 +1392,7 @@ static PyObject* PyBobIoHDF5File_Set(PyBobIoHDF5FileObject* self, PyObject* args PyErr_Format(PyExc_TypeError, "error setting object `%s' of HDF5 file `%s': no support for storing objects of type `%s' on HDF5 files", path, self->f->filename().c_str(), data->ob_type->tp_name); return 0; } - + try { if (!is_array) { //write as a scalar @@ -1516,7 +1516,7 @@ exist, we append the new scalar or array.\n\ "); static PyObject* PyBobIoHDF5File_Copy(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"file", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -1642,7 +1642,7 @@ static PyObject* PyBobIoHDF5File_ReadAttribute(PyBobIoHDF5FileObject* self, if (type_num == NPY_NOTYPE) return 0; ///< failure npy_intp pyshape[NPY_MAXDIMS]; - for (int k=0; k<shape.n(); ++k) pyshape[k] = shape.get()[k]; + for (size_t k=0; k<shape.n(); ++k) pyshape[k] = shape.get()[k]; PyObject* retval = PyArray_SimpleNew(shape.n(), pyshape, type_num); if (!retval) return 0; @@ -1665,7 +1665,7 @@ static PyObject* PyBobIoHDF5File_ReadAttribute(PyBobIoHDF5FileObject* self, } static PyObject* PyBobIoHDF5File_GetAttribute(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"name", "path", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -1723,7 +1723,7 @@ If you would like to retrieve all attributes at once, use\n\ "); static PyObject* PyBobIoHDF5File_GetAttributes(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"path", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -1869,7 +1869,7 @@ static PyObject* PyBobIoHDF5File_WriteAttribute(PyBobIoHDF5FileObject* self, } else { //write as an numpy array - + try { switch (is_array) { @@ -1909,7 +1909,7 @@ static PyObject* PyBobIoHDF5File_WriteAttribute(PyBobIoHDF5FileObject* self, } static PyObject* PyBobIoHDF5File_SetAttribute(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"name", "value", "path", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -1968,7 +1968,7 @@ path\n\ "); static PyObject* PyBobIoHDF5File_SetAttributes(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"attrs", "path", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -2041,7 +2041,7 @@ path\n\ "); static PyObject* PyBobIoHDF5File_DelAttribute(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"name", "path", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -2088,7 +2088,7 @@ path\n\ "); static PyObject* PyBobIoHDF5File_DelAttributes(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"attrs", "path", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -2182,7 +2182,7 @@ path\n\ "); static PyObject* PyBobIoHDF5File_HasAttribute(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { - + /* Parses input arguments in a single shot */ static const char* const_kwlist[] = {"name", "path", 0}; static char** kwlist = const_cast<char**>(const_kwlist); @@ -2384,7 +2384,7 @@ PyDoc_STRVAR(s_cwd_doc, static PyGetSetDef PyBobIoHDF5File_getseters[] = { { - s_cwd_str, + s_cwd_str, (getter)PyBobIoHDF5File_Cwd, 0, s_cwd_doc, diff --git a/xbob/io/include/xbob.io/api.h b/xbob/io/include/xbob.io/api.h index 99bfc6dcaef6612370e8e9594d2a5aca44521cff..2c33a9357f4f4a010ce583b3eee77b4e661061b0 100644 --- a/xbob/io/include/xbob.io/api.h +++ b/xbob/io/include/xbob.io/api.h @@ -1,6 +1,6 @@ /** * @author Andre Anjos <andre.anjos@idiap.ch> - * @date Tue 5 Nov 12:22:48 2013 + * @date Tue 5 Nov 12:22:48 2013 * * @brief C/C++ API for bob::io */ @@ -13,6 +13,8 @@ #define XBOB_IO_PREFIX "xbob.io" #define XBOB_IO_FULL_NAME "xbob.io._library" +#include <Python.h> + #include <xbob.io/config.h> #include <bob/config.h> #include <bob/io/File.h> @@ -24,7 +26,6 @@ #endif /* WITH_FFMPEG */ #include <boost/shared_ptr.hpp> -#include <Python.h> /******************* * C API functions * @@ -55,7 +56,7 @@ typedef struct { typedef struct { PyObject_HEAD - + /* Type-specific fields go here. */ PyBobIoFileObject* pyfile; Py_ssize_t curpos; @@ -171,7 +172,7 @@ typedef struct { ************************/ PyBobIo_AsTypenum_RET PyBobIo_AsTypenum PyBobIo_AsTypenum_PROTO; - + PyBobIo_TypeInfoAsTuple_RET PyBobIo_TypeInfoAsTuple PyBobIo_TypeInfoAsTuple_PROTO; #if WITH_FFMPEG @@ -290,7 +291,7 @@ typedef struct { # if PY_VERSION_HEX >= 0x02070000 if (PyCapsule_CheckExact(c_api_object)) { - PyXbobIo_API = (void **)PyCapsule_GetPointer(c_api_object, + PyXbobIo_API = (void **)PyCapsule_GetPointer(c_api_object, PyCapsule_GetName(c_api_object)); } # else diff --git a/xbob/io/videoreader.cpp b/xbob/io/videoreader.cpp index 0095d143c12487c572753112f2b12130443c3ab7..ed5b8152d501e6db9d981ae5d0da293e2e0d6b28 100644 --- a/xbob/io/videoreader.cpp +++ b/xbob/io/videoreader.cpp @@ -6,6 +6,7 @@ */ #define XBOB_IO_MODULE +#include "bobskin.h" #include <xbob.io/api.h> #if WITH_FFMPEG @@ -13,7 +14,6 @@ #include <numpy/arrayobject.h> #include <xbob.blitz/capi.h> #include <stdexcept> -#include "bobskin.h" #define VIDEOREADER_NAME "VideoReader" PyDoc_STRVAR(s_videoreader_str, XBOB_EXT_MODULE_PREFIX "." VIDEOREADER_NAME); @@ -71,7 +71,7 @@ static void PyBobIoVideoReader_Delete (PyBobIoVideoReaderObject* o) { } /* The __init__(self) method */ -static int PyBobIoVideoReader_Init(PyBobIoVideoReaderObject* self, +static int PyBobIoVideoReader_Init(PyBobIoVideoReaderObject* self, PyObject *args, PyObject* kwds) { /* Parses input arguments in a single shot */ @@ -80,7 +80,7 @@ static int PyBobIoVideoReader_Init(PyBobIoVideoReaderObject* self, char* filename = 0; PyObject* pycheck = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|O", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|O", kwlist, &filename, &pycheck)) return -1; bool check = false; @@ -334,9 +334,9 @@ static PyObject* PyBobIoVideoReader_Load(PyBobIoVideoReaderObject* self, PyObjec if (raise && PyObject_IsTrue(raise)) raise_on_error = true; const bob::core::array::typeinfo& info = self->v->video_type(); - + npy_intp shape[NPY_MAXDIMS]; - for (int 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]; int type_num = PyBobIo_AsTypenum(info.dtype); if (type_num == NPY_NOTYPE) return 0; ///< failure @@ -407,7 +407,7 @@ static PyObject* PyBobIoVideoReader_GetIndex (PyBobIoVideoReaderObject* self, Py if (i < 0) i += self->v->numberOfFrames(); ///< adjust for negative indexing - if (i < 0 || i >= self->v->numberOfFrames()) { + if (i < 0 || (size_t)i >= self->v->numberOfFrames()) { PyErr_Format(PyExc_IndexError, "video frame index out of range - `%s' only contains %" PY_FORMAT_SIZE_T "d frame(s)", self->v->filename().c_str(), self->v->numberOfFrames()); return 0; } @@ -415,7 +415,7 @@ static PyObject* PyBobIoVideoReader_GetIndex (PyBobIoVideoReaderObject* self, Py const bob::core::array::typeinfo& info = self->v->frame_type(); npy_intp shape[NPY_MAXDIMS]; - for (int 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]; int type_num = PyBobIo_AsTypenum(info.dtype); if (type_num == NPY_NOTYPE) return 0; ///< failure @@ -460,7 +460,7 @@ static PyObject* PyBobIoVideoReader_GetSlice (PyBobIoVideoReaderObject* self, Py npy_intp shape[NPY_MAXDIMS]; shape[0] = slicelength; - for (int k=0; k<info.nd; ++k) shape[k+1] = info.shape[k]; + for (size_t k=0; k<info.nd; ++k) shape[k+1] = info.shape[k]; PyObject* retval = PyArray_SimpleNew(info.nd+1, shape, type_num); if (!retval) return 0; @@ -575,7 +575,7 @@ static PyObject* PyBobIoVideoReaderIterator_Next (PyBobIoVideoReaderIteratorObje const bob::core::array::typeinfo& info = self->pyreader->v->frame_type(); npy_intp shape[NPY_MAXDIMS]; - for (int 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]; int type_num = PyBobIo_AsTypenum(info.dtype); if (type_num == NPY_NOTYPE) return 0; ///< failure diff --git a/xbob/io/videowriter.cpp b/xbob/io/videowriter.cpp index ab88ec0af5b18520e9fc721285b03cd852757d51..8ee51fa8e47811a1cdf7257cd5b009bca8609881 100644 --- a/xbob/io/videowriter.cpp +++ b/xbob/io/videowriter.cpp @@ -6,6 +6,7 @@ */ #define XBOB_IO_MODULE +#include "bobskin.h" #include <xbob.io/api.h> #if WITH_FFMPEG @@ -13,7 +14,6 @@ #include <numpy/arrayobject.h> #include <xbob.blitz/cppapi.h> #include <stdexcept> -#include "bobskin.h" #define VIDEOWRITER_NAME "VideoWriter" PyDoc_STRVAR(s_videowriter_str, XBOB_EXT_MODULE_PREFIX "." VIDEOWRITER_NAME); @@ -90,7 +90,7 @@ static void PyBobIoVideoWriter_Delete (PyBobIoVideoWriterObject* o) { } /* The __init__(self) method */ -static int PyBobIoVideoWriter_Init(PyBobIoVideoWriterObject* self, +static int PyBobIoVideoWriter_Init(PyBobIoVideoWriterObject* self, PyObject *args, PyObject* kwds) { /* Parses input arguments in a single shot */ @@ -112,7 +112,7 @@ static int PyBobIoVideoWriter_Init(PyBobIoVideoWriterObject* self, PyObject* pycheck = 0; if (!PyArg_ParseTupleAndKeywords(args, kwds, "snn|ddnssO", kwlist, - &filename, &height, &width, &framerate, &bitrate, &gop, &codec, + &filename, &height, &width, &framerate, &bitrate, &gop, &codec, &format, &pycheck)) return -1; if (pycheck && PyObject_IsTrue(pycheck)) { @@ -414,7 +414,7 @@ static PyObject* PyBobIoVideoWriter_Append(PyBobIoVideoWriterObject* self, PyObj Py_DECREF(frame); return 0; } - + if (frame->type_num != NPY_UINT8) { PyErr_Format(PyExc_TypeError, "input array should have dtype `uint8', but you passed an array with dtype == `%s'", PyBlitzArray_TypenumAsString(frame->type_num)); Py_DECREF(frame); @@ -470,7 +470,7 @@ static PyObject* PyBobIoVideoWriter_Close(PyBobIoVideoWriterObject* self) { } PyDoc_STRVAR(s_close_str, "close"); -PyDoc_STRVAR(s_close_doc, +PyDoc_STRVAR(s_close_doc, "x.close() -> None\n\ \n\ Closes the current video stream and forces writing the trailer.\n\