[pypy-svn] r73930 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test
afa at codespeak.net
afa at codespeak.net
Wed Apr 21 02:27:00 CEST 2010
Author: afa
Date: Wed Apr 21 02:26:58 2010
New Revision: 73930
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/object.py
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:
PySequence_Tuple
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/object.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/object.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/object.py Wed Apr 21 02:26:58 2010
@@ -96,14 +96,6 @@
def PyObject_Size(space, w_obj):
return space.int_w(space.len(w_obj))
- at cpython_api([PyObject], Py_ssize_t, error=-1)
-def PySequence_Size(space, w_obj):
- return space.int_w(space.len(w_obj))
-
- at cpython_api([PyObject], Py_ssize_t, error=-1)
-def PySequence_Length(space, w_obj):
- return space.int_w(space.len(w_obj))
-
@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
def PyCallable_Check(space, w_obj):
"""Determine if the object o is callable. Return 1 if the object is callable
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 Wed Apr 21 02:26:58 2010
@@ -21,6 +21,10 @@
Python expression len(o)."""
return space.int_w(space.len(w_obj))
+ at cpython_api([PyObject], Py_ssize_t, error=-1)
+def PySequence_Length(space, w_obj):
+ return space.int_w(space.len(w_obj))
+
@cpython_api([PyObject, CONST_STRING], PyObject)
def PySequence_Fast(space, w_obj, m):
@@ -76,3 +80,10 @@
the Python expression o[i]."""
return space.getitem(w_obj, space.wrap(i))
+ at cpython_api([PyObject], PyObject)
+def PySequence_Tuple(space, w_obj):
+ """Return a tuple object with the same contents as the arbitrary sequence o or
+ NULL on failure. If o is a tuple, a new reference will be returned,
+ otherwise a tuple will be constructed with the appropriate contents. This is
+ equivalent to the Python expression tuple(o)."""
+ return space.call_function(space.w_tuple, w_obj)
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 Wed Apr 21 02:26:58 2010
@@ -4737,18 +4737,6 @@
returned list is guaranteed to be new."""
raise NotImplementedError
- at cpython_api([PyObject], PyObject)
-def PySequence_Tuple(space, o):
- """
-
-
-
- Return a tuple object with the same contents as the arbitrary sequence o or
- NULL on failure. If o is a tuple, a new reference will be returned,
- otherwise a tuple will be constructed with the appropriate contents. This is
- equivalent to the Python expression tuple(o)."""
- raise NotImplementedError
-
@cpython_api([PyObject], PyObjectP)
def PySequence_Fast_ITEMS(space, o):
"""Return the underlying array of PyObject pointers. Assumes that o was returned
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 Wed Apr 21 02:26:58 2010
@@ -18,6 +18,10 @@
assert space.type(w_seq) is space.w_tuple
assert space.int_w(space.len(w_seq)) == 4
+ w_seq = api.PySequence_Tuple(w_set)
+ assert space.type(w_seq) is space.w_tuple
+ assert sorted(space.unwrap(w_seq)) == [1, 2, 3, 4]
+
def test_exception(self, space, api):
message = rffi.str2charp("message")
assert not api.PySequence_Fast(space.wrap(3), message)
More information about the Pypy-commit
mailing list