Changes between Initial Version and Version 1 of Ticket #13447, comment 27


Ignore:
Timestamp:
Sep 17, 2012, 3:30:10 AM (10 years ago)
Author:
Nils Bruin
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #13447, comment 27

    initial v1  
    1717So I think you have to bite the bullet and ensure that get_cparent doesn't access any python attributes or that you can avoid calling it in a `__dealloc__`.
    1818
    19 I'm afraid you will end up rewriting essentially all of sage, but people will be grateful. Of course, I could be wrong.
     19'''EDIT:''' Or perhaps not. While looking at the code a bit I concluded I don't understand a bit of it, due to the templating. I think what I wrote above has some truth to it, but I honestly cannot say whether it has any relevance to the problem at hand. It seems to explain what you're experiencing.
     20
     21We have:
     22{{{
     23    def __dealloc__(self):
     24        celement_destruct(&self.x, get_cparent((<Polynomial_template>self)._parent))
     25}}}
     26and for us:
     27{{{
     28get_cparent(parent) == <ntl_ZZ_pEContext_class>(parent._modulus)
     29}}}
     30The `_parent` attribute is a cython slot. However, it holds a reference to a python-managed object, so I think cython ensures it's properly taken into account in GC cycle counting. But that would suggest to me python could clear this slot to break cycles! So in that case, `Polynomial_template` is never safe. It could be I'm wrong, however.
     31
     32I haven't been able to locate what `parent._modulus` is in this case. I'd assume that's a cython slot too. Then that access would be just as safe as the `._parent` lookup before.
     33At this point perhaps Martin Albrecht, Robert Bradshaw and Yann Laigle-Chapuy can give some enlightenment about the design of the templates and their use in `Polynomial_ZZ_pEX`.