diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2006-04-10 20:28:17 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2006-04-10 20:28:17 (GMT) |
commit | 0bc2ab9a20745e3cc7a2ca4cc01a3708e273e2dc (patch) | |
tree | 8c4064913b744ff0a8bcd5fbdcac81c5e0bc0dc1 | |
parent | a19dc0beb1d2e499b86f56a992e78e7e3d767ee3 (diff) | |
download | cpython-0bc2ab9a20745e3cc7a2ca4cc01a3708e273e2dc.zip cpython-0bc2ab9a20745e3cc7a2ca4cc01a3708e273e2dc.tar.gz cpython-0bc2ab9a20745e3cc7a2ca4cc01a3708e273e2dc.tar.bz2 |
Patch #837242: id() for large ptr should return a long.
-rw-r--r-- | Doc/api/concrete.tex | 6 | ||||
-rw-r--r-- | Misc/NEWS | 4 | ||||
-rw-r--r-- | Objects/longobject.c | 12 |
3 files changed, 18 insertions, 4 deletions
diff --git a/Doc/api/concrete.tex b/Doc/api/concrete.tex index 98e0e03..1982bae 100644 --- a/Doc/api/concrete.tex +++ b/Doc/api/concrete.tex @@ -333,7 +333,9 @@ booleans. The following macros are available, however. The pointer value can be retrieved from the resulting value using \cfunction{PyLong_AsVoidPtr()}. \versionadded{1.5.2} -\end{cfuncdesc} + \versionchanged[If the integer is larger than LONG_MAX, + a positive long integer is returned]{2.5} + \end{cfuncdesc} \begin{cfuncdesc}{long}{PyLong_AsLong}{PyObject *pylong} Return a C \ctype{long} representation of the contents of @@ -394,6 +396,8 @@ booleans. The following macros are available, however. produce a usable \ctype{void} pointer for values created with \cfunction{PyLong_FromVoidPtr()}. \versionadded{1.5.2} + \versionchanged[For values outside 0..LONG_MAX, both signed and + unsigned integers are acccepted]{2.5} \end{cfuncdesc} @@ -12,6 +12,10 @@ What's New in Python 2.5 alpha 2? Core and builtins ----------------- +- Patch #837242: id() of any Python object always gives a positive + number, which might be a long integer. PyLong_FromVoidPtr and + PyLong_AsVoidPtr have been changed accordingly. + - Python on OS X 10.3 and above now uses dlopen() (via dynload_shlib.c) to load extension modules and now provides the dl module. As a result, sys.setdlopenflags() now works correctly on these systems. (SF patch diff --git a/Objects/longobject.c b/Objects/longobject.c index 26f78c2..49f5c3b 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -771,6 +771,8 @@ PyObject * PyLong_FromVoidPtr(void *p) { #if SIZEOF_VOID_P <= SIZEOF_LONG + if ((long)p < 0) + return PyLong_FromUnsignedLong((unsigned long)p); return PyInt_FromLong((long)p); #else @@ -783,7 +785,7 @@ PyLong_FromVoidPtr(void *p) /* optimize null pointers */ if (p == NULL) return PyInt_FromLong(0); - return PyLong_FromLongLong((PY_LONG_LONG)p); + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)p); #endif /* SIZEOF_VOID_P <= SIZEOF_LONG */ } @@ -802,8 +804,10 @@ PyLong_AsVoidPtr(PyObject *vv) if (PyInt_Check(vv)) x = PyInt_AS_LONG(vv); - else + else if (PyLong_Check(vv) && _PyLong_Sign(vv) < 0) x = PyLong_AsLong(vv); + else + x = PyLong_AsUnsignedLong(vv); #else #ifndef HAVE_LONG_LONG @@ -816,8 +820,10 @@ PyLong_AsVoidPtr(PyObject *vv) if (PyInt_Check(vv)) x = PyInt_AS_LONG(vv); - else + else if (PyLong_Check(vv) && _PyLong_Sign(vv) < 0) x = PyLong_AsLongLong(vv); + else + x = PyLong_AsUnsignedLongLong(vv); #endif /* SIZEOF_VOID_P <= SIZEOF_LONG */ |