wrapt icon indicating copy to clipboard operation
wrapt copied to clipboard

Wrapping bytearrays under ctypes

Open simonzack opened this issue 10 years ago • 4 comments
trafficstars

The following raises TypeError: expected an object with a writable buffer interface:

ctypes.c_char.from_buffer(wrapt.ObjectProxy(bytearray(b'12345')))

This is a corner case I've encountered in my own proxy implementation which also doesn't work, and doesn't seem to be possible to wrap in pure python without copying the bytearray. Now that I've discovered wrapt which is written in C. I'm hoping it can be implemented.

simonzack avatar Dec 02 '14 08:12 simonzack

As wrapt has a pure Python fallback, if it cannot be done in pure Python now, then wouldn't be able to be universally supported.

Anyway, I will have a dig and see what I can find.

GrahamDumpleton avatar Dec 02 '14 11:12 GrahamDumpleton

Thanks for considering it, I've come up with a simpler example, btw, I think it's the same underlying problem:

memoryview(wrapt.ObjectProxy(bytearray(b'12345')))

simonzack avatar Dec 03 '14 07:12 simonzack

I don't have a good answer of what to do here. What it comes down to is that yes you can likely do it in the C version of the object proxy, but you can't do it in the pure Python code version.

I am somewhat hesitant to implement on the C code side if the same thing can't be done on the pure Python side.

If I ever got a chance, it might be interesting to validate that it can be made to work for the C variant at least, but what you do then I am not sure. One could perhaps have it off by default, but have a way of enabling the support for those who were willing to live with fact that C extension must always exist.

GrahamDumpleton avatar Dec 09 '14 03:12 GrahamDumpleton

have it off by default, but have a way of enabling the support for those who were willing to live with fact that C extension must always exist

That's definitely good enough to me.

simonzack avatar Dec 09 '14 11:12 simonzack