[Python-bugs-list] [ python-Bugs-705231 ] Assertion failed, python aborts
SourceForge.net
noreply@sourceforge.net
Thu, 20 Mar 2003 03:14:18 -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 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