Author: mattip <[email protected]>
Branch: cpyext-ext
Changeset: r81825:954e2d6bb370
Date: 2016-01-16 22:17 +0200
http://bitbucket.org/pypy/pypy/changeset/954e2d6bb370/

Log:    add make_typedescr for W_GetSetPropertyEx <-> PyGetSetDescrObject
        conversion

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
@@ -59,9 +59,8 @@
             obj = getattr(module.fooType, m)
             docstring = obj.__doc__
             if not docstring:
-                raises(RuntimeError, module.cmp_docstring, obj, 'random')
+                raises(RuntimeError, module.cmp_docstring, obj, 'xxxrandomxxx')
             else:
-                import pdb;pdb.set_trace()
                 module.cmp_docstring(obj, docstring)
         assert str(type(module.fooType.int_member)) == "<type 
'member_descriptor'>"
 
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -117,6 +117,14 @@
 cpython_struct("PyMemberDescrObject", PyMemberDescrObjectFields,
                PyMemberDescrObjectStruct, level=2)
 
+PyGetSetDescrObjectStruct = lltype.ForwardReference()
+PyGetSetDescrObject = lltype.Ptr(PyGetSetDescrObjectStruct)
+PyGetSetDescrObjectFields = PyDescrObjectFields + (
+    ("d_getset", lltype.Ptr(PyGetSetDef)),
+    )
+cpython_struct("PyGetSetDescrObject", PyGetSetDescrObjectFields,
+               PyGetSetDescrObjectStruct, level=2)
+
 @bootstrap_function
 def init_memberdescrobject(space):
     make_typedescr(W_MemberDescr.typedef,
@@ -124,6 +132,10 @@
                    attach=memberdescr_attach,
                    realize=memberdescr_realize,
                    )
+    make_typedescr(W_GetSetPropertyEx.typedef,
+                   basestruct=PyGetSetDescrObject.TO,
+                   attach=getsetdescr_attach,
+                   )
 
 def memberdescr_attach(space, py_obj, w_obj):
     """
@@ -146,6 +158,16 @@
     state.set_lifeline(w_obj, obj)
     return w_obj
 
+def getsetdescr_attach(space, py_obj, w_obj):
+    """
+    Fills a newly allocated PyGetSetDescrObject with the given 
W_GetSetPropertyEx
+    object. The values must not be modified.
+    """
+    py_getsetdescr = rffi.cast(PyGetSetDescrObject, py_obj)
+    # XXX assign to d_dname, d_type?
+    assert isinstance(w_obj, W_GetSetPropertyEx)
+    py_getsetdescr.c_d_getset = w_obj.getset
+
 def convert_getset_defs(space, dict_w, getsets, w_type):
     getsets = rffi.cast(rffi.CArrayPtr(PyGetSetDef), getsets)
     if getsets:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to