Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pypy: type object 'c_char' has no attribute 'from_buffer' #16

Closed
liZe opened this issue Aug 12, 2013 · 8 comments
Closed

Pypy: type object 'c_char' has no attribute 'from_buffer' #16

liZe opened this issue Aug 12, 2013 · 8 comments

Comments

@liZe
Copy link
Member

liZe commented Aug 12, 2013

Launching WeasyPrint tests with pypy 2.0.2 gives this error:

weasyprint/tests/testing_utils.py:77: in wrapper
>               function(*args, **kwargs)
weasyprint/tests/test_draw.py:2714: in test_radial_gradients
>           save_pixels_to_png(pixels, 10, 16, '/tmp/a.png')
weasyprint/tests/test_draw.py:50: in save_pixels_to_png
>           data=bytearray(pixels), stride=width * 4
/usr/lib64/pypy2.0/site-packages/cairocffi/surfaces.py:646: in __init__
>           address, length = from_buffer(data)
/usr/lib64/pypy2.0/site-packages/cairocffi/surfaces.py:68: in from_buffer
>           return ctypes.addressof(ctypes.c_char.from_buffer(obj)), len(obj)
E           AttributeError: type object 'c_char' has no attribute 'from_buffer'
@SimonSapin
Copy link
Member

http://pythonhosted.org/cairocffi/api.html#cairocffi.ImageSurface

Note: Currently only array.array buffers are supported on PyPy.

@SimonSapin
Copy link
Member

(I know "it’s documented" is not an excuse, I wrote both of these pieces of code :))

@liZe
Copy link
Member Author

liZe commented Aug 12, 2013

No excuse but good explanation :)

@SimonSapin
Copy link
Member

The actual explanation is that PyPy has no "buffer API" like CPython’s. The GC reserves the right to move objects around in memory, and thus you can’t have a stable pointer to inside an object. array works because it has a specific buffer_info() method which PyPy supports (by allocating a static buffer and having the array object point to it.)

@SimonSapin
Copy link
Member

@liZe , do you think the docs should be expanded on this?

@liZe
Copy link
Member Author

liZe commented Aug 12, 2013

I've fixed the test in WeasyPrint (and you don't want to look at this commit) (no, really, you don't) (OK, this one).

Adding an explicit message for this exception may be even better: if it looks like an expected behaviour, users will probably read the doc or look for an open feature request, and find the line of documentation.

What about opening an issue? Someone may be interested in fixing it! (Just joking, at least for the second part.)

@SimonSapin
Copy link
Member

Ok, leaving this open for now. Patches welcome ;)

@liZe
Copy link
Member Author

liZe commented Aug 26, 2016

@liZe liZe closed this as completed Aug 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants