3333#endif
3434
3535/*[python input]
36- class intptr_t_converter (CConverter):
37- type = 'intptr_t '
36+ class HANDLE_converter (CConverter):
37+ type = 'void * '
3838 format_unit = '"_Py_PARSE_INTPTR"'
3939
40- class handle_return_converter(long_return_converter):
41- type = 'intptr_t'
42- cast = '(void *)'
43- conversion_fn = 'PyLong_FromVoidPtr'
40+ class HANDLE_return_converter(CReturnConverter):
41+ type = 'void *'
42+
43+ def render(self, function, data):
44+ self.declare(data)
45+ self.err_occurred_if(
46+ "_return_value == NULL || _return_value == INVALID_HANDLE_VALUE",
47+ data)
48+ data.return_conversion.append(
49+ 'return_value = PyLong_FromVoidPtr(_return_value);\n')
4450
4551class byte_char_return_converter(CReturnConverter):
4652 type = 'int'
@@ -59,7 +65,7 @@ class wchar_t_return_converter(CReturnConverter):
5965 data.return_conversion.append(
6066 'return_value = PyUnicode_FromOrdinal(_return_value);\n')
6167[python start generated code]*/
62- /*[python end generated code: output=da39a3ee5e6b4b0d input=b59f1663dba11997 ]*/
68+ /*[python end generated code: output=da39a3ee5e6b4b0d input=2b25dc89e9e59534 ]*/
6369
6470/*[clinic input]
6571module msvcrt
@@ -152,7 +158,7 @@ msvcrt_setmode_impl(PyObject *module, int fd, int flags)
152158/*[clinic input]
153159msvcrt.open_osfhandle -> long
154160
155- handle: intptr_t
161+ handle: HANDLE
156162 flags: int
157163 /
158164
@@ -164,13 +170,13 @@ to os.fdopen() to create a file object.
164170[clinic start generated code]*/
165171
166172static long
167- msvcrt_open_osfhandle_impl (PyObject * module , intptr_t handle , int flags )
168- /*[clinic end generated code: output=cede871bf939d6e3 input=cb2108bbea84514e ]*/
173+ msvcrt_open_osfhandle_impl (PyObject * module , void * handle , int flags )
174+ /*[clinic end generated code: output=b2fb97c4b515e4e6 input=d5db190a307cf4bb ]*/
169175{
170176 int fd ;
171177
172178 _Py_BEGIN_SUPPRESS_IPH
173- fd = _open_osfhandle (handle , flags );
179+ fd = _open_osfhandle (( intptr_t ) handle , flags );
174180 _Py_END_SUPPRESS_IPH
175181 if (fd == -1 )
176182 PyErr_SetFromErrno (PyExc_OSError );
@@ -179,7 +185,7 @@ msvcrt_open_osfhandle_impl(PyObject *module, intptr_t handle, int flags)
179185}
180186
181187/*[clinic input]
182- msvcrt.get_osfhandle -> handle
188+ msvcrt.get_osfhandle -> HANDLE
183189
184190 fd: int
185191 /
@@ -189,9 +195,9 @@ Return the file handle for the file descriptor fd.
189195Raises OSError if fd is not recognized.
190196[clinic start generated code]*/
191197
192- static intptr_t
198+ static void *
193199msvcrt_get_osfhandle_impl (PyObject * module , int fd )
194- /*[clinic end generated code: output=7ce761dd0de2b503 input=305900f4bfab76c7 ]*/
200+ /*[clinic end generated code: output=aca01dfe24637374 input=5fcfde9b17136aa2 ]*/
195201{
196202 intptr_t handle = -1 ;
197203
@@ -201,7 +207,7 @@ msvcrt_get_osfhandle_impl(PyObject *module, int fd)
201207 if (handle == -1 )
202208 PyErr_SetFromErrno (PyExc_OSError );
203209
204- return handle ;
210+ return ( HANDLE ) handle ;
205211}
206212
207213/* Console I/O */
@@ -389,25 +395,25 @@ msvcrt_ungetwch_impl(PyObject *module, int unicode_char)
389395
390396#ifdef _DEBUG
391397/*[clinic input]
392- msvcrt.CrtSetReportFile -> long
398+ msvcrt.CrtSetReportFile -> HANDLE
393399
394400 type: int
395- file: int
401+ file: HANDLE
396402 /
397403
398404Wrapper around _CrtSetReportFile.
399405
400406Only available on Debug builds.
401407[clinic start generated code]*/
402408
403- static long
404- msvcrt_CrtSetReportFile_impl (PyObject * module , int type , int file )
405- /*[clinic end generated code: output=df291c7fe032eb68 input=bb8f721a604fcc45 ]*/
409+ static void *
410+ msvcrt_CrtSetReportFile_impl (PyObject * module , int type , void * file )
411+ /*[clinic end generated code: output=9393e8c77088bbe9 input=290809b5f19e65b9 ]*/
406412{
407- long res ;
413+ HANDLE res ;
408414
409415 _Py_BEGIN_SUPPRESS_IPH
410- res = ( long ) _CrtSetReportFile (type , ( _HFILE ) file );
416+ res = _CrtSetReportFile (type , file );
411417 _Py_END_SUPPRESS_IPH
412418
413419 return res ;
@@ -540,6 +546,20 @@ insertint(PyObject *d, char *name, int value)
540546 }
541547}
542548
549+ static void
550+ insertptr (PyObject * d , char * name , void * value )
551+ {
552+ PyObject * v = PyLong_FromVoidPtr (value );
553+ if (v == NULL ) {
554+ /* Don't bother reporting this error */
555+ PyErr_Clear ();
556+ }
557+ else {
558+ PyDict_SetItemString (d , name , v );
559+ Py_DECREF (v );
560+ }
561+ }
562+
543563PyMODINIT_FUNC
544564PyInit_msvcrt (void )
545565{
@@ -568,9 +588,9 @@ PyInit_msvcrt(void)
568588 insertint (d , "CRTDBG_MODE_FILE" , _CRTDBG_MODE_FILE );
569589 insertint (d , "CRTDBG_MODE_WNDW" , _CRTDBG_MODE_WNDW );
570590 insertint (d , "CRTDBG_REPORT_MODE" , _CRTDBG_REPORT_MODE );
571- insertint (d , "CRTDBG_FILE_STDERR" , ( int ) _CRTDBG_FILE_STDERR );
572- insertint (d , "CRTDBG_FILE_STDOUT" , ( int ) _CRTDBG_FILE_STDOUT );
573- insertint (d , "CRTDBG_REPORT_FILE" , ( int ) _CRTDBG_REPORT_FILE );
591+ insertptr (d , "CRTDBG_FILE_STDERR" , _CRTDBG_FILE_STDERR );
592+ insertptr (d , "CRTDBG_FILE_STDOUT" , _CRTDBG_FILE_STDOUT );
593+ insertptr (d , "CRTDBG_REPORT_FILE" , _CRTDBG_REPORT_FILE );
574594#endif
575595
576596 /* constants for the crt versions */
0 commit comments