[pypy-svn] r77907 - in pypy/branch/jitffi/pypy/module/_ffi: . test

antocuni at codespeak.net antocuni at codespeak.net
Thu Oct 14 11:47:43 CEST 2010


Author: antocuni
Date: Thu Oct 14 11:47:42 2010
New Revision: 77907

Modified:
   pypy/branch/jitffi/pypy/module/_ffi/interp_ffi.py
   pypy/branch/jitffi/pypy/module/_ffi/test/test__ffi.py
Log:
add a way to the the actual address of the underlying function. Useful for testing


Modified: pypy/branch/jitffi/pypy/module/_ffi/interp_ffi.py
==============================================================================
--- pypy/branch/jitffi/pypy/module/_ffi/interp_ffi.py	(original)
+++ pypy/branch/jitffi/pypy/module/_ffi/interp_ffi.py	Thu Oct 14 11:47:42 2010
@@ -96,9 +96,17 @@
             assert voidres is None
             return space.w_None
 
+    @unwrap_spec('self', ObjSpace)
+    def getaddr(self, space):
+        """
+        Return the physical address in memory of the function
+        """
+        return space.wrap(rffi.cast(rffi.LONG, self.func.funcsym))
+
 W_FuncPtr.typedef = TypeDef(
     'FuncPtr',
-    __call__ = interp2app(W_FuncPtr.call)
+    __call__ = interp2app(W_FuncPtr.call),
+    getaddr = interp2app(W_FuncPtr.getaddr),
     )
 
 

Modified: pypy/branch/jitffi/pypy/module/_ffi/test/test__ffi.py
==============================================================================
--- pypy/branch/jitffi/pypy/module/_ffi/test/test__ffi.py	(original)
+++ pypy/branch/jitffi/pypy/module/_ffi/test/test__ffi.py	Thu Oct 14 11:47:42 2010
@@ -32,13 +32,19 @@
 
     
     def setup_class(cls):
-        from pypy.rlib.libffi import get_libc_name
+        from pypy.rpython.lltypesystem import rffi
+        from pypy.rlib.libffi import get_libc_name, CDLL, types
         from pypy.rlib.test.test_libffi import get_libm_name
         space = gettestobjspace(usemodules=('_ffi',))
         cls.space = space
         cls.w_libfoo_name = space.wrap(cls.prepare_c_example())
         cls.w_libc_name = space.wrap(get_libc_name())
-        cls.w_libm_name = space.wrap(get_libm_name(sys.platform))
+        libm_name = get_libm_name(sys.platform)
+        cls.w_libm_name = space.wrap(libm_name)
+        libm = CDLL(libm_name)
+        pow = libm.getpointer('pow', [], types.void)
+        pow_addr = rffi.cast(rffi.LONG, pow.funcsym)
+        cls.w_pow_addr = space.wrap(pow_addr)
 
     def test_libload(self):
         import _ffi
@@ -58,6 +64,12 @@
         libm = CDLL(self.libm_name)
         pow = libm.getfunc('pow', [types.double, types.double], types.double)
         assert pow(2, 3) == 8
+
+    def test_getaddr(self):
+        from _ffi import CDLL, types
+        libm = CDLL(self.libm_name)
+        pow = libm.getfunc('pow', [types.double, types.double], types.double)
+        assert pow.getaddr() == self.pow_addr
         
     def test_int_args(self):
         """



More information about the Pypy-commit mailing list