Skip to content

Commit 7727bc5

Browse files
committed
bpo-30555: Swap intptr_t to void* in _Py_{get,open}_osfhandle{,_noraise}
1 parent aaf6020 commit 7727bc5

File tree

8 files changed

+32
-32
lines changed

8 files changed

+32
-32
lines changed

Include/fileutils.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ PyAPI_FUNC(int) _Py_get_blocking(int fd);
118118

119119
PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking);
120120
#else /* MS_WINDOWS */
121-
PyAPI_FUNC(intptr_t) _Py_get_osfhandle_noraise(int fd);
121+
PyAPI_FUNC(void*) _Py_get_osfhandle_noraise(int fd);
122122

123-
PyAPI_FUNC(intptr_t) _Py_get_osfhandle(int fd);
123+
PyAPI_FUNC(void*) _Py_get_osfhandle(int fd);
124124

125-
PyAPI_FUNC(int) _Py_open_osfhandle_noraise(intptr_t handle, int flags);
125+
PyAPI_FUNC(int) _Py_open_osfhandle_noraise(void *handle, int flags);
126126

127-
PyAPI_FUNC(int) _Py_open_osfhandle(intptr_t handle, int flags);
127+
PyAPI_FUNC(int) _Py_open_osfhandle(void *handle, int flags);
128128
#endif /* MS_WINDOWS */
129129

130130
#endif /* Py_LIMITED_API */

