Can not write ffi.buffer into io.BytesIO

Issue #35 resolved
Konstantin Lopuhin
created an issue

Writing ffi.buffer into io.BytesIO fails on CPython 2.7, but works under PyPy trunk (both 32 bit). I added a test to backend_tests.py (diff attached)

Under PyPy::

py.test testing -k test_ffi_buffer_with_io test session starts platform linux2 -- Python 2.7.3[pypy-1.9.1-dev] -- pytest-2.3.2 collected 683 items

testing/test_ctypes.py s testing/test_ffi_backend.py .

681 tests deselected by '-ktest_ffi_buffer_with_io' 1 passed, 1 skipped, 681 deselected in 9.80 seconds

And under CPython 2.7.3 it fails (see attached file)

Comments (6)

  1. Konstantin Lopuhin reporter

    Thanks for the fix! But then the docs should also be updated - that the interface for getting a string from a buffer is done in Python 2.7 in the same way as in Python 3.x. I can make a pull request, if this will simplify something. Maybe it is worth adding some helper function and promote its usage? Because anyone supporting 2.6 will likely want to support 2.7 as well.

  2. Armin Rigo

    I gave up trying to find some consistent Python interface, and made my own simple buffer type. See the documentation update for ffi.buffer(). The new "minibuffer" object supports at the Python level a coherent interface, and at the C level it supports the NEWBUFFER protocol (unlike the Python 2.7 'buffer' object).

  3. Log in to comment