[issue3132] implement PEP 3118 struct changes

Mark Dickinson report at bugs.python.org
Fri Dec 3 09:36:34 CET 2010


Mark Dickinson <dickinsm at gmail.com> added the comment:

> For reference, Numpy's PEP 3118 implementation is here:

Thanks for that, and the other information you give;  that's helpful.

It sounds like we're on the same page with respect to alignment of substructs.  (Bar the mostly academic question of max versus lcm.)

I still like the idea of scoped endianness markers in the substructs, but  if we have to abandon that for compatibility with NumPy that's okay.

- I assumed the 'O' format in the PEP is supposed to be similar to Numpy
  object arrays. This implies some reference counting semantics. The
  Numpy PEP 3118 implementation assumes the memory contains borrowed
  references, valid at least until the buffer is released.
  Unpacking 'O' should probably INCREF whatever PyObject* pointer is
  there.

I'm still confused about how this could work:  when unpacking, how do you know whether the PyObject* pointer points to a valid object or not?  You can ensure that the pointer will always point to a valid object by having the *pack* operation increment reference counts, but then you need a way to automatically decref when the packed string goes out of scope.  So the object returned by 'pack' would somehow have to be something other than a plain string, so that it can deal with automatically doing the DECREF of the held PyObject* pointers when it goes out of scope.

What's the need to have the 'O' format in the struct module?  Is it really necessary there?  Can we get away with not implementing it?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3132>
_______________________________________


More information about the Python-bugs-list mailing list