Skip to content

Replace methods for Py_LIMITED_API support #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy-documentation.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: deploy documentation

on: [push, pull_request]
on: [pull_request]

jobs:
deploy:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-osx.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Test OSX

on: [push, pull_request]
on: [pull_request]

jobs:
build:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ jobs:
strategy:
fail-fast: false
matrix:
python: [python, python3]
cxx: [g++, clang++]
std: [c++98, c++11, c++14, c++17]
python: [python3]
cxx: [g++]
std: [c++98]
include:
# Add the appropriate docker image for each compiler.
# The images from teeks99/boost-python-test already have boost::python
# pre-reqs installed, see:
# https://github.com/teeks99/boost-python-test-docker
- cxx: clang++
docker-img: teeks99/boost-python-test:clang-12_1.76.0
#- cxx: clang++
# docker-img: teeks99/boost-python-test:clang-12_1.76.0
- cxx: g++
docker-img: teeks99/boost-python-test:gcc-10_1.76.0

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Test Windows

on: [push, pull_request]
on: [pull_request]

jobs:
build:
Expand Down
28 changes: 14 additions & 14 deletions include/boost/python/detail/caller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@
# include <boost/mpl/int.hpp>
# include <boost/mpl/next.hpp>

namespace boost { namespace python { namespace detail {
namespace boost { namespace python { namespace detail {

template <int N>
inline PyObject* get(mpl::int_<N>, PyObject* const& args_)
{
return PyTuple_GET_ITEM(args_,N);
return PyTuple_GetItem(args_,N);
}

inline Py_ssize_t arity(PyObject* const& args_)
{
return PyTuple_GET_SIZE(args_);
return PyTuple_Size(args_);
}

// This "result converter" is really just used as
Expand Down Expand Up @@ -80,7 +80,7 @@ inline ResultConverter create_result_converter(
{
return ResultConverter(args_);
}

template <class ArgPackage, class ResultConverter>
inline ResultConverter create_result_converter(
ArgPackage const&
Expand All @@ -93,7 +93,7 @@ inline ResultConverter create_result_converter(

#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
template <class ResultConverter>
struct converter_target_type
struct converter_target_type
{
static PyTypeObject const *get_pytype()
{
Expand All @@ -120,15 +120,15 @@ template<class Policies, class Sig> const signature_element* get_ret()
static const signature_element ret = {
(is_void<rtype>::value ? "void" : type_id<rtype>().name())
, &detail::converter_target_type<result_converter>::get_pytype
, boost::detail::indirect_traits::is_reference_to_non_const<rtype>::value
, boost::detail::indirect_traits::is_reference_to_non_const<rtype>::value
};

return &ret;
}

#endif


template <unsigned> struct caller_arity;

template <class F, class CallPolicies, class Sig>
Expand Down Expand Up @@ -187,7 +187,7 @@ struct caller
>::type base;

typedef PyObject* result_type;

caller(F f, CallPolicies p) : base(f,p) {}

};
Expand Down Expand Up @@ -217,14 +217,14 @@ struct caller_arity<N>
typedef typename first::type result_t;
typedef typename select_result_converter<Policies, result_t>::type result_converter;
typedef typename Policies::argument_package argument_package;

argument_package inner_args(args_);

# if N
# define BOOST_PP_LOCAL_MACRO(i) BOOST_PYTHON_ARG_CONVERTER(i)
# define BOOST_PP_LOCAL_LIMITS (0, N-1)
# include BOOST_PP_LOCAL_ITERATE()
# endif
# endif
// all converters have been checked. Now we can do the
// precall part of the policy
if (!m_data.second().precall(inner_args))
Expand All @@ -236,17 +236,17 @@ struct caller_arity<N>
, m_data.first()
BOOST_PP_ENUM_TRAILING_PARAMS(N, c)
);

return m_data.second().postcall(inner_args, result);
}

static unsigned min_arity() { return N; }

static py_func_sig_info signature()
{
const signature_element * sig = detail::signature<Sig>::elements();
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
// MSVC 15.7.2, when compiling to /O2 left the static const signature_element ret,
// MSVC 15.7.2, when compiling to /O2 left the static const signature_element ret,
// originally defined here, uninitialized. This in turn led to SegFault in Python interpreter.
// Issue is resolved by moving the generation of ret to separate function in detail namespace (see above).
const signature_element * ret = detail::get_ret<Policies, Sig>();
Expand All @@ -265,6 +265,6 @@ struct caller_arity<N>



#endif // BOOST_PP_IS_ITERATING
#endif // BOOST_PP_IS_ITERATING


6 changes: 3 additions & 3 deletions include/boost/python/detail/make_tuple.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ifndef BOOST_PYTHON_SYNOPSIS
# ifndef BOOST_PYTHON_SYNOPSIS
# // Copyright David Abrahams 2002.
# // Distributed under the Boost Software License, Version 1.0. (See
# // accompanying file LICENSE_1_0.txt or copy at
Expand All @@ -11,7 +11,7 @@
# define N BOOST_PP_ITERATION()

# define BOOST_PYTHON_MAKE_TUPLE_ARG(z, N, ignored) \
PyTuple_SET_ITEM( \
PyTuple_SetItem( \
result.ptr() \
, N \
, python::incref(python::object(a##N).ptr()) \
Expand All @@ -29,4 +29,4 @@
# undef BOOST_PYTHON_MAKE_TUPLE_ARG

# undef N
# endif // BOOST_PYTHON_SYNOPSIS
# endif // BOOST_PYTHON_SYNOPSIS
3 changes: 2 additions & 1 deletion include/boost/python/detail/wrap_python.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#ifdef _DEBUG
# ifndef BOOST_DEBUG_PYTHON
# ifdef _MSC_VER
# ifdef _MSC_VER
// VC8.0 will complain if system headers are #included both with
// and without _DEBUG defined, so we have to #include all the
// system headers used by pyconfig.h right here.
Expand Down Expand Up @@ -175,6 +175,7 @@ typedef int pid_t;
#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 2 && PY_MICRO_VERSION < 2
# include <boost/python/detail/python22_fixed.h>
#else
#define Py_LIMITED_API
# include <Python.h>
#endif

Expand Down
8 changes: 4 additions & 4 deletions include/boost/python/enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# include <boost/python/converter/rvalue_from_python_data.hpp>
# include <boost/python/converter/registered.hpp>

namespace boost { namespace python {
namespace boost { namespace python {

template <class T>
struct enum_ : public objects::enum_base
Expand Down Expand Up @@ -70,7 +70,7 @@ void* enum_<T>::convertible_from_python(PyObject* obj)
obj
, upcast<PyObject>(
converter::registered<T>::converters.m_class_object))

? obj : 0;
}

Expand All @@ -80,9 +80,9 @@ template <class T>
void enum_<T>::construct(PyObject* obj, converter::rvalue_from_python_stage1_data* data)
{
#if PY_VERSION_HEX >= 0x03000000
T x = static_cast<T>(PyLong_AS_LONG(obj));
T x = static_cast<T>(PyLong_AsLong(obj));
#else
T x = static_cast<T>(PyInt_AS_LONG(obj));
T x = static_cast<T>(PyInt_AsLong(obj));
#endif
void* const storage = ((converter::rvalue_from_python_storage<T>*)data)->storage.bytes;
new (storage) T(x);
Expand Down
20 changes: 10 additions & 10 deletions include/boost/python/object/make_instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
# include <boost/mpl/assert.hpp>
# include <boost/mpl/or.hpp>

namespace boost { namespace python { namespace objects {
namespace boost { namespace python { namespace objects {

template <class T, class Holder, class Derived>
struct make_instance_impl
{
typedef objects::instance<Holder> instance_t;

template <class Arg>
static inline PyObject* execute(Arg& x)
{
Expand All @@ -32,20 +32,20 @@ struct make_instance_impl
if (type == 0)
return python::detail::none();

PyObject* raw_result = type->tp_alloc(
PyObject* raw_result = type->Py_tp_alloc(
type, objects::additional_instance_size<Holder>::value);

if (raw_result != 0)
{
python::detail::decref_guard protect(raw_result);

instance_t* instance = (instance_t*)raw_result;

// construct the new C++ object and install the pointer
// in the Python object.
Holder *holder =Derived::construct(instance->storage.bytes, (PyObject*)instance, x);
holder->install(raw_result);

// Note the position of the internally-stored Holder,
// for the sake of destruction
const size_t offset = reinterpret_cast<size_t>(holder) -
Expand All @@ -58,7 +58,7 @@ struct make_instance_impl
return raw_result;
}
};


template <class T, class Holder>
struct make_instance
Expand All @@ -69,7 +69,7 @@ struct make_instance
{
return converter::registered<T>::converters.get_class_object();
}

static inline Holder* construct(void* storage, PyObject* instance, reference_wrapper<T const> x)
{
size_t allocated = objects::additional_instance_size<Holder>::value;
Expand All @@ -78,7 +78,7 @@ struct make_instance
return new (aligned_storage) Holder(instance, x);
}
};


}}} // namespace boost::python::object

Expand Down
Loading