Skip to content

Commit

Permalink
Python 3.13 build fixes (#2910)
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone authored Oct 17, 2024
1 parent 8abad8d commit 019976e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
30 changes: 11 additions & 19 deletions python/modules/IcePy/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,7 @@ IcePy::StreamUtil::setSlicedDataMember(PyObject* obj, const Ice::SlicedDataPtr&
assert(_sliceInfoType);
}

IcePy::PyObjectHandle args{PyTuple_New(0)};
if (!args.get())
{
assert(PyErr_Occurred());
throw AbortMarshaling();
}

PyObjectHandle sd{PyEval_CallObject(_slicedDataType, args.get())};
PyObjectHandle sd{PyObject_CallObject(_slicedDataType, nullptr)};
if (!sd.get())
{
assert(PyErr_Occurred());
Expand All @@ -329,7 +322,7 @@ IcePy::StreamUtil::setSlicedDataMember(PyObject* obj, const Ice::SlicedDataPtr&
int i = 0;
for (vector<Ice::SliceInfoPtr>::const_iterator p = slicedData->slices.begin(); p != slicedData->slices.end(); ++p)
{
PyObjectHandle slice{PyEval_CallObject(_sliceInfoType, args.get())};
PyObjectHandle slice{PyObject_CallObject(_sliceInfoType, nullptr)};
if (!slice.get())
{
assert(PyErr_Occurred());
Expand Down Expand Up @@ -1476,18 +1469,17 @@ IcePy::SequenceInfo::marshal(
Py_ssize_t sz = 0;
if (p != Py_None)
{
const void* buf = 0;
if (PyObject_AsReadBuffer(p, &buf, &sz) == 0)
Py_buffer pybuf;
if (pi && PyObject_GetBuffer(p, &pybuf, PyBUF_SIMPLE | PyBUF_FORMAT) == 0)
{
if (pi->kind == PrimitiveInfo::KindString)
{
PyErr_Format(PyExc_ValueError, "expected sequence value");
throw AbortMarshaling();
}
// Strings are handled as variable length types above.
assert(pi->kind != PrimitiveInfo::KindString);
sz = pybuf.len;
PyBuffer_Release(&pybuf);
}
else
{
PyErr_Clear(); // PyObject_AsReadBuffer sets an exception on failure.
PyErr_Clear(); // PyObject_GetBuffer sets an exception on failure.

PyObjectHandle fs;
if (pi)
Expand Down Expand Up @@ -1711,7 +1703,7 @@ IcePy::SequenceInfo::marshalPrimitiveSequence(const PrimitiveInfoPtr& pi, PyObje
if (pi->kind != PrimitiveInfo::KindString)
{
//
// With Python 3 and greater we marshal sequences of pritive types using the new
// With Python 3 and greater we marshal sequences of primitive types using the new
// buffer protocol when possible, for older versions we use the old buffer protocol.
//
Py_buffer pybuf;
Expand Down Expand Up @@ -1820,7 +1812,7 @@ IcePy::SequenceInfo::marshalPrimitiveSequence(const PrimitiveInfoPtr& pi, PyObje
}
else
{
PyErr_Clear(); // PyObject_GetBuffer/PyObject_AsReadBuffer sets an exception on failure.
PyErr_Clear(); // PyObject_GetBuffer sets an exception on failure.
}
}

Expand Down
9 changes: 2 additions & 7 deletions python/modules/IcePy/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,7 @@ PyObject*
IcePy::createExceptionInstance(PyObject* type)
{
assert(PyExceptionClass_Check(type));
IcePy::PyObjectHandle args{PyTuple_New(0)};
if (!args.get())
{
return nullptr;
}
return PyEval_CallObject(type, args.get());
return PyObject_CallObject(type, nullptr);
}

namespace
Expand Down Expand Up @@ -651,7 +646,7 @@ namespace
// PyTuple_SetItem takes ownership of the args[i] reference.
PyTuple_SetItem(pArgs.get(), static_cast<Py_ssize_t>(i), args[i]);
}
return PyEval_CallObject(type, pArgs.get());
return PyObject_CallObject(type, pArgs.get());
}
}

Expand Down

0 comments on commit 019976e

Please sign in to comment.