Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 79248aa

Browse files
committed
SF bug [#456252] Python should never stomp on [u]intptr_t.
pyport.h: typedef a new Py_intptr_t type. DELICATE ASSUMPTION: That HAVE_UINTPTR_T implies intptr_t is available as well as uintptr_t. If that turns out not to be true, things must get uglier (C99 wants both, so I think it's an assumption we're *likely* to get away with). thread_nt.h, PyThread_start_new_thread: MS _beginthread is documented as returning unsigned long; no idea why uintptr_t was being used. Others: Always use Py_[u]intptr_t, never [u]intptr_t directly.
1 parent 1936745 commit 79248aa

6 files changed

Lines changed: 22 additions & 17 deletions

File tree

Include/pyport.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,25 @@ Used in: LONG_LONG
6363

6464
/* uintptr_t is the C9X name for an unsigned integral type such that a
6565
* legitimate void* can be cast to uintptr_t and then back to void* again
66-
* without loss of information.
66+
* without loss of information. Similarly for intptr_t, wrt a signed
67+
* integral type.
6768
*/
6869
#ifdef HAVE_UINTPTR_T
69-
typedef uintptr_t Py_uintptr_t;
70+
typedef uintptr_t Py_uintptr_t;
71+
typedef intptr_t Py_intptr_t;
72+
7073
#elif SIZEOF_VOID_P <= SIZEOF_INT
71-
typedef unsigned int Py_uintptr_t;
74+
typedef unsigned int Py_uintptr_t;
75+
typedef int Py_intptr_t;
76+
7277
#elif SIZEOF_VOID_P <= SIZEOF_LONG
73-
typedef unsigned long Py_uintptr_t;
78+
typedef unsigned long Py_uintptr_t;
79+
typedef long Py_intptr_t;
80+
7481
#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)
75-
typedef unsigned LONG_LONG Py_uintptr_t;
82+
typedef unsigned LONG_LONG Py_uintptr_t;
83+
typedef LONG_LONG Py_intptr_t;
84+
7685
#else
7786
# error "Python needs a typedef for Py_uintptr_t in pyport.h."
7887
#endif /* HAVE_UINTPTR_T */

Modules/posixmodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ posix_spawnv(PyObject *self, PyObject *args)
15511551
PyObject *argv;
15521552
char **argvlist;
15531553
int mode, i, argc;
1554-
intptr_t spawnval;
1554+
Py_intptr_t spawnval;
15551555
PyObject *(*getitem)(PyObject *, int);
15561556

15571557
/* spawnv has three arguments: (mode, path, argv), where
@@ -1620,7 +1620,7 @@ posix_spawnve(PyObject *self, PyObject *args)
16201620
char **envlist;
16211621
PyObject *key, *val, *keys=NULL, *vals=NULL, *res=NULL;
16221622
int mode, i, pos, argc, envc;
1623-
intptr_t spawnval;
1623+
Py_intptr_t spawnval;
16241624
PyObject *(*getitem)(PyObject *, int);
16251625

16261626
/* spawnve has four arguments: (mode, path, argv, env), where
@@ -3689,8 +3689,8 @@ posix_pipe(PyObject *self, PyObject *args)
36893689
Py_END_ALLOW_THREADS
36903690
if (!ok)
36913691
return win32_error("CreatePipe", NULL);
3692-
read_fd = _open_osfhandle((intptr_t)read, 0);
3693-
write_fd = _open_osfhandle((intptr_t)write, 1);
3692+
read_fd = _open_osfhandle((Py_intptr_t)read, 0);
3693+
write_fd = _open_osfhandle((Py_intptr_t)write, 1);
36943694
return Py_BuildValue("(ii)", read_fd, write_fd);
36953695
#endif /* MS_WIN32 */
36963696
#endif

Modules/socketmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ PySocketSock_makefile(PySocketSockObject *s, PyObject *args)
14231423
char *mode = "r";
14241424
int bufsize = -1;
14251425
#ifdef MS_WIN32
1426-
intptr_t fd;
1426+
Py_intptr_t fd;
14271427
#else
14281428
int fd;
14291429
#endif

PC/msvcrtmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static PyObject *
9898
msvcrt_get_osfhandle(PyObject *self, PyObject *args)
9999
{
100100
int fd;
101-
intptr_t handle;
101+
Py_intptr_t handle;
102102

103103
if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd))
104104
return NULL;

PC/pyconfig.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,6 @@ typedef int pid_t;
294294
#if _MSC_VER >= 1200 /* This file only exists in VC 6.0 or higher */
295295
#include <basetsd.h>
296296
#endif
297-
#if defined(MS_WINDOWS) && !defined(MS_WIN64)
298-
typedef long intptr_t;
299-
typedef unsigned long uintptr_t;
300-
#endif
301297

302298
#if defined(MS_WIN64)
303299
/* maintain "win32" sys.platform for backward compatibility of Python code,

Python/thread_nt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static void PyThread__init_thread(void)
152152
*/
153153
int PyThread_start_new_thread(void (*func)(void *), void *arg)
154154
{
155-
uintptr_t rv;
155+
unsigned long rv;
156156
int success = 0;
157157

158158
dprintf(("%ld: PyThread_start_new_thread called\n", PyThread_get_thread_ident()));
@@ -161,7 +161,7 @@ int PyThread_start_new_thread(void (*func)(void *), void *arg)
161161

162162
rv = _beginthread(func, 0, arg); /* use default stack size */
163163

164-
if (rv != -1) {
164+
if (rv != (unsigned long)-1) {
165165
success = 1;
166166
dprintf(("%ld: PyThread_start_new_thread succeeded: %p\n", PyThread_get_thread_ident(), rv));
167167
}

0 commit comments

Comments
 (0)