Re: [Python-Dev] Buffer interface in abstract.c?
Why not pass the index to the As*Buffer routines as well and make getsegcount available too? Then you could code things like for(i=0; i<PyObject_GetBufferCount(obj); i++) { if ( PyObject_AsCharBuffer(obj, &buf, &count, i) < 0 ) return -1; write(fp, buf, count); } -- Jack Jansen | ++++ stop the execution of Mumia Abu-Jamal ++++ Jack.Jansen@oratrix.com | ++++ if you agree copy these lines to your sig ++++ www.oratrix.nl/~jack | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm
Jack Jansen wrote:
Why not pass the index to the As*Buffer routines as well and make getsegcount available too? Then you could code things like for(i=0; i<PyObject_GetBufferCount(obj); i++) { if ( PyObject_AsCharBuffer(obj, &buf, &count, i) < 0 ) return -1; write(fp, buf, count); }
Simply because multiple segments hasn't been seen. All objects supporting the buffer interface have a single segment. IMO, it is best to drop the argument to make typical usage easier. For handling multiple segments, a caller can use the raw interface rather than the handy functions. Cheers, -g -- Greg Stein, http://www.lyra.org/
On Tue, 3 Aug 1999, Greg Stein wrote:
Simply because multiple segments hasn't been seen. All objects supporting the buffer interface have a single segment. IMO, it is best
FYI, if/when NumPy objects support the buffer API, they will require multiple-segments.
Simply because multiple segments hasn't been seen. All objects supporting the buffer interface have a single segment. IMO, it is best
FYI, if/when NumPy objects support the buffer API, they will require multiple-segments.
same goes for PIL. in the worst case, there's one segment per line. ... on the other hand, I think something is missing from the buffer design; I definitely don't like that people can write and marshal objects that happen to implement the buffer interface, only to find that Python didn't do what they expected...
import unicode import marshal u = unicode.unicode s = u("foo") data = marshal.dumps(s) marshal.loads(data) 'f\000o\000o\000' type(marshal.loads(data)) <type 'string'>
as for PIL, I would also prefer if the exported buffer corresponded to what you get from im.tostring(). iirc, that cannot be done -- I cannot export via a temporary memory buffer, since there's no way to know when to get rid of it... </F>
Jack Jansen wrote:
Why not pass the index to the As*Buffer routines as well and make getsegcount available too? Then you could code things like for(i=0; i<PyObject_GetBufferCount(obj); i++) { if ( PyObject_AsCharBuffer(obj, &buf, &count, i) < 0 ) return -1; write(fp, buf, count); }
Well, just like Greg said, this is not much different than using the buffer interface directly. While the above would be a handy PyObject_WriteAsBuffer() kind of helper, I don't think that this is really used all that much. E.g. in mxODBC I use the APIs for accessing the raw char data in a buffer: the pointer is passed directly to the ODBC APIs without copying, which makes things quite fast. IMHO, this is the greatest advantage of the buffer interface. -- Marc-Andre Lemburg ______________________________________________________________________ Y2000: 150 days left Business: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/
participants (5)
-
David Ascher
-
Fredrik Lundh
-
Greg Stein
-
Jack Jansen
-
M.-A. Lemburg