Skip to content
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

Convert get/set/size to PEP-384 style #324

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions include/boost/python/detail/caller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ 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
2 changes: 1 addition & 1 deletion include/boost/python/detail/make_tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down
4 changes: 2 additions & 2 deletions include/boost/python/enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions src/converter/builtin_converters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ namespace
return numeric_cast<T>(result);
} else {
// None of PyInt_AsUnsigned*() functions check for negative
// overflow, so use PyInt_AS_LONG instead and check if number is
// overflow, so use PyInt_AsLong instead and check if number is
// negative, issuing the exception appropriately.
long result = PyInt_AS_LONG(intermediate);
long result = PyInt_AsLong(intermediate);
if (PyErr_Occurred())
throw_error_already_set();
if (result < 0) {
Expand Down Expand Up @@ -268,7 +268,7 @@ namespace
#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check(intermediate))
{
return PyInt_AS_LONG(intermediate);
return PyInt_AsLong(intermediate);
}
else
#endif
Expand All @@ -290,7 +290,7 @@ namespace
#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check(intermediate))
{
return numeric_cast<unsigned BOOST_PYTHON_LONG_LONG>(PyInt_AS_LONG(intermediate));
return numeric_cast<unsigned BOOST_PYTHON_LONG_LONG>(PyInt_AsLong(intermediate));
}
else
#endif
Expand Down Expand Up @@ -360,12 +360,12 @@ namespace
#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check(intermediate))
{
return PyInt_AS_LONG(intermediate);
return PyInt_AsLong(intermediate);
}
else
#endif
{
return PyFloat_AS_DOUBLE(intermediate);
return PyFloat_AsDouble(intermediate);
}
}
static PyTypeObject const* get_pytype() { return &PyFloat_Type;}
Expand Down Expand Up @@ -493,12 +493,12 @@ namespace
#if PY_VERSION_HEX < 0x03000000
else if (PyInt_Check(intermediate))
{
return PyInt_AS_LONG(intermediate);
return PyInt_AsLong(intermediate);
}
#endif
else
{
return PyFloat_AS_DOUBLE(intermediate);
return PyFloat_AsDouble(intermediate);
}
}
static PyTypeObject const* get_pytype() { return &PyComplex_Type;}
Expand Down
4 changes: 2 additions & 2 deletions src/object/class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ namespace objects
for (ssize_t i = 1; i <= num_bases; ++i)
{
type_handle c = (i >= static_cast<ssize_t>(num_types)) ? class_type() : get_class(types[i]);
// PyTuple_SET_ITEM steals this reference
PyTuple_SET_ITEM(bases.get(), static_cast<ssize_t>(i - 1), upcast<PyObject>(c.release()));
// PyTuple_SetItem steals this reference
PyTuple_SetItem(bases.get(), static_cast<ssize_t>(i - 1), upcast<PyObject>(c.release()));
}

// Call the class metatype to create a new class
Expand Down
2 changes: 1 addition & 1 deletion src/object/enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extern "C"
#if PY_VERSION_HEX >= 0x03000000
PyUnicode_FromFormat("%S.%s(%ld)", mod, self_->ob_type->tp_name, PyLong_AsLong(self_));
#else
PyString_FromFormat("%s.%s(%ld)", PyString_AsString(mod), self_->ob_type->tp_name, PyInt_AS_LONG(self_));
PyString_FromFormat("%s.%s(%ld)", PyString_AsString(mod), self_->ob_type->tp_name, PyInt_AsLong(self_));
#endif
}
else
Expand Down
18 changes: 9 additions & 9 deletions src/object/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function::function(
if (num_keywords != 0)
{
for (unsigned j = 0; j < keyword_offset; ++j)
PyTuple_SET_ITEM(m_arg_names.ptr(), j, incref(Py_None));
PyTuple_SetItem(m_arg_names.ptr(), j, incref(Py_None));
}

for (unsigned i = 0; i < num_keywords; ++i)
Expand All @@ -96,7 +96,7 @@ function::function(
kv = make_tuple(p->name);
}

PyTuple_SET_ITEM(
PyTuple_SetItem(
m_arg_names.ptr()
, i + keyword_offset
, incref(kv.ptr())
Expand All @@ -122,7 +122,7 @@ function::~function()

PyObject* function::call(PyObject* args, PyObject* keywords) const
{
std::size_t n_unnamed_actual = PyTuple_GET_SIZE(args);
std::size_t n_unnamed_actual = PyTuple_Size(args);
std::size_t n_keyword_actual = keywords ? PyDict_Size(keywords) : 0;
std::size_t n_actual = n_unnamed_actual + n_keyword_actual;

Expand Down Expand Up @@ -167,28 +167,28 @@ PyObject* function::call(PyObject* args, PyObject* keywords) const

// Fill in the positional arguments
for (std::size_t i = 0; i < n_unnamed_actual; ++i)
PyTuple_SET_ITEM(inner_args.get(), i, incref(PyTuple_GET_ITEM(args, i)));
PyTuple_SetItem(inner_args.get(), i, incref(PyTuple_GetItem(args, i)));

// Grab remaining arguments by name from the keyword dictionary
std::size_t n_actual_processed = n_unnamed_actual;

for (std::size_t arg_pos = n_unnamed_actual; arg_pos < max_arity ; ++arg_pos)
{
// Get the keyword[, value pair] corresponding
PyObject* kv = PyTuple_GET_ITEM(f->m_arg_names.ptr(), arg_pos);
PyObject* kv = PyTuple_GetItem(f->m_arg_names.ptr(), arg_pos);

// If there were any keyword arguments,
// look up the one we need for this
// argument position
PyObject* value = n_keyword_actual
? PyDict_GetItem(keywords, PyTuple_GET_ITEM(kv, 0))
? PyDict_GetItem(keywords, PyTuple_GetItem(kv, 0))
: 0;

if (!value)
{
// Not found; check if there's a default value
if (PyTuple_GET_SIZE(kv) > 1)
value = PyTuple_GET_ITEM(kv, 1);
if (PyTuple_Size(kv) > 1)
value = PyTuple_GetItem(kv, 1);

if (!value)
{
Expand All @@ -203,7 +203,7 @@ PyObject* function::call(PyObject* args, PyObject* keywords) const
++n_actual_processed;
}

PyTuple_SET_ITEM(inner_args.get(), arg_pos, incref(value));
PyTuple_SetItem(inner_args.get(), arg_pos, incref(value));
}

if (inner_args.get())
Expand Down
2 changes: 1 addition & 1 deletion src/object/iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace
{
PyObject* identity(PyObject* args_, PyObject*)
{
PyObject* x = PyTuple_GET_ITEM(args_,0);
PyObject* x = PyTuple_GetItem(args_,0);
Py_INCREF(x);
return x;
}
Expand Down
2 changes: 1 addition & 1 deletion src/object/life_support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern "C"
Py_XDECREF(((life_support*)self)->patient);
((life_support*)self)->patient = 0;
// Let the weak reference die. This probably kills us.
Py_XDECREF(PyTuple_GET_ITEM(arg, 0));
Py_XDECREF(PyTuple_GetItem(arg, 0));
return ::boost::python::detail::none();
}
}
Expand Down