summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2004-09-20 06:17:46 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2004-09-20 06:17:46 (GMT)
commit729d47db091f33ab366be2e43d7bee17f06d10d7 (patch)
tree712d94615c69815affc7f9961963afba96dcb74e /Objects
parentf13337dd387d323a875f0d45a95c5974066cc225 (diff)
downloadcpython-729d47db091f33ab366be2e43d7bee17f06d10d7.zip
cpython-729d47db091f33ab366be2e43d7bee17f06d10d7.tar.gz
cpython-729d47db091f33ab366be2e43d7bee17f06d10d7.tar.bz2
Patch #1024670: Support int objects in PyLong_AsUnsignedLong[Mask].
Diffstat (limited to 'Objects')
-rw-r--r--Objects/longobject.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 0103e5c..0ee9a69 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;
}