diff -r a45cb181e4d0 Objects/longobject.c --- a/Objects/longobject.c Wed Oct 17 20:29:07 2012 -0700 +++ b/Objects/longobject.c Thu Oct 18 22:03:11 2012 +0300 @@ -935,17 +935,19 @@ PyObject * PyLong_FromVoidPtr(void *p) { + /* always convert NULL to 0 */ + Py_uintptr_t x = (Py_uintptr_t)p - (Py_uintptr_t)(void *)NULL; +#if SIZEOF_VOID_P <= SIZEOF_LONG + return PyLong_FromUnsignedLong((unsigned long)x); +#else #ifndef HAVE_LONG_LONG # error "PyLong_FromVoidPtr: sizeof(void*) > sizeof(long), but no long long" #endif #if SIZEOF_LONG_LONG < SIZEOF_VOID_P # error "PyLong_FromVoidPtr: sizeof(PY_LONG_LONG) < sizeof(void*)" #endif - /* special-case null pointer */ - if (!p) - return PyLong_FromLong(0); - return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)(Py_uintptr_t)p); - + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)x); +#endif /* SIZEOF_VOID_P <= SIZEOF_LONG */ } /* Get a C pointer from a long int object. */ @@ -979,7 +981,8 @@ if (x == -1 && PyErr_Occurred()) return NULL; - return (void *)x; + /* always convert 0 to NULL */ + return (void *)((Py_uintptr_t)x + (Py_uintptr_t)(void *)NULL); } #ifdef HAVE_LONG_LONG