Python 2.6+ buffer protocol...

Been playing around with the Python 2.6+ buffer protocol this morning.  Notes:

  • it appears that ctypes could support buffer-supporting objects being passed as pointers natively (i.e. at C speed), but it doesn't seem to (at least with my cursory tests) there would likely be a lot of corner cases that would need to throw errors
  • there doesn't seem to be a hook at the Python level to say "my object can fill in a buffer on demand"?
  • the constants and one of the "functions" are defined as macros, so not ctypes-friendly for working with them

there are still some things that the array protocol in PyOpenGL provides that aren't there at the moment.

  • support for lists/tuples of equal-typed values (this isn't supported if you turn on ERROR_ON_COPY anyway)
  • ways for (python coded) objects to participate in the protocol (e.g. a wrapper object such as a VBO that passes "special" pointers (actually offsets))
  • ctypes parameter types that can access other parameters *after* conversion to buffer types (e.g. to get the dimensions of another argument)
I've altered PyOpenGL (a few days ago) to drop a number of (complex) wrapping steps when ERROR_ON_COPY is True, as with that case we can pass in many types and let the from_param of the argument handle them directly.  Anyway, good to see the buffer protocol moving forward, very good to have packages able to share data efficiently.

Comments

Comments are closed.

Pingbacks

Pingbacks are closed.