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:18:07 2012 +0300 @@ -935,17 +935,20 @@ PyObject * PyLong_FromVoidPtr(void *p) { + /* special-case null pointer */ + if (!p) + return PyLong_FromLong(0); +#if SIZEOF_VOID_P <= SIZEOF_LONG + 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 #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); - +#endif /* SIZEOF_VOID_P <= SIZEOF_LONG */ } /* Get a C pointer from a long int object. */ @@ -977,6 +980,9 @@ #endif /* SIZEOF_VOID_P <= SIZEOF_LONG */ + /* special-case null pointer */ + if (!x) + return NULL; if (x == -1 && PyErr_Occurred()) return NULL; return (void *)x;