]> granicus.if.org Git - python/commitdiff
Patch #1024670: Support int objects in PyLong_AsUnsignedLong[Mask].
authorMartin v. Löwis <martin@v.loewis.de>
Mon, 20 Sep 2004 06:17:46 +0000 (06:17 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Mon, 20 Sep 2004 06:17:46 +0000 (06:17 +0000)
Misc/NEWS
Objects/longobject.c

index 4daf763bbba6f714423822584bdbc2e880630dd4..3dac4a87d1f7052a9d07c886d92ee80df2ff06a8 100644 (file)
--- 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
 -----------------
index 0103e5c079eaf98e46fe42a35bb0ee6047e751aa..0ee9a694a99e4903956af3877b2c6164d60f2b92 100644 (file)
@@ -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;
        }