[pypy-commit] pypy default: cpyext: Fix order of slots which lead to the same __method__ name.
amauryfa
noreply at buildbot.pypy.org
Thu Feb 16 22:32:23 CET 2012
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch:
Changeset: r52573:59a514e97b66
Date: 2012-02-16 22:24 +0100
http://bitbucket.org/pypy/pypy/changeset/59a514e97b66/
Log: cpyext: Fix order of slots which lead to the same __method__ name.
First Number slots, then Mapping and Sequence.
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
@@ -185,6 +185,15 @@
space.fromcache(State).check_and_raise_exception(always=True)
return space.wrap(res)
+def wrap_delitem(space, w_self, w_args, func):
+ func_target = rffi.cast(objobjargproc, func)
+ check_num_args(space, w_args, 1)
+ w_key, = space.fixedview(w_args)
+ res = generic_cpy_call(space, func_target, w_self, w_key, None)
+ if rffi.cast(lltype.Signed, res) == -1:
+ space.fromcache(State).check_and_raise_exception(always=True)
+ return space.w_None
+
def wrap_ssizessizeargfunc(space, w_self, w_args, func):
func_target = rffi.cast(ssizessizeargfunc, func)
check_num_args(space, w_args, 2)
@@ -640,6 +649,19 @@
TPSLOT("__buffer__", "tp_as_buffer.c_bf_getreadbuffer", None, "wrap_getreadbuffer", ""),
)
+# partial sort to solve some slot conflicts:
+# Number slots before Mapping slots before Sequence slots.
+# These are the only conflicts between __name__ methods
+def slotdef_sort_key(slotdef):
+ if slotdef.slot_name.startswith('tp_as_number'):
+ return 1
+ if slotdef.slot_name.startswith('tp_as_mapping'):
+ return 2
+ if slotdef.slot_name.startswith('tp_as_sequence'):
+ return 3
+ return 0
+slotdefs = sorted(slotdefs, key=slotdef_sort_key)
+
slotdefs_for_tp_slots = unrolling_iterable(
[(x.method_name, x.slot_name, x.slot_names, x.slot_func)
for x in slotdefs])
diff --git a/pypy/module/cpyext/test/test_arraymodule.py b/pypy/module/cpyext/test/test_arraymodule.py
--- a/pypy/module/cpyext/test/test_arraymodule.py
+++ b/pypy/module/cpyext/test/test_arraymodule.py
@@ -43,6 +43,15 @@
assert arr[:2].tolist() == [1,2]
assert arr[1:3].tolist() == [2,3]
+ def test_slice_object(self):
+ module = self.import_module(name='array')
+ arr = module.array('i', [1,2,3,4])
+ assert arr[slice(1,3)].tolist() == [2,3]
+ arr[slice(1,3)] = module.array('i', [21, 22, 23])
+ assert arr.tolist() == [1, 21, 22, 23, 4]
+ del arr[slice(1, 3)]
+ assert arr.tolist() == [1, 23, 4]
+
def test_buffer(self):
module = self.import_module(name='array')
arr = module.array('i', [1,2,3,4])
More information about the pypy-commit
mailing list