From ac89ffca001993a3e1a29884ab1c299b88d2cc24 Mon Sep 17 00:00:00 2001 From: Pat Riehecky Date: Fri, 16 Oct 2020 13:20:44 -0500 Subject: [PATCH] Convert get/set/size to PEP-384 style --- include/boost/python/detail/caller.hpp | 4 ++-- include/boost/python/detail/make_tuple.hpp | 2 +- include/boost/python/enum.hpp | 4 ++-- src/converter/builtin_converters.cpp | 16 ++++++++-------- src/object/class.cpp | 4 ++-- src/object/enum.cpp | 2 +- src/object/function.cpp | 18 +++++++++--------- src/object/iterator.cpp | 2 +- src/object/life_support.cpp | 2 +- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/include/boost/python/detail/caller.hpp b/include/boost/python/detail/caller.hpp index 2834d6da99..a0eecfaec3 100644 --- a/include/boost/python/detail/caller.hpp +++ b/include/boost/python/detail/caller.hpp @@ -45,12 +45,12 @@ namespace boost { namespace python { namespace detail { template inline PyObject* get(mpl::int_, 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 diff --git a/include/boost/python/detail/make_tuple.hpp b/include/boost/python/detail/make_tuple.hpp index 57b285be1c..356694d624 100644 --- a/include/boost/python/detail/make_tuple.hpp +++ b/include/boost/python/detail/make_tuple.hpp @@ -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()) \ diff --git a/include/boost/python/enum.hpp b/include/boost/python/enum.hpp index 9631a0edc8..46a90a60f1 100644 --- a/include/boost/python/enum.hpp +++ b/include/boost/python/enum.hpp @@ -80,9 +80,9 @@ template void enum_::construct(PyObject* obj, converter::rvalue_from_python_stage1_data* data) { #if PY_VERSION_HEX >= 0x03000000 - T x = static_cast(PyLong_AS_LONG(obj)); + T x = static_cast(PyLong_AsLong(obj)); #else - T x = static_cast(PyInt_AS_LONG(obj)); + T x = static_cast(PyInt_AsLong(obj)); #endif void* const storage = ((converter::rvalue_from_python_storage*)data)->storage.bytes; new (storage) T(x); diff --git a/src/converter/builtin_converters.cpp b/src/converter/builtin_converters.cpp index ee2d5b4794..ae78cbe9a6 100644 --- a/src/converter/builtin_converters.cpp +++ b/src/converter/builtin_converters.cpp @@ -214,9 +214,9 @@ namespace return numeric_cast(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) { @@ -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 @@ -290,7 +290,7 @@ namespace #if PY_VERSION_HEX < 0x03000000 if (PyInt_Check(intermediate)) { - return numeric_cast(PyInt_AS_LONG(intermediate)); + return numeric_cast(PyInt_AsLong(intermediate)); } else #endif @@ -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;} @@ -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;} diff --git a/src/object/class.cpp b/src/object/class.cpp index c6bab76009..ec2c443050 100644 --- a/src/object/class.cpp +++ b/src/object/class.cpp @@ -554,8 +554,8 @@ namespace objects for (ssize_t i = 1; i <= num_bases; ++i) { type_handle c = (i >= static_cast(num_types)) ? class_type() : get_class(types[i]); - // PyTuple_SET_ITEM steals this reference - PyTuple_SET_ITEM(bases.get(), static_cast(i - 1), upcast(c.release())); + // PyTuple_SetItem steals this reference + PyTuple_SetItem(bases.get(), static_cast(i - 1), upcast(c.release())); } // Call the class metatype to create a new class diff --git a/src/object/enum.cpp b/src/object/enum.cpp index 293e705899..0858beefe8 100644 --- a/src/object/enum.cpp +++ b/src/object/enum.cpp @@ -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 diff --git a/src/object/function.cpp b/src/object/function.cpp index 787679e138..fdff8e8086 100644 --- a/src/object/function.cpp +++ b/src/object/function.cpp @@ -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) @@ -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()) @@ -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; @@ -167,7 +167,7 @@ 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; @@ -175,20 +175,20 @@ PyObject* function::call(PyObject* args, PyObject* keywords) const 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) { @@ -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()) diff --git a/src/object/iterator.cpp b/src/object/iterator.cpp index 3f6c4adacd..672c3218f9 100644 --- a/src/object/iterator.cpp +++ b/src/object/iterator.cpp @@ -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; } diff --git a/src/object/life_support.cpp b/src/object/life_support.cpp index 281c3bffc5..c258b9af66 100644 --- a/src/object/life_support.cpp +++ b/src/object/life_support.cpp @@ -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(); } }