[Python-bugs-list] [ python-Bugs-541883 ] delattr() causes python to segfault

noreply@sourceforge.net noreply@sourceforge.net
Sun, 14 Apr 2002 18:04:27 -0700


Bugs item #541883, was opened at 2002-04-10 02:51
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=541883&group_id=5470

Category: Python Interpreter Core
Group: Python 2.2
>Status: Closed
>Resolution: Fixed
Priority: 7
Submitted By: Vincent FIACK (vfiack)
Assigned to: Guido van Rossum (gvanrossum)
Summary: delattr() causes python to segfault

Initial Comment:
delattr() causes python to segfault with builtins types

First a normal case to see what it should do :

Python 2.2.1c2 (#1, Apr  3 2002, 14:02:46) 
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for 
more information.
>>> a = 5
>>> delattr(a, "__class__")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: 'int' object has only read-only attributes 
(del .__class__)



Then the faulty case :

Python 2.2.1c2 (#1, Apr  3 2002, 14:02:46) 
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for 
more information.
>>> a = 5
>>> a.__class__
<type 'int'>
>>> delattr(a, "__class__")
Segmentation fault.

I don't know why, but if i access to a.__class__ 
before deleting it, it cause this error. The same 
occurs if i use another base type such as a string or 
a list. I haven't tried other attributes than 
__class__, but it may worth trying.

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

>Comment By: Guido van Rossum (gvanrossum)
Date: 2002-04-14 21:04

Message:
Logged In: YES 
user_id=6380

Thanks! I fixed it pretty much the way Neal suggested; the
test I checked in is slightly different. Definitely a bugfix
candidate.

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

Comment By: Neal Norwitz (nnorwitz)
Date: 2002-04-14 20:55

Message:
Logged In: YES 
user_id=33168

Attached is a patch which fixes the problem,
not sure if this is appropriate or not.

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

Comment By: Michael Hudson (mwh)
Date: 2002-04-10 06:06

Message:
Logged In: YES 
user_id=6656

Confirmed in 2.2.1.

Arse.



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

Comment By: Vincent FIACK (vfiack)
Date: 2002-04-10 03:25

Message:
Logged In: YES 
user_id=34036

I tried on "Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 
bit (Intel)] on win32" and a similar error occurs.

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

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