Commit fe3ad497 authored by Manuel Günther's avatar Manuel Günther
Browse files

More (possible) memory leaks fixed

parent 082ebcf6
......@@ -272,8 +272,7 @@ static PyObject* PyBobIoFile_GetIndex (PyBobIoFileObject* self, Py_ssize_t i) {
return 0;
}
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
......@@ -330,8 +329,7 @@ static PyObject* PyBobIoFile_GetSlice (PyBobIoFileObject* self, PySliceObject* s
}
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
......@@ -412,8 +410,7 @@ static PyObject* PyBobIoFile_Read(PyBobIoFileObject* self, PyObject *args, PyObj
return 0;
}
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
......@@ -646,7 +643,6 @@ static PyObject* PyBobIoFileIterator_New(PyTypeObject* type, PyObject*, PyObject
}
static PyObject* PyBobIoFileIterator_Iter (PyBobIoFileIteratorObject* self) {
Py_INCREF(self);
return reinterpret_cast<PyObject*>(self);
}
......@@ -696,10 +692,9 @@ PyTypeObject PyBobIoFileIterator_Type = {
static PyObject* PyBobIoFile_Iter (PyBobIoFileObject* self) {
PyBobIoFileIteratorObject* retval = (PyBobIoFileIteratorObject*)PyBobIoFileIterator_New(&PyBobIoFileIterator_Type, 0, 0);
if (!retval) return 0;
Py_INCREF(self);
retval->pyfile = self;
retval->curpos = 0;
return reinterpret_cast<PyObject*>(retval);
return Py_BuildValue("N", retval);
}
PyTypeObject PyBobIoFile_Type = {
......
......@@ -537,8 +537,7 @@ static PyObject* PyBobIo_HDF5TypeAsTuple (const bob::io::base::HDF5Type& t) {
PyTuple_SET_ITEM(shape, i, value);
}
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
......@@ -552,9 +551,8 @@ static PyObject* PyBobIo_HDF5DescriptorAsTuple (const bob::io::base::HDF5Descrip
return 0;
}
PyObject* expand = d.expandable? Py_True : Py_False;
Py_INCREF(expand);
return Py_BuildValue("NNN", type, size, expand); //steals references
return Py_BuildValue("NNO", type, size, expand); //steals references, except for True/False
}
......@@ -592,8 +590,7 @@ static PyObject* PyBobIoHDF5File_Describe(PyBobIoHDF5FileObject* self, PyObject
return 0;
}
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
PyDoc_STRVAR(s_describe_str, "describe");
......@@ -738,8 +735,7 @@ static PyObject* PyBobIoHDF5File_Paths(PyBobIoHDF5FileObject* self, PyObject *ar
return 0;
}
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
PyDoc_STRVAR(s_keys_str, "keys");
......@@ -918,8 +914,7 @@ static PyObject* PyBobIoHDF5File_Xread(PyBobIoHDF5FileObject* self,
return 0;
}
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
static PyObject* PyBobIoHDF5File_Read(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) {
......@@ -988,8 +983,7 @@ static PyObject* PyBobIoHDF5File_ListRead(PyBobIoHDF5FileObject* self, PyObject
PyTuple_SET_ITEM(retval, k, item);
}
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
......@@ -1895,8 +1889,7 @@ static PyObject* PyBobIoHDF5File_ReadAttribute(PyBobIoHDF5FileObject* self,
return 0;
}
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
static PyObject* PyBobIoHDF5File_GetAttribute(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) {
......@@ -1984,9 +1977,7 @@ static PyObject* PyBobIoHDF5File_GetAttributes(PyBobIoHDF5FileObject* self, PyOb
boost::format m("unsupported HDF5 data type detected for attribute `%s' at path `%s' of file `%s' - returning None");
m % k->first % k->second.str() % filename;
PyErr_Warn(PyExc_UserWarning, m.str().c_str());
item = Py_None;
Py_INCREF(item);
Py_INCREF(Py_None);
item = Py_BuildValue("");
}
else item = PyBobIoHDF5File_ReadAttribute(self, path, k->first.c_str(), k->second);
......@@ -1996,8 +1987,7 @@ static PyObject* PyBobIoHDF5File_GetAttributes(PyBobIoHDF5FileObject* self, PyOb
if (PyDict_SetItemString(retval, k->first.c_str(), item) != 0) return 0;
}
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
......
......@@ -39,8 +39,7 @@ static PyObject* PyBobIo_Extensions(PyObject*) {
}
}
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
......@@ -184,8 +183,7 @@ static PyObject* create_module (void) {
return 0;
}
Py_INCREF(m);
return m;
return Py_BuildValue("O", m);
}
......
......@@ -25,15 +25,6 @@
#include <bob.blitz/cleanup.h>
#include <bob.core/config.h>
static int dict_set(PyObject* d, const char* key, const char* value) {
PyObject* v = Py_BuildValue("s", value);
if (!v) return 0;
auto v_ = make_safe(v);
int retval = PyDict_SetItemString(d, key, v);
if (retval == 0) return 1; //all good
return 0; //a problem occurred
}
static int dict_steal(PyObject* d, const char* key, PyObject* value) {
if (!value) return 0;
auto value_ = make_safe(value);
......@@ -42,6 +33,12 @@ static int dict_steal(PyObject* d, const char* key, PyObject* value) {
return 0; //a problem occurred
}
static int dict_set(PyObject* d, const char* key, const char* value) {
PyObject* v = Py_BuildValue("s", value);
return dict_steal(d, key, v);
}
/***********************************************************
* Version number generation
***********************************************************/
......@@ -132,9 +129,7 @@ static PyObject* build_version_dictionary() {
if (!dict_steal(retval, "bob.blitz", bob_blitz_version())) return 0;
if (!dict_steal(retval, "bob.core", bob_core_version())) return 0;
Py_INCREF(retval);
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
static PyMethodDef module_methods[] = {
......@@ -180,8 +175,7 @@ static PyObject* create_module (void) {
return 0;
}
Py_INCREF(m);
return m;
return Py_BuildValue("O", m);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment