[issue11627] segfault raising an arbitrary object as an exception

2011-07-15 Thread Roundup Robot

Roundup Robot devn...@psf.upfronthosting.co.za added the comment:

New changeset 8d05f697acd4 by Benjamin Peterson in branch '3.2':
catch nasty exception classes with __new__ that doesn't return a exception 
(closes #11627)
http://hg.python.org/cpython/rev/8d05f697acd4

New changeset bc1fbd6f667a by Benjamin Peterson in branch 'default':
merge 3.2 (#11627)
http://hg.python.org/cpython/rev/bc1fbd6f667a

--
nosy: +python-dev
resolution:  - fixed
stage:  - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-07-15 Thread Roundup Robot

Roundup Robot devn...@psf.upfronthosting.co.za added the comment:

New changeset 45b1ae1ef318 by Benjamin Peterson in branch '2.7':
port 8d05f697acd4 (#11627)
http://hg.python.org/cpython/rev/45b1ae1ef318

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-03-23 Thread Georg Brandl

Changes by Georg Brandl ge...@python.org:


--
nosy: +georg.brandl

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-03-22 Thread Nick Coghlan

Nick Coghlan ncogh...@gmail.com added the comment:

Note that this test code:

def raise_():
raise MyException
self.assertRaises(TypeError, raise_)

can be simplified to:

with self.assertRaises(TypeError):
raise MyException

in all currently maintained branches.

--
nosy: +ncoghlan

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-03-22 Thread Andreas Stührk

Andreas Stührk andy-pyt...@hammerhartes.de added the comment:

Thanks Nick, that is indeed much nicer. I updated the patch.

I also created a patch for 2.7, in case anyone thinks it's a good idea to fix 
it there, too.

--
Added file: http://bugs.python.org/file21346/issue11627_3.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-03-22 Thread Andreas Stührk

Changes by Andreas Stührk andy-pyt...@hammerhartes.de:


Added file: http://bugs.python.org/file21347/issue11627_py27.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-03-22 Thread Andreas Stührk

Andreas Stührk andy-pyt...@hammerhartes.de added the comment:

Another thing that can happen is that `__new__()` does return an instance of 
BaseException, but that the return value is not an instance of the expected 
class.

Example:

class MyException(OSError):
def __new__(*args):
return Exception()

try:
raise MyException
except OSError as e:
print(isinstance(e, OSError))

That would print False. Currently, the patch doesn't check for that, should 
it do so?

Also, the error message for the 2.7 patch doesn't include that old-style 
classes are allowed, hence the patch needs to be updated if it should go into 
2.7.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-03-21 Thread Michael Foord

New submission from Michael Foord mich...@voidspace.org.uk:

Python 3.2 (r32:88452, Feb 20 2011, 10:19:59) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type help, copyright, credits or license for more information.
 class Foo(Exception):
...  def __new__(*args):
...   return object()
... 
 try:
...  raise Foo
... except Exception as e:
...  print ('got it', e)
... 
Bus error

--
messages: 131687
nosy: michael.foord
priority: normal
severity: normal
status: open
title: segfault raising an arbitrary object as an exception
type: crash
versions: Python 3.2, Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-03-21 Thread Michael Foord

Michael Foord mich...@voidspace.org.uk added the comment:

Personally I don't think this should be valid at all (it should ideally be an 
error at the raise point). It is the kind of thing that causes difficulties for 
the other implementations trying to match CPython behaviour (this code works in 
Python 2.7 - you can catch the object()).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-03-21 Thread Andreas Stührk

Changes by Andreas Stührk andy-pyt...@hammerhartes.de:


--
nosy: +Trundle

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-03-21 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

Have you tried 3.1?

--
nosy: +pitrou

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-03-21 Thread Michael Foord

Michael Foord mich...@voidspace.org.uk added the comment:

This:

raise type('',(Exception,),{'__new__':lambda *a:object()}) 

Segfaults 3.2 but not 3.1.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-03-21 Thread Santoso Wijaya

Santoso Wijaya santoso.wij...@gmail.com added the comment:

Oddly, this works:

C:\Users\santaC:\python32\python.exe
Python 3.2 (r32:88445, Feb 20 2011, 21:30:00) [MSC v.1500 64 bit (AMD64)] on win
32
Type help, copyright, credits or license for more information.
 class Foo(Exception):
... def __new__(*args):
... obj = object()
... print('Returning {}'.format(repr(obj)))
... return obj
...
 try:
... raise Foo
... except Exception as e:
... print('Got it: {}'.format(repr(e)))
...
Returning object object at 0x022D26D0
Returning object object at 0x0254B8E0
Got it: object object at 0x0254B8E0
 ^Z


But this does not:

C:\Users\santaC:\python32\python.exe
Python 3.2 (r32:88445, Feb 20 2011, 21:30:00) [MSC v.1500 64 bit (AMD64)] on win
32
Type help, copyright, credits or license for more information.
 class Foo(Exception):
... def __new__(*args):
... obj = object()
... print('Returning', repr(obj))
... return obj
...
 try:
... raise Foo
... except Exception as e:
... print('Got it:', repr(e))
...
Returning object object at 0x022F36D0
Returning object object at 0x022F38B0

crash!

--
nosy: +santa4nt

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-03-21 Thread Santoso Wijaya

Santoso Wijaya santoso.wij...@gmail.com added the comment:

Also, why is the print() in __new__ executed twice?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-03-21 Thread Andreas Stührk

Andreas Stührk andy-pyt...@hammerhartes.de added the comment:

On Mon, Mar 21, 2011 at 10:27 PM, Santoso Wijaya rep...@bugs.python.org wrote:

 Santoso Wijaya santoso.wij...@gmail.com added the comment:

 Also, why is the print() in __new__ executed twice?

Because `PyErr_NormalizeException()` is called twice: First time when
the exceptions is raised, and then a second time when the exception is
caught. Because the previous call didn't instantiate an instance of a
exception, the second call will (try to) create a new exception
instance.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-03-21 Thread Andreas Stührk

Andreas Stührk andy-pyt...@hammerhartes.de added the comment:

Attached is a patch. I'm not too happy about the error message though, I think 
it's more confusing than helpful.

--
keywords: +patch
Added file: http://bugs.python.org/file21328/issue11627.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-03-21 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

Le lundi 21 mars 2011 à 22:57 +, Andreas Stührk a écrit :
 Andreas Stührk andy-pyt...@hammerhartes.de added the comment:
 
 Attached is a patch. I'm not too happy about the error message though,
 I think it's more confusing than helpful.

You could try something more explicit, such as
calling %s() should have returned an instance of BaseException, not %s
% (type, Py_TYPE(value))

By the way, you have a tab character in your patch. Please only use
spaces for indentation.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-03-21 Thread Andreas Stührk

Andreas Stührk andy-pyt...@hammerhartes.de added the comment:

 Antoine Pitrou pit...@free.fr added the comment:
 You could try something more explicit, such as
 calling %s() should have returned an instance of BaseException, not %s
 % (type, Py_TYPE(value))

Thanks, updated the patch.

 By the way, you have a tab character in your patch. Please only use
 spaces for indentation.

I am terribly sorry for that. I always realise after the first changed
line that my editor is in the wrong C mode.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11627] segfault raising an arbitrary object as an exception

2011-03-21 Thread Andreas Stührk

Changes by Andreas Stührk andy-pyt...@hammerhartes.de:


Added file: http://bugs.python.org/file21329/issue11627_2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11627
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com