[pypy-commit] pypy ffi-backend: getcname()

arigo noreply at buildbot.pypy.org
Sat Jul 7 14:34:59 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: ffi-backend
Changeset: r55966:bfdd6f3a991d
Date: 2012-07-07 14:34 +0200
http://bitbucket.org/pypy/pypy/changeset/bfdd6f3a991d/

Log:	getcname()

diff --git a/pypy/module/_cffi_backend/__init__.py b/pypy/module/_cffi_backend/__init__.py
--- a/pypy/module/_cffi_backend/__init__.py
+++ b/pypy/module/_cffi_backend/__init__.py
@@ -27,5 +27,7 @@
         'typeof': 'func.typeof',
         'offsetof': 'func.offsetof',
         '_getfields': 'func._getfields',
+        'getcname': 'func.getcname',
+
         'buffer': 'cbuffer.buffer',
         }
diff --git a/pypy/module/_cffi_backend/func.py b/pypy/module/_cffi_backend/func.py
--- a/pypy/module/_cffi_backend/func.py
+++ b/pypy/module/_cffi_backend/func.py
@@ -61,3 +61,11 @@
 @unwrap_spec(ctype=ctypeobj.W_CType)
 def _getfields(space, ctype):
     return ctype._getfields()
+
+# ____________________________________________________________
+
+ at unwrap_spec(ctype=ctypeobj.W_CType, replace_with=str)
+def getcname(space, ctype, replace_with):
+    p = ctype.name_position
+    s = '%s%s%s' % (ctype.name[:p], replace_with, ctype.name[p:])
+    return space.wrap(s)
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -1367,3 +1367,8 @@
         # XXX pypy doesn't support the following assignment so far
         buf[:4:2] = 'XY'
         assert str(c) == 'XIYthere'
+
+def test_getcname():
+    BUChar = new_primitive_type("unsigned char")
+    BArray = new_array_type(new_pointer_type(BUChar), 123)
+    assert getcname(BArray, "<-->") == "unsigned char<-->[123]"


More information about the pypy-commit mailing list