1. Python CFFI
  2. Untitled project
  3. cffi
Issue #65 resolved

support memoryview to char* conversion

Jean-Paul Calderone
created an issue

As it is possible to pass a Python bytes instance as the value for char* parameter of a C function, it would be nice if it were possible to pass a memoryview instance as well.

This is useful for implementing the socket-like interface, for example. socket.send(memoryview) works, but in order to implement this using cffi, it's necessary to do an extra conversion to bytes first, eg .send(memoryview.tobytes()). If cffi did this it could probably do it with less copying.

Comments (4)

  1. Cory Benfield

    Sorry to resurrect this issue, but I've been looking at something like this to implement recv_into for PyOpenSSL. Without this there's a minimum of two memory copies: one by OpenSSL into the temporary ffi.new('char[]') that I have to create, and then another from the ffi.buffer() into the memoryview object.

  2. Log in to comment