2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-24 18:12:43 +00:00

Further suppressed internal structure overflow problems which were cropping up with msvc6/7.

[SVN r16482]
This commit is contained in:
Dave Abrahams
2002-12-02 19:41:45 +00:00
parent 8b79380977
commit 9163c40a1a
9 changed files with 87 additions and 231 deletions

View File

@@ -20,7 +20,7 @@
# include <boost/preprocessor/facilities/intercept.hpp>
# include <boost/preprocessor/iteration/local.hpp>
# include <boost/mpl/aux_/lambda_support.hpp>
# include <boost/python/detail/mpl_lambda.hpp>
# include <boost/mpl/bool_c.hpp>
# include <boost/type.hpp>
@@ -66,7 +66,7 @@ namespace detail
BOOST_STATIC_CONSTANT(bool, value = (is_ref & is_key));
typedef mpl::bool_c<value> type;
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T))
BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T))
};
# else
typedef char (&yes_keywords_t)[1];
@@ -90,7 +90,7 @@ namespace detail
== sizeof(detail::yes_keywords_t)));
typedef mpl::bool_c<value> type;
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T))
BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T))
};
# endif
}

View File

@@ -18,7 +18,7 @@
# include <boost/type_traits/remove_pointer.hpp>
# include <boost/mpl/if.hpp>
# include <boost/mpl/bool_c.hpp>
# include <boost/mpl/aux_/lambda_support.hpp>
# include <boost/python/detail/mpl_lambda.hpp>
# ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
# include <boost/python/detail/is_function_ref_tester.hpp>
@@ -86,7 +86,7 @@ template <class T>
struct is_reference_to_member_function_pointer
: is_reference_to_member_function_pointer_impl<T>
{
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T))
BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T))
};
template <class T>
@@ -192,7 +192,7 @@ struct is_reference_to_class
>::value)
);
typedef mpl::bool_c<value> type;
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_class,(T))
BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_class,(T))
};
template <class T>
@@ -285,7 +285,7 @@ template <class T>
struct is_pointer_to_function
: mpl::if_<is_pointer<T>, is_pointer_to_function_aux<T>, mpl::bool_c<false> >::type
{
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_pointer_to_function,(T))
BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_pointer_to_function,(T))
};
struct false_helper1
@@ -422,7 +422,7 @@ struct is_reference_to_function_pointer
, mpl::bool_c<false>
>::type
{
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_function_pointer,(T))
BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_function_pointer,(T))
};
@@ -453,7 +453,7 @@ struct is_reference_to_member_function_pointer
, mpl::bool_c<false>
>::type
{
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T))
BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T))
};
template <typename V>
@@ -470,7 +470,7 @@ struct is_reference_to_class
& (sizeof(reference_to_class_helper(t)) == sizeof(inner_yes_type)))
);
typedef mpl::bool_c<value> type;
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_class,(T))
BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_class,(T))
};
template <typename V>

View File

