]> granicus.if.org Git - python/commitdiff
SF bug [#456252] Python should never stomp on [u]intptr_t.
authorTim Peters <tim.peters@gmail.com>
Wed, 29 Aug 2001 21:37:10 +0000 (21:37 +0000)
committerTim Peters <tim.peters@gmail.com>
Wed, 29 Aug 2001 21:37:10 +0000 (21:37 +0000)
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.

Include/pyport.h
Modules/posixmodule.c
Modules/socketmodule.c
PC/msvcrtmodule.c
PC/pyconfig.h
Python/thread_nt.h

index 176e21ed5e01b05dcc44039b27916cddf9da940e..aa9c1f71703bb79767c55aba470384aa41c92f78 100644 (file)
@@ -63,16 +63,25 @@ Used in:  LONG_LONG
 
 /* uintptr_t is the C9X name for an unsigned integral type such that a
  * legitimate void* can be cast to uintptr_t and then back to void* again
- * without loss of information.
+ * without loss of information.  Similarly for intptr_t, wrt a signed
+ * integral type.
  */
 #ifdef HAVE_UINTPTR_T
-typedef uintptr_t Py_uintptr_t;
+typedef uintptr_t      Py_uintptr_t;
+typedef intptr_t       Py_intptr_t;
+
 #elif SIZEOF_VOID_P <= SIZEOF_INT
-typedef unsigned int Py_uintptr_t;
+typedef unsigned int   Py_uintptr_t;
+typedef int            Py_intptr_t;
+
 #elif SIZEOF_VOID_P <= SIZEOF_LONG
-typedef unsigned long Py_uintptr_t;
+typedef unsigned long  Py_uintptr_t;
+typedef long           Py_intptr_t;
+
 #elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)
-typedef unsigned LONG_LONG Py_uintptr_t;
+typedef unsigned LONG_LONG     Py_uintptr_t;
+typedef LONG_LONG              Py_intptr_t;
+
 #else
 #   error "Python needs a typedef for Py_uintptr_t in pyport.h."
 #endif /* HAVE_UINTPTR_T */
index c1ec84a13e9fcc624e3b7943f4dba2df9c031c6d..5f6f21d39f9d0b232d23f22532505647aa59edec 100644 (file)
@@ -1551,7 +1551,7 @@ posix_spawnv(PyObject *self, PyObject *args)
        PyObject *argv;
        char **argvlist;
        int mode, i, argc;
-       intptr_t spawnval;
+       Py_intptr_t spawnval;
        PyObject *(*getitem)(PyObject *, int);
 
        /* spawnv has three arguments: (mode, path, argv), where
@@ -1620,7 +1620,7 @@ posix_spawnve(PyObject *self, PyObject *args)
        char **envlist;
        PyObject *key, *val, *keys=NULL, *vals=NULL, *res=NULL;
        int mode, i, pos, argc, envc;
-       intptr_t spawnval;
+       Py_intptr_t spawnval;
        PyObject *(*getitem)(PyObject *, int);
 
        /* spawnve has four arguments: (mode, path, argv, env), where
@@ -3689,8 +3689,8 @@ posix_pipe(PyObject *self, PyObject *args)
        Py_END_ALLOW_THREADS
        if (!ok)
                return win32_error("CreatePipe", NULL);
-       read_fd = _open_osfhandle((intptr_t)read, 0);
-       write_fd = _open_osfhandle((intptr_t)write, 1);
+       read_fd = _open_osfhandle((Py_intptr_t)read, 0);
+       write_fd = _open_osfhandle((Py_intptr_t)write, 1);
        return Py_BuildValue("(ii)", read_fd, write_fd);
 #endif /* MS_WIN32 */
 #endif
index 46ca35fa40906deac9b28c1f2428c024b80b3151..4ddaf9c969d21b84d45fb5de01a1232050d75aec 100644 (file)
@@ -1423,7 +1423,7 @@ PySocketSock_makefile(PySocketSockObject *s, PyObject *args)
        char *mode = "r";
        int bufsize = -1;
 #ifdef MS_WIN32
-       intptr_t fd;
+       Py_intptr_t fd;
 #else
        int fd;
 #endif
index 2714458d2f21b7b162a48ac81816362ff0c2ead3..45843702367b059dffa6e1b91d3c9dc7be216ce3 100755 (executable)
@@ -98,7 +98,7 @@ static PyObject *
 msvcrt_get_osfhandle(PyObject *self, PyObject *args)
 {
        int fd;
-       intptr_t handle;
+       Py_intptr_t handle;
 
        if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd))
                return NULL;
index 1e279edc656de8cd74efa56f9eb9f27f9a41080b..f2876056b9e9fbbae50e3889fdcdf9bdd01756a2 100644 (file)
@@ -294,10 +294,6 @@ typedef int pid_t;
 #if _MSC_VER >= 1200 /* This file only exists in VC 6.0 or higher */
 #include <basetsd.h>
 #endif
-#if defined(MS_WINDOWS) && !defined(MS_WIN64)
-typedef long intptr_t;
-typedef unsigned long uintptr_t;
-#endif
 
 #if defined(MS_WIN64)
 /* maintain "win32" sys.platform for backward compatibility of Python code,
index f32304f175fe16fd924ee5d6b19ae08266b44ce1..1d276274eb4cfdb3271f220a4712c9319799dcbb 100644 (file)
@@ -152,7 +152,7 @@ static void PyThread__init_thread(void)
  */
 int PyThread_start_new_thread(void (*func)(void *), void *arg)
 {
-       uintptr_t rv;
+       unsigned long rv;
        int success = 0;
 
        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)
 
        rv = _beginthread(func, 0, arg); /* use default stack size */
  
-       if (rv != -1) {
+       if (rv != (unsigned long)-1) {
                success = 1;
                dprintf(("%ld: PyThread_start_new_thread succeeded: %p\n", PyThread_get_thread_ident(), rv));
        }