[pypy-commit] pypy refactor-slots: Add @slot_factory decorator
rlamy
pypy.commits at gmail.com
Mon Oct 2 07:36:24 EDT 2017
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: refactor-slots
Changeset: r92556:901c1e4af3a0
Date: 2017-10-02 13:35 +0200
http://bitbucket.org/pypy/pypy/changeset/901c1e4af3a0/
Log: Add @slot_factory decorator
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
@@ -427,6 +427,14 @@
return space.newint(generic_cpy_call(space, func_target, w_self, w_other))
+SLOT_FACTORIES = {}
+def slot_factory(tp_name):
+ def decorate(func):
+ SLOT_FACTORIES[tp_name] = func
+ return func
+ return decorate
+
+
def build_slot_tp_function(space, typedef, name):
w_type = space.gettypeobject(typedef)
@@ -675,8 +683,8 @@
w_obj = space.w_None
return space.call_function(get_fn, w_self, w_obj, w_value)
slot_func = slot_tp_descr_get
- elif name == 'tp_descr_set':
- return make_tp_descr_set(space, typedef)
+ elif name in SLOT_FACTORIES:
+ return SLOT_FACTORIES[name](space, typedef)
else:
# missing: tp_as_number.nb_nonzero, tp_as_number.nb_coerce
# tp_as_sequence.c_sq_contains, tp_as_sequence.c_sq_length
@@ -685,6 +693,7 @@
return slot_func
+ at slot_factory('tp_descr_set')
def make_tp_descr_set(space, typedef):
w_type = space.gettypeobject(typedef)
name = 'descr_set'
@@ -709,6 +718,7 @@
return 0
return slot_tp_descr_set
+
def slot_from___buffer__(space, typedef, buff_fn):
name = 'bf_getbuffer'
@slot_function([PyObject, Py_bufferP, rffi.INT_real],
More information about the pypy-commit
mailing list