diff --git a/doc/tutorial/doc/tutorial.qbk b/doc/tutorial/doc/tutorial.qbk index 6abc11f2..9bd3c3fb 100644 --- a/doc/tutorial/doc/tutorial.qbk +++ b/doc/tutorial/doc/tutorial.qbk @@ -186,6 +186,10 @@ And so on... Finally: Or something similar. If all is well, you should now have built the DLLs and run the Python program. +[note Starting from Boost 1.35, bjam erases the generated executables +(e.g. pyd file) after the test has concluded to conserve disk space. +To keep bjam from doing that, pass --preserve-test-targets to bjam.] + [:[*There you go... Have fun!]] [endsect] diff --git a/doc/v2/object.html b/doc/v2/object.html index f35fa579..6fa48fa5 100644 --- a/doc/v2/object.html +++ b/doc/v2/object.html @@ -655,6 +655,11 @@ namespace boost { namespace python { namespace api template <class A0, class A1,...class An> object operator()(A0 const&, A1 const&,...An const&) const; + detail::args_proxy operator* () const; + object operator()(detail::args_proxy const &args) const; + object operator()(detail::args_proxy const &args, + detail::kwds_proxy const &kwds) const; + // truth value testing // typedef unspecified bool_type; @@ -704,6 +709,25 @@ object operator()(A0 const& a1, A1 const& a2,...An const& aN) const; call<object>(object(*static_cast<U*>(this)).ptr(), a1, a2,...aN) + +
+object operator()(detail::args_proxy const &args) const; ++
+object operator()(detail::args_proxy const &args, + detail::kwds_proxy const &kwds) const; ++
operator bool_type() const;diff --git a/doc/v2/pickle.html b/doc/v2/pickle.html index 1daf5ddb..22e198d6 100644 --- a/doc/v2/pickle.html +++ b/doc/v2/pickle.html @@ -1,112 +1,93 @@ - + -
+
+ It is often necessary to save and restore the contents of an object to + a file. One approach to this problem is to write a pair of functions that + read and write data from a file in a special format. A powerful + alternative approach is to use Python's pickle module. Exploiting + Python's ability for introspection, the pickle module recursively + converts nearly arbitrary Python objects into a stream of bytes that can + be written to a file.
-Pickle is a Python module for object serialization, also known -as persistence, marshalling, or flattening. +The Boost Python Library supports the pickle module through the + interface as described in detail in the Python Library + Reference for pickle. This interface involves the special methods + __getinitargs__, __getstate__ and __setstate__ + as described in the following. Note that Boost.Python is also fully + compatible with Python's cPickle module.
+-It is often necessary to save and restore the contents of an object to -a file. One approach to this problem is to write a pair of functions -that read and write data from a file in a special format. A powerful -alternative approach is to use Python's pickle module. Exploiting -Python's ability for introspection, the pickle module recursively -converts nearly arbitrary Python objects into a stream of bytes that -can be written to a file. +
-The Boost Python Library supports the pickle module -through the interface as described in detail in the -Python Library Reference for pickle. This interface -involves the special methods __getinitargs__, -__getstate__ and __setstate__ as described -in the following. Note that Boost.Python is also fully compatible -with Python's cPickle module. +
If __getinitargs__ is not defined, pickle.load + will call the constructor (__init__) without arguments; + i.e., the object must be default-constructible.
+- If __getinitargs__ is not defined, pickle.load - will call the constructor (__init__) without arguments; - i.e., the object must be default-constructible. +
-
-
+
struct world_pickle_suite : boost::python::pickle_suite
{
static
@@ -117,26 +98,28 @@ provide pickle support.
}
};
-+
class_<world>("world", args<const std::string&>())
// ...
.def_pickle(world_pickle_suite())
// ...
-+
struct world_pickle_suite : boost::python::pickle_suite
{
static
@@ -161,92 +144,76 @@ provide pickle support.
}
};
-+
class_<world>("world", args<const std::string&>())
// ...
.def_pickle(world_pickle_suite())
// ...
-- For simplicity, the __dict__ is not included in the result - of __getstate__. This is not generally recommended, but a - valid approach if it is anticipated that the object's - __dict__ will always be empty. Note that the safety guard - described below will catch the cases where this assumption is violated. +
For simplicity, the __dict__ is not included in the result of + __getstate__. This is not generally recommended, but a valid + approach if it is anticipated that the object's __dict__ will + always be empty. Note that the safety guard described below will catch + the cases where this assumption is violated.
+__getstate__ is defined and the instance's + __dict__ is not empty.
-The pickle protocol described above has an important pitfall that the -end user of a Boost.Python extension module might not be aware of: -- -__getstate__ is defined and the instance's __dict__ -is not empty. - -
+
The author of a Boost.Python extension class might provide a + __getstate__ method without considering the possibilities + that:
- The author of a Boost.Python extension class might provide a - __getstate__ method without considering the possibilities - that: +-
-
- - To alert the user to this highly unobvious problem, a safety guard is - provided. If __getstate__ is defined and the instance's - __dict__ is not empty, Boost.Python tests if the class has - an attribute __getstate_manages_dict__. An exception is - raised if this attribute is not defined: - -
+To alert the user to this highly unobvious problem, a safety guard is + provided. If __getstate__ is defined and the instance's + __dict__ is not empty, Boost.Python tests if the class has an + attribute __getstate_manages_dict__. An exception is raised if + this attribute is not defined:
+RuntimeError: Incomplete pickle support (__getstate_manages_dict__ not set) -- - To resolve this problem, it should first be established that the - __getstate__ and __setstate__ methods manage the - instances's __dict__ correctly. Note that this can be done - either at the C++ or the Python level. Finally, the safety guard - should intentionally be overridden. E.g. in C++ (from - pickle3.cpp): - -+To resolve this problem, it should first be established that the + __getstate__ and __setstate__ methods manage the + instances's __dict__ correctly. Note that this can be done + either at the C++ or the Python level. Finally, the safety guard should + intentionally be overridden. E.g. in C++ (from pickle3.cpp): +struct world_pickle_suite : boost::python::pickle_suite { // ... static bool getstate_manages_dict() { return true; } }; -- - Alternatively in Python: - -+Alternatively in Python: +import your_bpl_module class your_class(your_bpl_module.your_class): __getstate_manages_dict__ = 1 @@ -255,54 +222,41 @@ is not empty. def __setstate__(self, state): # your code here+
-
-Practical Advice
+Practical Advice
-
-
-
+See also the + tutorial section on injecting additional methods from Python. +pickle4.cpp
The + pickle4.cpp example demonstrates an alternative technique for + implementing pickle support. First we direct Boost.Python via the + class_::enable_pickling() member function to define only the + basic attributes required for pickling: +class_<world>("world", args<const std::string&>()) // ... .enable_pickling() // ... -- -This enables the standard Python pickle interface as described -in the Python documentation. By "injecting" a -__getinitargs__ method into the definition of the wrapped -class we make all instances pickleable: - -+This enables the standard Python pickle interface as described in the +Python documentation. By "injecting" a __getinitargs__ method into +the definition of the wrapped class we make all instances pickleable: +# import the wrapped world class from pickle4_ext import world @@ -312,18 +266,15 @@ class we make all instances pickleable: # now inject __getinitargs__ (Python is a dynamic language!) world.__getinitargs__ = world_getinitargs -+
-Updated: Feb 2004. -
Updated: Feb 2004.
+