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: delattr() causes python to segfault
Type: Stage:
Components: Interpreter Core Versions: Python 2.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: gvanrossum, mwh, nnorwitz, vfiack
Priority: high Keywords:

Created on 2002-04-10 06:51 by vfiack, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
delattr-patch nnorwitz, 2002-04-15 00:55 patch to fix crash
Messages (5)
msg10238 - (view) Author: Vincent FIACK (vfiack) Date: 2002-04-10 06:51
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.
msg10239 - (view) Author: Vincent FIACK (vfiack) Date: 2002-04-10 07:25
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.
msg10240 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2002-04-10 10:06
Logged In: YES 
user_id=6656

Confirmed in 2.2.1.

Arse.

msg10241 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2002-04-15 00:55
Logged In: YES 
user_id=33168

Attached is a patch which fixes the problem,
not sure if this is appropriate or not.
msg10242 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-04-15 01:04
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.
History
Date User Action Args
2022-04-10 16:05:12adminsetgithub: 36405
2002-04-10 06:51:38vfiackcreate