[pypy-commit] pypy cffi-1.0: ffi.cast()

arigo noreply at buildbot.pypy.org
Sun May 3 11:19:02 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r77001:1a6ff2029062
Date: 2015-05-03 11:19 +0200
http://bitbucket.org/pypy/pypy/changeset/1a6ff2029062/

Log:	ffi.cast()

diff --git a/pypy/module/_cffi_backend/ffi_obj.py b/pypy/module/_cffi_backend/ffi_obj.py
--- a/pypy/module/_cffi_backend/ffi_obj.py
+++ b/pypy/module/_cffi_backend/ffi_obj.py
@@ -154,6 +154,16 @@
                     _cffi_backend.callback(ctype, python_callable, error))""")
 
 
+    def descr_cast(self, w_arg, w_ob):
+        """\
+Similar to a C cast: returns an instance of the named C
+type initialized with the given 'source'.  The source is
+casted between integers or pointers of any type."""
+        #
+        w_ctype = self.ffi_type(w_arg, ACCEPT_STRING | ACCEPT_CTYPE)
+        return w_ctype.cast(w_ob)
+
+
     @unwrap_spec(w_arg=W_CData)
     def descr_from_handle(self, w_arg):
         """\
@@ -295,6 +305,7 @@
         addressof   = interp2app(W_FFIObject.descr_addressof),
         alignof     = interp2app(W_FFIObject.descr_alignof),
         callback    = interp2app(W_FFIObject.descr_callback),
+        cast        = interp2app(W_FFIObject.descr_cast),
         from_handle = interp2app(W_FFIObject.descr_from_handle),
         getctype    = interp2app(W_FFIObject.descr_getctype),
         new         = interp2app(W_FFIObject.descr_new),


More information about the pypy-commit mailing list