Skip to content

Commit 3e644c6

Browse files
committed
Convert get/set/size to PEP-384 style
1 parent f1320bf commit 3e644c6

File tree

9 files changed

+27
-27
lines changed

9 files changed

+27
-27
lines changed

include/boost/python/detail/caller.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ namespace boost { namespace python { namespace detail {
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

include/boost/python/detail/make_tuple.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -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()) \

include/boost/python/enum.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -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);

src/converter/builtin_converters.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ namespace
214214
return numeric_cast<T>(result);
215215
} else {
216216
// None of PyInt_AsUnsigned*() functions check for negative
217-
// overflow, so use PyInt_AS_LONG instead and check if number is
217+
// overflow, so use PyInt_AsLong instead and check if number is
218218
// negative, issuing the exception appropriately.
219-
long result = PyInt_AS_LONG(intermediate);
219+
long result = PyInt_AsLong(intermediate);
220220
if (PyErr_Occurred())
221221
throw_error_already_set();
222222
if (result < 0) {
@@ -268,7 +268,7 @@ namespace
268268
#if PY_VERSION_HEX < 0x03000000
269269
if (PyInt_Check(intermediate))
270270
{
271-
return PyInt_AS_LONG(intermediate);
271+
return PyInt_AsLong(intermediate);
272272
}
273273
else
274274
#endif
@@ -290,7 +290,7 @@ namespace
290290
#if PY_VERSION_HEX < 0x03000000
291291
if (PyInt_Check(intermediate))
292292
{
293-
return numeric_cast<unsigned BOOST_PYTHON_LONG_LONG>(PyInt_AS_LONG(intermediate));
293+
return numeric_cast<unsigned BOOST_PYTHON_LONG_LONG>(PyInt_AsLong(intermediate));
294294
}
295295
else
296296
#endif
@@ -360,12 +360,12 @@ namespace
360360
#if PY_VERSION_HEX < 0x03000000
361361
if (PyInt_Check(intermediate))
362362
{
363-
return PyInt_AS_LONG(intermediate);
363+
return PyInt_AsLong(intermediate);
364364
}
365365
else
366366
#endif
367367
{
368-
return PyFloat_AS_DOUBLE(intermediate);
368+
return PyFloat_AsDouble(intermediate);
369369
}
370370
}
371371
static PyTypeObject const* get_pytype() { return &PyFloat_Type;}
@@ -493,12 +493,12 @@ namespace
493493
#if PY_VERSION_HEX < 0x03000000
494494
else if (PyInt_Check(intermediate))
495495
{
496-
return PyInt_AS_LONG(intermediate);
496+
return PyInt_AsLong(intermediate);
497497
}
498498
#endif
499499
else
500500
{
501-
return PyFloat_AS_DOUBLE(intermediate);
501+
return PyFloat_AsDouble(intermediate);
502502
}
503503
}
504504
static PyTypeObject const* get_pytype() { return &PyComplex_Type;}

src/object/class.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,8 @@ namespace objects
559559
for (ssize_t i = 1; i <= num_bases; ++i)
560560
{
561561
type_handle c = (i >= static_cast<ssize_t>(num_types)) ? class_type() : get_class(types[i]);
562-
// PyTuple_SET_ITEM steals this reference
563-
PyTuple_SET_ITEM(bases.get(), static_cast<ssize_t>(i - 1), upcast<PyObject>(c.release()));
562+
// PyTuple_SetItem steals this reference
563+
PyTuple_SetItem(bases.get(), static_cast<ssize_t>(i - 1), upcast<PyObject>(c.release()));
564564
}
565565

566566
// Call the class metatype to create a new class

src/object/enum.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extern "C"
5252
#if PY_VERSION_HEX >= 0x03000000
5353
PyUnicode_FromFormat("%S.%s(%ld)", mod, self_->ob_type->tp_name, PyLong_AsLong(self_));
5454
#else
55-
PyString_FromFormat("%s.%s(%ld)", PyString_AsString(mod), self_->ob_type->tp_name, PyInt_AS_LONG(self_));
55+
PyString_FromFormat("%s.%s(%ld)", PyString_AsString(mod), self_->ob_type->tp_name, PyInt_AsLong(self_));
5656
#endif
5757
}
5858
else

src/object/function.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function::function(
7878
if (num_keywords != 0)
7979
{
8080
for (unsigned j = 0; j < keyword_offset; ++j)
81-
PyTuple_SET_ITEM(m_arg_names.ptr(), j, incref(Py_None));
81+
PyTuple_SetItem(m_arg_names.ptr(), j, incref(Py_None));
8282
}
8383

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

99-
PyTuple_SET_ITEM(
99+
PyTuple_SetItem(
100100
m_arg_names.ptr()
101101
, i + keyword_offset
102102
, incref(kv.ptr())
@@ -122,7 +122,7 @@ function::~function()
122122

123123
PyObject* function::call(PyObject* args, PyObject* keywords) const
124124
{
125-
std::size_t n_unnamed_actual = PyTuple_GET_SIZE(args);
125+
std::size_t n_unnamed_actual = PyTuple_Size(args);
126126
std::size_t n_keyword_actual = keywords ? PyDict_Size(keywords) : 0;
127127
std::size_t n_actual = n_unnamed_actual + n_keyword_actual;
128128

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

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

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

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

180180
// If there were any keyword arguments,
181181
// look up the one we need for this
182182
// argument position
183183
PyObject* value = n_keyword_actual
184-
? PyDict_GetItem(keywords, PyTuple_GET_ITEM(kv, 0))
184+
? PyDict_GetItem(keywords, PyTuple_GetItem(kv, 0))
185185
: 0;
186186

187187
if (!value)
188188
{
189189
// Not found; check if there's a default value
190-
if (PyTuple_GET_SIZE(kv) > 1)
191-
value = PyTuple_GET_ITEM(kv, 1);
190+
if (PyTuple_Size(kv) > 1)
191+
value = PyTuple_GetItem(kv, 1);
192192

193193
if (!value)
194194
{
@@ -203,7 +203,7 @@ PyObject* function::call(PyObject* args, PyObject* keywords) const
203203
++n_actual_processed;
204204
}
205205

206-
PyTuple_SET_ITEM(inner_args.get(), arg_pos, incref(value));
206+
PyTuple_SetItem(inner_args.get(), arg_pos, incref(value));
207207
}
208208

209209
if (inner_args.get())

src/object/iterator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace
1414
{
1515
PyObject* identity(PyObject* args_, PyObject*)
1616
{
17-
PyObject* x = PyTuple_GET_ITEM(args_,0);
17+
PyObject* x = PyTuple_GetItem(args_,0);
1818
Py_INCREF(x);
1919
return x;
2020
}

src/object/life_support.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extern "C"
3030
Py_XDECREF(((life_support*)self)->patient);
3131
((life_support*)self)->patient = 0;
3232
// Let the weak reference die. This probably kills us.
33-
Py_XDECREF(PyTuple_GET_ITEM(arg, 0));
33+
Py_XDECREF(PyTuple_GetItem(arg, 0));
3434
return ::boost::python::detail::none();
3535
}
3636
}

0 commit comments

Comments
 (0)