diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000000000000000000000000000000000..8bbc97b6642c0b9ade2dc904d5b87ab4a951f359 --- /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 925996fdf7ecdc1696f162916f773600d2f32504..189a4fc56a5e752823de42431e78830ce2a5ef99 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 449ad62482fd41691d07d0285a71476e09c126c1..2fcf70f6f4f76c89d2dd1bcc8e26266c2498a406 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 0000000000000000000000000000000000000000..5898fa59c92e0949a94d6f0408322d0dde8f1ab7 --- /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 0000000000000000000000000000000000000000..6e72599e697e874dc38b900ae2a6e590f368e863 --- /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 0000000000000000000000000000000000000000..d6f0011fece2edffea89ac756732595a3f2caefd --- /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 b80ea7fe54b5cb5537f9410c98e3607ceaefc44a..bd18228dd4955ec2c5d284632c0ecc551b2b6f8c 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());