<br><br><div><span class="gmail_quote">On 6/8/06, <b class="gmail_sendername">Thomas Heller</b> <<a href="mailto:theller@python.net">theller@python.net</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Brett Cannon wrote:<br>> I fixed the crasher for ``int(buffer(array.array('c')))`` by making<br>> buffer objects operate properly. Problem is that by doing so I broke<br>> the ctypes tests with a bunch of similar errors::
<br><br>You have not yet committed this fix, right?</blockquote><div><br>Nope; I was waiting to hear back on all of this; no committing of code that knowingly breaks tests and all.<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> ======================================================================<br>> ERROR: test_endian_double (ctypes.test.test_byteswap.Test)<br>> ----------------------------------------------------------------------
<br>> Traceback (most recent call last):<br>> File "/code/python/trunk/Lib/ctypes/test/test_byteswap.py", line<br>> 134, in test_endian_double<br>> self.failUnlessEqual(bin(struct.pack("d",
math.pi)), bin(s))<br>> File "/code/python/trunk/Lib/ctypes/test/test_byteswap.py", line 7, in bin<br>> return hexlify(buffer(s)).upper()<br>> TypeError: requested buffer type not available<br>>
<br>> Turns out the test does the following::<br>><br>> binascii.hexlify(buffer(ctypes.c_double(math.pi)))<br>><br>> This is a problem because binascii.hexlify() uses "t#" as its argument<br>> format string to PyArg_ParseTuple() and that fails now with a
<br>> TypeError since ctypes.c_double (which subclasses ctypes._SimpleCData<br>> which defines the buffer interface) does not have a char buffer<br>> defined.<br>><br>> Now this used to pass since buffer objects just used the read or write
<br>> buffer in place of the char buffer, regardless if the wrapped object<br>> had a char buffer function defined.<br>><br>> But in checking out what "t#" did, I found a slight ambiguity in the<br>> docs. The docs say "read-only character buffer" for the short
<br>> description, but "read-only buffer" for the longer description. Which<br>> is it?<br><br>I am using binascii.hexlify(buffer(obj)) as a simple way to look at the bytes of<br>the memory block.<br><br>
I think that hexlify should be able to use any buffer object that has<br>a readable memory block, not only those with charbuffers.<br><br>The docs say that the binascii methods are used to "convert between binary<br>
and various ASCII-encoded binary representations".</blockquote><div><br><br>Perhaps s# should be used instead since the docs say a read buffer can be used for that.</div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> Plus, Thomas, you might want to change _SimpleCData if you want it to<br>> truly suport char buffers.<br><br>I did not implement that because the memory block contains binary data,<br>not text.</blockquote><div><br>
<br>OK.<br><br>-Brett<br></div><br></div><br>