[pypy-svn] pypy default: cpyext: implement PyInt_GetMax() and restore support for longs in Py_BuildValue

amauryfa commits-noreply at bitbucket.org
Wed Mar 23 19:06:21 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r42882:5301744fdfc1
Date: 2011-03-23 18:18 +0100
http://bitbucket.org/pypy/pypy/changeset/5301744fdfc1/

Log:	cpyext: implement PyInt_GetMax() and restore support for longs in
	Py_BuildValue

diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py
--- a/pypy/module/cpyext/stubs.py
+++ b/pypy/module/cpyext/stubs.py
@@ -1751,12 +1751,6 @@
     """
     raise NotImplementedError
 
- at cpython_api([], lltype.Signed, error=CANNOT_FAIL)
-def PyInt_GetMax(space):
-    """Return the system's idea of the largest integer it can handle (LONG_MAX,
-    as defined in the system header files)."""
-    raise NotImplementedError
-
 @cpython_api([], rffi.INT_real, error=CANNOT_FAIL)
 def PyInt_ClearFreeList(space):
     """Clear the integer free list. Return the number of items that could not

diff --git a/pypy/module/cpyext/intobject.py b/pypy/module/cpyext/intobject.py
--- a/pypy/module/cpyext/intobject.py
+++ b/pypy/module/cpyext/intobject.py
@@ -5,9 +5,16 @@
     cpython_api, build_type_checkers, PyObject,
     CONST_STRING, CANNOT_FAIL, Py_ssize_t)
 from pypy.rlib.rarithmetic import r_uint
+import sys
 
 PyInt_Check, PyInt_CheckExact = build_type_checkers("Int")
 
+ at cpython_api([], lltype.Signed, error=CANNOT_FAIL)
+def PyInt_GetMax(space):
+    """Return the system's idea of the largest integer it can handle (LONG_MAX,
+    as defined in the system header files)."""
+    return sys.maxint
+
 @cpython_api([lltype.Signed], PyObject)
 def PyInt_FromLong(space, ival):
     """Create a new integer object with a value of ival.

diff --git a/pypy/module/cpyext/src/modsupport.c b/pypy/module/cpyext/src/modsupport.c
--- a/pypy/module/cpyext/src/modsupport.c
+++ b/pypy/module/cpyext/src/modsupport.c
@@ -241,13 +241,12 @@
 
 		case 'I':
 		{
-      Py_FatalError("I unsupported so far");
-			//unsigned int n;
-			//n = va_arg(*p_va, unsigned int);
-			//if (n > (unsigned long)PyInt_GetMax())
-			//	return PyLong_FromUnsignedLong((unsigned long)n);
-			//else
-			//	return PyInt_FromLong(n);
+			unsigned int n;
+			n = va_arg(*p_va, unsigned int);
+			if (n > (unsigned long)PyInt_GetMax())
+				return PyLong_FromUnsignedLong((unsigned long)n);
+			else
+				return PyInt_FromLong(n);
 		}
 		
 		case 'n':
@@ -260,23 +259,20 @@
 
 		case 'k':
 		{
-      Py_FatalError("Py_BuildValue k unsupported so far\n");
-			/* unsigned long n; */
-			/* n = va_arg(*p_va, unsigned long); */
-			/* if (n > (unsigned long)PyInt_GetMax()) */
-			/* 	return PyLong_FromUnsignedLong(n); */
-			/* else */
-			/* 	return PyInt_FromLong(n); */
+			unsigned long n;
+			n = va_arg(*p_va, unsigned long);
+			if (n > (unsigned long)PyInt_GetMax())
+				return PyLong_FromUnsignedLong(n);
+			else
+				return PyInt_FromLong(n);
 		}
 
 #ifdef HAVE_LONG_LONG
 		case 'L':
-      Py_FatalError("Py_BuildValue L unsupported for now\n");
-			//return PyLong_FromLongLong((PY_LONG_LONG)va_arg(*p_va, PY_LONG_LONG));
+			return PyLong_FromLongLong((PY_LONG_LONG)va_arg(*p_va, PY_LONG_LONG));
 
 		case 'K':
-      Py_FatalError("Py_BuildValue K unsupported for now\n");
-			//return PyLong_FromUnsignedLongLong((PY_LONG_LONG)va_arg(*p_va, unsigned PY_LONG_LONG));
+			return PyLong_FromUnsignedLongLong((PY_LONG_LONG)va_arg(*p_va, unsigned PY_LONG_LONG));
 #endif
 #ifdef Py_USING_UNICODE
 		case 'u':


More information about the Pypy-commit mailing list