[pypy-svn] r36018 - in pypy/dist/pypy: rlib/rctypes rlib/rctypes/test rpython

arigo at codespeak.net arigo at codespeak.net
Thu Dec 28 13:12:14 CET 2006


Author: arigo
Date: Thu Dec 28 13:12:12 2006
New Revision: 36018

Modified:
   pypy/dist/pypy/rlib/rctypes/rprimitive.py
   pypy/dist/pypy/rlib/rctypes/test/test_rprimitive.py
   pypy/dist/pypy/rpython/controllerentry.py
   pypy/dist/pypy/rpython/rcontrollerentry.py
Log:
- is_true support.
- fix float support.


Modified: pypy/dist/pypy/rlib/rctypes/rprimitive.py
==============================================================================
--- pypy/dist/pypy/rlib/rctypes/rprimitive.py	(original)
+++ pypy/dist/pypy/rlib/rctypes/rprimitive.py	Thu Dec 28 13:12:12 2006
@@ -37,7 +37,7 @@
         CTypeController.__init__(self, ctype)
         self.VALUETYPE = ctypes_annotation_list[ctype]
         self.RETTYPE   = return_lltype(self.VALUETYPE)
-        self.is_integer_type = isinstance(self.VALUETYPE, lltype.Number)
+        self.is_char_type = self.VALUETYPE in (lltype.Char, lltype.UniChar)
         self.knowntype = rctypesobject.Primitive(self.VALUETYPE)
 
     def new(self, *initialvalue):
@@ -58,9 +58,9 @@
     get_value._annspecialcase_ = 'specialize:arg(0)'
 
     def set_value(self, obj, value):
-        # for integer types, any integer is accepted and silently cast
-        if not self.is_integer_type:
-            # otherwise, check that we got the correct type of 'value'
+        # for integer and float types, any integer is accepted and silently
+        # cast.  For char types, do a precise check
+        if self.is_char_type:
             if lltype.typeOf(value) != self.RETTYPE:
                 raise TypeError("'value' must be set to a %s" % (
                     self.RETTYPE,))
@@ -72,6 +72,13 @@
     # they are returned by most operations
     return_value = get_value
 
+    def is_true(self, obj):
+        llvalue = self.get_value(obj)
+        if self.is_char_type:
+            llvalue = ord(llvalue)
+        return bool(llvalue)
+    is_true._annspecialcase_ = 'specialize:arg(0)'
+
 
 for _ctype in ctypes_annotation_list:
     PrimitiveCTypeController.register_for_type(_ctype)

Modified: pypy/dist/pypy/rlib/rctypes/test/test_rprimitive.py
==============================================================================
--- pypy/dist/pypy/rlib/rctypes/test/test_rprimitive.py	(original)
+++ pypy/dist/pypy/rlib/rctypes/test/test_rprimitive.py	Thu Dec 28 13:12:12 2006
@@ -284,7 +284,6 @@
         interpret(func, [])
 
     def test_truth_value(self):
-        py.test.skip("in-progress")
         bigzero = r_ulonglong(0)
         big = r_ulonglong(2L**42)
         def func(n, z):

Modified: pypy/dist/pypy/rpython/controllerentry.py
==============================================================================
--- pypy/dist/pypy/rpython/controllerentry.py	(original)
+++ pypy/dist/pypy/rpython/controllerentry.py	Thu Dec 28 13:12:12 2006
@@ -89,6 +89,13 @@
         from pypy.rpython.rcontrollerentry import rtypedelegate
         return rtypedelegate(self.setitem, hop)
 
+    def ctrl_is_true(self, s_obj):
+        return delegate(self.is_true, s_obj)
+
+    def rtype_is_true(self, hop):
+        from pypy.rpython.rcontrollerentry import rtypedelegate
+        return rtypedelegate(self.is_true, hop)
+
 
 def delegate(boundmethod, *args_s):
     bk = getbookkeeper()
@@ -124,6 +131,9 @@
         assert s_attr.is_constant()
         s_cin.controller.ctrl_setattr(s_cin.s_real_obj, s_attr, s_value)
 
+    def is_true(s_cin):
+        return s_cin.controller.ctrl_is_true(s_cin.s_real_obj)
+
 
 class __extend__(pairtype(SomeControlledInstance, annmodel.SomeObject)):
 

Modified: pypy/dist/pypy/rpython/rcontrollerentry.py
==============================================================================
--- pypy/dist/pypy/rpython/rcontrollerentry.py	(original)
+++ pypy/dist/pypy/rpython/rcontrollerentry.py	Thu Dec 28 13:12:12 2006
@@ -23,6 +23,9 @@
     def rtype_setattr(self, hop):
         return self.controller.rtype_setattr(hop)
 
+    def rtype_is_true(self, hop):
+        return self.controller.rtype_is_true(hop)
+
 
 class __extend__(pairtype(ControlledInstanceRepr, Repr)):
 



More information about the Pypy-commit mailing list