1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include <Python.h>
#include <cstdio>
#include <libglom/init.h>
#include <iostream>
#include "config.h"
#include "glom/python_embed/glom_python.h"
#ifdef __linux__
extern "C" void __libc_freeres(void);
#endif
namespace Glom
{
bool glom_python_module_is_available()
{
const gchar* name = "glom_" GLOM_ABI_VERSION_UNDERLINED;
PyObject* module_glom = PyImport_ImportModule((char*)name);
if(!module_glom)
{
std::cerr << "Glom: A python import of " << name << " failed." << std::endl;
}
Py_XDECREF(module_glom);
return module_glom != 0;
}
bool gda_python_module_is_available()
{
//TODO: How can we requests a specific version to avoid confusion
//between the parallel-installed Gda-5.0 and Gda-6.0 APIs?
//Python code usually uses "from gi.repository import Gda" so that
//the code may use Gda. rather than gi.repository.Gda in the code.
const gchar* name = "gi.repository.Gda";
PyObject* module_glom = PyImport_ImportModule((char*)name);
if(!module_glom)
{
std::cerr << "Glom: A python import of " << name << " failed." << std::endl;
}
Py_XDECREF(module_glom);
return module_glom != 0;
}
}
int main ()
{
#ifdef __linux__
atexit(__libc_freeres);
#endif
Glom::libglom_init(); // Calls PyInitialize()
if(!Glom::gda_python_module_is_available())
return EXIT_FAILURE;
if(!Glom::glom_python_module_is_available())
return EXIT_FAILURE;
Glom::libglom_deinit(); // Calls Py_Finalize();
return EXIT_SUCCESS;
}
|