Commits

Armin Rigo  committed bfdd6f3

getcname()

  • Participants
  • Parent commits 8c71371
  • Branches ffi-backend

Comments (0)

Files changed (3)

File pypy/module/_cffi_backend/__init__.py

         'typeof': 'func.typeof',
         'offsetof': 'func.offsetof',
         '_getfields': 'func._getfields',
+        'getcname': 'func.getcname',
+
         'buffer': 'cbuffer.buffer',
         }

File pypy/module/_cffi_backend/func.py

 @unwrap_spec(ctype=ctypeobj.W_CType)
 def _getfields(space, ctype):
     return ctype._getfields()
+
+# ____________________________________________________________
+
+@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)

File pypy/module/_cffi_backend/test/_backend_test_c.py

         # 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]"