Skip to content

Argument Clinic does not increase NoneType refcount when returning NoneType from a function with no parameters #95007

Description

@noamcohen97

Bug report

/*[clinicinput]
function->NoneType
[clinicstartgeneratedcode]*/

will produce this function:

staticPyObject*function(PyObject*module, PyObject*Py_UNUSED(ignored))
{
returnfunction_impl(module);
}

while function_impl returns Py_None (as it should, if using NoneType return converter), refcount is not increased.

here is a working example of NoneType return converter:

/*[clinicinput]
function->NoneTypea: int/
[clinicstartgeneratedcode]*/
staticPyObject*function(PyObject*module, PyObject*arg)
{
PyObject*return_value=NULL;
inta;
PyObject*_return_value;
a=_PyLong_AsInt(arg);
if (a==-1&&PyErr_Occurred()) {
goto exit;
}
_return_value=function_impl(module, a);
if (_return_value!=Py_None) {
goto exit;
}
return_value=Py_None;
Py_INCREF(Py_None);
exit:
returnreturn_value;
}

Generation also fails when generating a function with a single object parameter.

It seems like the problem is with default_return_converter in clinic.py, being set to True

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions