Author: Amaury Forgeot d'Arc <[email protected]>
Branch:
Changeset: r91188:5b724c72fb87
Date: 2017-05-01 02:07 +0200
http://bitbucket.org/pypy/pypy/changeset/5b724c72fb87/
Log: Populate tp_descr_get and tp_descr_set slots
diff --git a/pypy/module/cpyext/test/test_userslots.py
b/pypy/module/cpyext/test/test_userslots.py
--- a/pypy/module/cpyext/test/test_userslots.py
+++ b/pypy/module/cpyext/test/test_userslots.py
@@ -47,6 +47,33 @@
w_year = space.getattr(w_obj, space.newtext('year'))
assert space.int_w(w_year) == 1
+ def test_descr_slots(self, space, api):
+ w_descr = space.appexec([], """():
+ class Descr(object):
+ def __get__(self, obj, type):
+ return 42
+ def __set__(self, obj, value):
+ obj.append('set')
+ def __delete__(self, obj):
+ obj.append('del')
+ return Descr()
+ """)
+ w_descrtype = space.type(w_descr)
+ py_descr = make_ref(space, w_descr)
+ py_descrtype = rffi.cast(PyTypeObjectPtr, make_ref(space, w_descrtype))
+ w_obj = space.newlist([])
+ py_obj = make_ref(space, w_obj)
+ w_res = generic_cpy_call(space, py_descrtype.c_tp_descr_get,
+ py_descr, py_obj, py_obj)
+ assert space.int_w(w_res) == 42
+ assert generic_cpy_call(
+ space, py_descrtype.c_tp_descr_set,
+ py_descr, py_obj, make_ref(space, space.w_None)) == 0
+ assert generic_cpy_call(
+ space, py_descrtype.c_tp_descr_set,
+ py_descr, py_obj, None) == 0
+ assert space.eq_w(w_obj, space.wrap(['set', 'del']))
+
class AppTestUserSlots(AppTestCpythonExtensionBase):
def test_tp_hash_from_python(self):
# to see that the functions are being used,
diff --git a/pypy/module/cpyext/userslot.py b/pypy/module/cpyext/userslot.py
--- a/pypy/module/cpyext/userslot.py
+++ b/pypy/module/cpyext/userslot.py
@@ -109,4 +109,14 @@
def slot_tp_getattr(space, w_obj1, w_obj2):
return space.getattr(w_obj1, w_obj2)
+@slot_function([PyObject, PyObject, PyObject], PyObject)
+def slot_tp_descr_get(space, w_self, w_obj, w_type):
+ return space.get(w_self, w_obj, w_type)
+@slot_function([PyObject, PyObject, PyObject], rffi.INT_real, error=-1)
+def slot_tp_descr_set(space, w_self, w_obj, w_value):
+ if w_value is not None:
+ space.set(w_self, w_obj, w_value)
+ else:
+ space.delete(w_self, w_obj)
+ return 0
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit