diff Objects/longobject.c @ 33524:30d428f992f9 legacy-trunk

Patch #1024670: Support int objects in PyLong_AsUnsignedLong[Mask].
author Martin v. Löwis <martin@v.loewis.de>
date Mon, 20 Sep 2004 06:17:46 +0000
parents fee592fb5643
children 46300b1aa2f6
line wrap: on
line diff
--- a/Objects/longobject.c	Sun Sep 19 18:36:45 2004 +0000
+++ b/Objects/longobject.c	Mon Sep 20 06:17:46 2004 +0000
@@ -245,6 +245,15 @@
 	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 @@
 	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;
 	}