[pypy-issue] Issue #2588: ctypes package error: "TypeError: expected a readable buffer object" (pypy/pypy)

MilesCranmer issues-reply at bitbucket.org
Tue Jun 20 21:40:45 EDT 2017

New issue 2588: ctypes package error: "TypeError: expected a readable buffer object"


I am trying out PyPy on the following python 2.7 package (written with ctypes calls): https://github.com/ledatelescope/bifrost.

Everything installs correctly.

However, in running the test suite, I get the following errors (about 2/3 of the tests have this error):


Exception in thread Pipeline_0/SigprocSourceBlock_0:
Traceback (most recent call last):
  File "/workspace/pypy2-v5.8.0-linux64/lib-python/2.7/threading.py", line 797, in __bootstrap_inner
  File "/workspace/pypy2-v5.8.0-linux64/lib-python/2.7/threading.py", line 750, in run
    self.__target(*self.__args, **self.__kwargs)
  File "build/bdist.linux-x86_64/egg/bifrost/pipeline.py", line 308, in run
  File "build/bdist.linux-x86_64/egg/bifrost/pipeline.py", line 380, in main
    ostrides = self.on_data(ireader, ospans)
  File "build/bdist.linux-x86_64/egg/bifrost/blocks/sigproc.py", line 109, in on_data
    ospan.data[:nframe] = indata
  File "build/bdist.linux-x86_64/egg/bifrost/ring2.py", line 399, in data
  File "build/bdist.linux-x86_64/egg/bifrost/ndarray.py", line 224, in __new__
    data_buffer, offset, strides)
TypeError: expected a readable buffer object

The minimal reproducible code is:


>>>> import bifrost
>>>> from bifrost import blocks as blocks
>>>> from bifrost import pipeline as bfp
>>>> with bfp.Pipeline() as pipeline:
....     blocks.read_sigproc(['data/2chan4bitNoDM.fil'], 4096)
....     pipeline.run()

This reads in a file from "data" into the pipeline class, which calls a C++ backend to allocate a ring buffer and put the data on it. 

The relevant code where the error is: https://github.com/ledatelescope/bifrost/blob/master/python/bifrost/ndarray.py


BufferType = ctypes.c_byte*nbyte
data_buffer_ptr = ctypes.cast(buffer, ctypes.POINTER(BufferType))
data_buffer     = data_buffer_ptr.contents

obj = np.ndarray.__new__(cls, shape, dtype_np,
                         data_buffer, offset, strides)
obj.bf = BFArrayInfo(space, dtype, native, conjugated, ownbuffer)

Please let me know if you would like any other info.

Here are some system stats:

➜  test git:(master) ✗ pypy --version
Python 2.7.13 (c925e7381036, Jun 05 2017, 21:20:51)
[PyPy 5.8.0 with GCC 6.2.0 20160901]

➜  test git:(master) ✗ uname -a
Linux 004a0c817a24 4.9.27-14.31.amzn1.x86_64 #1 SMP Wed May 10 01:58:40 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

This is running inside a Docker (which is running Ubuntu 16.04).

You can try this package with:
docker pull mcranmer/bifrost:cpu-base

Then, clone Bifrost and install it with pypy.

More information about the pypy-issue mailing list