[pypy-svn] r72999 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test
fijal at codespeak.net
fijal at codespeak.net
Sat Mar 27 23:49:33 CET 2010
Author: fijal
Date: Sat Mar 27 23:49:31 2010
New Revision: 72999
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/sequence.py
pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sequence.py
Log:
Implement PySequence_Fast_GET_SIZE
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/sequence.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/sequence.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/sequence.py Sat Mar 27 23:49:31 2010
@@ -32,3 +32,15 @@
register_container(space, w_obj)
return w_res
+ at cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL)
+def PySequence_Fast_GET_SIZE(space, w_obj):
+ """Returns the length of o, assuming that o was returned by
+ PySequence_Fast() and that o is not NULL. The size can also be
+ gotten by calling PySequence_Size() on o, but
+ PySequence_Fast_GET_SIZE() is faster because it can assume o is a list
+ or tuple."""
+ if isinstance(w_obj, listobject.W_ListObject):
+ return len(w_obj.wrappeditems)
+ assert isinstance(w_obj, tupleobject.W_TupleObject)
+ return len(w_obj.wrappeditems)
+
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py Sat Mar 27 23:49:31 2010
@@ -5105,15 +5105,6 @@
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
- at cpython_api([PyObject], Py_ssize_t)
-def PySequence_Fast_GET_SIZE(space, o):
- """Returns the length of o, assuming that o was returned by
- PySequence_Fast() and that o is not NULL. The size can also be
- gotten by calling PySequence_Size() on o, but
- PySequence_Fast_GET_SIZE() is faster because it can assume o is a list
- or tuple."""
- raise NotImplementedError
-
@cpython_api([PyObject], rffi.INT_real)
def PySet_Check(space, p):
"""Return true if p is a set object or an instance of a subtype.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sequence.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sequence.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_sequence.py Sat Mar 27 23:49:31 2010
@@ -18,6 +18,12 @@
return PySequence_Fast_GET_ITEM(lst, index);
'''
),
+ ("fast_getsize", "METH_VARARGS",
+ '''
+ PyObject *lst = PyTuple_GetItem(args, 0);
+ return PyInt_FromLong(PySequence_Fast_GET_SIZE(lst));
+ '''
+ ),
])
t = (1, 2, 3, 4)
assert module.newiter(t) is t
@@ -32,3 +38,4 @@
else:
raise Exception("DID NOT RAISE")
assert module.fast_getitem((1, 2, 3), 1) == 2
+ assert module.fast_getsize([1, 2, 3]) == 3
More information about the Pypy-commit
mailing list