[pypy-svn] r72958 - pypy/branch/cpython-extension/pypy/module/cpyext
xoraxax at codespeak.net
xoraxax at codespeak.net
Sat Mar 27 17:03:48 CET 2010
Author: xoraxax
Date: Sat Mar 27 17:03:46 2010
New Revision: 72958
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/api.py
pypy/branch/cpython-extension/pypy/module/cpyext/tupleobject.py
Log:
Implement 2 tuple functions.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/api.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/api.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/api.py Sat Mar 27 17:03:46 2010
@@ -344,6 +344,10 @@
w_obj_type = space.type(w_obj)
return int(space.is_w(w_obj_type, w_type) or space.is_true(space.issubtype(w_obj_type, w_type)))
+def general_check_exact(space, w_obj, w_type):
+ w_obj_type = space.type(w_obj)
+ return int(space.is_w(w_obj_type, w_type))
+
# Make the wrapper for the cases (1) and (2)
def make_wrapper(space, callable):
def wrapper(*args):
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/tupleobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/tupleobject.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/tupleobject.py Sat Mar 27 17:03:46 2010
@@ -1,6 +1,7 @@
from pypy.rpython.lltypesystem import rffi, lltype
from pypy.module.cpyext.api import cpython_api, PyObject, Py_ssize_t, \
- general_check, CANNOT_FAIL, register_container
+ general_check, CANNOT_FAIL, register_container, \
+ general_check_exact
from pypy.module.cpyext.macros import Py_DECREF
from pypy.module.cpyext.pyerrors import PyErr_BadInternalCall
from pypy.objspace.std.tupleobject import W_TupleObject
@@ -10,6 +11,11 @@
w_type = space.w_tuple
return general_check(space, w_obj, w_type)
+ at cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
+def PyTuple_CheckExact(space, w_obj):
+ w_type = space.w_tuple
+ return general_check_exact(space, w_obj, w_type)
+
@cpython_api([Py_ssize_t], PyObject)
def PyTuple_New(space, size):
return space.newtuple([space.w_None] * size)
@@ -31,3 +37,11 @@
w_obj = w_t.wrappeditems[pos]
register_container(space, w_t)
return w_obj
+
+ at cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL)
+def PyTuple_GET_SIZE(space, w_t):
+ """Return the size of the tuple p, which must be non-NULL and point to a tuple;
+ no error checking is performed. """
+ assert isinstance(w_t, W_TupleObject)
+ return len(w_t.wrappeditems)
+
More information about the Pypy-commit
mailing list