[glom] Python: Trying to stop the PyDateTime_Check() crash.
- From: Murray Cumming <murrayc src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glom] Python: Trying to stop the PyDateTime_Check() crash.
- Date: Mon, 7 Dec 2009 09:26:26 +0000 (UTC)
commit 050b1908fc0bff5cdc3ff007c9642f134bbc0cb6
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Dec 7 10:26:12 2009 +0100
Python: Trying to stop the PyDateTime_Check() crash.
* glom/libglom/init.cc: libglom_init(): Call the PyDateTime_IMPORT
macro, which is needed to stop PyDateTime_Check() and PyDate_Check()
from crashing, at least in my simple test case. It still crashes in
Glom though.
* glom/main.cc: Do not initialize Python here because Glom::init()
already did it, though doing it twice does not seem to be a problem.
ChangeLog | 11 +++++++++++
glom/libglom/init.cc | 9 ++++++++-
glom/main.cc | 7 +++++--
glom/test_pyembed.cc | 1 +
glom/test_pyembed_singleline.cc | 1 +
5 files changed, 26 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8c331fc..1712de4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-12-07 Murray Cumming <murrayc murrayc com>
+
+ Python: Trying to stop the PyDateTime_Check() crash.
+
+ * glom/libglom/init.cc: libglom_init(): Call the PyDateTime_IMPORT
+ macro, which is needed to stop PyDateTime_Check() and PyDate_Check()
+ from crashing, at least in my simple test case. It still crashes in
+ Glom though.
+ * glom/main.cc: Do not initialize Python here because Glom::init()
+ already did it, though doing it twice does not seem to be a problem.
+
2009-12-04 Murray Cumming <murrayc murrayc-desktop>
Rename some functions to avoid fear of linking to the wrong one.
diff --git a/glom/libglom/init.cc b/glom/libglom/init.cc
index 902f158..3b90762 100644
--- a/glom/libglom/init.cc
+++ b/glom/libglom/init.cc
@@ -19,6 +19,9 @@
*/
#include <Python.h> //Include it before anything else to avoid "_POSIX_C_SOURCE redefined".
+#if PY_VERSION_HEX >= 0x02040000
+# include <datetime.h> /* From Python */
+#endif
#include <glom/libglom/connectionpool.h>
#include <giomm.h>
@@ -29,11 +32,15 @@ namespace Glom
void libglom_init()
{
- if (!Glib::thread_supported()) Glib::thread_init(0); //So we can use GMutex.
+ if (!Glib::thread_supported())
+ Glib::thread_init(0); //So we can use GMutex.
+
Gnome::Gda::init();
Gio::init();
Py_Initialize();
+ PyDateTime_IMPORT; //A macro, needed to use PyDate_Check(), PyDateTime_Check(), etc.
+ g_assert(PyDateTimeAPI); //This should have been set by the PyDateTime_IMPORT macro.
}
void libglom_deinit()
diff --git a/glom/main.cc b/glom/main.cc
index 98a6ad8..5b1c88e 100644
--- a/glom/main.cc
+++ b/glom/main.cc
@@ -22,6 +22,9 @@
//We use Python for calculated fields.
#include <Python.h> //Include it before anything else to avoid "_POSIX_C_SOURCE redefined".
+#if PY_VERSION_HEX >= 0x02040000
+# include <datetime.h> /* From Python */
+#endif
//#include <gnome.h>
#include <glom/libglom/init.h>
@@ -422,7 +425,7 @@ main(int argc, char* argv[])
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
- Glom::libglom_init();
+ Glom::libglom_init(); //Also initializes python.
#ifdef GLOM_ENABLE_MAEMO
if(!(Osso::initialize("org.maemo.glom", PACKAGE_NAME)))
@@ -437,8 +440,8 @@ main(int argc, char* argv[])
Glom::OptionGroup group;
context.set_main_group(group);
+
//We use python for calculated-fields:
- Py_Initialize();
PySys_SetArgv(argc, argv);
std::auto_ptr<Gtk::Main> mainInstance;
diff --git a/glom/test_pyembed.cc b/glom/test_pyembed.cc
index d161eb1..89af06c 100644
--- a/glom/test_pyembed.cc
+++ b/glom/test_pyembed.cc
@@ -46,6 +46,7 @@ void evaluate_function_implementation(const Glib::ustring& func_impl)
std::cout << func_def << std::endl;
Py_Initialize();
+ //PyDateTime_IMPORT; //A macro, needed to use PyDate_Check(), PyDateTime_Check(), etc.
PyObject* pMain = PyImport_AddModule((gchar*)"__main__");
PyObject* pDict = PyModule_GetDict(pMain);
diff --git a/glom/test_pyembed_singleline.cc b/glom/test_pyembed_singleline.cc
index 12dd9f7..e292c90 100644
--- a/glom/test_pyembed_singleline.cc
+++ b/glom/test_pyembed_singleline.cc
@@ -5,6 +5,7 @@
void evaluate_function_implementation(const Glib::ustring& func_impl)
{
Py_Initialize();
+ //PyDateTime_IMPORT; //A macro, needed to use PyDate_Check(), PyDateTime_Check(), etc.
PyObject* pMain = PyImport_AddModule("__main__");
PyObject* pDict = PyModule_GetDict(pMain);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]