From: Martin v. Löwis Date: Mon, 20 Sep 2004 06:17:46 +0000 (+0000) Subject: Patch #1024670: Support int objects in PyLong_AsUnsignedLong[Mask]. X-Git-Tag: v2.4b1~232 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=729d47db091f33ab366be2e43d7bee17f06d10d7;p=thirdparty%2FPython%2Fcpython.git Patch #1024670: Support int objects in PyLong_AsUnsignedLong[Mask]. --- diff --git a/Misc/NEWS b/Misc/NEWS index 4daf763bbba6..3dac4a87d1f7 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,7 +12,7 @@ What's New in Python 2.4 beta 1? Core and builtins ----------------- -... +- PyLong_AsUnsignedLong[Mask] now support int objects as well. Extension modules ----------------- diff --git a/Objects/longobject.c b/Objects/longobject.c index 0103e5c079ea..0ee9a694a99e 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -245,6 +245,15 @@ PyLong_AsUnsignedLong(PyObject *vv) int i; if (vv == NULL || !PyLong_Check(vv)) { + if (vv != NULL && PyInt_Check(vv)) { + long val = PyInt_AsLong(vv); + if (val < 0) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned long"); + return (unsigned long) -1; + } + return val; + } PyErr_BadInternalCall(); return (unsigned long) -1; } @@ -279,6 +288,8 @@ PyLong_AsUnsignedLongMask(PyObject *vv) int i, sign; if (vv == NULL || !PyLong_Check(vv)) { + if (vv != NULL && PyInt_Check(vv)) + return PyInt_AsUnsignedLongMask(vv); PyErr_BadInternalCall(); return (unsigned long) -1; }