Commit 0b33fa9f authored by Peterson, Peter's avatar Peterson, Peter
Browse files

Remove python 2/3 compatibility code from bindings

parent 471507af
...@@ -239,15 +239,8 @@ IPeaksWorkspaceIterator makePyIterator(IPeaksWorkspace &self) { ...@@ -239,15 +239,8 @@ IPeaksWorkspaceIterator makePyIterator(IPeaksWorkspace &self) {
void export_IPeaksWorkspaceIterator() { void export_IPeaksWorkspaceIterator() {
class_<IPeaksWorkspaceIterator>("IPeaksWorkspaceIterator", no_init) class_<IPeaksWorkspaceIterator>("IPeaksWorkspaceIterator", no_init)
.def( .def("__next__", &IPeaksWorkspaceIterator::next,
#if PY_VERSION_HEX >= 0x03000000 return_value_policy<reference_existing_object>())
"__next__"
#else
"next"
#endif
,
&IPeaksWorkspaceIterator::next,
return_value_policy<reference_existing_object>())
.def("__iter__", objects::identity_function()); .def("__iter__", objects::identity_function());
} }
......
...@@ -20,15 +20,8 @@ void export_SpectrumInfoPythonIterator() { ...@@ -20,15 +20,8 @@ void export_SpectrumInfoPythonIterator() {
// Export to Python // Export to Python
class_<SpectrumInfoPythonIterator>("SpectrumInfoPythonIterator", no_init) class_<SpectrumInfoPythonIterator>("SpectrumInfoPythonIterator", no_init)
.def("__iter__", objects::identity_function()) .def("__iter__", objects::identity_function())
.def( .def("__next__", &SpectrumInfoPythonIterator::next,
#if PY_VERSION_HEX >= 0x03000000 return_value_policy<copy_const_reference>());
"__next__"
#else
"next"
#endif
,
&SpectrumInfoPythonIterator::next,
return_value_policy<copy_const_reference>());
/* /*
Return value policy for next is to copy the const reference. Copy by value is Return value policy for next is to copy the const reference. Copy by value is
essential for python 2.0 compatibility because items (SpectrumInfoItem) will essential for python 2.0 compatibility because items (SpectrumInfoItem) will
......
...@@ -40,37 +40,6 @@ namespace converter = boost::python::converter; ...@@ -40,37 +40,6 @@ namespace converter = boost::python::converter;
// Forward declare // Forward declare
@EXPORT_DECLARE@ @EXPORT_DECLARE@
#if PY_VERSION_HEX < 0x03000000
/**
* Adds a from_python converter to converter unicode strings to std::string
* by encoding them in utf-8 if possible. Adapted from
* https://www.boost.org/doc/libs/1_68_0/libs/python/doc/html/faq/how_can_i_automatically_convert_.html
*/
struct from_unicode_py2 {
from_unicode_py2() {
converter::registry::push_back(&convertible, &construct,
type_id<std::string>());
}
static void *convertible(PyObject *obj_ptr) {
return (PyUnicode_Check(obj_ptr)) ? obj_ptr : 0;
}
static void construct(PyObject *obj_ptr,
converter::rvalue_from_python_stage1_data *data) {
PyObject *pyutf8 = PyUnicode_AsUTF8String(obj_ptr);
if (pyutf8 == 0)
boost::python::throw_error_already_set();
const char *value = PyString_AsString(pyutf8);
if (value == 0)
boost::python::throw_error_already_set();
using rvalue_from_python_std_string = converter::rvalue_from_python_storage<std::string>;
void *storage = reinterpret_cast<rvalue_from_python_std_string*>(data)->storage.bytes;
new (storage) std::string(value);
data->convertible = storage;
Py_DECREF(pyutf8); // Must be deleted after the std::string has taken a copy
}
};
#endif
BOOST_PYTHON_MODULE(_kernel) { BOOST_PYTHON_MODULE(_kernel) {
// Doc string options - User defined, python arguments, C++ call signatures // Doc string options - User defined, python arguments, C++ call signatures
boost::python::docstring_options docstrings(true, true, false); boost::python::docstring_options docstrings(true, true, false);
...@@ -98,11 +67,6 @@ BOOST_PYTHON_MODULE(_kernel) { ...@@ -98,11 +67,6 @@ BOOST_PYTHON_MODULE(_kernel) {
def("paper_citation", &Mantid::Kernel::MantidVersion::paperCitation, def("paper_citation", &Mantid::Kernel::MantidVersion::paperCitation,
"Returns The citation for the Mantid paper"); "Returns The citation for the Mantid paper");
#if PY_VERSION_HEX < 0x03000000
// accept unicode strings wherever we see std::string (as long as they can be
// encoded in utf8)
from_unicode_py2();
#endif
Mantid::PythonInterface::Registry::TypeRegistry::registerBuiltins(); Mantid::PythonInterface::Registry::TypeRegistry::registerBuiltins();
@EXPORT_FUNCTIONS@ @EXPORT_FUNCTIONS@
......
...@@ -88,9 +88,6 @@ noCopyConstructor:${CMAKE_SOURCE_DIR}/Framework/Geometry/inc/MantidGeometry/Rend ...@@ -88,9 +88,6 @@ noCopyConstructor:${CMAKE_SOURCE_DIR}/Framework/Geometry/inc/MantidGeometry/Rend
// ----------------- Upstream libs --------------- // ----------------- Upstream libs ---------------
// Always ignore bin dir
*:*${CMAKE_BINARY_DIR}/*
// All ANN files as they are upstream anyway // All ANN files as they are upstream anyway
*:*${CMAKE_SOURCE_DIR}/Framework/Kernel/src/ANN/* *:*${CMAKE_SOURCE_DIR}/Framework/Kernel/src/ANN/*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment