Skip to content

Remove the unnecessary self return converter in winreg.c #142579

@aisk

Description

@aisk

Bug report

Bug description:

There is an Argument Clinic converter (marked as “HACK” in the comment) in winreg.c:

cpython/PC/winreg.c

Lines 268 to 277 in a275385

# HACK: this only works for PyHKEYObjects, nothing else.
# Should this be generalized and enshrined in clinic.py,
# destroy this converter with prejudice.
class self_return_converter(CReturnConverter):
type = 'PyHKEYObject *'
def render(self, function, data):
self.declare(data)
data.return_conversion.append(
'return_value = (PyObject *)_return_value;\n')

It is only used in the HKEY.__enter__ method. In that method, the type of the return value PyObject * is cast to a PyHKEYObject *:

cpython/PC/winreg.c

Lines 335 to 344 in a275385

/*[clinic input]
winreg.HKEYType.__enter__ -> self
[clinic start generated code]*/
static PyHKEYObject *
winreg_HKEYType___enter___impl(PyHKEYObject *self)
/*[clinic end generated code: output=52c34986dab28990 input=c40fab1f0690a8e2]*/
{
return (PyHKEYObject*)Py_XNewRef(self);
}

What the self_return_converter does is simply cast the PyHKEYObject * back to PyObject *, which is unnecessary.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions