[pypy-svn] r25999 - in pypy/dist/pypy/rpython: . rctypes rctypes/test

arigo at codespeak.net arigo at codespeak.net
Wed Apr 19 20:50:55 CEST 2006


Author: arigo
Date: Wed Apr 19 20:50:53 2006
New Revision: 25999

Modified:
   pypy/dist/pypy/rpython/rctypes/rpyobject.py
   pypy/dist/pypy/rpython/rctypes/test/test_rpyobject.py
   pypy/dist/pypy/rpython/rfloat.py
Log:
Assigning to .value on py_object instances.
Cannot read .value: this couldn't be properly annotated
without falling back to SomeObjects!


Modified: pypy/dist/pypy/rpython/rctypes/rpyobject.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/rpyobject.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/rpyobject.py	Wed Apr 19 20:50:53 2006
@@ -1,7 +1,17 @@
 from pypy.rpython.rmodel import inputconst
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.rctypes.rmodel import CTypesValueRepr
+from pypy.rpython.robject import pyobj_repr
 
 
 class CTypesPyObjRepr(CTypesValueRepr):
-    pass
+
+    # reading .value is not allowed, as it can't be annotated!
+
+    def rtype_setattr(self, hop):
+        s_attr = hop.args_s[1]
+        assert s_attr.is_constant()
+        assert s_attr.const == 'value'
+        v_pyobj, v_attr, v_newvalue = hop.inputargs(self, lltype.Void,
+                                                    pyobj_repr)
+        self.setvalue(hop.llops, v_pyobj, v_newvalue)

Modified: pypy/dist/pypy/rpython/rctypes/test/test_rpyobject.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/test/test_rpyobject.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/test/test_rpyobject.py	Wed Apr 19 20:50:53 2006
@@ -54,3 +54,12 @@
         res = interpret(wrap, [9])
         assert lltype.typeOf(res.c_data[0]) == lltype.Ptr(lltype.PyObject)
         assert res.c_data[0]._obj.value == 9
+
+    def test_specialize_ass_value(self):
+        # reading .value is not allowed, as it can't be annotated!
+        def func(x):
+            o = py_object()
+            o.value = x
+
+        interpret(func, [9])
+        interpret(func, [9.2])

Modified: pypy/dist/pypy/rpython/rfloat.py
==============================================================================
--- pypy/dist/pypy/rpython/rfloat.py	(original)
+++ pypy/dist/pypy/rpython/rfloat.py	Wed Apr 19 20:50:53 2006
@@ -1,7 +1,7 @@
 from pypy.annotation.pairtype import pairtype
 from pypy.annotation import model as annmodel
 from pypy.rpython.lltypesystem.lltype import \
-     Signed, Unsigned, Bool, Float, Void
+     Signed, Unsigned, Bool, Float, Void, pyobjectptr
 from pypy.rpython.error import TyperError
 from pypy.rpython.rmodel import FloatRepr
 from pypy.rpython.rmodel import IntegerRepr, BoolRepr, StringRepr
@@ -198,12 +198,14 @@
     def convert_from_to((r_from, r_to), v, llops):
         if r_to.lowleveltype == Float:
             return llops.gencapicall('PyFloat_AsDouble', [v],
-                                     resulttype=Float)
+                                     resulttype=Float,
+                                   _callable=lambda pyo: float(pyo._obj.value))
         return NotImplemented
 
 class __extend__(pairtype(FloatRepr, PyObjRepr)):
     def convert_from_to((r_from, r_to), v, llops):
         if r_from.lowleveltype == Float:
             return llops.gencapicall('PyFloat_FromDouble', [v],
-                                     resulttype=pyobj_repr)
+                                     resulttype=pyobj_repr,
+                                     _callable=lambda x: pyobjectptr(x))
         return NotImplemented



More information about the Pypy-commit mailing list