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: code that generates a segfault on Python 2.1-2.3
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: arigo, bachtor, brett.cannon, ddorfman, georg.brandl, mwh
Priority: high Keywords:

Created on 2004-07-15 23:56 by bachtor, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (7)
msg21647 - (view) Author: Ted Bach (bachtor) Date: 2004-07-15 23:56
On a Redhat Linux 9 based system, the following causes
a segfault:


""" In python, you can call any expression.
"""

class foo:
  def __init__(s,times=1):
     s.times = times
  def __call__(s): print s.times
  def __mul__(s,o): return foo(o)
  def __coerce__(s,o):
    if isinstance(o,int):
      return o,s


(foo(3)*10)()   # no segfault
 
(10*foo(3))()   # segfaults
# prints 10
msg21648 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2004-07-16 13:45
Logged In: YES 
user_id=6656

Isn't this likely to be a dup of bug 

[ 980352 ] coercion results used dangerously

?  I haven't thought about either very hard, but both involve 
__coerce__ and core dumps...
msg21649 - (view) Author: Dima Dorfman (ddorfman) Date: 2004-07-22 14:18
Logged In: YES 
user_id=908995

This is not the same problem as bug #980352; this one is an infinite recusion 
in the instance code (deriving foo from object makes the example work).
msg21650 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2004-08-07 21:44
Logged In: YES 
user_id=4771

Here is a shorter example:

  class foo:
      def __coerce__(self, other):
          return other, self
  foo()+1   # segfault: infinite recursion in C

classobject.c seems hopelessly prone to infinite recursion in C: whenever an operation needs coercion, __coerce__ is called and the operator PyNumber_Xxx() is called again on the result.  The most obvious cases of recursion are taken care of, but there are and will always be more convoluted ways to create this recursion.

There might be a way to solve the problem cleanly but currently I only see the solution of adding a C recursion check (Py_EnterRecursiveCall / Py_LeaveRecursiveCall).
msg21651 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-06-08 17:26
Logged In: YES 
user_id=1188172

Still persists with Python 2.4.
msg21652 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2006-06-13 21:51
Logged In: YES 
user_id=357491

Rev. 46932 for 2.5 and rev. 46934 for 2.4 has the fix.
msg21653 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2006-06-13 21:55
Logged In: YES 
user_id=357491

Actually, that's 46933, not 2 for the HEAD rev.
History
Date User Action Args
2022-04-11 14:56:05adminsetgithub: 40578
2004-07-15 23:56:06bachtorcreate