mirror of
https://github.com/boostorg/python.git
synced 2026-01-22 05:22:45 +00:00
Added type checking when converting some Python types from python as return values.
[SVN r14478]
This commit is contained in:
@@ -24,13 +24,13 @@ BOOST_PYTHON_DECL rvalue_from_python_chain const* implicit_conversion_chain(
|
||||
BOOST_PYTHON_DECL rvalue_from_python_stage1_data rvalue_from_python_stage1(
|
||||
PyObject* source, registration const&);
|
||||
|
||||
BOOST_PYTHON_DECL void* rvalue_from_python_stage2(
|
||||
PyObject*, rvalue_from_python_stage1_data&, void* storage);
|
||||
BOOST_PYTHON_DECL void* rvalue_result_from_python(
|
||||
PyObject*, rvalue_from_python_stage1_data&);
|
||||
|
||||
BOOST_PYTHON_DECL void* reference_from_python(PyObject*, registration const&);
|
||||
BOOST_PYTHON_DECL void* pointer_from_python(PyObject*, registration const&);
|
||||
BOOST_PYTHON_DECL void* reference_result_from_python(PyObject*, registration const&);
|
||||
BOOST_PYTHON_DECL void* pointer_result_from_python(PyObject*, registration const&);
|
||||
|
||||
BOOST_PYTHON_DECL void void_from_python(PyObject*);
|
||||
BOOST_PYTHON_DECL void void_result_from_python(PyObject*);
|
||||
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
18
include/boost/python/converter/pytype_result_from_python.hpp
Normal file
18
include/boost/python/converter/pytype_result_from_python.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
// 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 PYTYPE_RESULT_FROM_PYTHON_DWA2002716_HPP
|
||||
# define PYTYPE_RESULT_FROM_PYTHON_DWA2002716_HPP
|
||||
|
||||
# include <boost/python/detail/raw_pyobject.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
BOOST_PYTHON_DECL python::detail::new_reference
|
||||
pytype_result_from_python(PyTypeObject* type, PyObject* source);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // PYTYPE_RESULT_FROM_PYTHON_DWA2002716_HPP
|
||||
@@ -77,7 +77,7 @@ struct return_from_python<void>
|
||||
|
||||
result_type operator()(PyObject* x) const
|
||||
{
|
||||
converter::void_from_python(x);
|
||||
(void_result_from_python)(x);
|
||||
# ifdef BOOST_NO_VOID_RETURNS
|
||||
return result_type();
|
||||
# endif
|
||||
@@ -101,21 +101,24 @@ namespace detail
|
||||
inline typename return_rvalue_from_python<T>::result_type
|
||||
return_rvalue_from_python<T>::operator()(PyObject* obj)
|
||||
{
|
||||
return *(T*)rvalue_from_python_stage2(obj, m_data.stage1, m_data.storage.bytes);
|
||||
return *(T*)
|
||||
(rvalue_result_from_python)(obj, m_data.stage1);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T return_reference_from_python<T>::operator()(PyObject* obj) const
|
||||
{
|
||||
return python::detail::void_ptr_to_reference(
|
||||
reference_from_python(obj, registered<T>::converters)
|
||||
(reference_result_from_python)(obj, registered<T>::converters)
|
||||
, (T(*)())0);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T return_pointer_from_python<T>::operator()(PyObject* obj) const
|
||||
{
|
||||
return T(pointer_from_python(obj, registered_pointee<T>::converters));
|
||||
return T(
|
||||
(pointer_result_from_python)(obj, registered_pointee<T>::converters)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
# include <boost/python/object.hpp>
|
||||
# include <boost/python/converter/pytype_arg_from_python.hpp>
|
||||
# include <boost/python/converter/pytype_result_from_python.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
@@ -153,7 +154,7 @@ namespace converter
|
||||
|
||||
result_type operator()(PyObject* x) const
|
||||
{
|
||||
return list(python::detail::new_reference(x));
|
||||
return list((pytype_result_from_python)(&PyList_Type, x));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
# include <boost/python/object.hpp>
|
||||
# include <boost/python/converter/pytype_arg_from_python.hpp>
|
||||
# include <boost/python/converter/pytype_result_from_python.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
@@ -91,7 +92,7 @@ namespace converter
|
||||
|
||||
result_type operator()(PyObject* x) const
|
||||
{
|
||||
return long_(python::detail::new_reference(x));
|
||||
return long_((pytype_result_from_python)(&PyLong_Type, x));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user