summaryrefslogtreecommitdiff
path: root/src/py_utils.cc
diff options
context:
space:
mode:
authorDimitri John Ledkov <xnox@ubuntu.com>2019-12-03 22:59:35 +0000
committerJohn Wiegley <johnw@newartisans.com>2019-12-05 15:06:44 +0100
commit12a74c66c6656bbf6a89bfae83b76e3df37d9199 (patch)
tree189bc4543ff839662d4032dbf66cd2e283f17829 /src/py_utils.cc
parent23d818175a81e46a899c5e8b00be54cfa0881a4e (diff)
downloadfork-ledger-12a74c66c6656bbf6a89bfae83b76e3df37d9199.tar.gz
fork-ledger-12a74c66c6656bbf6a89bfae83b76e3df37d9199.tar.bz2
fork-ledger-12a74c66c6656bbf6a89bfae83b76e3df37d9199.zip
Port to python3
Diffstat (limited to 'src/py_utils.cc')
-rw-r--r--src/py_utils.cc19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/py_utils.cc b/src/py_utils.cc
index c2f84f55..419af734 100644
--- a/src/py_utils.cc
+++ b/src/py_utils.cc
@@ -33,7 +33,9 @@
#include "pyinterp.h"
#include "pyutils.h"
+#if PY_MAJOR_VERSION < 3
#include "pyfstream.h"
+#endif
namespace ledger {
@@ -88,14 +90,18 @@ struct string_from_python
{
static void* convertible(PyObject* obj_ptr)
{
- if (!PyUnicode_Check(obj_ptr) &&
- !PyString_Check(obj_ptr)) return 0;
+ if (!PyUnicode_Check(obj_ptr)
+#if PY_MAJOR_VERSION < 3
+ && !PyString_Check(obj_ptr)
+#endif
+ ) return 0;
return obj_ptr;
}
static void construct(PyObject* obj_ptr,
converter::rvalue_from_python_stage1_data* data)
{
+#if PY_MAJOR_VERSION < 3
if (PyString_Check(obj_ptr)) {
const char* value = PyString_AsString(obj_ptr);
if (value == 0) throw_error_already_set();
@@ -105,6 +111,7 @@ struct string_from_python
new (storage) string(value);
data->convertible = storage;
} else {
+#endif
VERIFY(PyUnicode_Check(obj_ptr));
Py_ssize_t size = PyUnicode_GET_SIZE(obj_ptr);
@@ -125,14 +132,16 @@ struct string_from_python
(data)->storage.bytes;
new (storage) string(str);
data->convertible = storage;
+#if PY_MAJOR_VERSION < 3
}
+#endif
}
};
typedef register_python_conversion<string, string_to_python, string_from_python>
string_python_conversion;
-
+#if PY_MAJOR_VERSION < 3
struct istream_to_python
{
static PyObject* convert(const std::istream&)
@@ -195,7 +204,7 @@ struct ostream_from_python
typedef register_python_conversion<std::ostream,
ostream_to_python, ostream_from_python>
ostream_python_conversion;
-
+#endif
void export_utils()
{
@@ -248,8 +257,10 @@ void export_utils()
bool_python_conversion();
string_python_conversion();
+#if PY_MAJOR_VERSION < 3
istream_python_conversion();
ostream_python_conversion();
+#endif
}
} // namespace ledger