[pypy-svn] r78885 - in pypy/branch/fast-forward/pypy/module/cpyext: . src test
afa at codespeak.net
afa at codespeak.net
Mon Nov 8 18:10:21 CET 2010
Author: afa
Date: Mon Nov 8 18:10:19 2010
New Revision: 78885
Modified:
pypy/branch/fast-forward/pypy/module/cpyext/longobject.py
pypy/branch/fast-forward/pypy/module/cpyext/src/getargs.c
pypy/branch/fast-forward/pypy/module/cpyext/test/test_longobject.py
Log:
Add PyLong_AsUnsignedLongLongMask, and remove most "#if 0" in getargs.c
Modified: pypy/branch/fast-forward/pypy/module/cpyext/longobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/cpyext/longobject.py (original)
+++ pypy/branch/fast-forward/pypy/module/cpyext/longobject.py Mon Nov 8 18:10:19 2010
@@ -70,6 +70,15 @@
raised."""
return rffi.cast(rffi.ULONGLONG, space.r_ulonglong_w(w_long))
+ at cpython_api([PyObject], rffi.ULONGLONG, error=-1)
+def PyLong_AsUnsignedLongLongMask(space, w_long):
+ """Will first attempt to cast the object to a PyIntObject or
+ PyLongObject, if it is not already one, and then return its value as
+ unsigned long long, without checking for overflow.
+ """
+ num = space.bigint_w(w_long)
+ return num.ulonglongmask()
+
@cpython_api([PyObject, rffi.CArrayPtr(rffi.INT_real)], lltype.Signed,
error=-1)
def PyLong_AsLongAndOverflow(space, w_long, overflow_ptr):
Modified: pypy/branch/fast-forward/pypy/module/cpyext/src/getargs.c
==============================================================================
--- pypy/branch/fast-forward/pypy/module/cpyext/src/getargs.c (original)
+++ pypy/branch/fast-forward/pypy/module/cpyext/src/getargs.c Mon Nov 8 18:10:19 2010
@@ -557,8 +557,6 @@
switch (c) {
case 'b': { /* unsigned byte -- very short int */
- Py_FatalError("'b' unimplemented for PyArg_*\n");
-#if 0
char *p = va_arg(*p_va, char *);
long ival;
if (float_argument_error(arg))
@@ -579,13 +577,10 @@
else
*p = (unsigned char) ival;
break;
-#endif
}
case 'B': {/* byte sized bitfield - both signed and unsigned
values allowed */
- Py_FatalError("'B' unimplemented for PyArg_*\n");
-#if 0
char *p = va_arg(*p_va, char *);
long ival;
if (float_argument_error(arg))
@@ -596,12 +591,9 @@
else
*p = (unsigned char) ival;
break;
-#endif
}
case 'h': {/* signed short int */
- Py_FatalError("'h' unimplemented for PyArg_*\n");
-#if 0
short *p = va_arg(*p_va, short *);
long ival;
if (float_argument_error(arg))
@@ -622,13 +614,10 @@
else
*p = (short) ival;
break;
-#endif
}
case 'H': { /* short int sized bitfield, both signed and
unsigned allowed */
- Py_FatalError("'H' unimplemented for PyArg_*\n");
-#if 0
unsigned short *p = va_arg(*p_va, unsigned short *);
long ival;
if (float_argument_error(arg))
@@ -639,7 +628,6 @@
else
*p = (unsigned short) ival;
break;
-#endif
}
case 'i': {/* signed int */
int *p = va_arg(*p_va, int *);
@@ -665,8 +653,6 @@
}
case 'I': { /* int sized bitfield, both signed and
unsigned allowed */
- Py_FatalError("'I' unimplemented for PyArg_*\n");
-#if 0
unsigned int *p = va_arg(*p_va, unsigned int *);
unsigned int ival;
if (float_argument_error(arg))
@@ -677,7 +663,6 @@
else
*p = ival;
break;
-#endif
}
case 'n': /* Py_ssize_t */
#if SIZEOF_SIZE_T != SIZEOF_LONG
@@ -708,8 +693,6 @@
}
case 'k': { /* long sized bitfield */
- Py_FatalError("'k' unimplemented for PyArg_*\n");
-#if 0
unsigned long *p = va_arg(*p_va, unsigned long *);
unsigned long ival;
if (PyInt_Check(arg))
@@ -720,13 +703,10 @@
return converterr("integer<k>", arg, msgbuf, bufsize);
*p = ival;
break;
-#endif
}
#ifdef HAVE_LONG_LONG
case 'L': {/* PY_LONG_LONG */
- Py_FatalError("'L' unimplemented for PyArg_*\n");
-#if 0
PY_LONG_LONG *p = va_arg( *p_va, PY_LONG_LONG * );
PY_LONG_LONG ival = PyLong_AsLongLong( arg );
if (ival == (PY_LONG_LONG)-1 && PyErr_Occurred() ) {
@@ -735,12 +715,9 @@
*p = ival;
}
break;
-#endif
}
case 'K': { /* long long sized bitfield */
- Py_FatalError("'K' unimplemented for PyArg_*\n");
-#if 0
unsigned PY_LONG_LONG *p = va_arg(*p_va, unsigned PY_LONG_LONG *);
unsigned PY_LONG_LONG ival;
if (PyInt_Check(arg))
@@ -751,7 +728,6 @@
return converterr("integer<K>", arg, msgbuf, bufsize);
*p = ival;
break;
-#endif
}
#endif // HAVE_LONG_LONG
@@ -777,8 +753,6 @@
#ifndef WITHOUT_COMPLEX
case 'D': {/* complex double */
- Py_FatalError("'D' unimplemented for PyArg_*\n");
-#if 0
Py_complex *p = va_arg(*p_va, Py_complex *);
Py_complex cval;
cval = PyComplex_AsCComplex(arg);
@@ -787,7 +761,6 @@
else
*p = cval;
break;
-#endif
}
#endif /* WITHOUT_COMPLEX */
@@ -985,8 +958,6 @@
break;
}
case 'e': {/* encoded string */
- Py_FatalError("'e' unimplemented for PyArg_*\n");
-#if 0
char **buffer;
const char *encoding;
PyObject *s;
@@ -1150,7 +1121,6 @@
}
Py_DECREF(s);
break;
-#endif
}
#ifdef Py_USING_UNICODE
Modified: pypy/branch/fast-forward/pypy/module/cpyext/test/test_longobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/cpyext/test/test_longobject.py (original)
+++ pypy/branch/fast-forward/pypy/module/cpyext/test/test_longobject.py Mon Nov 8 18:10:19 2010
@@ -64,8 +64,11 @@
assert api.PyErr_Occurred()
api.PyErr_Clear()
+ assert api.PyLong_AsUnsignedLongLongMask(
+ space.wrap(1<<64)) == 0
+
def test_as_long_and_overflow(self, space, api):
- overflow = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
+ overflow = lltype.malloc(rffi.CArrayPtr(rffi.INT_real).TO, 1, flavor='raw')
assert api.PyLong_AsLongAndOverflow(
space.wrap(sys.maxint), overflow) == sys.maxint
assert api.PyLong_AsLongAndOverflow(
@@ -75,7 +78,7 @@
lltype.free(overflow, flavor='raw')
def test_as_longlong_and_overflow(self, space, api):
- overflow = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
+ overflow = lltype.malloc(rffi.CArrayPtr(rffi.INT_real).TO, 1, flavor='raw')
assert api.PyLong_AsLongLongAndOverflow(
space.wrap(1<<62), overflow) == 1<<62
assert api.PyLong_AsLongLongAndOverflow(
More information about the Pypy-commit
mailing list