From 46e82ddb13baae9d814c73b7a537e1ed6607717c Mon Sep 17 00:00:00 2001 From: Andre Anjos <andre.dos.anjos@gmail.com> Date: Wed, 29 Jan 2014 15:18:56 +0100 Subject: [PATCH] Use cleanup from xbob.blitz --- xbob/math/cleanup.h | 37 --------------------------------- xbob/math/histogram.cpp | 2 +- xbob/math/linsolve.cpp | 2 +- xbob/math/lp_interior_point.cpp | 2 +- xbob/math/pavx.cpp | 2 +- xbob/math/scatter.cpp | 2 +- 6 files changed, 5 insertions(+), 42 deletions(-) delete mode 100644 xbob/math/cleanup.h diff --git a/xbob/math/cleanup.h b/xbob/math/cleanup.h deleted file mode 100644 index d6f0011..0000000 --- a/xbob/math/cleanup.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @author Andre Anjos <andre.anjos@idiap.ch> - * @date Wed 11 Dec 08:42:53 2013 - * - * @brief Some C++ tricks to make our life dealing with Python references a bit - * easier - */ - -#include <Python.h> -#include <memory> - -/** - * Calls Py_DECREF(x) on the input object x. Usage pattern: - * - * PyObject* x = ... // builds x with a new python reference - * auto protected_x = make_safe(x); - * - * After this point, no need to worry about DECREF'ing x anymore. - * You can still use `x' inside your code, or protected_x.get(). - */ -template <typename T> std::shared_ptr<T> make_safe(T* o) { - return std::shared_ptr<T>(o, [&](T* p){Py_DECREF(p);}); -} - -/** - * Calls Py_XDECREF(x) on the input object x. Usage pattern: - * - * PyObject* x = ... // builds x with a new python reference, x may be NULL - * auto protected_x = make_xsafe(x); - * - * After this point, no need to worry about XDECREF'ing x anymore. - * You can still use `x' inside your code, or protected_x.get(). Note - * `x' may be NULL with this method. - */ -template <typename T> std::shared_ptr<T> make_xsafe(T* o) { - return std::shared_ptr<T>(o, [&](T* p){Py_XDECREF(p);}); -} diff --git a/xbob/math/histogram.cpp b/xbob/math/histogram.cpp index 27f5e57..6126e1e 100644 --- a/xbob/math/histogram.cpp +++ b/xbob/math/histogram.cpp @@ -8,9 +8,9 @@ * Copyright (C) 2011-2013 Idiap Research Institute, Martigny, Switzerland */ -#include "cleanup.h" #include "histogram.h" #include <xbob.blitz/cppapi.h> +#include <xbob.blitz/cleanup.h> #include "bob/math/histogram.h" static PyObject* py_histogram_intersection_1 diff --git a/xbob/math/linsolve.cpp b/xbob/math/linsolve.cpp index 5adb11a..d1b7b6a 100644 --- a/xbob/math/linsolve.cpp +++ b/xbob/math/linsolve.cpp @@ -8,9 +8,9 @@ * Copyright (C) 2011-2013 Idiap Research Institute, Martigny, Switzerland */ -#include "cleanup.h" #include "histogram.h" #include <xbob.blitz/cppapi.h> +#include <xbob.blitz/cleanup.h> #include "bob/math/linsolve.h" static PyObject* py_linsolve_1(PyObject*, PyObject* args, PyObject* kwds) { diff --git a/xbob/math/lp_interior_point.cpp b/xbob/math/lp_interior_point.cpp index 59ab057..1750a2a 100644 --- a/xbob/math/lp_interior_point.cpp +++ b/xbob/math/lp_interior_point.cpp @@ -9,9 +9,9 @@ * Copyright (C) 2011-2013 Idiap Research Institute, Martigny, Switzerland */ -#include "cleanup.h" #include "lp_interior_point.h" #include <xbob.blitz/cppapi.h> +#include <xbob.blitz/cleanup.h> #include <bob/math/LPInteriorPoint.h> #include <structmember.h> diff --git a/xbob/math/pavx.cpp b/xbob/math/pavx.cpp index f1ca247..00f5f0d 100644 --- a/xbob/math/pavx.cpp +++ b/xbob/math/pavx.cpp @@ -6,9 +6,9 @@ * @brief Binds the Pool-Adjacent-Violators Algorithm */ -#include "cleanup.h" #include "pavx.h" #include <xbob.blitz/cppapi.h> +#include <xbob.blitz/cleanup.h> #include "bob/math/pavx.h" #include "bob/core/cast.h" diff --git a/xbob/math/scatter.cpp b/xbob/math/scatter.cpp index 1fdf322..73d0ec9 100644 --- a/xbob/math/scatter.cpp +++ b/xbob/math/scatter.cpp @@ -7,9 +7,9 @@ * Copyright (C) 2011-2013 Idiap Research Institute, Martigny, Switzerland */ -#include "cleanup.h" #include "scatter.h" #include <xbob.blitz/cppapi.h> +#include <xbob.blitz/cleanup.h> #include <bob/math/stats.h> PyObject* py_scatter (PyObject*, PyObject* args, PyObject* kwds) { -- GitLab