From e0737c56c1e384e05064a0c6e1ac46979371041b Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Wed, 19 Dec 2018 22:58:32 +0100 Subject: New upstream version 2.0.0+repack --- boost/libs/mpi/src/python/serialize.cpp | 79 +++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 boost/libs/mpi/src/python/serialize.cpp (limited to 'boost/libs/mpi/src/python/serialize.cpp') diff --git a/boost/libs/mpi/src/python/serialize.cpp b/boost/libs/mpi/src/python/serialize.cpp new file mode 100644 index 00000000..92004a34 --- /dev/null +++ b/boost/libs/mpi/src/python/serialize.cpp @@ -0,0 +1,79 @@ +// (C) Copyright 2006 Douglas Gregor + +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Authors: Douglas Gregor + +/** @file serialize.cpp + * + * This file provides Boost.Serialization support for Python objects. + */ +#include +#include +#include + +namespace boost { namespace python { + +struct pickle::data_t { + object module; + object dumps; + object loads; +}; + + +/// Data used for communicating with the Python `pickle' module. +pickle::data_t* pickle::data; + +str pickle::dumps(object obj, int protocol) +{ + if (!data) initialize_data(); + return extract((data->dumps)(obj, protocol)); +} + +object pickle::loads(str s) +{ + if (!data) initialize_data(); + return ((data->loads)(s)); +} + +void pickle::initialize_data() +{ + data = new data_t; + data->module = object(handle<>(PyImport_ImportModule("pickle"))); + data->dumps = data->module.attr("dumps"); + data->loads = data->module.attr("loads"); +} + +} } // end namespace boost::python + +BOOST_PYTHON_DIRECT_SERIALIZATION_ARCHIVE_IMPL( + ::boost::mpi::packed_iarchive, + ::boost::mpi::packed_oarchive) + +namespace boost { namespace mpi { namespace python { namespace detail { + + boost::python::object skeleton_proxy_base_type; + + // A map from Python type objects to skeleton/content handlers + typedef std::map + skeleton_content_handlers_type; + + BOOST_MPI_PYTHON_DECL skeleton_content_handlers_type skeleton_content_handlers; + + bool + skeleton_and_content_handler_registered(PyTypeObject* type) + { + return + skeleton_content_handlers.find(type) != skeleton_content_handlers.end(); + } + + void + register_skeleton_and_content_handler(PyTypeObject* type, + const skeleton_content_handler& handler) + { + skeleton_content_handlers[type] = handler; + } + +} } } } // end namespace boost::mpi::python::detail -- cgit v1.2.3