Skip to content

Commit 1ff1bfe

Browse files
committed
Replace methods for Py_LIMITED_API support
To allow building multi-version Python 3 extensions. The replaced methods are error-checking variants. Ref: boostorg#221
1 parent 1727b67 commit 1ff1bfe

File tree

9 files changed

+146
-146
lines changed

9 files changed

+146
-146
lines changed

include/boost/python/detail/caller.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@
4040
# include <boost/mpl/int.hpp>
4141
# include <boost/mpl/next.hpp>
4242

43-
namespace boost { namespace python { namespace detail {
43+
namespace boost { namespace python { namespace detail {
4444

4545
template <int N>
4646
inline PyObject* get(mpl::int_<N>, PyObject* const& args_)
4747
{
48-
return PyTuple_GET_ITEM(args_,N);
48+
return PyTuple_GetItem(args_,N);
4949
}
5050

5151
inline Py_ssize_t arity(PyObject* const& args_)
5252
{
53-
return PyTuple_GET_SIZE(args_);
53+
return PyTuple_Size(args_);
5454
}
5555

5656
// This "result converter" is really just used as
@@ -80,7 +80,7 @@ inline ResultConverter create_result_converter(
8080
{
8181
return ResultConverter(args_);
8282
}
83-
83+
8484
template <class ArgPackage, class ResultConverter>
8585
inline ResultConverter create_result_converter(
8686
ArgPackage const&
@@ -93,7 +93,7 @@ inline ResultConverter create_result_converter(
9393

9494
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
9595
template <class ResultConverter>
96-
struct converter_target_type
96+
struct converter_target_type
9797
{
9898
static PyTypeObject const *get_pytype()
9999
{
@@ -120,15 +120,15 @@ template<class Policies, class Sig> const signature_element* get_ret()
120120
static const signature_element ret = {
121121
(is_void<rtype>::value ? "void" : type_id<rtype>().name())
122122
, &detail::converter_target_type<result_converter>::get_pytype
123-
, boost::detail::indirect_traits::is_reference_to_non_const<rtype>::value
123+
, boost::detail::indirect_traits::is_reference_to_non_const<rtype>::value
124124
};
125125

126126
return &ret;
127127
}
128128

129129
#endif
130130

131-
131+
132132
template <unsigned> struct caller_arity;
133133

134134
template <class F, class CallPolicies, class Sig>
@@ -187,7 +187,7 @@ struct caller
187187
>::type base;
188188

189189
typedef PyObject* result_type;
190-
190+
191191
caller(F f, CallPolicies p) : base(f,p) {}
192192

193193
};
@@ -217,14 +217,14 @@ struct caller_arity<N>
217217
typedef typename first::type result_t;
218218
typedef typename select_result_converter<Policies, result_t>::type result_converter;
219219
typedef typename Policies::argument_package argument_package;
220-
220+
221221
argument_package inner_args(args_);
222222

223223
# if N
224224
# define BOOST_PP_LOCAL_MACRO(i) BOOST_PYTHON_ARG_CONVERTER(i)
225225
# define BOOST_PP_LOCAL_LIMITS (0, N-1)
226226
# include BOOST_PP_LOCAL_ITERATE()
227-
# endif
227+
# endif
228228
// all converters have been checked. Now we can do the
229229
// precall part of the policy
230230
if (!m_data.second().precall(inner_args))
@@ -236,17 +236,17 @@ struct caller_arity<N>
236236
, m_data.first()
237237
BOOST_PP_ENUM_TRAILING_PARAMS(N, c)
238238
);
239-
239+
240240
return m_data.second().postcall(inner_args, result);
241241
}
242242

243243
static unsigned min_arity() { return N; }
244-
244+
245245
static py_func_sig_info signature()
246246
{
247247
const signature_element * sig = detail::signature<Sig>::elements();
248248
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
249-
// MSVC 15.7.2, when compiling to /O2 left the static const signature_element ret,
249+
// MSVC 15.7.2, when compiling to /O2 left the static const signature_element ret,
250250
// originally defined here, uninitialized. This in turn led to SegFault in Python interpreter.
251251
// Issue is resolved by moving the generation of ret to separate function in detail namespace (see above).
252252
const signature_element * ret = detail::get_ret<Policies, Sig>();
@@ -265,6 +265,6 @@ struct caller_arity<N>
265265

266266

267267

268-
#endif // BOOST_PP_IS_ITERATING
268+
#endif // BOOST_PP_IS_ITERATING
269269

270270

include/boost/python/detail/make_tuple.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ifndef BOOST_PYTHON_SYNOPSIS
1+
# ifndef BOOST_PYTHON_SYNOPSIS
22
# // Copyright David Abrahams 2002.
33
# // Distributed under the Boost Software License, Version 1.0. (See
44
# // accompanying file LICENSE_1_0.txt or copy at
@@ -11,7 +11,7 @@
1111
# define N BOOST_PP_ITERATION()
1212

1313
# define BOOST_PYTHON_MAKE_TUPLE_ARG(z, N, ignored) \
14-
PyTuple_SET_ITEM( \
14+
PyTuple_SetItem( \
1515
result.ptr() \
1616
, N \
1717
, python::incref(python::object(a##N).ptr()) \
@@ -29,4 +29,4 @@
2929
# undef BOOST_PYTHON_MAKE_TUPLE_ARG
3030

3131
# undef N
32-
# endif // BOOST_PYTHON_SYNOPSIS
32+
# endif // BOOST_PYTHON_SYNOPSIS

include/boost/python/enum.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# include <boost/python/converter/rvalue_from_python_data.hpp>
1212
# include <boost/python/converter/registered.hpp>
1313

14-
namespace boost { namespace python {
14+
namespace boost { namespace python {
1515

1616
template <class T>
1717
struct enum_ : public objects::enum_base
@@ -70,7 +70,7 @@ void* enum_<T>::convertible_from_python(PyObject* obj)
7070
obj
7171
, upcast<PyObject>(
7272
converter::registered<T>::converters.m_class_object))
73-
73+
7474
? obj : 0;
7575
}
7676

@@ -80,9 +80,9 @@ template <class T>
8080
void enum_<T>::construct(PyObject* obj, converter::rvalue_from_python_stage1_data* data)
8181
{
8282
#if PY_VERSION_HEX >= 0x03000000
83-
T x = static_cast<T>(PyLong_AS_LONG(obj));
83+
T x = static_cast<T>(PyLong_AsLong(obj));
8484
#else
85-
T x = static_cast<T>(PyInt_AS_LONG(obj));
85+
T x = static_cast<T>(PyInt_AsLong(obj));
8686
#endif
8787
void* const storage = ((converter::rvalue_from_python_storage<T>*)data)->storage.bytes;
8888
new (storage) T(x);

0 commit comments

Comments
 (0)