[glom/glom-1-18] Revert "Do not crash if PyDateTime_IMPORT fails."
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/glom-1-18] Revert "Do not crash if PyDateTime_IMPORT fails."
- Date: Wed, 30 Mar 2011 12:42:44 +0000 (UTC)
commit 33e91893064e9c7af91056e6d7aee3bbdc5d4297
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Mar 30 14:26:31 2011 +0200
Revert "Do not crash if PyDateTime_IMPORT fails."
This reverts commit 9718918d098a2a2a83c669ae45fb99d08e9b693c.
Conflicts:
ChangeLog
ChangeLog | 21 +++++++
glom/libglom/init.cc | 34 +++-------
glom/libglom/init.h | 10 ---
.../libglom/python_embed/pygdavalue_conversions.cc | 64 ++++++++++----------
4 files changed, 62 insertions(+), 67 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3dec573..97327df 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2011-03-14 Murray Cumming <murrayc murrayc com>
+
+ Reverted the previous commit to prevent a crash if PyDateTime_IMPORT fails.
+
+ * glom/libglom/init.[h|cc]: Added libglom_pydatetime_import() and
+ libglom_pydatetime_imported(). Remove the g_assert() when it fails.
+ * glom/libglom/python_embed/pygdavalue_conversions.cc: Use the new
+ utility function instead of repeating our reimplementation here.
+
+ There will now just be an error message on stderr. We must fix this properly
+ but in the meantime it is better than requiring the use of a separate glom
+ branch just for OnlineGlom.
+ See https://bugzilla.gnome.org/show_bug.cgi?id=644702
+
+ This commit was reverted because we really must repeat the implementation
+ everywhere, because the PyDateTime variable is declared in Python's datetime.h
+ header, and the macros then try to use that local instance. The copy in
+ init.cc is not available to callers.
+ And we cannot include datetime.h from init.h because it is full of other
+ problems that cause compiler warnings.
+
2011-03-18 Murray Cumming <murrayc murrayc com>
libglom: Added utils::build_sql_select_count_rows().
diff --git a/glom/libglom/init.cc b/glom/libglom/init.cc
index 639b967..f345601 100644
--- a/glom/libglom/init.cc
+++ b/glom/libglom/init.cc
@@ -38,40 +38,26 @@
namespace Glom
{
-static bool pydatetime_imported = false;
-
-bool libglom_pydatetime_imported()
+void libglom_init()
{
- return pydatetime_imported;
-}
+ if (!Glib::thread_supported())
+ Glib::thread_init(0); //So we can use GMutex.
-void libglom_pydatetime_import()
-{
+ Gnome::Gda::init();
+ Gio::init();
+
+ Py_Initialize();
PyDateTime_IMPORT; //A macro, needed to use PyDate_Check(), PyDateTime_Check(), etc.
- if(!PyDateTimeAPI) //This should have been set by the PyDateTime_IMPORT macro.
+ if(!PyDateTimeAPI)
{
//Give people a clue on stdout:
std::cerr << G_STRFUNC << ": PyDateTime_IMPORT (a python module import) failed." << std::endl;
//This gives more information. When this happens it is generally a linker
- //failure while importing a python module.
- //See https://bugzilla.gnome.org/show_bug.cgi?id=644702
+ //failure while importing a python module:
PyErr_Print();
}
- else
- pydatetime_imported = true;
-}
-
-void libglom_init()
-{
- if (!Glib::thread_supported())
- Glib::thread_init(0); //So we can use GMutex.
-
- Gnome::Gda::init();
- Gio::init();
-
- Py_Initialize();
- libglom_pydatetime_import();
+ g_assert(PyDateTimeAPI); //This should have been set by the PyDateTime_IMPORT macro.
}
void libglom_deinit()
diff --git a/glom/libglom/init.h b/glom/libglom/init.h
index ea8f2b7..c1c5d78 100644
--- a/glom/libglom/init.h
+++ b/glom/libglom/init.h
@@ -85,16 +85,6 @@ void libglom_init();
void libglom_deinit();
-/** For some reason, we must call this repeatedly.
- * Maybe it is happening in different processes somehow.
- */
-void libglom_pydatetime_import();
-
-/** Whether libglom_init() successfully imported the python DateTime API.
- * This lets other code work around it when it is broken.
- */
-bool libglom_pydatetime_imported();
-
} //namespace Glom
#endif //GLOM_LIBGLOM_INIT_H
diff --git a/glom/libglom/python_embed/pygdavalue_conversions.cc b/glom/libglom/python_embed/pygdavalue_conversions.cc
index ed7a46a..4368ea9 100644
--- a/glom/libglom/python_embed/pygdavalue_conversions.cc
+++ b/glom/libglom/python_embed/pygdavalue_conversions.cc
@@ -3,7 +3,6 @@
# include <datetime.h> /* From Python */
#endif
#include "pygdavalue_conversions.h"
-#include <libglom/init.h>
#include <boost/python.hpp>
@@ -86,41 +85,40 @@ glom_pygda_value_from_pyobject(GValue* boxed, const boost::python::object& input
// Causes a C++ compiler warning, so we use its definition directly.
// See http://bugs.python.org/issue7463.
// PyDateTime_IMPORT; //A macro, needed to use PyDate_Check(), PyDateTime_Check(), etc.
- Glom::libglom_pydatetime_import();
- if(Glom::libglom_pydatetime_imported())
- {
- //TODO: Find some way to do this with boost::python
- PyObject* input_c = input.ptr();
- if(PyDateTime_Check (input_c)) {
- GdaTimestamp gda;
- gda.year = PyDateTime_GET_YEAR(input_c);
- gda.month = PyDateTime_GET_MONTH(input_c);
- gda.day = PyDateTime_GET_DAY(input_c);
- gda.hour = PyDateTime_DATE_GET_HOUR(input_c);
- gda.minute = PyDateTime_DATE_GET_MINUTE(input_c);
- gda.second = PyDateTime_DATE_GET_SECOND(input_c);
- gda.timezone = 0;
- gda_value_set_timestamp (boxed, &gda);
- return true;
+ PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_Import((char*)"datetime", (char*)"datetime_CAPI");
+ g_assert(PyDateTimeAPI); //This should have been set by the PyDateTime_IMPORT macro
+
+ //TODO: Find some way to do this with boost::python
+ PyObject* input_c = input.ptr();
+ if (PyDateTime_Check (input_c)) {
+ GdaTimestamp gda;
+ gda.year = PyDateTime_GET_YEAR(input_c);
+ gda.month = PyDateTime_GET_MONTH(input_c);
+ gda.day = PyDateTime_GET_DAY(input_c);
+ gda.hour = PyDateTime_DATE_GET_HOUR(input_c);
+ gda.minute = PyDateTime_DATE_GET_MINUTE(input_c);
+ gda.second = PyDateTime_DATE_GET_SECOND(input_c);
+ gda.timezone = 0;
+ gda_value_set_timestamp (boxed, &gda);
+ return true;
} else if (PyDate_Check (input_c)) {
- GDate *gda = g_date_new_dmy(
- PyDateTime_GET_DAY(input_c),
- (GDateMonth)PyDateTime_GET_MONTH(input_c),
- PyDateTime_GET_YEAR(input_c) );
- g_value_init (boxed, G_TYPE_DATE);
- g_value_set_boxed(boxed, gda);
- g_date_free(gda);
- return true;
+ GDate *gda = g_date_new_dmy(
+ PyDateTime_GET_DAY(input_c),
+ (GDateMonth)PyDateTime_GET_MONTH(input_c),
+ PyDateTime_GET_YEAR(input_c) );
+ g_value_init (boxed, G_TYPE_DATE);
+ g_value_set_boxed(boxed, gda);
+ g_date_free(gda);
+ return true;
} else if (PyTime_Check (input_c)) {
- GdaTime gda;
- gda.hour = PyDateTime_TIME_GET_HOUR(input_c);
- gda.minute = PyDateTime_TIME_GET_MINUTE(input_c);
- gda.second = PyDateTime_TIME_GET_SECOND(input_c);
- gda.timezone = 0;
- gda_value_set_time (boxed, &gda);
- return true;
+ GdaTime gda;
+ gda.hour = PyDateTime_TIME_GET_HOUR(input_c);
+ gda.minute = PyDateTime_TIME_GET_MINUTE(input_c);
+ gda.second = PyDateTime_TIME_GET_SECOND(input_c);
+ gda.timezone = 0;
+ gda_value_set_time (boxed, &gda);
+ return true;
}
- }
#else
//std::cout << "DEBUG Dates not supported." << std::endl;
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]