@@ -8,12 +8,39 @@
# include <boost/mpl/aux_/lambda_support.hpp>
# if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
# if 0 // defined(BOOST_MSVC) && BOOST_MSVC <= 1300
// This approach fails, unfortunately
# include <boost/preprocessor/enum_params.hpp>
# include <boost/preprocessor/comma_if.hpp>
# define BOOST_PYTHON_LAMBDA_SUPPORT_FORMAL_ARG(R,class_,i,param) \
BOOST_PP_COMMA_IF(i) class_ param \
/**/
# define BOOST_PYTHON_LAMBDA_SUPPORT_ACTUAL_ARG(R,_,i,param) \
BOOST_PP_COMMA_IF(i) param \
/**/
# define BOOST_PYTHON_MPL_LAMBDA_SUPPORT(i,name,params) \
struct rebind; \
}; \
template <BOOST_PP_ENUM_PARAMS_Z(1, i, class X)> \
struct name < BOOST_PP_ENUM_PARAMS_Z(1, i, X) >::rebind \
template < \
BOOST_PP_LIST_FOR_EACH_I_R( \
1 \
, BOOST_PYTHON_LAMBDA_SUPPORT_FORMAL_ARG \
, class \
, BOOST_PP_TUPLE_TO_LIST(i,params) \
) \
> \
struct name < \
BOOST_PP_LIST_FOR_EACH_I_R( \
1 \
, BOOST_PYTHON_LAMBDA_SUPPORT_ACTUAL_ARG \
, class \
, BOOST_PP_TUPLE_TO_LIST(i,params) \
) \
>::rebind \
{ \
BOOST_STATIC_CONSTANT(int, arity = i); \
BOOST_PP_LIST_FOR_EACH_I_R( \

View File

@@ -6,12 +6,10 @@
#ifndef MSVC_TYPEINFO_DWA200222_HPP
# define MSVC_TYPEINFO_DWA200222_HPP
#include <boost/type.hpp>
#include <typeinfo>
#include <boost/type_traits/is_array.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/is_volatile.hpp>
#include <boost/type.hpp>
#include <boost/type_traits/config.hpp>
//
// Fix for MSVC's broken typeid() implementation which doesn't strip
// decoration. This fix doesn't handle cv-qualified array types. It
@@ -24,78 +22,62 @@ namespace boost { namespace python { namespace detail {
typedef std::type_info const& typeinfo;
template<int>struct value_id_accessor;
template<>
struct value_id_accessor<0>
{
template <class T>
static typeinfo get(T*) { return typeid(T); }
};
template<>
struct value_id_accessor<1>
{
template <class T>
static typeinfo get(T const*) { return typeid(T); }
};
template<>
struct value_id_accessor<2>
{
template <class T>
static typeinfo get(T volatile*) { return typeid(T); }
};
template<>
struct value_id_accessor<3>
{
template <class T>
static typeinfo get(T const volatile*) { return typeid(T); }
};
template <bool> struct bool_t{};
template <class T>
static typeinfo typeid_nonref(T*, ...) { return typeid(T); }
template <class T>
inline typeinfo typeid_nonref(boost::type<T>* = 0)
{
bool const c = is_const<T>::value;
bool const v = is_volatile<T>::value;
return value_id_accessor<(2 * v + c)>::get((T*)0);
}
static typeinfo typeid_nonref(T const*, int) { return typeid(T); }
template <class T>
inline typeinfo typeid_ref(T&(*)())
{
return typeid_nonref<T>();
}
static typeinfo typeid_nonref(T volatile*, int) { return typeid(T); }
template <class T>
inline typeinfo array_ref_typeid(bool_t<true>, bool_t<false>, boost::type<T>* = 0)
{
return typeid_ref((T&(*)())0);
}
static typeinfo typeid_nonref(T const volatile*, long) { return typeid(T); }
# ifdef BOOST_INTEL_CXX_VERSION
// The const volatile overload above confuses Intel when dealing with arrays
template <class T, unsigned N>
static typeinfo typeid_nonref(T(*)[N], long) { return typeid(T[N]); }
# endif
template <class T>
inline typeinfo array_ref_typeid(bool_t<false>, bool_t<true>, boost::type<T>* = 0)
inline typeinfo typeid_ref_1(T&(*)())
{
return typeid_ref((T(*)())0);
return detail::typeid_nonref((T*)0,0L);
}
// A non-reference
template <class T>
inline typeinfo array_ref_typeid(bool_t<false>, bool_t<false>, boost::type<T>* = 0)
inline typeinfo typeid_ref(type<T>*, T&(*)(type<T>))
{
return typeid_ref((T&(*)())0);
return detail::typeid_nonref((T*)0,0L);
}
// A reference
template <class T>
inline typeinfo typeid_ref(type<T>*, ...)
{
return detail::typeid_ref_1((T(*)())0);
}
template< typename T > T&(* is_ref_tester1(type<T>) )(type<T>) { return 0; }
inline char BOOST_TT_DECL is_ref_tester1(...) { return 0; }
template <class T>
inline typeinfo msvc_typeid(boost::type<T>* = 0)
{
typedef bool_t<is_array<T>::value> array_tag;
typedef bool_t<is_reference<T>::value> ref_tag;
return array_ref_typeid(array_tag(), ref_tag(), (boost::type<T>*)0);
return detail::typeid_ref(
(boost::type<T>*)0, detail::is_ref_tester1(type<T>())
);
}
# ifndef NDEBUG
inline typeinfo assert_array_typeid_compiles()
{
return msvc_typeid<char const[3]>(), msvc_typeid<char[3]>();
}
# endif
}}} // namespace boost::python::detail
# endif // BOOST_MSVC

View File

@@ -1,126 +0,0 @@
#error obsolete
// Copyright David Abrahams 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.
#ifndef THIS_ARG_FROM_PYTHON_DWA20021122_HPP
# define THIS_ARG_FROM_PYTHON_DWA20021122_HPP
# include <boost/python/arg_from_python.hpp>
# include <boost/python/back_reference.hpp>
# include <boost/python/detail/not_specified.hpp>
# include <boost/mpl/aux_/lambda_support.hpp>
namespace boost { namespace python { namespace detail {
template <class T, class Wrap = not_specified>
struct this_ptr_arg_from_python : converter::arg_lvalue_from_python_base
{
this_ptr_arg_from_python(PyObject* x)
: converter::arg_lvalue_from_python_base(
converter::get_lvalue_from_python(x, converter::registered<T>::converters))
{}
typedef T* result_type;
T* operator()() const
{
return static_cast<T*>(this->result());
}
bool use_default() const
{
return dynamic_cast<Wrap*>((*this)());
}
};
template <class T, class Wrap = not_specified>
struct this_ref_arg_from_python : this_ptr_arg_from_python<T,Wrap>
{
typedef this_ptr_arg_from_python<T,Wrap> base;
this_ref_arg_from_python(PyObject* x) : base(x) {}
typedef T& result_type;
result_type operator()() const
{
return *this->base::operator()();
}
};
// An MPL metafunction class which returns a `this' converter
// appropriate for ArgType, where the target of the member function is
// a class of type T.
template <class T, class Wrap = not_specified>
struct gen_this_from_python
{
// Note: there will almost always be an compile-time error if the
// argument type is neither a reference nor a pointer, since T*
// will be extracted in that case and passed on to the wrapped
// function.
template <class ArgType> struct apply
{
BOOST_STATIC_CONSTANT(
bool, use_ptr
= is_pointer<ArgType>::value
|| boost::python::detail::is_reference_to_pointer<ArgType>::value
&& boost::python::detail::is_reference_to_const<ArgType>::value
&& !boost::python::detail::is_reference_to_volatile<ArgType>::value);
typedef typename mpl::if_c<
is_back_reference<ArgType>::value
, nullary<arg_from_python<ArgType> >
, typename mpl::if_c<
use_ptr
, this_ptr_arg_from_python<T,Wrap>
, this_ref_arg_from_python<T,Wrap>
>::type
>::type type;
};
};
// An MPL iterator which iterates over a sequence whose first element
// is gen_this_from_python<T> and the remainder of which is an endless
// sequence of gen_arg_from_python
template <class T, class Wrap = not_specified>
struct method_args_from_python
{
typedef gen_this_from_python<T,Wrap> type;
typedef args_from_python next;
};
template <class VirtualFunction, class Default>
struct defaulted_virtual_fn
{
defaulted_virtual_fn(VirtualFunction dispatch, Default const& default_impl)
: dispatch(dispatch), default_impl(default_impl) {};
VirtualFunction dispatch;
Default default_impl;
};
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class T>
struct is_defaulted_virtual_fn
{ BOOST_STATIC_CONSTANT(bool, value = false); };
template <class T,class U>
struct is_defaulted_virtual_fn<defaulted_virtual_fn<T,U> >
{ BOOST_STATIC_CONSTANT(bool, value = true); };
# else
template <class T>
struct is_defaulted_virtual_fn
{
template <class T, class U>
static char helper(defaulted_virtual_fn<T,U>* x);
static char (& helper(...)) [2];
BOOST_STATIC_CONSTANT(bool, value = sizeof(helper((T*)0)) == 1);
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_defaulted_virtual_fn,(T))
};
# endif
}}} // namespace boost::python::detail
#endif // THIS_ARG_FROM_PYTHON_DWA20021122_HPP

View File

@@ -22,7 +22,9 @@
#include <boost/mpl/push_front.hpp>
#include <boost/mpl/iterator_range.hpp>
#include <boost/mpl/logical/not.hpp>
#include <boost/mpl/aux_/lambda_support.hpp>
# include <boost/python/detail/mpl_lambda.hpp>
#include <boost/mpl/lambda.hpp>
#include <boost/mpl/begin_end.hpp>
#include <boost/mpl/find_if.hpp>
@@ -104,7 +106,7 @@ namespace detail
sizeof(f(t())) == sizeof(::boost::type_traits::yes_type));
typedef mpl::bool_c<value> type;
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_optional,(T))
BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_optional,(T))
};
///////////////////////////////////////
@@ -126,7 +128,7 @@ namespace detail
struct is_optional : is_optional_impl<T>
{
typedef mpl::bool_c<is_optional_impl<T>::value> type;
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_optional,(T))
BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_optional,(T))
};
#endif // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)

