[pypy-commit] pypy default: Test and fix for issue1107: "x in y" must return a bool.
arigo
noreply at buildbot.pypy.org
Mon Apr 2 10:51:38 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r54144:849cc68d148d
Date: 2012-04-02 10:47 +0200
http://bitbucket.org/pypy/pypy/changeset/849cc68d148d/
Log: Test and fix for issue1107: "x in y" must return a bool.
diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -167,6 +167,7 @@
if rffi.cast(lltype.Signed, res) == -1:
space.fromcache(State).check_and_raise_exception(always=True)
+# Warning, confusing function name (like CPython). Used only for sq_contains.
def wrap_objobjproc(space, w_self, w_args, func):
func_target = rffi.cast(objobjproc, func)
check_num_args(space, w_args, 1)
@@ -174,7 +175,7 @@
res = generic_cpy_call(space, func_target, w_self, w_value)
if rffi.cast(lltype.Signed, res) == -1:
space.fromcache(State).check_and_raise_exception(always=True)
- return space.wrap(res)
+ return space.wrap(bool(res))
def wrap_objobjargproc(space, w_self, w_args, func):
func_target = rffi.cast(objobjargproc, func)
diff --git a/pypy/module/cpyext/test/test_typeobject.py b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -432,6 +432,34 @@
res = obj.__setitem__('foo', None)
assert res is None
+ def test_sq_contains(self):
+ module = self.import_extension('foo', [
+ ("new_obj", "METH_NOARGS",
+ '''
+ PyObject *obj;
+ Foo_Type.tp_as_sequence = &tp_as_sequence;
+ tp_as_sequence.sq_contains = sq_contains;
+ if (PyType_Ready(&Foo_Type) < 0) return NULL;
+ obj = PyObject_New(PyObject, &Foo_Type);
+ return obj;
+ '''
+ )],
+ '''
+ static int
+ sq_contains(PyObject *self, PyObject *value)
+ {
+ return 42;
+ }
+ PySequenceMethods tp_as_sequence;
+ static PyTypeObject Foo_Type = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "foo.foo",
+ };
+ ''')
+ obj = module.new_obj()
+ res = "foo" in obj
+ assert res is True
+
def test_tp_iter(self):
module = self.import_extension('foo', [
("tp_iter", "METH_O",
More information about the pypy-commit
mailing list