Issue #16277: in PyLong_FromVoidPtr, add missing branch for sizeof(void*) <= sizeof...
authorMark Dickinson <mdickinson@enthought.com>
Thu, 18 Oct 2012 18:21:43 +0000 (19:21 +0100)
committerMark Dickinson <mdickinson@enthought.com>
Thu, 18 Oct 2012 18:21:43 +0000 (19:21 +0100)
Objects/longobject.c

index b9a0d8543a63166ea7593b9e9e4d8a2dec7deb84..3a675c4331924054643fe984fca8adfb8a7f915a 100644 (file)
@@ -926,6 +926,13 @@ _PyLong_AsByteArray(PyLongObject* v,
 PyObject *
 PyLong_FromVoidPtr(void *p)
 {
+#if SIZEOF_VOID_P <= SIZEOF_LONG
+    /* special-case null pointer */
+    if (!p)
+        return PyLong_FromLong(0);
+    return PyLong_FromUnsignedLong((unsigned long)(Py_uintptr_t)p);
+#else
+
 #ifndef HAVE_LONG_LONG
 #   error "PyLong_FromVoidPtr: sizeof(void*) > sizeof(long), but no long long"
 #endif
@@ -936,6 +943,7 @@ PyLong_FromVoidPtr(void *p)
     if (!p)
         return PyLong_FromLong(0);
     return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)(Py_uintptr_t)p);
+#endif /* SIZEOF_VOID_P <= SIZEOF_LONG */
 
 }