Modules/_io/winconsoleio.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ char _PyIO_get_console_type(PyObject *path_or_fd) {
6363
int fd = PyLong_AsLong(path_or_fd);
6464
PyErr_Clear();
6565
if (fd >= 0) {
66-
HANDLE handle = (HANDLE)_Py_get_osfhandle_noraise(fd);
66+
HANDLE handle = _Py_get_osfhandle_noraise(fd);
6767
if (handle == INVALID_HANDLE_VALUE)
6868
return '\0';
6969
return _get_console_type(handle);
@@ -345,7 +345,7 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj,
345345
goto bad_mode;
346346

347347
if (fd >= 0) {
348-
handle = (HANDLE)_Py_get_osfhandle_noraise(fd);
348+
handle = _Py_get_osfhandle_noraise(fd);
349349
self->closefd = 0;
350350
} else {
351351
DWORD access = GENERIC_READ;
@@ -378,9 +378,9 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj,
378378
}
379379

380380
if (self->writable)
381-
self->fd = _Py_open_osfhandle_noraise((intptr_t)handle, _O_WRONLY | _O_BINARY);
381+
self->fd = _Py_open_osfhandle_noraise(handle, _O_WRONLY | _O_BINARY);
382382
else
383-
self->fd = _Py_open_osfhandle_noraise((intptr_t)handle, _O_RDONLY | _O_BINARY);
383+
self->fd = _Py_open_osfhandle_noraise(handle, _O_RDONLY | _O_BINARY);
384384
if (self->fd < 0) {
385385
CloseHandle(handle);
386386
PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, nameobj);
@@ -652,7 +652,7 @@ readinto(winconsoleio *self, char *buf, Py_ssize_t len)
652652
return -1;
653653
}
654654

655-
HANDLE handle = (HANDLE)_Py_get_osfhandle(self->fd);
655+
HANDLE handle = _Py_get_osfhandle(self->fd);
656656
if (handle == INVALID_HANDLE_VALUE)
657657
return -1;
658658

@@ -788,7 +788,7 @@ _io__WindowsConsoleIO_readall_impl(winconsoleio *self)
788788
if (self->fd == -1)
789789
return err_closed();
790790

791-
handle = (HANDLE)_Py_get_osfhandle(self->fd);
791+
handle = _Py_get_osfhandle(self->fd);
792792
if (handle == INVALID_HANDLE_VALUE)
793793
return NULL;
794794

@@ -968,7 +968,7 @@ _io__WindowsConsoleIO_write_impl(winconsoleio *self, Py_buffer *b)
968968
if (!self->writable)
969969
return err_mode("writing");
970970

971-
handle = (HANDLE)_Py_get_osfhandle(self->fd);
971+
handle = _Py_get_osfhandle(self->fd);
972972
if (handle == INVALID_HANDLE_VALUE)
973973
return NULL;
974974

Modules/mmapmodule.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1266,8 +1266,8 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
12661266
*/
12671267
if (fileno != -1 && fileno != 0) {
12681268
/* Ensure that fileno is within the CRT's valid range */
1269-
fh = (HANDLE)_Py_get_osfhandle(fileno);
1270-
if (fh == (HANDLE)INVALID_HANDLE_VALUE)
1269+
fh = _Py_get_osfhandle(fileno);
1270+
if (fh == INVALID_HANDLE_VALUE)
12711271
return NULL;
12721272

12731273
/* Win9x appears to need us seeked to zero */

Modules/posixmodule.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -8454,8 +8454,8 @@ os_pipe_impl(PyObject *module)
84548454
Py_BEGIN_ALLOW_THREADS
84558455
ok = CreatePipe(&read, &write, &attr, 0);
84568456
if (ok) {
8457-
fds[0] = _Py_open_osfhandle_noraise((intptr_t)read, _O_RDONLY);
8458-
fds[1] = _Py_open_osfhandle_noraise((intptr_t)write, _O_WRONLY);
8457+
fds[0] = _Py_open_osfhandle_noraise(read, _O_RDONLY);
8458+
fds[1] = _Py_open_osfhandle_noraise(write, _O_WRONLY);
84598459
if (fds[0] == -1 || fds[1] == -1) {
84608460
CloseHandle(read);
84618461
CloseHandle(write);

PC/_testconsole.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ _testconsole_write_input_impl(PyObject *module, PyObject *file,
6868
prec->Event.KeyEvent.uChar.UnicodeChar = *p;
6969
}
7070

71-
HANDLE hInput = (HANDLE)_Py_get_osfhandle(((winconsoleio*)file)->fd);
71+
HANDLE hInput = _Py_get_osfhandle(((winconsoleio*)file)->fd);
7272
if (hInput == INVALID_HANDLE_VALUE)
7373
goto error;
7474

PC/msvcrtmodule.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static long
167167
msvcrt_open_osfhandle_impl(PyObject *module, intptr_t handle, int flags)
168168
/*[clinic end generated code: output=cede871bf939d6e3 input=cb2108bbea84514e]*/
169169
{
170-
return _Py_open_osfhandle(handle, flags);
170+
return _Py_open_osfhandle((void*)handle, flags);
171171
}
172172

173173
/*[clinic input]
@@ -185,7 +185,7 @@ static intptr_t
185185
msvcrt_get_osfhandle_impl(PyObject *module, int fd)
186186
/*[clinic end generated code: output=7ce761dd0de2b503 input=305900f4bfab76c7]*/
187187
{
188-
return _Py_get_osfhandle(fd);
188+
return (intptr_t)_Py_get_osfhandle(fd);
189189
}
190190

191191
/* Console I/O */

Parser/myreadline.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
205205
if (!Py_LegacyWindowsStdioFlag && sys_stdin == stdin) {
206206
HANDLE hStdIn, hStdErr;
207207

208-
hStdIn = (HANDLE)_Py_get_osfhandle_noraise(fileno(sys_stdin));
209-
hStdErr = (HANDLE)_Py_get_osfhandle_noraise(fileno(stderr));
208+
hStdIn = _Py_get_osfhandle_noraise(fileno(sys_stdin));
209+
hStdErr = _Py_get_osfhandle_noraise(fileno(stderr));
210210

211211
if (_get_console_type(hStdIn) == 'r') {
212212
fflush(sys_stdout);

Python/fileutils.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ _Py_fstat_noraise(int fd, struct _Py_stat_struct *status)
614614
HANDLE h;
615615
int type;
616616

617-
h = (HANDLE)_Py_get_osfhandle_noraise(fd);
617+
h = _Py_get_osfhandle_noraise(fd);
618618

619619
if (h == INVALID_HANDLE_VALUE) {
620620
/* errno is already set by _get_osfhandle, but we also set
@@ -737,7 +737,7 @@ get_inheritable(int fd, int raise)
737737
HANDLE handle;
738738
DWORD flags;
739739

740-
handle = (HANDLE)_Py_get_osfhandle_noraise(fd);
740+
handle = _Py_get_osfhandle_noraise(fd);
741741
if (handle == INVALID_HANDLE_VALUE) {
742742
if (raise)
743743
PyErr_SetFromErrno(PyExc_OSError);
@@ -806,7 +806,7 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
806806
}
807807

808808
#ifdef MS_WINDOWS
809-
handle = (HANDLE)_Py_get_osfhandle_noraise(fd);
809+
handle = _Py_get_osfhandle_noraise(fd);
810810
if (handle == INVALID_HANDLE_VALUE) {
811811
if (raise)
812812
PyErr_SetFromErrno(PyExc_OSError);
@@ -1459,7 +1459,7 @@ _Py_dup(int fd)
14591459
#endif
14601460

14611461
#ifdef MS_WINDOWS
1462-
handle = (HANDLE)_Py_get_osfhandle(fd);
1462+
handle = _Py_get_osfhandle(fd);
14631463
if (handle == INVALID_HANDLE_VALUE)
14641464
return -1;
14651465

@@ -1576,34 +1576,34 @@ _Py_set_blocking(int fd, int blocking)
15761576
return -1;
15771577
}
15781578
#else /* MS_WINDOWS */
1579-
intptr_t
1579+
void*
15801580
_Py_get_osfhandle_noraise(int fd)
15811581
{
15821582
_Py_BEGIN_SUPPRESS_IPH
1583-
return _get_osfhandle(fd);
1583+
return (void*)_get_osfhandle(fd);
15841584
_Py_END_SUPPRESS_IPH
15851585
}
15861586

1587-
intptr_t
1587+
void*
15881588
_Py_get_osfhandle(int fd)
15891589
{
1590-
intptr_t handle = _Py_get_osfhandle_noraise(fd);
1591-
if (handle == (intptr_t)INVALID_HANDLE_VALUE)
1590+
void *handle = _Py_get_osfhandle_noraise(fd);
1591+
if (handle == INVALID_HANDLE_VALUE)
15921592
PyErr_SetFromErrno(PyExc_OSError);
15931593

15941594
return handle;
15951595
}
15961596

15971597
int
1598-
_Py_open_osfhandle_noraise(intptr_t handle, int flags)
1598+
_Py_open_osfhandle_noraise(void *handle, int flags)
15991599
{
16001600
_Py_BEGIN_SUPPRESS_IPH
1601-
return _open_osfhandle(handle, flags);
1601+
return _open_osfhandle((intptr_t)handle, flags);
16021602
_Py_END_SUPPRESS_IPH
16031603
}
16041604

16051605
int
1606-
_Py_open_osfhandle(intptr_t handle, int flags)
1606+
_Py_open_osfhandle(void *handle, int flags)
16071607
{
16081608
int fd = _Py_open_osfhandle_noraise(handle, flags);
16091609
if (fd == -1)

0 commit comments

Comments
 (0)