Bugs item #1165306, was opened at 2005-03-17 15:56
Message generated for change (Comment added) made by remyblank
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1165306&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 6
Submitted By: Remy Blank (remyblank)
Assigned to: Michael Hudson (mwh)
Summary: Property access with decorator makes interpreter crash

Initial Comment:
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):

[EMAIL PROTECTED] 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.

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

>Comment By: Remy Blank (remyblank)
Date: 2005-03-17 21:13

Message:
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.

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2005-03-17 19:43

Message:
Logged In: YES 
user_id=6380

Looks OK on cursory inspection.

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

Comment By: Michael Hudson (mwh)
Date: 2005-03-17 18:28

Message:
Logged In: YES 
user_id=6656

Let's attach a test case too.

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

Comment By: Michael Hudson (mwh)
Date: 2005-03-17 18:15

Message:
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? :)

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2005-03-17 18:03

Message:
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?

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

Comment By: Michael Hudson (mwh)
Date: 2005-03-17 17:44

Message:
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).

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

Comment By: Michael Hudson (mwh)
Date: 2005-03-17 16:17

Message:
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...

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1165306&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to