From fbb8428df706033e5b87ec27e15cc030d5230800 Mon Sep 17 00:00:00 2001
From: Andre Anjos <andre.dos.anjos@gmail.com>
Date: Wed, 29 Jan 2014 14:45:28 +0100
Subject: [PATCH] Python2 C-API support (fine-tunning after Python3 changes)

---
 xbob/io/file.cpp        | 4 ++++
 xbob/io/hdf5.cpp        | 3 +++
 xbob/io/videoreader.cpp | 6 +++++-
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/xbob/io/file.cpp b/xbob/io/file.cpp
index e4b3cc6..d7d13c6 100644
--- a/xbob/io/file.cpp
+++ b/xbob/io/file.cpp
@@ -279,7 +279,11 @@ static PyObject* PyBobIoFile_GetIndex (PyBobIoFileObject* self, Py_ssize_t i) {
 static PyObject* PyBobIoFile_GetSlice (PyBobIoFileObject* self, PySliceObject* slice) {
 
   Py_ssize_t start, stop, step, slicelength;
+#if PY_VERSION_HEX < 0x03000000
+  if (PySlice_GetIndicesEx(slice,
+#else
   if (PySlice_GetIndicesEx(reinterpret_cast<PyObject*>(slice),
+#endif
         self->f->size(), &start, &stop, &step, &slicelength) < 0) return 0;
 
   //creates the return array
diff --git a/xbob/io/hdf5.cpp b/xbob/io/hdf5.cpp
index 68ff783..2bdb2e0 100644
--- a/xbob/io/hdf5.cpp
+++ b/xbob/io/hdf5.cpp
@@ -868,7 +868,10 @@ value >= 0, or a list of arrays otherwise.\n\
  */
 
 static void null_char_array_deleter(char*) {}
+
+#if PY_VERSION_HEX >= 0x03000000
 static void char_array_deleter(char* o) { delete[] o; }
+#endif
 
 static std::shared_ptr<char> PyBobIo_GetString(PyObject* o) {
 
diff --git a/xbob/io/videoreader.cpp b/xbob/io/videoreader.cpp
index f5f499c..8f4063b 100644
--- a/xbob/io/videoreader.cpp
+++ b/xbob/io/videoreader.cpp
@@ -457,7 +457,11 @@ static PyObject* PyBobIoVideoReader_GetIndex (PyBobIoVideoReaderObject* self, Py
 static PyObject* PyBobIoVideoReader_GetSlice (PyBobIoVideoReaderObject* self, PySliceObject* slice) {
 
   Py_ssize_t start, stop, step, slicelength;
-  if (PySlice_GetIndicesEx(reinterpret_cast<PyObject*>(slice), 
+#if PY_VERSION_HEX < 0x03000000
+  if (PySlice_GetIndicesEx(slice, 
+#else
+  if (PySlice_GetIndicesEx(reinterpret_cast<PyObject*>(slice),
+#endif
         self->v->numberOfFrames(), &start, &stop, &step, &slicelength) < 0) return 0;
 
   //creates the return array
-- 
GitLab