#10903: Update Singular to 3-1-3-3.
------------------------+---------------------------------------------------
   Reporter:  malb      |          Owner:  tbd                                  
       
       Type:  defect    |         Status:  needs_info                           
       
   Priority:  critical  |      Milestone:  sage-4.7.2                           
       
  Component:  packages  |       Keywords:  singular SageDays34 sd34             
       
Work_issues:            |       Upstream:  N/A                                  
       
   Reviewer:            |         Author:  Burcin Erocal, Martin Albrecht, 
Volker Braun
     Merged:            |   Dependencies:  #11339                               
       
------------------------+---------------------------------------------------

Comment(by vbraun):

 The rules for using/setting `currRing` when calling libSingular are:

   * The Sage library Python code should never make any assumptions about
 `currRing`.
   * `currRing` can only be assumed to stay defined within pure C/Cython
 code.

 This is particularly important because the garbage collector can run
 between any two Python instructions, but not within C/Cython!

 In order to identify code where we forget to set `currRing`, I implemented
 a function `poison_currRing()` in `sage.libs.singular.singular` that will
 set `currRing` to NULL, triggering a segfault if we forget to set it back
 to a meaningful value before calling libSingular. Using the Python
 debugger hook, this function can be called between each Python command
 (but not within Cython code).

 It can be globally enabled by uncommenting the lines
 {{{
 ### Debugging for Singular, see trac #10903
 from sage.libs.singular.ring import poison_currRing
 sys.settrace(poison_currRing)
 }}}
 at the very end of `sage/all.py`.

 Using this code, I identified and fixed various places in the Sage library
 of the form
 {{{
 #!python
   rChangeCurrRing(_ring)
   self.parent().some_python_method()
   libSingular_func()
 }}}
 Note that calling some python method in-between exits Cython and allows
 Python to run the garbage collector etc! Not only do you exit Cython when
 you return from your Cython function, but also if you call Python in-
 between.

 I also ran into an issue where code uses iteritems() to iterate over
 `locals()`, `globals()`, or dictionaries returned by `gc.get_referrers()`.
 This can potentially raise a `RuntimeError` if those dictionaries change
 during the iteration. Hooking into the python debugger loop is a good way
 of triggering precisely that. This also happens in the `PolyBoRi` Python
 interface, this is now fixed upstream at
 
https://sourceforge.net/tracker/?func=detail&aid=3416946&group_id=210499&atid=1013986

 With the attached patch, I can run the whole Sage testsuite without errors
 while continuosly poisoning `currRing`. If you do not patch `PolyBoRi`,
 you get some otherwise harmless errors from it but no segfaults. Note that
 the patch does not enable the poisoning by default. I am quite sure that
 the patch fixes all remaining Sage/Singular segfault issues. Please give
 it a try!

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10903#comment:42>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to