[C++-sig] can boost::python class imlement buffer protocol? (original) (raw)

Neal Becker ndbecker2 at gmail.com
Fri Jan 16 20:23:20 CET 2009


Neal Becker wrote:

David Abrahams wrote:

on Wed Jan 07 2009, Neal Becker <ndbecker2-AT-gmail.com> wrote: This would require filling in tpasbuffer field in the PyTypeObject structure for the class. Is this possible? Any clue how/where this could be done? I honestly don't know the answers to these questions, sorry. As a workaround, I currently implemented an 'asbuffer' member function. For example: template inline object asbuffer (ublas::vector & m) { return object (handle<> (PyBufferFromReadWriteMemory ((void*)(&m.data()[0]), m.size()*sizeof(T)))); }

Actually, this isn't all that useful. The problem is, you want to use with_custodian_and_ward_postcall<0,1> on this. But you can't because buffer object doesn't support weak references. So while the above can provide a buffer interface, it has no idea of lifetime management.

I wonder whether python buffer object could be made to support weak refs? Of course, if there was really a way to add a buffer interface to my boost::python object that would be even better.



More information about the Cplusplus-sig mailing list