From 637ca5d41eb7f6366f1bfa1bd8851c92d7541f15 Mon Sep 17 00:00:00 2001 From: Andre Anjos <andre.anjos@idiap.ch> Date: Fri, 13 Dec 2013 15:41:00 +0100 Subject: [PATCH] Compilation is now working --- .gitmodules | 6 ++++++ buildout.cfg | 11 +++-------- setup.py | 12 +++++++++--- src/xbob.blitz | 1 + src/xbob.io | 1 + xbob/machine/cleanup.h | 37 +++++++++++++++++++++++++++++++++++++ xbob/machine/externals.cpp | 2 +- 7 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 .gitmodules create mode 160000 src/xbob.blitz create mode 160000 src/xbob.io create mode 100644 xbob/machine/cleanup.h diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..8bbc97b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "src/xbob.blitz"] + path = src/xbob.blitz + url = git@github.com:anjos/xbob.blitz +[submodule "src/xbob.io"] + path = src/xbob.io + url = git@github.com:anjos/xbob.io diff --git a/buildout.cfg b/buildout.cfg index 925996f..189a4fc 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -3,8 +3,8 @@ ; Mon 16 Apr 08:29:18 2012 CEST [buildout] -parts = xbob.blitz xbob.math xbob.io xbob.math scripts -eggs = xbob.math +parts = xbob.blitz xbob.io xbob.machine scripts +eggs = xbob.machine ipdb extensions = mr.developer auto-checkout = * @@ -21,17 +21,12 @@ recipe = xbob.buildout:develop setup = src/xbob.blitz eggs = xbob.buildout xbob.extension -[xbob.math] -recipe = xbob.buildout:develop -setup = src/xbob.math -eggs = xbob.blitz xbob.buildout xbob.extension - [xbob.io] recipe = xbob.buildout:develop setup = src/xbob.io eggs = xbob.blitz xbob.buildout xbob.extension -[xbob.math] +[xbob.machine] recipe = xbob.buildout:develop eggs = xbob.blitz diff --git a/setup.py b/setup.py index 449ad62..2fcf70f 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,11 @@ from setuptools import setup, find_packages, dist dist.Distribution(dict(setup_requires=['xbob.blitz'])) from xbob.blitz.extension import Extension +import os +package_dir = os.path.dirname(os.path.realpath(__file__)) +package_dir = os.path.join(package_dir, 'xbob', 'machine', 'include') +include_dirs = [package_dir] + packages = ['bob-machine >= 1.3'] version = '2.0.0a0' @@ -38,7 +43,7 @@ setup( ext_modules = [ Extension("xbob.machine._externals", [ - "xbob/io/externals.cpp", + "xbob/machine/externals.cpp", ], packages = packages, include_dirs = include_dirs, @@ -46,10 +51,11 @@ setup( ), Extension("xbob.machine._library", [ - #"xbob/measure/activation.cpp", - "xbob/measure/main.cpp", + #"xbob/machine/activation.cpp", + "xbob/machine/main.cpp", ], packages = packages, + include_dirs = include_dirs, version = version, ), ], diff --git a/src/xbob.blitz b/src/xbob.blitz new file mode 160000 index 0000000..5898fa5 --- /dev/null +++ b/src/xbob.blitz @@ -0,0 +1 @@ +Subproject commit 5898fa59c92e0949a94d6f0408322d0dde8f1ab7 diff --git a/src/xbob.io b/src/xbob.io new file mode 160000 index 0000000..6e72599 --- /dev/null +++ b/src/xbob.io @@ -0,0 +1 @@ +Subproject commit 6e72599e697e874dc38b900ae2a6e590f368e863 diff --git a/xbob/machine/cleanup.h b/xbob/machine/cleanup.h new file mode 100644 index 0000000..d6f0011 --- /dev/null +++ b/xbob/machine/cleanup.h @@ -0,0 +1,37 @@ +/** + * @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/machine/externals.cpp b/xbob/machine/externals.cpp index b80ea7f..bd18228 100644 --- a/xbob/machine/externals.cpp +++ b/xbob/machine/externals.cpp @@ -60,7 +60,7 @@ PyMODINIT_FUNC XBOB_EXT_ENTRY_NAME (void) { PyObject* m = Py_InitModule3(XBOB_EXT_MODULE_NAME, module_methods, module_docstr); /* register some constants */ - PyModule_AddIntConstant(m, "__api_version__", XBOB_IO_API_VERSION); + PyModule_AddIntConstant(m, "__api_version__", XBOB_MACHINE_API_VERSION); PyModule_AddStringConstant(m, "__version__", XBOB_EXT_MODULE_VERSION); PyModule_AddObject(m, "versions", build_version_dictionary()); -- GitLab