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: Property access with decorator makes interpreter crash
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mwh Nosy List: gvanrossum, mwh, rblank
Priority: high Keywords:

Created on 2005-03-17 14:56 by rblank, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
crashTest.py rblank, 2005-03-17 14:57 Script producing the interpreter crash
instancemethod-new-check.diff mwh, 2005-03-17 17:15 more checking for instancemethod_new
instancemethod-new-test.diff mwh, 2005-03-17 17:28 simple test
Messages (10)
msg24669 - (view) Author: Remy Blank (rblank) Date: 2005-03-17 14:56
The attached file makes the interpreter crash.
Basially, a method is decorated, and used as the getter
function for a property. Accessing the property
provokes the crash.

I get the following output (linux-2.6.10):

joe@pat TestCases $ ./crashTest.py
Creating instance
Getting value
Segmentation fault

Using python-2.3.4 from Gentoo, i.e. it has a few
patches from 2.3.5.

On Windows XP with python-2.4, I get a "Python has
encountered a problem and needs to close." dialog box.
msg24670 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2005-03-17 15:17
Logged In: YES 
user_id=6656

Confirmed, on 2.4 HEAD, even.

There's a lot going on in your test file that is unecessary, though; this is a 
smaller test case:

types.MethodType(lambda :None, None)(1)

instancemethod_call doesn't seem to expect im_class to be NULL...
msg24671 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2005-03-17 16:44
Logged In: YES 
user_id=6656

Hmm.  A little CVS log reading finds us this:

revision 2.170
date: 2003/04/09 19:35:08;  author: gvanrossum;  state: Exp;  lines: +2 -2
branches:  2.170.10;
Make it possible to call instancemethod() with 2 arguments.

Guido, what was the motivation for this?  Is it possible to create 
instancemethods with im_class == NULL some other way?  (If there is, I 
don't see it).

Also, you didn't add a unit test <poke> (in fact, instancemethod_new only 
gets called twice during a run of the test suite, both times with three 
arguments).
msg24672 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2005-03-17 17:03
Logged In: YES 
user_id=6380

Looks like I wasn't finished with the thought when I checked
it in. I think I was trying to make instancemethod generally
useful as a currying primitive. That should probably be
considered more careful; please roll it back.

(I think it may have been part of the aborted experiment to
get rid of bound methods.)

Is there time to backport this to 2.4.1?
msg24673 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2005-03-17 17:15
Logged In: YES 
user_id=6656

Well, it's a bit more subtle than I thought:

>>> def f(): pass
... 
>>> print f.__get__(1).im_class
None

The problem occurs when *both* im_self and im_class are None; and I'm 
now reasonably convinced that calling the type object is the only way this 
can be acheived.  So a simple check along these lines in 
instancemethod_new would suffice (patch attached), and seems less likely 
to break code.

I suspect this has missed 2.4.1.

remyblank: let me guess your code wasn't doing what you thought it did? :)
msg24674 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2005-03-17 17:28
Logged In: YES 
user_id=6656

Let's attach a test case too.
msg24675 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2005-03-17 18:43
Logged In: YES 
user_id=6380

Looks OK on cursory inspection.
msg24676 - (view) Author: Remy Blank (rblank) Date: 2005-03-17 20:13
Logged In: YES 
user_id=568100

> remyblank: let me guess your code wasn't doing what you
thought it did? :)

Err... Not sure what you mean... What would be the correct
way to do what I thought it did?

The code was largely inspired by a Cookbook entry. These are
still my first steps with decorators, and I have to admit I
don't yet fully understand why I have to create a MethodType
manually.
msg24677 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2005-03-27 21:16
Logged In: YES 
user_id=6656

> > remyblank: let me guess your code wasn't doing what
> > you thought it did? :)
> 
> Err... Not sure what you mean... What would be the correct
> way to do what I thought it did?

Well, I don't know, but what it was doing was trying to create a method 
bound to None...

I'll check this in soon.
msg24678 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2005-03-30 16:32
Logged In: YES 
user_id=6656

Fixed, in 

Objects/classobject.c revision 2.177
Lib/test/test_new.py revision 1.20

Thanks for the report!
History
Date User Action Args
2022-04-11 14:56:10adminsetgithub: 41711
2005-03-17 14:56:55rblankcreate