#15820: Implement sequences of bounded integers
-------------------------------------+-------------------------------------
       Reporter:  SimonKing          |        Owner:
           Type:  enhancement        |       Status:  needs_work
       Priority:  major              |    Milestone:  sage-6.4
      Component:  algebra            |   Resolution:
       Keywords:  sequence bounded   |    Merged in:
  integer                            |    Reviewers:
        Authors:  Simon King         |  Work issues:  memory corruption
Report Upstream:  N/A                |       Commit:
         Branch:                     |  b331dc4f12e7291e9537f607ed155085cabc3fcd
  u/SimonKing/ticket/15820           |     Stopgaps:
   Dependencies:                     |
-------------------------------------+-------------------------------------
Changes (by SimonKing):

 * status:  needs_review => needs_work
 * work_issues:   => memory corruption


Comment:

 I found that the following function achieves to crash sage:
 {{{
 #!python
 def _biseq_stresstest():
     cdef int i
     from sage.misc.prandom import randint
     cdef list L = [BoundedIntegerSequence(6, [randint(0,5) for x in
 range(randint(4,10))]) for y in range(100)]
     cdef int branch
     cdef BoundedIntegerSequence S, T
     for i from 0<=i<10000:
         if (i%1000) == 0:
             print i
         branch = randint(0,4)
         if branch == 0:
             L[randint(0,99)] = L[randint(0,99)]+L[randint(0,99)]
         elif branch == 1:
             x = randint(0,99)
             if len(L[x]):
                 y = randint(0,len(L[x])-1)
                 z = randint(y,len(L[x])-1)
                 L[randint(0,99)] = L[x][y:z]
             else:
                 L[x] = BoundedIntegerSequence(6, [randint(0,5) for x in
 range(randint(4,10))])
         elif branch == 2:
             t = list(L[randint(0,99)])
             t = repr(L[randint(0,99)])
             t = L[randint(0,99)].list()
         elif branch == 3:
             x = randint(0,99)
             if len(L[x]):
                 t = L[x][randint(0,len(L[x])-1)]
                 try:
                     t = L[x].index(t)
                 except ValueError:
                     print L[x]
                     print t
                     raise
             else:
                 L[x] = BoundedIntegerSequence(6, [randint(0,5) for x in
 range(randint(4,10))])
         elif branch == 4:
             S = L[randint(0,99)]
             T = L[randint(0,99)]
             startswith_biseq(S.data,T.data)
             contains_biseq(S.data, T.data, 0)
             max_overlap_biseq(S.data, T.data)
 }}}

 Can someone please see what happens on other machines? On mine (with the
 above function, but also with something that was supposed to be the corner
 stone in my current project), crashes occur in `sage_free` or `mpz_clear`.
 Surprisingly, the variables-to-be-freed/cleared should be just fine, in
 some cases they haven't even been touched after allocation.

 My wild guess is that using `sage_malloc` (in
 `bounded_integer_sequences.pyx`) somehow interferes with gmp's (mpir's?)
 memory management. Even if the reason is different, I suppose it would
 make sense to get rid of `sage_malloc` and `sage_free` in my code. After
 all, I use it for buffers whose length is known at compile time. Hence, I
 should better use arrays.

 So, my plan is: Use arrays instead of `sage_malloc`, and hope that this is
 enough to let above function pass, which would then become a doctest.

--
Ticket URL: <http://trac.sagemath.org/ticket/15820#comment:118>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to