mirror of
https://github.com/boostorg/python.git
synced 2026-01-22 05:22:45 +00:00
* function pointer from a function should work also. * make_function/make_constructor now return object instead of a raw pointer. * module::setattr() now accepts anything which can be passed to object's constructor. * Rework upcast<> to catch more errors at compile-time instead of infinite-looping. * Rationalize class<>::def() in preparation for docstring support * Partial docstring support in module::def (untested) * dependent<> trick moved to detail namespace and separate header * Added __doc__ attribute to C++ function wrapper objects * Sunk implementation of function_object into a library source file. [SVN r14724]
64 lines
2.1 KiB
C++
64 lines
2.1 KiB
C++
// (C) Copyright R.W. Grosse-Kunstleve 2002.
|
|
// Permission to copy, use, modify, sell and distribute this software
|
|
// is granted provided this copyright notice appears in all copies. This
|
|
// software is provided "as is" without express or implied warranty, and
|
|
// with no claim as to its suitability for any purpose.
|
|
|
|
#include <boost/python/make_function.hpp>
|
|
#include <boost/python/object/class.hpp>
|
|
#include <boost/python/tuple.hpp>
|
|
#include <boost/python/list.hpp>
|
|
#include <boost/python/dict.hpp>
|
|
#include <boost/python/detail/api_placeholder.hpp>
|
|
|
|
namespace boost { namespace python {
|
|
|
|
namespace {
|
|
|
|
tuple instance_reduce(object instance_obj)
|
|
{
|
|
list result;
|
|
object instance_class(instance_obj.attr("__class__"));
|
|
result.append(instance_class);
|
|
object none;
|
|
object getinitargs = getattr(instance_obj, "__getinitargs__", none);
|
|
tuple initargs;
|
|
if (getinitargs.ptr() != none.ptr()) {
|
|
initargs = tuple(getinitargs());
|
|
}
|
|
result.append(initargs);
|
|
object getstate = getattr(instance_obj, "__getstate__", none);
|
|
object instance_dict = getattr(instance_obj, "__dict__", none);
|
|
long len_instance_dict = 0;
|
|
if (instance_dict.ptr() != none.ptr()) {
|
|
len_instance_dict = len(instance_dict);
|
|
}
|
|
if (getstate.ptr() != none.ptr()) {
|
|
if (len_instance_dict > 0) {
|
|
object getstate_manages_dict = getattr(
|
|
instance_obj, "__getstate_manages_dict__", none);
|
|
if (getstate_manages_dict.ptr() == none.ptr()) {
|
|
PyErr_SetString(PyExc_RuntimeError,
|
|
"Incomplete pickle support"
|
|
" (__getstate_manages_dict__ not set)");
|
|
throw_error_already_set();
|
|
}
|
|
}
|
|
result.append(getstate());
|
|
}
|
|
else if (len_instance_dict > 0) {
|
|
result.append(instance_dict);
|
|
}
|
|
return tuple(result);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
object const& make_instance_reduce_function()
|
|
{
|
|
static object result(&instance_reduce);
|
|
return result;
|
|
}
|
|
|
|
}} // namespace boost::python
|