Skip to content

Commit

Permalink
Applied new versioning system; removed some unused defines
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Guenther committed May 22, 2015
1 parent 90826b1 commit 9e12d80
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 174 deletions.
19 changes: 19 additions & 0 deletions bob/learn/em/include/bob.learn.em/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,23 @@
/* Macros that define versions and important names */
#define BOB_LEARN_EM_API_VERSION 0x0200

#ifdef BOB_IMPORT_VERSION

/***************************************
* Here we define some functions that should be used to build version dictionaries in the version.cpp file
* There will be a compiler warning, when these functions are not used, so use them!
***************************************/

#include <Python.h>
#include <boost/preprocessor/stringize.hpp>

/**
* bob.learn.em c/c++ api version
*/
static PyObject* bob_learn_em_version() {
return Py_BuildValue("{ss}", "api", BOOST_PP_STRINGIZE(BOB_LEARN_EM_API_VERSION));
}

#endif // BOB_IMPORT_VERSION

#endif /* BOB_LEARN_EM_CONFIG_H */
4 changes: 3 additions & 1 deletion bob/learn/em/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ static PyObject* create_module (void) {

if (PyModule_AddObject(module, "_C_API", c_api_object) < 0) return 0;


/* imports bob.learn.em's C-API dependencies */
if (import_bob_blitz() < 0) return 0;
if (import_bob_core_logging() < 0) return 0;
if (import_bob_core_random() < 0) return 0;
if (import_bob_io_base() < 0) return 0;
if (import_bob_sp() < 0) return 0;
if (import_bob_learn_activation() < 0) return 0;
if (import_bob_learn_linear() < 0) return 0;

return Py_BuildValue("O", module);
Expand Down
35 changes: 3 additions & 32 deletions bob/learn/em/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

#include <bob.blitz/cppapi.h>
#include <bob.blitz/cleanup.h>
#include <bob.core/api.h>
#include <bob.core/random_api.h>
#include <bob.io.base/api.h>

#include <bob.sp/api.h>
#include <bob.learn.activation/api.h>
#include <bob.learn.linear/api.h>

#include <bob.extension/documentation.h>
Expand Down Expand Up @@ -49,37 +51,6 @@

#include <bob.learn.em/ZTNorm.h>



#if PY_VERSION_HEX >= 0x03000000
#define PyInt_Check PyLong_Check
#define PyInt_AS_LONG PyLong_AS_LONG
#define PyString_Check PyUnicode_Check
#define PyString_AS_STRING(x) PyBytes_AS_STRING(make_safe(PyUnicode_AsUTF8String(x)).get())
#endif

#define TRY try{

#define CATCH(message,ret) }\
catch (std::exception& e) {\
PyErr_SetString(PyExc_RuntimeError, e.what());\
return ret;\
} \
catch (...) {\
PyErr_Format(PyExc_RuntimeError, "%s " message ": unknown exception caught", Py_TYPE(self)->tp_name);\
return ret;\
}

#define CATCH_(message, ret) }\
catch (std::exception& e) {\
PyErr_SetString(PyExc_RuntimeError, e.what());\
return ret;\
} \
catch (...) {\
PyErr_Format(PyExc_RuntimeError, message ": unknown exception caught");\
return ret;\
}

/// inserts the given key, value pair into the given dictionaries
static inline int insert_item_string(PyObject* dict, PyObject* entries, const char* key, Py_ssize_t value){
auto v = make_safe(Py_BuildValue("n", value));
Expand Down
147 changes: 7 additions & 140 deletions bob/learn/em/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,143 +5,17 @@
* @brief Binds configuration information available from bob
*/

#ifdef NO_IMPORT_ARRAY
#undef NO_IMPORT_ARRAY
#endif
#include <bob.blitz/capi.h>
#include <bob.blitz/cleanup.h>
#include <bob.learn.em/config.h>

#define BOB_IMPORT_VERSION
#include <bob.blitz/config.h>
#include <bob.blitz/cleanup.h>
#include <bob.core/config.h>
#include <bob.io.base/config.h>
#include <bob.sp/config.h>
#include <bob.math/config.h>
#include <bob.learn.activation/config.h>
#include <bob.learn.linear/config.h>
#include <bob.learn.em/config.h>
// TODO: add other dependencies

#include <string>
#include <cstdlib>
#include <blitz/blitz.h>
#include <boost/preprocessor/stringize.hpp>
#include <boost/version.hpp>
#include <boost/format.hpp>


static int dict_set(PyObject* d, const char* key, const char* value) {
PyObject* v = Py_BuildValue("s", value);
if (!v) return 0;
int retval = PyDict_SetItemString(d, key, v);
Py_DECREF(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;
int retval = PyDict_SetItemString(d, key, value);
Py_DECREF(value);
if (retval == 0) return 1; //all good
return 0; //a problem occurred
}

/**
* Describes the version of Boost libraries installed
*/
static PyObject* boost_version() {
boost::format f("%d.%d.%d");
f % (BOOST_VERSION / 100000);
f % (BOOST_VERSION / 100 % 1000);
f % (BOOST_VERSION % 100);
return Py_BuildValue("s", f.str().c_str());
}

/**
* Describes the compiler version
*/
static PyObject* compiler_version() {
# if defined(__GNUC__) && !defined(__llvm__)
boost::format f("%s.%s.%s");
f % BOOST_PP_STRINGIZE(__GNUC__);
f % BOOST_PP_STRINGIZE(__GNUC_MINOR__);
f % BOOST_PP_STRINGIZE(__GNUC_PATCHLEVEL__);
return Py_BuildValue("ss", "gcc", f.str().c_str());
# elif defined(__llvm__) && !defined(__clang__)
return Py_BuildValue("ss", "llvm-gcc", __VERSION__);
# elif defined(__clang__)
return Py_BuildValue("ss", "clang", __clang_version__);
# else
return Py_BuildValue("s", "unsupported");
# endif
}

/**
* Python version with which we compiled the extensions
*/
static PyObject* python_version() {
boost::format f("%s.%s.%s");
f % BOOST_PP_STRINGIZE(PY_MAJOR_VERSION);
f % BOOST_PP_STRINGIZE(PY_MINOR_VERSION);
f % BOOST_PP_STRINGIZE(PY_MICRO_VERSION);
return Py_BuildValue("s", f.str().c_str());
}

/**
* Numpy version
*/
static PyObject* numpy_version() {
return Py_BuildValue("{ssss}", "abi", BOOST_PP_STRINGIZE(NPY_VERSION),
"api", BOOST_PP_STRINGIZE(NPY_API_VERSION));
}

/**
* bob.blitz c/c++ api version
*/
static PyObject* bob_blitz_version() {
return Py_BuildValue("{ss}", "api", BOOST_PP_STRINGIZE(BOB_BLITZ_API_VERSION));
}

/**
* bob.core c/c++ api version
*/
static PyObject* bob_core_version() {
return Py_BuildValue("{ss}", "api", BOOST_PP_STRINGIZE(BOB_CORE_API_VERSION));
}

/**
* bob.io.base c/c++ api version
*/
static PyObject* bob_io_base_version() {
return Py_BuildValue("{ss}", "api", BOOST_PP_STRINGIZE(BOB_IO_BASE_API_VERSION));
}

/**
* bob.sp c/c++ api version
*/
static PyObject* bob_sp_version() {
return Py_BuildValue("{ss}", "api", BOOST_PP_STRINGIZE(BOB_SP_API_VERSION));
}

/**
* bob.math c/c++ api version
*/
static PyObject* bob_math_version() {
return Py_BuildValue("{ss}", "api", BOOST_PP_STRINGIZE(BOB_MATH_API_VERSION));
}

/**
* bob.learn.activation c/c++ api version
*/
static PyObject* bob_learn_activation_version() {
return Py_BuildValue("{ss}", "api", BOOST_PP_STRINGIZE(BOB_LEARN_ACTIVATION_API_VERSION));
}

/**
* bob.learn.linear c/c++ api version
*/
static PyObject* bob_learn_linear_version() {
return Py_BuildValue("{ss}", "api", BOOST_PP_STRINGIZE(BOB_LEARN_LINEAR_API_VERSION));
}


static PyObject* build_version_dictionary() {
Expand All @@ -150,11 +24,12 @@ static PyObject* build_version_dictionary() {
if (!retval) return 0;
auto retval_ = make_safe(retval);

if (!dict_set(retval, "Blitz++", BZ_VERSION)) return 0;
if (!dict_steal(retval, "Blitz++", blitz_version())) return 0;
if (!dict_steal(retval, "Boost", boost_version())) return 0;
if (!dict_steal(retval, "Compiler", compiler_version())) return 0;
if (!dict_steal(retval, "Python", python_version())) return 0;
if (!dict_steal(retval, "NumPy", numpy_version())) return 0;
if (!dict_steal(retval, "HDF5", hdf5_version())) return 0;
if (!dict_steal(retval, "bob.blitz", bob_blitz_version())) return 0;
if (!dict_steal(retval, "bob.core", bob_core_version())) return 0;
if (!dict_steal(retval, "bob.io.base", bob_io_base_version())) return 0;
Expand All @@ -163,8 +38,7 @@ static PyObject* build_version_dictionary() {
if (!dict_steal(retval, "bob.learn.activation", bob_learn_activation_version())) return 0;
if (!dict_steal(retval, "bob.learn.linear", bob_learn_linear_version())) return 0;

Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}

static PyMethodDef module_methods[] = {
Expand Down Expand Up @@ -204,13 +78,6 @@ static PyObject* create_module (void) {
if (!externals) return 0;
if (PyModule_AddObject(m, "externals", externals) < 0) return 0;

/* imports dependencies */
if (import_bob_blitz() < 0) {
PyErr_Print();
PyErr_Format(PyExc_ImportError, "cannot import `%s'", BOB_EXT_MODULE_NAME);
return 0;
}

return Py_BuildValue("O", m);
}

Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.3b0
2.0.3b1

0 comments on commit 9e12d80

Please sign in to comment.