Ticket #8888: 0002-python-Convert-a-number-of-assertion-constructs-to-B.patch

File 0002-python-Convert-a-number-of-assertion-constructs-to-B.patch, 10.6 KB (added by Petr Machata <pmachata@…>, 9 years ago)

This converts a whole bunch of static-assert-alike construct with BOOST_MPL_ASSERT_MSG.

  • boost/python/args_fwd.hpp

    From dd31026cc96129b0cefbe9932236861157cbfa56 Mon Sep 17 00:00:00 2001
    From: Petr Machata <pmachata@redhat.com>
    Date: Thu, 5 Sep 2013 23:20:57 +0200
    Subject: [PATCH 2/3] [python] Convert a number of assertion constructs to
     BOOST_MPL_ASSERT_MSG
    
    - There are a number of separate mechanisms involving typedefs that
      simulate a functionality similar to BOOST_STATIC_ASSERT or
      BOOST_MPL_ASSERT_MSG.  Instead of reinventing the wheel, we just use
      the latter--that because unlike the former, it allows us to specify
      an error message.
    ---
     boost/python/args_fwd.hpp              |    9 ---------
     boost/python/class.hpp                 |   24 +++++-------------------
     boost/python/def.hpp                   |    7 ++++---
     boost/python/detail/defaults_gen.hpp   |   11 +++++------
     boost/python/init.hpp                  |   20 +++++---------------
     boost/python/make_constructor.hpp      |    5 ++---
     boost/python/make_function.hpp         |    9 ++++-----
     boost/python/object/pickle_support.hpp |   10 +++-------
     8 files changed, 28 insertions(+), 67 deletions(-)
    
    diff --git a/boost/python/args_fwd.hpp b/boost/python/args_fwd.hpp
    index 3923946..83933f4 100644
    a b namespace detail  
    3636      BOOST_STATIC_CONSTANT(std::size_t, size = 0);
    3737      static keyword_range range() { return keyword_range(); }
    3838  };
    39 
    40   namespace error
    41   {
    42     template <int keywords, int function_args>
    43     struct more_keywords_than_function_arguments
    44     {
    45         typedef char too_many_keywords[keywords > function_args ? -1 : 1];
    46     };
    47   }
    4839}
    4940
    5041}} // namespace boost::python
  • boost/python/class.hpp

    diff --git a/boost/python/class.hpp b/boost/python/class.hpp
    index 253667b..a8e4111 100644
    a b  
    3939# include <boost/mpl/for_each.hpp>
    4040# include <boost/mpl/bool.hpp>
    4141# include <boost/mpl/not.hpp>
     42# include <boost/mpl/assert.hpp>
    4243
    4344# include <boost/detail/workaround.hpp>
    4445
    namespace detail  
    107108  namespace error
    108109  {
    109110    //
    110     // A meta-assertion mechanism which prints nice error messages and
    111     // backtraces on lots of compilers. Usage:
    112     //
    113     //      assertion<C>::failed
    114     //
    115     // where C is an MPL metafunction class
    116     //
    117    
    118     template <class C> struct assertion_failed { };
    119     template <class C> struct assertion_ok { typedef C failed; };
    120 
    121     template <class C>
    122     struct assertion
    123         : mpl::if_<C, assertion_ok<C>, assertion_failed<C> >::type
    124     {};
    125 
    126     //
    127111    // Checks for validity of arguments used to define virtual
    128112    // functions with default implementations.
    129113    //
    namespace detail  
    141125            // https://svn.boost.org/trac/boost/ticket/5803
    142126            //typedef typename assertion<mpl::not_<is_same<Default,Fn> > >::failed test0;
    143127# if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
    144             typedef typename assertion<is_polymorphic<T> >::failed test1;
     128            BOOST_MPL_ASSERT_MSG(is_polymorphic<T>::value,
     129                                 NOT_POLYMORPHIC, (T));
    145130# endif
    146             typedef typename assertion<is_member_function_pointer<Fn> >::failed test2;
     131            BOOST_MPL_ASSERT_MSG(is_member_function_pointer<Fn>::value,
     132                                 NOT_MEMBER_FUNCTION_POINTER, (Fn));
    147133            not_a_derived_class_member<Default>(Fn());
    148134        }
    149135    };
  • boost/python/def.hpp

    diff --git a/boost/python/def.hpp b/boost/python/def.hpp
    index 76829b0..bde35f3 100644
    a b  
    1515# include <boost/python/signature.hpp>
    1616# include <boost/python/detail/scope.hpp>
    1717
     18# include <boost/mpl/assert.hpp>
     19
    1820namespace boost { namespace python {
    1921
    2022namespace detail
    namespace detail  
    3537      char const* name, F const& fn, Helper const& helper)
    3638  {
    3739      // Must not try to use default implementations except with method definitions.
    38       typedef typename error::multiple_functions_passed_to_def<
    39           Helper::has_default_implementation
    40           >::type assertion;
     40      BOOST_MPL_ASSERT_MSG(!Helper::has_default_implementation,
     41                           MULTIPLE_FUNCTIONS_PASSED_TO_DEF, (Helper));
    4142     
    4243      detail::scope_setattr_doc(
    4344          name, boost::python::make_function(
  • boost/python/detail/defaults_gen.hpp

    diff --git a/boost/python/detail/defaults_gen.hpp b/boost/python/detail/defaults_gen.hpp
    index 0b3e0e2..f77912e 100644
    a b  
    2626#include <boost/mpl/begin_end.hpp>
    2727#include <boost/mpl/next.hpp>
    2828#include <boost/mpl/deref.hpp>
     29#include <boost/mpl/assert.hpp>
    2930#include <cstddef>
    3031
    3132namespace boost { namespace python {
    namespace detail  
    211212        : ::boost::python::detail::overloads_common<fstubs_name>(                           \
    212213            doc, keywords.range())                                                          \
    213214    {                                                                                       \
    214         typedef typename ::boost::python::detail::                                          \
    215             error::more_keywords_than_function_arguments<                                   \
    216                 N,n_args>::too_many_keywords assertion;                                     \
     215        BOOST_MPL_ASSERT_MSG(N <= n_args,                                                   \
     216                             MORE_KEYWORDS_THAN_FUNCTION_ARGUMENTS, ());                    \
    217217    }                                                                                       \
    218218    template <std::size_t N>                                                                \
    219219    fstubs_name(::boost::python::detail::keywords<N> const& keywords, char const* doc = 0)  \
    220220        : ::boost::python::detail::overloads_common<fstubs_name>(                           \
    221221            doc, keywords.range())                                                          \
    222222    {                                                                                       \
    223         typedef typename ::boost::python::detail::                                          \
    224             error::more_keywords_than_function_arguments<                                   \
    225                 N,n_args>::too_many_keywords assertion;                                     \
     223        BOOST_MPL_ASSERT_MSG(N <= n_args,                                                   \
     224                             MORE_KEYWORDS_THAN_FUNCTION_ARGUMENTS, ());                    \
    226225    }
    227226
    228227# if defined(BOOST_NO_VOID_RETURNS)
  • boost/python/init.hpp

    diff --git a/boost/python/init.hpp b/boost/python/init.hpp
    index 6598fd3..c9edea9 100644
    a b  
    2626#include <boost/mpl/prior.hpp>
    2727#include <boost/mpl/joint_view.hpp>
    2828#include <boost/mpl/back.hpp>
     29#include <boost/mpl/assert.hpp>
    2930
    3031#include <boost/type_traits/is_same.hpp>
    3132
    struct optional; // forward declaration  
    6364
    6465namespace detail
    6566{
    66   namespace error
    67   {
    68     template <int keywords, int init_args>
    69     struct more_keywords_than_init_arguments
    70     {
    71         typedef char too_many_keywords[init_args - keywords >= 0 ? 1 : -1];
    72     };
    73   }
    74 
    7567  //  is_optional<T>::value
    7668  //
    7769  //      This metaprogram checks if T is an optional
    class init : public init_base<init<BOOST_PYTHON_OVERLOAD_ARGS> >  
    244236    init(char const* doc_, detail::keywords<N> const& kw)
    245237        : base(doc_, kw.range())
    246238    {
    247         typedef typename detail::error::more_keywords_than_init_arguments<
    248             N, n_arguments::value + 1
    249             >::too_many_keywords assertion;
     239        BOOST_MPL_ASSERT_MSG(N <= n_arguments::value + 1,
     240                             MORE_KEYWORDS_THAN_INIT_ARGUMENTS, ());
    250241    }
    251242
    252243    template <std::size_t N>
    253244    init(detail::keywords<N> const& kw, char const* doc_ = 0)
    254245        : base(doc_, kw.range())
    255246    {
    256         typedef typename detail::error::more_keywords_than_init_arguments<
    257             N, n_arguments::value + 1
    258             >::too_many_keywords assertion;
     247        BOOST_MPL_ASSERT_MSG(N <= n_arguments::value + 1,
     248                             MORE_KEYWORDS_THAN_INIT_ARGUMENTS, ());
    259249    }
    260250
    261251    template <class CallPoliciesT>
  • boost/python/make_constructor.hpp

    diff --git a/boost/python/make_constructor.hpp b/boost/python/make_constructor.hpp
    index 8ae722b..597b679 100644
    a b namespace detail  
    181181  {
    182182      enum { arity = mpl::size<Sig>::value - 1 };
    183183     
    184       typedef typename detail::error::more_keywords_than_function_arguments<
    185           NumKeywords::value, arity
    186           >::too_many_keywords assertion;
     184      BOOST_MPL_ASSERT_MSG(NumKeywords::value <= arity,
     185                           MORE_KEYWORDS_THAN_FUNCTION_ARGUMENTS, ());
    187186   
    188187      typedef typename outer_constructor_signature<Sig>::type outer_signature;
    189188
  • boost/python/make_function.hpp

    diff --git a/boost/python/make_function.hpp b/boost/python/make_function.hpp
    index f2f2a9e..68751f3 100644
    a b  
    1515
    1616# include <boost/mpl/size.hpp>
    1717# include <boost/mpl/int.hpp>
     18# include <boost/mpl/assert.hpp>
    1819
    1920namespace boost { namespace python {
    2021
    namespace detail  
    5253      )
    5354  {
    5455      enum { arity = mpl::size<Sig>::value - 1 };
    55      
    56       typedef typename detail::error::more_keywords_than_function_arguments<
    57           NumKeywords::value, arity
    58           >::too_many_keywords assertion;
    59    
     56      BOOST_MPL_ASSERT_MSG(NumKeywords::value <= arity,
     57                           MORE_KEYWORDS_THAN_FUNCTION_ARGUMENTS, ());
     58
    6059      return objects::function_object(
    6160          detail::caller<F,CallPolicies,Sig>(f, p)
    6261        , kw);
  • boost/python/object/pickle_support.hpp

    diff --git a/boost/python/object/pickle_support.hpp b/boost/python/object/pickle_support.hpp
    index cbdbcbb..097fcfc 100644
    a b  
    66# define BOOST_PYTHON_OBJECT_PICKLE_SUPPORT_RWGK20020603_HPP
    77
    88# include <boost/python/detail/prefix.hpp>
     9# include <boost/mpl/assert.hpp>
    910
    1011namespace boost { namespace python {
    1112
    BOOST_PYTHON_DECL object const& make_instance_reduce_function();  
    2122struct pickle_suite;
    2223
    2324namespace error_messages {
    24 
    25   template <class T>
    26   struct missing_pickle_suite_function_or_incorrect_signature {};
    27 
    2825  inline void must_be_derived_from_pickle_suite(pickle_suite const&) {}
    2926}
    3027
    namespace detail {  
    105102      Class_&,
    106103      ...)
    107104    {
    108       typedef typename
    109         error_messages::missing_pickle_suite_function_or_incorrect_signature<
    110           Class_>::error_type error_type;
     105      BOOST_MPL_ASSERT_MSG
     106        (false, MISSING_PICKLE_SUITE_FUNCTION_OR_INCORRECT_SIGNATURE, ());
    111107    }
    112108  };
    113109