cStringIO change in 2.4 vs 2.5. Regression?

  • Thread starter =?ISO-8859-1?Q?Markus_Sch=F6pflin?=
  • Start date
?

=?ISO-8859-1?Q?Markus_Sch=F6pflin?=

Hello,

I just stumbled accross a difference between cStringIO in Python 2.4
and 2.5. You can no longer feed arrays to cStringIO.

Python 2.4:

---%<---
ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on
Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from array import array
>>> a = array('B', (0, 1, 2))
>>> a array('B', [0, 1, 2])
>>> from StringIO import StringIO
>>> StringIO(a)
>>> from cStringIO import StringIO
>>> StringIO(a)
<cStringIO.StringI object at 0x0086A248>
--->%---

Python 2.5:

---%<---
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from array import array
>>> a = array('B', (0, 1, 2))
>>> a array('B', [0, 1, 2])
>>> from StringIO import StringIO
>>> StringIO(a)
>>> from cStringIO import StringIO
>>> StringIO(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: expected a character buffer object
--->%---

Has this change been done on purpose or is it a regression?

If it's not a regression, is there another way to feed an array to
cStringIO without expensive conversion?

TIA, Markus
 
T

Terry Reedy

| Hello,
|
| I just stumbled accross a difference between cStringIO in Python 2.4
| and 2.5. You can no longer feed arrays to cStringIO.
[snip]
| Has this change been done on purpose or is it a regression?

I doubt that an intentional change would have been made for cStringIO and
not StringIO. Two ways to investigate: scan the detailed listing of 2.5
changes for mention of array and cStringIO modules; check the source code
checkin messages for both for the relevant time period. This might also
suggest who to send an inquiry to who might not be reading here.

If you do not get a satifactory resolution here, file a bug report on SF.
But remember that all bug fixers are volunteers just like you, so any
investigation you do and report on to make response easier will likely make
it quicker also.

tjr
 
?

=?ISO-8859-1?Q?Markus_Sch=F6pflin?=

Terry said:
| Hello,
|
| I just stumbled accross a difference between cStringIO in Python 2.4
| and 2.5. You can no longer feed arrays to cStringIO.
[snip]
| Has this change been done on purpose or is it a regression?

I doubt that an intentional change would have been made for cStringIO and
not StringIO. Two ways to investigate: scan the detailed listing of 2.5
changes for mention of array and cStringIO modules; check the source code
checkin messages for both for the relevant time period. This might also
suggest who to send an inquiry to who might not be reading here.

First of all, thank you very much for you answer and sorry for the
late reply, I was AFK for some days.

I scanned the NEWS file and the only change which caught my attention is

- Patches #1298449 and #1298499: Add some missing checks for error
returns in cStringIO.c.

but the corresponding check-in doesn't look suspicious.

Next I had a look at the source code of the trunk:

cStringIO.c:newIobject() calls abstract.c:pyObject_AsCharBuffer(),
which, AFAICT, is the only possible source for the exception reported.
The exception is raised when the given object doesn't have
conversions to an I/O buffer, but when looking at arraymodule.c there
is array_as_buffer which provides the needed conversions.

The code looks pretty much the same on the 2.5 branch, so I don't have
an explanation for the observed behaviour.
If you do not get a satifactory resolution here, file a bug report on SF.
But remember that all bug fixers are volunteers just like you, so any
investigation you do and report on to make response easier will likely make
it quicker also.

I think I'll file a bug at SF... maybe someone else will spot something.

Thanks, Markus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top