Skip to content

Commit

Permalink
Replace _PyArg_NoKeywords for Python 3.13
Browse files Browse the repository at this point in the history
It's no longer available in the public headers [1]

On Linux with GCC 11:

  error: there are no arguments to ‘_PyArg_NoKeywords’ that depend on a template parameter, so a declaration of ‘_PyArg_NoKeywords’ must be available [-fpermissive]
    226 |                 if (!_PyArg_NoKeywords("function", iKw))

[1] python/cpython#110964
  • Loading branch information
bdegreve committed Aug 11, 2024
1 parent 5629f61 commit b493184
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
17 changes: 13 additions & 4 deletions lass/python/pycallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* The Original Developer is the Initial Developer.
*
* All portions of the code written by the Initial Developer are:
* Copyright (C) 2004-2011 the Initial Developer.
* Copyright (C) 2004-2024 the Initial Developer.
* All Rights Reserved.
*
* Contributor(s):
Expand Down Expand Up @@ -79,17 +79,26 @@ const std::string MultiCallbackImplBase::repr() const

// wrapping the call ourselves as the macro's and templates have difficulties
// automatically wrapping everything up
PyObject * MultiCallback::_tp_call(PyObject * self, PyObject *args, PyObject* LASS_UNUSED(kwargs))
PyObject * MultiCallback::_tp_call(PyObject * self, PyObject *args, PyObject* kwargs)
{
LockGIL LASS_UNUSED(lock);
if (!PyType_IsSubtype(self->ob_type , MultiCallback::_lassPyClassDef.type() ))
{
PyErr_SetString(PyExc_TypeError,"not castable to MultiCallback");
return 0;
}
if (!_PyArg_NoKeywords("function", kwargs))
if (kwargs)
{
return 0;
if (!PyDict_CheckExact(kwargs))
{
PyErr_BadInternalCall();
return 0;
}
if (PyDict_Size(kwargs) != 0)
{
PyErr_SetString(PyExc_TypeError, "function takes no keyword arguments");
return 0;
}
}
return static_cast<MultiCallback*>(self)->callVar(args);
}
Expand Down
15 changes: 12 additions & 3 deletions lass/python/pyobject_plus.inl
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,20 @@ template <PyCFunction DispatcherAddress> struct FunctionTypeDispatcher<lass::pyt
*/
template <PyCFunction DispatcherAddress> struct FunctionTypeDispatcher<lass::python::impl::ArgKwSlot ,DispatcherAddress>
{
static PyObject* fun(PyObject* iSelf, PyObject* iArgs, PyObject* LASS_UNUSED(iKw))
static PyObject* fun(PyObject* iSelf, PyObject* iArgs, PyObject* iKw)
{
if (!_PyArg_NoKeywords("function", iKw))
if (iKw)
{
return 0;
if (!PyDict_CheckExact(iKw))
{
PyErr_BadInternalCall();
return 0;
}
if (PyDict_Size(iKw) != 0)
{
PyErr_SetString(PyExc_TypeError, "function takes no keyword arguments");
return 0;
}
}
return DispatcherAddress(iSelf, iArgs);
}
Expand Down

0 comments on commit b493184

Please sign in to comment.