[Python-bugs-list] [ python-Bugs-705231 ] Assertion failed, python aborts

SourceForge.net noreply@sourceforge.net
Thu, 20 Mar 2003 04:43:39 -0800


Bugs item #705231, was opened at 2003-03-17 21:49
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=705231&group_id=5470

Category: Python Interpreter Core
Group: Python 2.2.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Anze Slosar (anze)
Assigned to: Nobody/Anonymous (nobody)
Summary: Assertion  failed, python aborts

Initial Comment:
This bug is reproducible with python 2.2.1 althogh it
fails only occasionally as the flow depends on random
numbers. 
It aborts by saying:

python: Objects/floatobject.c:582: float_pow: Assertion
`(*__errno_location ()) == 34' failed.
Aborted

I tried python 2.2.2 but as I try to install rpms I run
into every growing list of dependencies. I couldn't
reproduce the exact cause of the bug, but it is caused
by the following simple code (trying to invent
expressions for numbers using genetic algorithm (the
code itself is buggy in the Kill method, but I have
trouble debugging it because python crashes).

makeeq.py:

#!/usr/bin/env python
# Make equations using rpn and genetic algorithms

from random import *
from math import *
import rpn


def RanPosP(list):
    return int(uniform(0,len(list))+1)

def RanPos(list):
    return int(uniform(0,len(list)))

def AddUnary(list):
    a1=RanPosP(list)
    a2=RanPos(Unary)
    list=list[:a1]+[Unary[a2]]+list[a1:]
    return list

def AddBinary(list):
    a1=RanPosP(list)
    a2=RanPos(Binary)
    num=int(uniform(0,10))
    #print "Add binary:",list,num,rpn.Binary()[a2]
    list=list[:a1]+[num]+[Binary[a2]]+list[a1:]
    #print 'Add binary:',list
    return list

        
class RPNGen:
    def __init__(self,target):
        self.pool=[[1]]
        self.rpn=[1.0]
        self.target=target

    def GetRPN(self):
        self.rpn=map(rpn.SolveRPN,self.pool)
    
    def Grow(self,N):
        for x in range(N):
            ihave=[]
            while rpn.SolveRPN(ihave)==None:
                ml=len(self.pool)
                #print self.pool
                ii=int(uniform(0,ml))
                action=int(uniform(0,4))
                #print action
                if action==0:
                   ihave=(AddUnary(self.pool[ii]))

                elif action==1:
                    ihave=(AddBinary(self.pool[ii]))

                elif action==2:
                    jj=int(uniform(0,len(self.pool)))
                    bit=self.pool[jj]
                    a1=int(uniform(0,len(bit)))
                    a2=int(uniform(0,len(bit)))
                    if a2>a1:
                        bit=bit[a1:a2]
                    else:
                        bit=bit[a2:a1]
                    a3=int(uniform(0,len(self.pool[ii])))
                   
ihave=(self.pool[ii][:a3]+bit+self.pool[ii][a3:])

                elif action==3:
                    bit=self.pool[ii]
                    a1=int(uniform(0,len(bit)))
                    a2=int(uniform(0,len(bit)))
                   
ihave=(self.pool[ii][:a1]+self.pool[ii][a2:])
            self.pool.append(ihave)
            self.rpn.append(rpn.SolveRPN(ihave))
                
        #print self.pool,self.rpn
        deletelist=[]
        for cc in range(len(self.pool)):
            if self.rpn[cc]==None:
                deletelist.append(cc)

        while len(deletelist)>0:
            cc=deletelist.pop()
            self.rpn.pop(cc)
            self.pool.pop(cc)

    def Kill(self,N):
        TODO=N
        print "TODO:",TODO
        difs=map(lambda
x,y:abs(x-self.target)-len(self.pool)/10.0,self.rpn,self.pool)
        dict={}
        for x in range(N):
            dict[difs[x]]=x
            mn=min(dict.keys())
        for x in range(N+1,len(difs)):
            print 'dict:',dict
            if difs[x]>mn:
                del dict[mn]
                dict[difs[x]]=x
                mn=min(dict.keys())
        list=dict.values()
        list.sort()
        TODO-=len(list)

        for cc in range(len(list)):
            dd=list.pop()
            #print "asd", dd,
            self.rpn.pop(dd)
            self.pool.pop(dd)
                
            
    

Test=RPNGen(137.03599976)    
Binary=rpn.Binary()
Unary=rpn.Unary()

for i in range(100):
    Test.Grow(100)
    #print len(Test.pool)
    
for i in range(100):
    Test.Grow(100)
    Test.Kill(100)
    print len(Test.pool)    

for i in range(99):
    Test.Kill(200)
    Test.Grow(100)
    print len(Test.pool)    


for i in range(99):
    Test.Kill(1)
    print len(Test.pool),Test.rpn


    #print len(Test.pool),Test.pool, Test.rpn
    
print Test.pool
print Test.rpn

-----------------------------------------------
rpn.py:

#module for rpn
from math import *

def Unary():
    return ['sin','cos','tan','asin','acos','atan','neg']

def Binary():
    return ['+','-','*','/','^']

def SolveRPN(rpnl):
    stack=[]
    for each in rpnl:
        try:
            num=float(each)
            stack.append(num)
        except:
            try:
                #must be an operator then.
                if each=='+':
                    stack.append(stack.pop()+stack.pop())
                elif each=='-':
                    a1=stack.pop()
                    a2=stack.pop()
                    stack.append(a2-a1)
                elif each=='*':
                    stack.append(stack.pop()*stack.pop())
                elif each=='/':
                    a1=stack.pop()
                    a2=stack.pop()
                    stack.append(a2/a1)
                elif each=='^':
                    a1=stack.pop()
                    a2=stack.pop()
                    stack.append(a2**a1)
                elif each=='cos':
                    stack[-1]=cos(stack[-1])
                elif each=='sin':
                    stack[-1]=sin(stack[-1])
                elif each=='tan':
                    stack[-1]=tan(stack[-1])
                elif each=='acos':
                    stack[-1]=acos(stack[-1])
                elif each=='asin':
                    stack[-1]=asin(stack[-1])
                elif each=='atan':
                    stack[-1]=atan(stack[-1])
                elif each=='neg':
                    stack[-1]=-1.0*stack[-1]
                else:
                    print "Unknown operation",each
            except:
                return None
    if len(stack)<>1:
        #print "Stack ended non-empty:",stack
        return None
    return stack[0]
                




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

>Comment By: Anze Slosar (anze)
Date: 2003-03-20 12:43

Message:
Logged In: YES 
user_id=447507

Crashes with python 2.2.2 as well, but seems to work under
Solaris.

Here's what gdb says:

(gdb) [anze@APPCH numbers]> gdb `which python2` core.1406
GNU gdb Red Hat Linux (5.2-2)
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public
License, and you are
welcome to change it and/or distribute copies of it under
certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show
warranty" for details.
This GDB was configured as "i386-redhat-linux"...
(no debugging symbols found)...
Core was generated by `python2 ./makeeq.py'.
Program terminated with signal 6, Aborted.
Reading symbols from /lib/libdl.so.2...(no debugging symbols
found)...done.
Loaded symbols for /lib/libdl.so.2
Reading symbols from /lib/i686/libpthread.so.0...
(no debugging symbols found)...done.
Loaded symbols for /lib/i686/libpthread.so.0
Reading symbols from /lib/libutil.so.1...(no debugging
symbols found)...done.
Loaded symbols for /lib/libutil.so.1
Reading symbols from /lib/i686/libm.so.6...(no debugging
symbols found)...done.
Loaded symbols for /lib/i686/libm.so.6
Reading symbols from /lib/i686/libc.so.6...(no debugging
symbols found)...done.
Loaded symbols for /lib/i686/libc.so.6
Reading symbols from /lib/ld-linux.so.2...(no debugging
symbols found)...done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from
/usr/lib/python2.2/lib-dynload/structmodule.so...
(no debugging symbols found)...done.
Loaded symbols for
/usr/lib/python2.2/lib-dynload/structmodule.so
Reading symbols from
/usr/lib/python2.2/lib-dynload/_codecsmodule.so...
(no debugging symbols found)...done.
Loaded symbols for
/usr/lib/python2.2/lib-dynload/_codecsmodule.so
Reading symbols from
/usr/lib/python2.2/lib-dynload/mathmodule.so...
(no debugging symbols found)...done.
Loaded symbols for /usr/lib/python2.2/lib-dynload/mathmodule.so
Reading symbols from
/usr/lib/python2.2/lib-dynload/timemodule.so...
(no debugging symbols found)...done.
Loaded symbols for /usr/lib/python2.2/lib-dynload/timemodule.so
#0  0x42029331 in kill () from /lib/i686/libc.so.6
(gdb) w
Ambiguous command "w": watch, whatis, where, while,
while-stepping, ws.
(gdb) whe
#0  0x42029331 in kill () from /lib/i686/libc.so.6
#1  0x40030bdb in raise () from /lib/i686/libpthread.so.0
#2  0x4202a8c2 in abort () from /lib/i686/libc.so.6
#3  0x42022ecb in __assert_fail () from /lib/i686/libc.so.6
#4  0x080befeb in float_pow ()
#5  0x080af00f in ternary_op ()
#6  0x080af6fc in PyNumber_Power ()
#7  0x08077dda in eval_frame ()
#8  0x0807b49c in PyEval_EvalCodeEx ()
#9  0x0807c4fe in fast_function ()
#10 0x0807a367 in eval_frame ()
#11 0x0807b49c in PyEval_EvalCodeEx ()
#12 0x0807c4fe in fast_function ()
#13 0x0807a367 in eval_frame ()
#14 0x0807b49c in PyEval_EvalCodeEx ()
#15 0x08077491 in PyEval_EvalCode ()
#16 0x080970a1 in run_node ()
#17 0x08096176 in PyRun_SimpleFileExFlags ()
#18 0x08095b9f in PyRun_AnyFileExFlags ()
#19 0x08053c42 in Py_Main ()
#20 0x08053393 in main ()
#21 0x42017589 in __libc_start_main () from /lib/i686/libc.so.6
(gdb) 


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

Comment By: Anze Slosar (anze)
Date: 2003-03-20 11:14

Message:
Logged In: YES 
user_id=447507

Operating system is RedHat 8.0 with custom 2.4.20 kernel. I
did the following:

 [anze@as280 anze]$ ldd `which python`
        libdl.so.2 => /lib/libdl.so.2 (0x4002d000)
        libpthread.so.0 => /lib/i686/libpthread.so.0
(0x40031000)
        libutil.so.1 => /lib/libutil.so.1 (0x40061000)
        libm.so.6 => /lib/i686/libm.so.6 (0x40064000)
        libc.so.6 => /lib/i686/libc.so.6 (0x42000000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
[anze@as280 anze]$ rpm -qf /lib/i686/libm.so.6
glibc-2.2.93-5
[anze@as280 anze]$ 

So it seems to me that libm is from glibc-2.2.93-5. Compiler
is stock redhat gcc-3.2, but I haven't compiled anything
myself...


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

Comment By: Tim Peters (tim_one)
Date: 2003-03-17 22:06

Message:
Logged In: YES 
user_id=31435

Which operating system and C compiler?  Since the assert() 
is checking the errno result from your platform libm's pow() 
function, the resolution of this is going to depend on which C 
library you're using.

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=705231&group_id=5470