mirror of
https://github.com/boostorg/python.git
synced 2026-01-24 18:12:43 +00:00
https://svn.boost.org/svn/boost/trunk ................ r43810 | eric_niebler | 2008-03-23 14:51:40 -0700 (Sun, 23 Mar 2008) | 1 line mark up new foreach tests ................ r43823 | fmhess | 2008-03-24 08:07:00 -0700 (Mon, 24 Mar 2008) | 3 lines Fixed compile error with new enable_shared_from_this code, reported by Tim Blechmann ................ r43825 | ramey | 2008-03-24 08:46:09 -0700 (Mon, 24 Mar 2008) | 1 line removed EXIT_SUCCESS ................ r43826 | ramey | 2008-03-24 08:46:43 -0700 (Mon, 24 Mar 2008) | 1 line fixed minor typo ................ r43829 | pdimov | 2008-03-24 09:00:28 -0700 (Mon, 24 Mar 2008) | 1 line New enable_shared_from_this tests, fix. ................ r43838 | danieljames | 2008-03-24 10:03:15 -0700 (Mon, 24 Mar 2008) | 12 lines Merge new changes to unordered & hash. - Unordered tests can run lightweight test or Boost.Test (at least theoretically). - Workaround Open BSD's incorrect numeric_limits. - Move the hash extensions in their own file. - Various small improvements to the unordered docs. - Fix some unordered examples. Merged revisions 43117-43837 via svnmerge from https://svn.boost.org/svn/boost/branches/unordered/trunk ................ r43845 | dave | 2008-03-24 11:27:22 -0700 (Mon, 24 Mar 2008) | 1 line Work around vc9 bugs ................ r43847 | anthonyw | 2008-03-24 14:44:36 -0700 (Mon, 24 Mar 2008) | 1 line removed forward declaration for undefined type exclusive_lock ................ r43852 | hkaiser | 2008-03-25 06:40:53 -0700 (Tue, 25 Mar 2008) | 1 line Wave: Removed an assertion causing compilation problems on certain platforms. ................ r43856 | pdimov | 2008-03-25 08:46:40 -0700 (Tue, 25 Mar 2008) | 1 line _internal_accept_owner now checks if _owned isn't already true. ................ r43861 | dave | 2008-03-25 13:47:38 -0700 (Tue, 25 Mar 2008) | 2 lines Work around intel-10.0-win compiler bug ................ r43864 | dave | 2008-03-25 15:28:59 -0700 (Tue, 25 Mar 2008) | 2 lines Account for intel 10.x compiler bug ................ r43865 | dave | 2008-03-25 16:06:50 -0700 (Tue, 25 Mar 2008) | 2 lines Work around intel-win-10.0 preprocessor bug ................ r43866 | danieljames | 2008-03-26 02:10:29 -0700 (Wed, 26 Mar 2008) | 3 lines Boost.Thread's documentation no longer has a build section - so just link to the library's documentation like we do for other libraries. ................ r43867 | bemandawes | 2008-03-26 08:59:52 -0700 (Wed, 26 Mar 2008) | 1 line Initial commit ................ r43873 | pdimov | 2008-03-26 11:34:29 -0700 (Wed, 26 Mar 2008) | 1 line Added "Throws: nothing" to get_deleter. ................ r43875 | bemandawes | 2008-03-26 14:26:55 -0700 (Wed, 26 Mar 2008) | 1 line Initial commit ................ r43876 | danieljames | 2008-03-26 22:49:45 -0700 (Wed, 26 Mar 2008) | 2 lines Update the thread links in the generated getting started documentation. ................ r43879 | chris_kohlhoff | 2008-03-27 07:18:07 -0700 (Thu, 27 Mar 2008) | 3 lines Fix double-free error that occurs when an exception is thrown from a handler that has been dispatched (i.e. not posted) through a strand. ................ r43880 | ramey | 2008-03-27 08:53:37 -0700 (Thu, 27 Mar 2008) | 1 line removed suppression of builds for certain platforms with shared libraries ................ r43882 | ramey | 2008-03-27 10:11:23 -0700 (Thu, 27 Mar 2008) | 1 line tweaks to sneak past PGI compiler error message ................ r43883 | ramey | 2008-03-27 10:12:22 -0700 (Thu, 27 Mar 2008) | 1 line added test to check warnings on type trait ................ r43884 | dgregor | 2008-03-27 12:44:37 -0700 (Thu, 27 Mar 2008) | 1 line Change Boost.Function allocator behavior, from Emil Dotchevski ................ r43887 | pdimov | 2008-03-27 15:13:55 -0700 (Thu, 27 Mar 2008) | 1 line Silence unused parameter warning. ................ r43888 | pdimov | 2008-03-27 15:20:11 -0700 (Thu, 27 Mar 2008) | 1 line detail::yield(k) added. ................ r43895 | danieljames | 2008-03-27 16:38:01 -0700 (Thu, 27 Mar 2008) | 25 lines Merged revisions 43838-43894 via svnmerge from https://svn.boost.org/svn/boost/branches/unordered/trunk ........ r43840 | danieljames | 2008-03-24 17:25:07 +0000 (Mon, 24 Mar 2008) | 1 line Fix a g++ warning. ........ r43844 | danieljames | 2008-03-24 17:56:28 +0000 (Mon, 24 Mar 2008) | 1 line It's a new-ish year. ........ r43885 | danieljames | 2008-03-27 20:36:10 +0000 (Thu, 27 Mar 2008) | 1 line The release script doesn't need to copy images and css - because that's now done in the jamfiles. Also tweak the shell script a tad bit. ........ r43890 | danieljames | 2008-03-27 23:01:40 +0000 (Thu, 27 Mar 2008) | 1 line Starting to add a docbook bibliography. ........ r43894 | danieljames | 2008-03-27 23:24:18 +0000 (Thu, 27 Mar 2008) | 1 line Redeclare 'data' in iterator_base to help compilers which have trouble with accessing the nested typedef. ........ ................ r43900 | noel_belcourt | 2008-03-27 19:10:04 -0700 (Thu, 27 Mar 2008) | 4 lines Fix address-model support for 32/64 bit code generation. Replaced -mcmodel with -m32 / -m64. ................ r43901 | bemandawes | 2008-03-27 19:11:13 -0700 (Thu, 27 Mar 2008) | 1 line Remove per email from Dave ................ r43906 | eric_niebler | 2008-03-27 23:10:55 -0700 (Thu, 27 Mar 2008) | 1 line proto support for BOOST_PROTO_MAX_FUNCTION_CALL_ARITY ................ [SVN r43910]
112 lines
3.3 KiB
C++
112 lines
3.3 KiB
C++
// Copyright Ralf W. Grosse-Kunstleve 2002-2004. Distributed under 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)
|
|
|
|
/*
|
|
This example shows how to make an Extension Class "pickleable".
|
|
|
|
The world class below contains member data (secret_number) that
|
|
cannot be restored by any of the constructors. Therefore it is
|
|
necessary to provide the __getstate__/__setstate__ pair of pickle
|
|
interface methods.
|
|
|
|
The object's __dict__ is included in the result of __getstate__.
|
|
This requires more code (compare with pickle2.cpp), but is
|
|
unavoidable if the object's __dict__ is not always empty.
|
|
|
|
For more information refer to boost/libs/python/doc/pickle.html.
|
|
*/
|
|
|
|
#include <boost/python/module.hpp>
|
|
#include <boost/python/def.hpp>
|
|
#include <boost/python/class.hpp>
|
|
#include <boost/python/tuple.hpp>
|
|
#include <boost/python/dict.hpp>
|
|
#include <boost/python/extract.hpp>
|
|
#include <boost/python/back_reference.hpp>
|
|
|
|
#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
|
|
# define make_tuple boost::python::make_tuple
|
|
#endif
|
|
|
|
namespace boost_python_test {
|
|
|
|
// A friendly class.
|
|
class world
|
|
{
|
|
public:
|
|
world(const std::string& _country) : secret_number(0) {
|
|
this->country = _country;
|
|
}
|
|
std::string greet() const { return "Hello from " + country + "!"; }
|
|
std::string get_country() const { return country; }
|
|
void set_secret_number(int number) { secret_number = number; }
|
|
int get_secret_number() const { return secret_number; }
|
|
private:
|
|
std::string country;
|
|
int secret_number;
|
|
};
|
|
|
|
struct world_pickle_suite : boost::python::pickle_suite
|
|
{
|
|
static
|
|
boost::python::tuple
|
|
getinitargs(const world& w)
|
|
{
|
|
using namespace boost::python;
|
|
return make_tuple(w.get_country());
|
|
}
|
|
|
|
static
|
|
boost::python::tuple
|
|
getstate(boost::python::object w_obj)
|
|
{
|
|
using namespace boost::python;
|
|
world const& w = extract<world const&>(w_obj)();
|
|
|
|
return make_tuple(w_obj.attr("__dict__"), w.get_secret_number());
|
|
}
|
|
|
|
static
|
|
void
|
|
setstate(boost::python::object w_obj, boost::python::tuple state)
|
|
{
|
|
using namespace boost::python;
|
|
world& w = extract<world&>(w_obj)();
|
|
|
|
if (len(state) != 2)
|
|
{
|
|
PyErr_SetObject(PyExc_ValueError,
|
|
("expected 2-item tuple in call to __setstate__; got %s"
|
|
% state).ptr()
|
|
);
|
|
throw_error_already_set();
|
|
}
|
|
|
|
// restore the object's __dict__
|
|
dict d = extract<dict>(w_obj.attr("__dict__"))();
|
|
d.update(state[0]);
|
|
|
|
// restore the internal state of the C++ object
|
|
long number = extract<long>(state[1]);
|
|
if (number != 42)
|
|
w.set_secret_number(number);
|
|
}
|
|
|
|
static bool getstate_manages_dict() { return true; }
|
|
};
|
|
|
|
}
|
|
|
|
BOOST_PYTHON_MODULE(pickle3_ext)
|
|
{
|
|
using namespace boost_python_test;
|
|
boost::python::class_<world>(
|
|
"world", boost::python::init<const std::string&>())
|
|
.def("greet", &world::greet)
|
|
.def("get_secret_number", &world::get_secret_number)
|
|
.def("set_secret_number", &world::set_secret_number)
|
|
.def_pickle(world_pickle_suite())
|
|
;
|
|
}
|