Commit 9bcc54db authored by Manuel Günther's avatar Manuel Günther

Fixed memory leaks.

parent 871ef255
......@@ -94,7 +94,6 @@ PyObject* PyBobIpBase_scale(PyObject*, PyObject* args, PyObject* kwargs) {
return 0;
}
} else {
assert (!isnan(scale_factor));
// create output in the same dimensions as input
switch (src->ndim){
case 2:{
......@@ -133,7 +132,6 @@ PyObject* PyBobIpBase_scale(PyObject*, PyObject* args, PyObject* kwargs) {
}
if (!isnan(scale_factor)){
Py_INCREF(dst);
return PyBlitzArray_AsNumpyArray(dst,0);
}
......@@ -265,7 +263,6 @@ PyObject* PyBobIpBase_rotate(PyObject*, PyObject* args, PyObject* kwargs) {
return 0;
}
} else {
assert (!isnan(scale_factor));
// create output in the same dimensions as input
switch (src->ndim){
case 2:{
......@@ -304,7 +301,6 @@ PyObject* PyBobIpBase_rotate(PyObject*, PyObject* args, PyObject* kwargs) {
}
if (nargs == 2){
Py_INCREF(dst);
return PyBlitzArray_AsNumpyArray(dst,0);
}
......@@ -481,5 +477,3 @@ PyObject* PyBobIpBase_extrapolateMask(PyObject*, PyObject* args, PyObject* kwarg
BOB_CATCH_FUNCTION("in extrapolate_mask", 0)
}
......@@ -492,7 +492,6 @@ static PyObject* PyBobIpBaseDCTFeatures_extract(PyBobIpBaseDCTFeaturesObject* se
}
if (return_out){
Py_INCREF(output);
return PyBlitzArray_AsNumpyArray(output, 0);
} else {
Py_RETURN_NONE;
......@@ -629,4 +628,3 @@ bool init_BobIpBaseDCTFeatures(PyObject* module)
Py_INCREF(&PyBobIpBaseDCTFeatures_Type);
return PyModule_AddObject(module, "DCTFeatures", (PyObject*)&PyBobIpBaseDCTFeatures_Type) >= 0;
}
......@@ -459,7 +459,6 @@ static PyObject* PyBobIpBaseFaceEyesNorm_extract(PyBobIpBaseFaceEyesNormObject*
}
if (nargs == 3){
Py_INCREF(output);
return PyBlitzArray_AsNumpyArray(output,0);
} else {
Py_RETURN_NONE;
......@@ -513,4 +512,3 @@ bool init_BobIpBaseFaceEyesNorm(PyObject* module)
Py_INCREF(&PyBobIpBaseFaceEyesNorm_Type);
return PyModule_AddObject(module, "FaceEyesNorm", (PyObject*)&PyBobIpBaseFaceEyesNorm_Type) >= 0;
}
......@@ -30,7 +30,6 @@ bob::extension::FunctionDoc s_median = bob::extension::FunctionDoc(
template <typename T, int D> PyObject* inner_median(PyBlitzArrayObject* src, PyBlitzArrayObject* dst, const blitz::TinyVector<int,2>& radius) {
bob::ip::base::medianFilter(*PyBlitzArrayCxx_AsBlitz<T, D>(src), *PyBlitzArrayCxx_AsBlitz<T, D>(dst), radius);
Py_INCREF(dst);
return PyBlitzArray_AsNumpyArray(dst, 0);
}
......@@ -126,10 +125,7 @@ PyObject* PyBobIpBase_sobel(PyObject*, PyObject* args, PyObject* kwargs) {
// perform Sobel filtering
bob::ip::base::sobel(*PyBlitzArrayCxx_AsBlitz<double,2>(src), *PyBlitzArrayCxx_AsBlitz<double,3>(dst), border);
Py_INCREF(dst);
return PyBlitzArray_AsNumpyArray(dst, 0);
BOB_CATCH_FUNCTION("in sobel", 0)
}
......@@ -254,7 +254,6 @@ static auto filter = bob::extension::FunctionDoc(
template <typename T, int D>
static PyObject* filter_inner(PyBobIpBaseGaussianObject* self, PyBlitzArrayObject* input, PyBlitzArrayObject* output){
self->cxx->filter(*PyBlitzArrayCxx_AsBlitz<T,D>(input), *PyBlitzArrayCxx_AsBlitz<double,D>(output));
Py_INCREF(output);
return PyBlitzArray_AsNumpyArray(output, 0);
}
......@@ -352,4 +351,3 @@ bool init_BobIpBaseGaussian(PyObject* module)
Py_INCREF(&PyBobIpBaseGaussian_Type);
return PyModule_AddObject(module, "Gaussian", (PyObject*)&PyBobIpBaseGaussian_Type) >= 0;
}
......@@ -773,11 +773,10 @@ static PyObject* _allocate(PyBobIpBaseGaussianScaleSpaceObject* self){
const blitz::TinyVector<int,3> shape = self->cxx->getOutputShape(i);
Py_ssize_t o[] = {shape[0], shape[1], shape[2]};
PyBlitzArrayObject* array = (PyBlitzArrayObject*)PyBlitzArray_SimpleNew(NPY_FLOAT64, 3, o);
PyList_SET_ITEM(list, i, Py_BuildValue("O", PyBlitzArray_AsNumpyArray(array, 0)));
PyList_SET_ITEM(list, i, PyBlitzArray_AsNumpyArray(array, 0));
}
Py_INCREF(list);
return list;
return Py_BuildValue("O", list);
}
static PyObject* PyBobIpBaseGaussianScaleSpace_allocateOutput(PyBobIpBaseGaussianScaleSpaceObject* self, PyObject* args, PyObject* kwargs) {
......@@ -839,7 +838,7 @@ static PyObject* PyBobIpBaseGaussianScaleSpace_process(PyBobIpBaseGaussianScaleS
// create output in desired shape
dst = _allocate(self);
}
auto dst_ = make_xsafe(dst);
auto dst_ = make_safe(dst);
// convert output to list of arrays
std::vector<blitz::Array<double,3>> output(size);
......@@ -871,8 +870,7 @@ static PyObject* PyBobIpBaseGaussianScaleSpace_process(PyBobIpBaseGaussianScaleS
return 0;
}
Py_INCREF(dst);
return dst;
return Py_BuildValue("O", dst);
BOB_CATCH_MEMBER("cannot process image", 0)
}
......@@ -967,4 +965,3 @@ bool init_BobIpBaseGaussianScaleSpace(PyObject* module)
Py_INCREF(&PyBobIpBaseGaussianScaleSpace_Type);
return PyModule_AddObject(module, "GaussianScaleSpace", (PyObject*)&PyBobIpBaseGaussianScaleSpace_Type) >= 0;
}
......@@ -121,8 +121,7 @@ static PyObject* createGLCMProperty() {
if (insert_item_string(retval, entries, "inverse_difference_moment_normalized", GLCMProperty::inv_diff_mom_norm) < 0) return 0;
if (PyDict_SetItemString(retval, "entries", entries) < 0) return 0;
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
BOB_CATCH_FUNCTION("create glmc", 0)
}
......@@ -673,7 +672,6 @@ static PyObject* PyBobIpBaseGLCM_extract(PyBobIpBaseGLCMObject* self, PyObject*
default: return 0;
}
Py_INCREF(output);
return PyBlitzArray_AsNumpyArray(output, 0);
BOB_CATCH_MEMBER("cannot extract GLCM matrix from image", 0)
......@@ -756,8 +754,7 @@ static PyObject* PyBobIpBaseGLCM_propertiesByName(PyBobIpBaseGLCMObject* self, P
PyList_SET_ITEM(result, i, Py_BuildValue("O", PyBlitzArray_AsNumpyArray(values, 0)));
}
Py_INCREF(result);
return result;
return Py_BuildValue("O", result);
BOB_CATCH_MEMBER("cannot extract GLCM matrix from image", 0)
}
......@@ -833,4 +830,3 @@ bool init_BobIpBaseGLCM(PyObject* module)
// here we actually bind the _GLCM class, which will be sub-typed in python later on (I cannot set attributes in C++ classes directly)
return PyModule_AddObject(module, "_GLCM", (PyObject*)&PyBobIpBaseGLCM_Type) >= 0;
}
......@@ -38,8 +38,7 @@ static PyObject* createGradientMagnitude() {
if (insert_item_string(retval, entries, "SqrtMagnitude", bob::ip::base::GradientMagnitudeType::SqrtMagnitude) < 0) return 0;
if (PyDict_SetItemString(retval, "entries", entries) < 0) return 0;
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
int PyBobIpBaseGradientMagnitude_Converter(PyObject* o, bob::ip::base::GradientMagnitudeType* b) {
......@@ -96,8 +95,7 @@ static PyObject* createBlockNorm() {
if (insert_item_string(retval, entries, "Nonorm", bob::ip::base::BlockNorm::Nonorm) < 0) return 0;
if (PyDict_SetItemString(retval, "entries", entries) < 0) return 0;
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
int PyBobIpBaseBlockNorm_Converter(PyObject* o, bob::ip::base::BlockNorm* b) {
......@@ -646,7 +644,6 @@ static PyObject* PyBobIpBaseHOG_computeHistogram(PyBobIpBaseHOGObject* self, PyO
self->cxx->computeHistogram(*PyBlitzArrayCxx_AsBlitz<double,2>(mag), *PyBlitzArrayCxx_AsBlitz<double,2>(ori), *PyBlitzArrayCxx_AsBlitz<double,1>(hist));
// return the histogram
Py_INCREF(hist);
return PyBlitzArray_AsNumpyArray(hist, 0);
BOB_CATCH_MEMBER("cannot compute histogram", 0)
......@@ -674,7 +671,6 @@ static PyObject* extract_inner(PyBobIpBaseHOGObject* self, PyBlitzArrayObject* i
else
input_.reference(bob::core::array::cast<double>(*PyBlitzArrayCxx_AsBlitz<T,2>(input)));
self->cxx->extract(input_, *PyBlitzArrayCxx_AsBlitz<double,3>(output));
Py_INCREF(output);
return PyBlitzArray_AsNumpyArray(output, 0);
}
......@@ -819,4 +815,3 @@ bool init_BobIpBaseHOG(PyObject* module)
Py_INCREF(&PyBobIpBaseHOG_Type);
return PyModule_AddObject(module, "HOG", (PyObject*)&PyBobIpBaseHOG_Type) >= 0;
}
......@@ -842,7 +842,6 @@ template <typename T>
static PyObject* extract_inner(PyBobIpBaseLBPObject* self, PyBlitzArrayObject* input, PyBlitzArrayObject* output, bool iii, bool ret_img){
self->cxx->extract(*PyBlitzArrayCxx_AsBlitz<T,2>(input), *PyBlitzArrayCxx_AsBlitz<uint16_t,2>(output), iii);
if (ret_img){
Py_INCREF(output);
return PyBlitzArray_AsNumpyArray(output, 0);
} else {
Py_RETURN_NONE;
......@@ -1083,4 +1082,3 @@ bool init_BobIpBaseLBP(PyObject* module)
Py_INCREF(&PyBobIpBaseLBP_Type);
return PyModule_AddObject(module, "LBP", (PyObject*)&PyBobIpBaseLBP_Type) >= 0;
}
......@@ -266,7 +266,6 @@ static auto process = bob::extension::FunctionDoc(
template <typename T, int D>
static PyObject* process_inner(PyBobIpBaseMultiscaleRetinexObject* self, PyBlitzArrayObject* input, PyBlitzArrayObject* output){
self->cxx->process(*PyBlitzArrayCxx_AsBlitz<T,D>(input), *PyBlitzArrayCxx_AsBlitz<double,D>(output));
Py_INCREF(output);
return PyBlitzArray_AsNumpyArray(output, 0);
}
......@@ -364,4 +363,3 @@ bool init_BobIpBaseMultiscaleRetinex(PyObject* module)
Py_INCREF(&PyBobIpBaseMultiscaleRetinex_Type);
return PyModule_AddObject(module, "MultiscaleRetinex", (PyObject*)&PyBobIpBaseMultiscaleRetinex_Type) >= 0;
}
......@@ -267,7 +267,6 @@ static auto process = bob::extension::FunctionDoc(
template <typename T, int D>
static PyObject* process_inner(PyBobIpBaseSelfQuotientImageObject* self, PyBlitzArrayObject* input, PyBlitzArrayObject* output){
self->cxx->process(*PyBlitzArrayCxx_AsBlitz<T,D>(input), *PyBlitzArrayCxx_AsBlitz<double,D>(output));
Py_INCREF(output);
return PyBlitzArray_AsNumpyArray(output, 0);
}
......@@ -365,4 +364,3 @@ bool init_BobIpBaseSelfQuotientImage(PyObject* module)
Py_INCREF(&PyBobIpBaseSelfQuotientImage_Type);
return PyModule_AddObject(module, "SelfQuotientImage", (PyObject*)&PyBobIpBaseSelfQuotientImage_Type) >= 0;
}
......@@ -630,7 +630,6 @@ static auto computeDescriptor = bob::extension::FunctionDoc(
template <typename T>
static PyObject* compute_inner(PyBobIpBaseSIFTObject* self, PyBlitzArrayObject* src, const std::vector<boost::shared_ptr<bob::ip::base::GSSKeypoint> >& keypoints, PyBlitzArrayObject* dst){
self->cxx->computeDescriptor(*PyBlitzArrayCxx_AsBlitz<T,2>(src), keypoints, *PyBlitzArrayCxx_AsBlitz<double,4>(dst));
Py_INCREF(dst);
return PyBlitzArray_AsNumpyArray(dst,0);
}
......@@ -751,4 +750,3 @@ bool init_BobIpBaseSIFT(PyObject* module)
Py_INCREF(&PyBobIpBaseSIFT_Type);
return PyModule_AddObject(module, "SIFT", (PyObject*)&PyBobIpBaseSIFT_Type) >= 0;
}
......@@ -334,7 +334,6 @@ static auto process = bob::extension::FunctionDoc(
template <typename T>
static PyObject* process_inner(PyBobIpBaseTanTriggsObject* self, PyBlitzArrayObject* input, PyBlitzArrayObject* output){
self->cxx->process(*PyBlitzArrayCxx_AsBlitz<T,2>(input), *PyBlitzArrayCxx_AsBlitz<double,2>(output));
Py_INCREF(output);
return PyBlitzArray_AsNumpyArray(output, 0);
}
......@@ -430,4 +429,3 @@ bool init_BobIpBaseTanTriggs(PyObject* module)
Py_INCREF(&PyBobIpBaseTanTriggs_Type);
return PyModule_AddObject(module, "TanTriggs", (PyObject*)&PyBobIpBaseTanTriggs_Type) >= 0;
}
......@@ -157,8 +157,7 @@ static PyObject* build_version_dictionary() {
if (!dict_steal(retval, "VLFeat", vlfeat_version())) return 0;
#endif // HAVE_VLFEAT
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
static PyMethodDef module_methods[] = {
......
......@@ -376,8 +376,7 @@ static PyObject* PyBobIpBaseVLSIFT_extract(PyBobIpBaseVLSIFTObject* self, PyObje
PyList_SET_ITEM(dst, i, PyBlitzArrayCxx_AsNumpy(features[i]));
}
Py_INCREF(dst);
return dst;
return Py_BuildValue("O", dst);
BOB_CATCH_MEMBER("cannot extract SIFT features for image", 0)
}
......@@ -706,7 +705,6 @@ static PyObject* PyBobIpBaseVLDSIFT_extract(PyBobIpBaseVLDSIFTObject* self, PyOb
// finally, extract the features
self->cxx->extract(*PyBlitzArrayCxx_AsBlitz<float,2>(src), *PyBlitzArrayCxx_AsBlitz<float,2>(dst));
Py_INCREF(dst);
return PyBlitzArray_AsNumpyArray(dst,0);
BOB_CATCH_MEMBER("cannot extract dense SIFT features for image", 0)
......
......@@ -217,7 +217,6 @@ static auto filter = bob::extension::FunctionDoc(
template <typename T, int D>
static PyObject* filter_inner(PyBobIpBaseWeightedGaussianObject* self, PyBlitzArrayObject* input, PyBlitzArrayObject* output){
self->cxx->filter(*PyBlitzArrayCxx_AsBlitz<T,D>(input), *PyBlitzArrayCxx_AsBlitz<double,D>(output));
Py_INCREF(output);
return PyBlitzArray_AsNumpyArray(output, 0);
}
......@@ -315,4 +314,3 @@ bool init_BobIpBaseWeightedGaussian(PyObject* module)
Py_INCREF(&PyBobIpBaseWeightedGaussian_Type);
return PyModule_AddObject(module, "WeightedGaussian", (PyObject*)&PyBobIpBaseWeightedGaussian_Type) >= 0;
}
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