[Python-bugs-list] [ python-Bugs-433228 ] repr(list) woes when len(list) big

noreply@sourceforge.net noreply@sourceforge.net
Fri, 15 Jun 2001 22:14:28 -0700


Bugs item #433228, was updated on 2001-06-14 12:37
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=433228&group_id=5470

Category: Python Interpreter Core
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Tim Peters (tim_one)
>Assigned to: Tim Peters (tim_one)
Summary: repr(list) woes when len(list) big

Initial Comment:
This code fatally confuses Win2K:

ints = range(100000)
x = map(ints, ints)

"ints" isn't a callable object, so call_object does 
PyObject_Repr on it in order to produce an error msg.  
In the bowels of list_repr, i gets to 21069 and that's 
all:  string_concat's call to PyObject_MALLOC never 
returns.  size==136374 at this point, so it's not like 
we're asking for an unreasonable amount of memory, 
Win2K is just lost.  Hitting Ctrl+C does interrupt the 
program, but it dies immediately then with a memory 
fault inside MS's runtime libraries.

The simpler

x = repr(range(100000))

is much the same, except list_repr's i sticks at 15713 
then, and hitting Ctrl+C confuses the debugger.

On Linux there are no memory faults, but on Fred's 
laptop the second program snippet showed no sign of 
completing.  Since list_repr uses a quadratic-time 
algorithm, that much was expected; whether it's 
reasonable is open to debate.


----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2001-06-15 22:14

Message:
Logged In: YES 
user_id=31435

Closed.  I gave Python linear-time repr() implementations 
for dicts, lists and tuples:

Include/stringobject.h; new revision: 2.28
Objects/dictobject.c; new revision: 2.104
Objects/listobject.c,v new revision: 2.96
Objects/stringobject.c; new revision 2.119
Objects/tupleobject.c; new revision: 2.53

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2001-06-15 17:15

Message:
Logged In: YES 
user_id=31435

WRT #1, I patched call_object() (ceval.c rev 2.247),
and now it displays

TypeError: object of type 'list' is not callable

WRT #2, I'm leaving this report open, because interrupting 
via Ctrl+C can lead to memory faults on Win2K (see original 
report), and because the 2.2 Python pprint.pprint(x) is 
much faster than builtin repr(x) for large x of list, tuple 
and dict types (on both Windows and Linux).  This makes "an 
excuse" less appealing than it was in 2.1.  Making repr() 
linear-time in these cases is straightforward, but requires 
a Python-level way to get at string.join.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-06-15 09:40

Message:
Logged In: YES 
user_id=6380

Seem to be two things:

1) The error message in call_object() uses repr() of an
unknown object.

THIS IS EVIL. Error messages should NEVER use the repr of an
object unless they know for sure that the repr fits in a few
hundred bytes.
They should show the type of the unknown object instead.

2) Repr of a very long list is inefficient.

I can live with that; it falls in the category "then don't
do that". it can be interrupted with ^C.


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=433228&group_id=5470