[pypy-svn] r50923 - in pypy/dist/pypy/rpython/lltypesystem: . test

fijal at codespeak.net fijal at codespeak.net
Wed Jan 23 15:32:29 CET 2008


Author: fijal
Date: Wed Jan 23 15:32:29 2008
New Revision: 50923

Modified:
   pypy/dist/pypy/rpython/lltypesystem/lltype.py
   pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py
Log:
Some weird cast. Pure-python only right now.


Modified: pypy/dist/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lltype.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/lltype.py	Wed Jan 23 15:32:29 2008
@@ -7,6 +7,7 @@
 from pypy.tool.tls import tlsobject
 from types import NoneType
 from sys import maxint
+import struct
 import weakref
 
 log = py.log.Producer('lltype')
@@ -1772,6 +1773,9 @@
     assert oddint & 1, "only odd integers can be cast back to ptr"
     return _ptr(PTRTYPE, oddint, solid=True)
 
+def cast_float_to_int(val):
+    return struct.unpack('i', struct.pack('f', val))[0]
+
 def attachRuntimeTypeInfo(GCSTRUCT, funcptr=None, destrptr=None):
     if not isinstance(GCSTRUCT, RttiStruct):
         raise TypeError, "expected a RttiStruct: %s" % GCSTRUCT

Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py	Wed Jan 23 15:32:29 2008
@@ -696,6 +696,9 @@
     assert cast_ptr_to_int(t) == 21
     assert s == cast_pointer(Ptr(S), t)
 
+def test_cast_float():
+    assert cast_float_to_int(2.3) == 0x40133333
+
 def test_str_of_dead_ptr():
     S = Struct('S', ('x', Signed))
     T = GcStruct('T', ('s', S))



More information about the Pypy-commit mailing list