Karim Belabas on Sat, 16 Jun 2012 09:28:28 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: segfault on reading vector |
* Charles Greathouse [2012-06-15 16:29]: > I wrote a quick script to help someone with an "insert operators into > 123456789 to make 100" problem. In essence, it was 9 nested loops > building a string with > if(trap(,0,eval(s9)==100), > listput(v,s9) > ) > inside, where v is a List. At the end it returns Vec(v). The program > runs without problems, but when I try to access the return value I get > *** type: bug in PARI/GP (Segmentation Fault), please report > on both > GP/PARI CALCULATOR Version 2.6.0 (development git-d1d257d) > i686 running mingw (ix86/GMP-5.0.1 kernel) 32-bit version > compiled: May 9 2012, gcc version 4.6.3 (GCC) > (readline v6.2 enabled, extended help enabled) > and even on the old > GP/PARI CALCULATOR Version 2.4.2 (development CHANGES-1.1971) > i686 running cygwin (ix86/GMP-4.2.1 kernel) 32-bit version > compiled: Dec 23 2007, gcc-3.4.4 (cygming special, gdc 0.12, using dmd 0.125) > (readline v5.2 enabled, extended help enabled) > > I don't know why this is -- a general bug, a Windows-specific bug, or > a problem with my code. I tried it with iferr as well (only on 2.6.0) > with the same result. > > If I change the program to print the results and return a tally, it > works without difficulty. The full code is [...] Can't reproduce this so far, and valgrind shows nothing suspicious :-(. Side notes : 1) Why do you need to trap exceptions ? Just removing op[n9] should do the trick 2) A slightly more elegant ( and more than twice slower ) version test()={ my(op = ["","+","-","*","/"], v = List()); forvec(s = vector(9, i, [1,5]), my(t); t = Str(1, op[s[1]], 2, op[s[2]], 3, op[s[3]], 4, op[s[3]], 5, op[s[5]], 6, op[s[6]], 7, op[s[7]], 8, op[s[8]], 9); if(eval(t) == 100, listput(v, t)) ); Vec(v) }; Cheers, K.B. > test()={ > my(s1,s2,s3,s4,s5,s6,s7,s8,s9,op=["","+","-","*","/"],v=List()); > for(n1=1,5, > s1=Str(1, op[n1]); > for(n2=1,5, > s2=Str(s1, 2, op[n2]); > for(n3=1,5, > s3=Str(s2, 3, op[n3]); > for(n4=1,5, > s4=Str(s3, 4, op[n4]); > for(n5=1,5, > s5=Str(s4, 5, op[n5]); > for(n6=1,5, > s6=Str(s5, 6, op[n6]); > for(n7=1,5, > s7=Str(s6, 7, op[n7]); > for(n8=1,5, > s8=Str(s7, 8, op[n8]); > for(n9=1,5, > s9=Str(s8, 9, op[n9]); > if(trap(,0,eval(s9)==100), > listput(v,s9) > ) > ) > ) > ) > ) > ) > ) > ) > ) > ); > Vec(v) > }; > > (inelegant, but runs fast enough) -- Karim Belabas, IMB (UMR 5251) Tel: (+33) (0)5 40 00 26 17 Universite Bordeaux 1 Fax: (+33) (0)5 40 00 69 50 351, cours de la Liberation http://www.math.u-bordeaux1.fr/~belabas/ F-33405 Talence (France) http://pari.math.u-bordeaux1.fr/ [PARI/GP] `