Skip to content

Commit ac2746f

Browse files
committed
* Generalized use of force_instantiate()
* Proper handling for numeric conversion overflows * Moved internal converter names out of the way to prepare for user conversions * Added comments * Fixed a bug where None could be converted to the NULL target of a member function call, causing a crash. * Wiped out and restarted todo.txt * long long support * Added more regression tests and checks for current limitations [SVN r14094]
1 parent e2b4178 commit ac2746f

36 files changed

Lines changed: 2896 additions & 2393 deletions
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright David Abrahams 2002. Permission to copy, use,
2+
// modify, sell and distribute this software is granted provided this
3+
// copyright notice appears in all copies. This software is provided
4+
// "as is" without express or implied warranty, and with no claim as
5+
// to its suitability for any purpose.
6+
#ifndef ARG_FROM_PYTHON_DWA2002128_HPP
7+
# define ARG_FROM_PYTHON_DWA2002128_HPP
8+
9+
# include <boost/python/converter/arg_from_python.hpp>
10+
11+
namespace boost { namespace python {
12+
13+
template <class T>
14+
struct arg_from_python
15+
: converter::select_arg_from_python<T>::type
16+
{
17+
typedef typename converter::select_arg_from_python<T>::type base;
18+
arg_from_python(PyObject*);
19+
};
20+
21+
// specialization for PyObject*
22+
template <>
23+
struct arg_from_python<PyObject*>
24+
{
25+
typedef PyObject* result_type;
26+
27+
arg_from_python(PyObject*) {}
28+
bool convertible() const { return true; }
29+
PyObject* operator()(PyObject* source) const { return source; }
30+
};
31+
32+
template <>
33+
struct arg_from_python<PyObject* const&>
34+
{
35+
typedef PyObject* const& result_type;
36+
arg_from_python(PyObject*) {}
37+
bool convertible() const { return true; }
38+
PyObject*const& operator()(PyObject*const& source) const { return source; }
39+
};
40+
41+
//
42+
// implementations
43+
//
44+
template <class T>
45+
inline arg_from_python<T>::arg_from_python(PyObject* source)
46+
: base(source)
47+
{
48+
}
49+
50+
}} // namespace boost::python
51+
52+
#endif // ARG_FROM_PYTHON_DWA2002128_HPP

include/boost/python/call.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#ifndef CALL_DWA2002411_HPP
77
# define CALL_DWA2002411_HPP
88

9-
# include <boost/python/converter/callback.hpp>
9+
# include <boost/python/converter/arg_to_python.hpp>
10+
# include <boost/python/converter/return_from_python.hpp>
1011
# include <boost/python/detail/preprocessor.hpp>
1112
# include <boost/preprocessor/comma_if.hpp>
1213
# include <boost/preprocessor/enum.hpp>
@@ -26,19 +27,19 @@ template <
2627
class R \
2728
BOOST_PP_COMMA_IF(nargs) BOOST_PP_ENUM_PARAMS(nargs, class A) \
2829
> \
29-
typename converter::callback_from_python<R>::result_type \
30+
typename converter::return_from_python<R>::result_type \
3031
call(PyObject* callable \
3132
BOOST_PP_COMMA_IF(nargs) BOOST_PYTHON_ENUM_PARAMS2(nargs, (A,const& a)) \
3233
, boost::type<R>* = 0 \
3334
) \
3435
{ \
35-
converter::callback_from_python<R> converter; \
36+
converter::return_from_python<R> converter; \
3637
return converter( \
3738
PyEval_CallFunction( \
3839
callable \
3940
, const_cast<char*>(BOOST_PYTHON_ARG_STRING(nargs)) \
4041
BOOST_PP_COMMA_IF(nargs) \
41-
BOOST_PP_ENUM(nargs,BOOST_PYTHON_CALLBACK_TO_PYTHON_GET,nil) \
42+
BOOST_PP_ENUM(nargs,BOOST_PYTHON_ARG_TO_PYTHON_GET,nil) \
4243
)); \
4344
}
4445

include/boost/python/call_method.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#ifndef CALL_METHOD_DWA2002411_HPP
77
# define CALL_METHOD_DWA2002411_HPP
88

9-
# include <boost/python/converter/callback.hpp>
9+
# include <boost/python/converter/arg_to_python.hpp>
10+
# include <boost/python/converter/return_from_python.hpp>
1011
# include <boost/python/detail/preprocessor.hpp>
1112
# include <boost/preprocessor/comma_if.hpp>
1213
# include <boost/preprocessor/enum.hpp>
@@ -26,20 +27,20 @@ template <
2627
class R \
2728
BOOST_PP_COMMA_IF(nargs) BOOST_PP_ENUM_PARAMS(nargs, class A) \
2829
> \
29-
typename converter::callback_from_python<R>::result_type \
30+
typename converter::return_from_python<R>::result_type \
3031
call_method(PyObject* self, char const* name \
3132
BOOST_PP_COMMA_IF(nargs) BOOST_PYTHON_ENUM_PARAMS2(nargs, (A,const& a)) \
3233
, boost::type<R>* = 0 \
3334
) \
3435
{ \
35-
converter::callback_from_python<R> converter; \
36+
converter::return_from_python<R> converter; \
3637
return converter( \
3738
PyEval_CallMethod( \
3839
self \
3940
, const_cast<char*>(name) \
4041
, const_cast<char*>(BOOST_PYTHON_ARG_STRING(nargs)) \
4142
BOOST_PP_COMMA_IF(nargs) \
42-
BOOST_PP_ENUM(nargs,BOOST_PYTHON_CALLBACK_TO_PYTHON_GET,nil) \
43+
BOOST_PP_ENUM(nargs,BOOST_PYTHON_ARG_TO_PYTHON_GET,nil) \
4344
)); \
4445
}
4546

0 commit comments

Comments
 (0)