Opened 6 years ago
Closed 6 years ago
#15446 closed defect (fixed)
GP interface confused by stack overflow when enlarging results vector
Reported by:  pbruin  Owned by:  

Priority:  major  Milestone:  sage6.2 
Component:  interfaces  Keywords:  gp stack overflow 
Cc:  Merged in:  
Authors:  Peter Bruin  Reviewers:  Alejandro Argaez 
Report Upstream:  N/A  Work issues:  
Branch:  ab293b2 (Commits)  Commit:  ab293b23647b01c03eae0e5c0a9f189ebcc2cc3c 
Dependencies:  Stopgaps: 
Description
From Georgi Guninski on sagesupport (https://groups.google.com/forum/#!topic/sagesupport/A_GilhiUAwM):
sage: gp("{T(n)=n+1}") sage: for n in [ 1 .. 2**20]: a=gp.T(n) print n #wait some time.. ... 65535 65536  TypeError TypeError: Error executing code in GP: CODE: sage[131074]=65537; PARI/GP ERROR: *** at toplevel: sage[131074]=65537 *** ^ *** array index (131074) out of allowed range [1131073].
after this trying:
sage: gp.T(1)
again raises exception.
After the above computation, the log file .sage/gpexpect.log
ends with
? sage[131070]=65535; sage[131070]=65535; ? sage[131071]=T(sage[131070]); sage[131071]=T(sage[131070]); ? sage=concat(sage, vector(131072,k,0)); sage=concat(sage, vector(131072,k,0)); *** at toplevel: sage=concat(sage,vec *** ^ *** the PARI stack overflows ! current stack size: 10000000 (9.537 Mbytes) [hint] you can increase GP stack with allocatemem() ? allocatemem() allocatemem() *** Warning: new stack size = 20000000 (19.073 Mbytes). ? sage=concat(sage, vector(131072,k,0)); sage=concat(sage, vector(131072,k,0)); ? sage[131072]=65536; sage[131072]=65536; ? sage[131073]=T(sage[131072]); sage[131073]=T(sage[131072]); ? sage[131074]=65537; sage[131074]=65537; *** at toplevel: sage[131074]=65537 *** ^ *** array index (131074) out of allowed range [1131073]. ?
It appears that the vector sage
wasn't doubled correctly; probably it got messed up by the failed concat()
.
Change History (9)
comment:1 Changed 6 years ago by
 Milestone changed from sage6.1 to sage6.2
comment:2 Changed 6 years ago by
 Branch set to u/pbruin/15446gp_results_vector
 Commit set to ab293b23647b01c03eae0e5c0a9f189ebcc2cc3c
 Status changed from new to needs_review
comment:3 Changed 6 years ago by
 Commit changed from ab293b23647b01c03eae0e5c0a9f189ebcc2cc3c to 229fd4c77e034dff5250277d4f9ecc030effe7c7
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
229fd4c  use separate variables instead of a vector for GP results

comment:4 Changed 6 years ago by
Never mind the commit in comment:3, this breaks when there are more than 65535 variables.
comment:5 Changed 6 years ago by
 Commit changed from 229fd4c77e034dff5250277d4f9ecc030effe7c7 to ab293b23647b01c03eae0e5c0a9f189ebcc2cc3c
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
ab293b2  fix resizing of GP results vector when stack overflow occurs

comment:6 followup: ↓ 7 Changed 6 years ago by
 Status changed from needs_review to positive_review
comment:7 in reply to: ↑ 6 Changed 6 years ago by
Alejandro, could you fill in your name (more precisely your real name, not Trac username) in the "Reviewer" field?
comment:8 Changed 6 years ago by
 Reviewers set to Alejandro Argaez
comment:9 Changed 6 years ago by
 Branch changed from u/pbruin/15446gp_results_vector to ab293b23647b01c03eae0e5c0a9f189ebcc2cc3c
 Resolution set to fixed
 Status changed from positive_review to closed
The problem appears to be fixed by introducing a temporary variable to hold the result of
concat()
instead of directly assigning it tosage
.