mirror of
https://github.com/boostorg/python.git
synced 2026-01-22 17:32:55 +00:00
Preparation for delivering nicely-formatted error messages in
Boost.Python. The major change is that, instead of being
boost::function2<PyObject*,PyObject*,PyObject*>, py_function is now a
runtime-polymorphic wrapper for compile-time polymorphic
behavior (just like function) of our own which carries more
information/behaviors. In particular, you can retrieve an array of
c-strings describing the types in the function signature.
Additionally, the minimum and maximum arity are stored in the
py_function object instead of in the 'function' object which wraps it.
* data_members.hpp -
Adjustments for the new py_function. Workarounds for CodeWarrior
Pro 8.3 bugs in function template argument deduction with
pointers-to-members.
* has_back_reference.hpp, test/back_reference.cpp,
test/select_holder.cpp -
Updated to follow the metafunction protocol
* init.hpp, detail/defaults_gen.hpp -
Make Keywords a more-specific type in function signatures to
prevent string literals that show up as char[N] from binding to
the wrong argument (at least Intel 7.1 for Windows does this).
* make_function.hpp -
Adjustments for the new py_function. Arities are now computed
by caller<>.
* opaque_pointer_converter.hpp, type_id.hpp -
Use BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS facilities;
generate specializations that all compilers can handle.
* raw_function.hpp -
Adjustments for the new py_function.
* caller.hpp -
Added arity and signature type name reporting.
* detail/config.hpp
Enable __declspec(dllexport) for Cygwin, thereby fixing the
recent horrible Cygwin linking problems.
* detail/msvc_typeinfo.hpp -
Always pass boost::type<T>* explicitly, thereby working around
incompatible notions of how to specialize function templates with
default arguments on various compilers.
* object/function.hpp
, object/function_handle.hpp
, object/function_object.hpp
, object/function_object.cpp
Adjustments for the new py_function. Arities are carried by
py_function.
* object/iterator.hpp, object/iterator.cpp
Adjustments for the new py_function; we have to compute a
signature of types to construct it with.
* object/py_function.hpp
Removed dependency on boost::function; see the comment at the
top of this entry for more details.
* object/select_holder.hpp
Clean up to more closely follow MPL idioms.
* test/Jamfile -
Adjust the embedding test for the new Cygwin use of declspec.
Update bases and pointee tests with missing properties.
* test/input_iterator.cpp -
Updates for the new iterator adaptors.
* test/opaque.py -
Add Python encoding comment to suppress PendinDeprecationWarning
with recent Python builds.
* test/str.cpp
Pass a Python long instead of a float to string.expandtabs,
suppressing a PendinDeprecationWarning with recent Python builds.
* libs/utility/counting_iterator_example.cpp
Borland workaround
* libs/utility/indirect_iterator_example.cpp
const-correctness fix.
*
[SVN r19247]
This commit is contained in:
@@ -14,33 +14,42 @@
|
||||
#include <boost/python/refcount.hpp>
|
||||
#include <boost/python/extract.hpp>
|
||||
|
||||
#include <boost/python/detail/signature.hpp>
|
||||
#include <boost/mpl/vector/vector10.hpp>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
py_function_impl_base::~py_function_impl_base()
|
||||
{
|
||||
}
|
||||
|
||||
unsigned py_function_impl_base::max_arity() const
|
||||
{
|
||||
return this->min_arity();
|
||||
}
|
||||
|
||||
extern PyTypeObject function_type;
|
||||
|
||||
function::function(
|
||||
py_function const& implementation
|
||||
, unsigned min_arity
|
||||
, unsigned max_arity
|
||||
, python::detail::keyword const* names_and_defaults
|
||||
, unsigned num_keywords
|
||||
)
|
||||
: m_fn(implementation)
|
||||
, m_min_arity(min_arity)
|
||||
// was using std::max here, but a problem with MinGW-2.95 and
|
||||
// our <boost/numeric/...> directory prevents it.
|
||||
, m_max_arity(max_arity > min_arity ? max_arity : min_arity)
|
||||
{
|
||||
if (names_and_defaults != 0)
|
||||
{
|
||||
unsigned keyword_offset
|
||||
= m_max_arity > num_keywords ? m_max_arity - num_keywords : 0;
|
||||
unsigned int max_arity = m_fn.max_arity();
|
||||
unsigned int keyword_offset
|
||||
= max_arity > num_keywords ? max_arity - num_keywords : 0;
|
||||
|
||||
|
||||
unsigned tuple_size = num_keywords ? m_max_arity : 0;
|
||||
unsigned tuple_size = num_keywords ? max_arity : 0;
|
||||
m_arg_names = object(handle<>(PyTuple_New(tuple_size)));
|
||||
|
||||
if (num_keywords != 0)
|
||||
@@ -86,7 +95,8 @@ PyObject* function::call(PyObject* args, PyObject* keywords) const
|
||||
do
|
||||
{
|
||||
// Check for a plausible number of arguments
|
||||
if (total_args >= f->m_min_arity && total_args <= f->m_max_arity)
|
||||
if (total_args >= f->m_fn.min_arity()
|
||||
&& total_args <= f->m_fn.max_arity())
|
||||
{
|
||||
// This will be the args that actually get passed
|
||||
handle<> args2(allow_null(borrowed(args)));
|
||||
@@ -242,7 +252,7 @@ namespace
|
||||
}
|
||||
|
||||
// Something for the end of the chain of binary operators
|
||||
PyObject* not_implemented_impl(PyObject*, PyObject*)
|
||||
PyObject* not_implemented(PyObject*, PyObject*)
|
||||
{
|
||||
Py_INCREF(Py_NotImplemented);
|
||||
return Py_NotImplemented;
|
||||
@@ -250,9 +260,11 @@ namespace
|
||||
|
||||
handle<function> not_implemented_function()
|
||||
{
|
||||
|
||||
static object keeper(
|
||||
function_object(¬_implemented_impl, 2, 3
|
||||
, python::detail::keyword_range())
|
||||
function_object(
|
||||
py_function(¬_implemented, mpl::vector1<void>(), 2)
|
||||
, python::detail::keyword_range())
|
||||
);
|
||||
return handle<function>(borrowed(downcast<function>(keeper.ptr())));
|
||||
}
|
||||
@@ -478,48 +490,38 @@ PyTypeObject function_type = {
|
||||
};
|
||||
|
||||
object function_object(
|
||||
py_function const& f, unsigned min_arity, unsigned max_arity
|
||||
py_function const& f
|
||||
, python::detail::keyword_range const& keywords)
|
||||
{
|
||||
return python::object(
|
||||
python::detail::new_non_null_reference(
|
||||
new function(
|
||||
f, min_arity, max_arity, keywords.first, keywords.second - keywords.first)));
|
||||
f, keywords.first, keywords.second - keywords.first)));
|
||||
}
|
||||
|
||||
object function_object(
|
||||
py_function const& f
|
||||
, unsigned arity
|
||||
, python::detail::keyword_range const& kw)
|
||||
object function_object(py_function const& f)
|
||||
{
|
||||
return function_object(f, arity, arity, kw);
|
||||
}
|
||||
|
||||
object function_object(py_function const& f, unsigned arity)
|
||||
{
|
||||
return function_object(f, arity, arity, python::detail::keyword_range());
|
||||
return function_object(f, python::detail::keyword_range());
|
||||
}
|
||||
|
||||
|
||||
handle<> function_handle_impl(py_function const& f, unsigned min_arity, unsigned max_arity)
|
||||
handle<> function_handle_impl(py_function const& f)
|
||||
{
|
||||
return python::handle<>(
|
||||
allow_null(
|
||||
new function(f, min_arity, max_arity, 0, 0)));
|
||||
new function(f, 0, 0)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
object BOOST_PYTHON_DECL make_raw_function(objects::py_function f, std::size_t min_args)
|
||||
object BOOST_PYTHON_DECL make_raw_function(objects::py_function f)
|
||||
{
|
||||
static keyword k;
|
||||
|
||||
return objects::function_object(
|
||||
f
|
||||
, min_args
|
||||
, std::numeric_limits<std::size_t>::max()
|
||||
, keyword_range(&k,&k));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user