This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: SystemError from tuple() builtin
Type: Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: moshez Nosy List: glchapman, moshez, tim.peters, twouters
Priority: high Keywords:

Created on 2001-05-01 02:18 by glchapman, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Messages (7)
msg4575 - (view) Author: Greg Chapman (glchapman) Date: 2001-05-01 02:18
The following produces a SystemError under Python 2.1:

>>> class Test:
... 	def __init__(self):
... 		self.list = [1]
... 	def __len__(self):
... 		return 0
... 	def __getitem__(self, index):
... 		return self.list[index]
... 
>>> t = Test()
>>> tuple(t)
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
SystemError: C:\USERS\greg\PROG\CPP\PYTHON\Python-2.1
\Objects\tupleobject.c:506: bad argument to internal 
function

The problem is the call made by PySequence_Tuple to 
_PyTuple_Resize.  The above code results in an attempt 
to resize the empty tuple, the ref count of which is 
greater than 1.


msg4576 - (view) Author: Greg Chapman (glchapman) Date: 2001-05-01 02:41
Logged In: YES 
user_id=86307

Apropos this report and the recent python-dev 
thread "Iterators, map, xreadlines and docs":

>>> f = open(r"c:\autoexec.bat")
>>> l = list(f.xreadlines())
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
TypeError: len() of unsized object

Admittedly, using xreadlines like this is silly, but it 
probably ought to work.  Both PySequence_Tuple and 
PySequence_List require len() (PySequence_Size) to succeed, 
even though they then pretty much ignore the returned 
length.  Perhaps they should be changed to be consistent 
with the changes in map.
msg4577 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2001-05-08 05:01
Logged In: YES 
user_id=31435

Greg, list(f.xreadlines()) happens to work already under 
current CVS Python.  But note for the future that attaching 
a feature request to an unrelated bug report is a low-
probability way to get anyone to notice ...
msg4578 - (view) Author: Thomas Wouters (twouters) * (Python committer) Date: 2001-05-28 11:34
Logged In: YES 
user_id=34209

Hey, howlong has this bug been sitting here ?? Must be
something wrong with SF's bug mail stuff, because even
though this bug is assigned to me, I haven't seen it before
:P Anyway, fixing this, both for 2.2 and 2.1.1.
msg4579 - (view) Author: Thomas Wouters (twouters) * (Python committer) Date: 2001-05-28 13:18
Logged In: YES 
user_id=34209

There, fixed for 2.1.1 and 2.2. (revisions 2.50 and
2.48.4.1)

Moshe'll have to decide whether he wants the fix for 2.0.1
(there is no big reason not to, but I don't know where he is
with 2.0.1, so I don't want to check it in without his
okay.) Bug reassigned to Moshe for that purpose.
msg4580 - (view) Author: Thomas Wouters (twouters) * (Python committer) Date: 2001-05-28 13:20
Logged In: YES 
user_id=34209

(Eh... I should have said: revisions 2.50 and 2.48.4.1 of
Objects/tupleobject.c)
msg4581 - (view) Author: Thomas Wouters (twouters) * (Python committer) Date: 2001-07-09 15:27
Logged In: YES 
user_id=34209

I guess this didn't make it to 2.0.1 :) Closing.
History
Date User Action Args
2022-04-10 16:04:01adminsetgithub: 34438
2001-05-01 02:18:03glchapmancreate