From: AN Long Date: Thu, 11 Dec 2025 17:06:26 +0000 (+0900) Subject: gh-142579: Remove the self converter hack in winreg.c (GH-142580) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ffc71721241f6cf7224423b47aa0c01d0c5de978;p=thirdparty%2FPython%2Fcpython.git gh-142579: Remove the self converter hack in winreg.c (GH-142580) --- diff --git a/PC/clinic/winreg.c.h b/PC/clinic/winreg.c.h index d76a8d8aef8c..92cf6e8a9be1 100644 --- a/PC/clinic/winreg.c.h +++ b/PC/clinic/winreg.c.h @@ -73,19 +73,13 @@ PyDoc_STRVAR(winreg_HKEYType___enter____doc__, #define WINREG_HKEYTYPE___ENTER___METHODDEF \ {"__enter__", (PyCFunction)winreg_HKEYType___enter__, METH_NOARGS, winreg_HKEYType___enter____doc__}, -static PyHKEYObject * +static PyObject * winreg_HKEYType___enter___impl(PyHKEYObject *self); static PyObject * winreg_HKEYType___enter__(PyObject *self, PyObject *Py_UNUSED(ignored)) { - PyObject *return_value = NULL; - PyHKEYObject *_return_value; - - _return_value = winreg_HKEYType___enter___impl((PyHKEYObject *)self); - return_value = (PyObject *)_return_value; - - return return_value; + return winreg_HKEYType___enter___impl((PyHKEYObject *)self); } #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ @@ -1842,4 +1836,4 @@ exit: #ifndef WINREG_QUERYREFLECTIONKEY_METHODDEF #define WINREG_QUERYREFLECTIONKEY_METHODDEF #endif /* !defined(WINREG_QUERYREFLECTIONKEY_METHODDEF) */ -/*[clinic end generated code: output=ce7e8e38884851fb input=a9049054013a1b77]*/ +/*[clinic end generated code: output=97295995db2c24e9 input=a9049054013a1b77]*/ diff --git a/PC/winreg.c b/PC/winreg.c index bcb02b122990..26bcd259efd9 100644 --- a/PC/winreg.c +++ b/PC/winreg.c @@ -264,19 +264,8 @@ class HKEY_return_converter(CReturnConverter): self.err_occurred_if_null_pointer("_return_value", data) data.return_conversion.append( 'return_value = PyHKEY_FromHKEY(_PyModule_GetState(module), _return_value);\n') - -# 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') [python start generated code]*/ -/*[python end generated code: output=da39a3ee5e6b4b0d input=4979f33998ffb6f8]*/ +/*[python end generated code: output=da39a3ee5e6b4b0d input=b34c8217647f5fef]*/ #include "clinic/winreg.c.h" @@ -333,14 +322,14 @@ winreg_HKEYType_Detach_impl(PyHKEYObject *self) } /*[clinic input] -winreg.HKEYType.__enter__ -> self +winreg.HKEYType.__enter__ [clinic start generated code]*/ -static PyHKEYObject * +static PyObject * winreg_HKEYType___enter___impl(PyHKEYObject *self) -/*[clinic end generated code: output=52c34986dab28990 input=c40fab1f0690a8e2]*/ +/*[clinic end generated code: output=70ec10933068a08c input=85f6abf60774c88c]*/ { - return (PyHKEYObject*)Py_XNewRef(self); + return Py_XNewRef(self); }