[glom] Python embedding: Python >2.7 build fixes.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Python embedding: Python >2.7 build fixes.
- Date: Fri, 17 May 2013 18:33:48 +0000 (UTC)
commit 7d10c867fd04cc1983014802da7b960ec9981f20
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Apr 3 18:49:23 2013 +0200
Python embedding: Python >2.7 build fixes.
* glom/libglom/python_embed/pygdavalue_conversions.cc:
More use of the redefinition of PyDateTime_IMPORT for
python versions before 2.7, but not after.
ChangeLog | 8 +++++
glom/libglom/init.cc | 12 +++++--
.../libglom/python_embed/pygdavalue_conversions.cc | 30 ++++++++-----------
3 files changed, 29 insertions(+), 21 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index bf59d72..e8904fe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,14 @@
2013-04-03 Murray Cumming <murrayc murrayc com>
+ Python embedding: Python >2.7 build fixes.
+
+ * glom/libglom/python_embed/pygdavalue_conversions.cc:
+ More use of the redefinition of PyDateTime_IMPORT for
+ python versions before 2.7, but not after.
+
+2013-04-03 Murray Cumming <murrayc murrayc com>
+
Python embedding: Deal with TODO.
* glom/libglom/python_embed/pygdavalue_conversions.cc:
diff --git a/glom/libglom/init.cc b/glom/libglom/init.cc
index 9c35e54..d677141 100644
--- a/glom/libglom/init.cc
+++ b/glom/libglom/init.cc
@@ -31,15 +31,15 @@
#include <pygobject.h>
-//TODO: Remove this redefine when Python fixes the compiler error in their macro:
+//Python versions before python 2.7 have a compiler error in their PyDateTime_IMPORT macro:
// http://bugs.python.org/issue7463
-// Note that this sets a local copy of PyDateTimeAPI (in Python's datetime.h
-// header) so it _must_ be repeated and called before any code that use the
-// Python PyDate* macros (!) such as PyDateTime_Check
+// so we reimplement the macro for older versions:
+#if PY_VERSION_HEX < 0x02070000
#undef PyDateTime_IMPORT
#define PyDateTime_IMPORT \
PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_Import((char*)"datetime", \
(char*)"datetime_CAPI")
+#endif //PY_VERSION_HEX
namespace Glom
{
@@ -57,6 +57,10 @@ void libglom_init()
Gio::init();
Py_Initialize();
+
+ // Note that this sets a local copy of PyDateTimeAPI (in Python's datetime.h
+ // header) so it _must_ be repeated and called before any code that use the
+ // Python PyDate* macros (!) such as PyDateTime_Check
PyDateTime_IMPORT; //A macro, needed to use PyDate_Check(), PyDateTime_Check(), etc.
if(!PyDateTimeAPI)
{
diff --git a/glom/libglom/python_embed/pygdavalue_conversions.cc
b/glom/libglom/python_embed/pygdavalue_conversions.cc
index 11f279d..2edde69 100644
--- a/glom/libglom/python_embed/pygdavalue_conversions.cc
+++ b/glom/libglom/python_embed/pygdavalue_conversions.cc
@@ -11,6 +11,15 @@
#include <libgda/gda-blob-op.h>
#include <iostream>
+//Python versions before python 2.7 have a compiler error in their PyDateTime_IMPORT macro:
+// http://bugs.python.org/issue7463
+// so we reimplement the macro for older versions:
+#if PY_VERSION_HEX < 0x02070000
+#undef PyDateTime_IMPORT
+#define PyDateTime_IMPORT \
+ PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_Import((char*)"datetime", \
+ (char*)"datetime_CAPI")
+#endif //PY_VERSION_HEX
/**
* pygda_value_from_pyobject:
@@ -104,16 +113,7 @@ glom_pygda_value_from_pyobject(GValue* boxed, const boost::python::object& input
// Note that this sets a local copy of PyDateTimeAPI (in Python's datetime.h
// header) so it _must_ be repeated and called before any code that use the
// Python PyDate* macros (!) such as PyDateTime_Check
-
- //Python versions before python 2.7 have a compiler error in their PyDateTime_IMPORT macro:
- // http://bugs.python.org/issue7463
- // so we reimplement the macro for older versions:
-#if PY_VERSION_HEX >= 0x02070000
PyDateTime_IMPORT; //A macro, needed to use PyDate_Check(), PyDateTime_Check(), etc.
-#else
- PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_Import((char*)"datetime", (char*)"datetime_CAPI");
-#endif
-
if(PyDateTimeAPI) //This should have been set but it can fail:
https://bugzilla.gnome.org/show_bug.cgi?id=644702
{
//TODO: Find some way to do this with boost::python
@@ -169,14 +169,10 @@ boost::python::object glom_pygda_value_as_boost_pyobject(const Glib::ValueBase&
(value_type == GDA_TYPE_TIME) ||
(value_type == GDA_TYPE_TIMESTAMP))
{
- // We shouldn't need to call PyDateTime_IMPORT again,
- // after already doing it in libglom_init(),
- // but PyDate_FromDate() crashes (with valgrind warnings) if we don't.
- //
- // 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.
- PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_Import((char*)"datetime", (char*)"datetime_CAPI");
+ // Note that this sets a local copy of PyDateTimeAPI (in Python's datetime.h
+ // header) so it _must_ be repeated and called before any code that use the
+ // Python PyDate* macros (!) such as PyDateTime_Check
+ 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
}
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]