View File

@@ -74,8 +74,7 @@ bpl-test exception_translator ;
bpl-test pearu1 : test_cltree.py cltree.cpp ;
bpl-test try : newtest.py m1.cpp m2.cpp ;
# Had to break this up into two files for MSVC6
extension builtin_converters : test_builtin_converters.cpp test_builtin_converters2.cpp <dll>../build/boost_python ;
extension builtin_converters : test_builtin_converters.cpp <dll>../build/boost_python ;
boost-python-runtest builtin_converters : test_builtin_converters.py <pyd>builtin_converters ;
bpl-test test_pointer_adoption ;

View File

@@ -44,10 +44,6 @@ using boost::python::handle;
using boost::python::object;
using boost::python::borrowed;
// MSVC6 can't process this whole file at once, so we break it up into
// two parts. See test_builtin_converters2.cpp
#ifndef BOOST_PYTHON_WRAP_MORE_BUILTIN_CONVERTERS
// Used to test that arbitrary handle<>s can be returned
handle<PyTypeObject> get_type(handle<> x)
{
@@ -61,10 +57,8 @@ handle<> return_null_handle()
char const* rewrap_value_mutable_cstring(char* x) { return x; }
void wrap_more();
BOOST_PYTHON_MODULE(builtin_converters)
{
{
def("get_type", get_type);
def("return_null_handle", return_null_handle);
@@ -80,7 +74,7 @@ BOOST_PYTHON_MODULE(builtin_converters)
def("rewrap_value_unsigned_long", by_value<unsigned long>::rewrap);
// using Python's macro instead of Boost's - we don't seem to get the
// config right all the time.
# ifdef HAVE_LONG_LONG
#ifdef HAVE_LONG_LONG
def("rewrap_value_long_long", by_value<LONG_LONG>::rewrap);
def("rewrap_value_unsigned_long_long", by_value<unsigned LONG_LONG>::rewrap);
# endif
@@ -98,14 +92,6 @@ BOOST_PYTHON_MODULE(builtin_converters)
// Expose this to illustrate our failings ;-). See test_builtin_converters.py
def("rewrap_value_mutable_cstring", rewrap_value_mutable_cstring);
wrap_more();
}
#else // BOOST_PYTHON_WRAP_MORE_BUILTIN_CONVERTERS -- this part
// compiled into test_builtin_converters2.cpp
void wrap_more()
{
def("rewrap_const_reference_bool", by_const_reference<bool>::rewrap);
def("rewrap_const_reference_char", by_const_reference<char>::rewrap);
@@ -133,10 +119,6 @@ void wrap_more()
def("rewrap_const_reference_cstring", by_const_reference<char const*>::rewrap);
def("rewrap_const_reference_handle", by_const_reference<handle<> >::rewrap);
def("rewrap_const_reference_object", by_const_reference<object>::rewrap);
def("rewrap_reference_object", by_reference<object>::rewrap);
}
#endif // BOOST_PYTHON_WRAP_MORE_BUILTIN_CONVERTERS

View File

@@ -1,10 +0,0 @@
// Copyright David Abrahams 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.
// This file just defines the rest of the tests that MSVC6 can't
// compile unless we break the file up. It's a hack, I'll admit...
#define BOOST_PYTHON_WRAP_MORE_BUILTIN_CONVERTERS
#include "test_builtin_converters.cpp"