-
-
Notifications
You must be signed in to change notification settings - Fork 567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proper deallocation of the (unique) pari instance #13741
Comments
comment:1
I don't know how to make a proper doctest. One could (just for testing) create a second pari instance - and the fact that there is no crash would then constitute the test... What do you think? |
comment:2
Replying to @simon-king-jena:
That might be a good idea. I'll have a look at the libpari interface code and see if that looks feasible. |
comment:4
I don't think allocating a second instance is possible at all because of C stuff in PARI which would get overwritten (e.g. calling pari_init twice in a row would not be that nice). We could hope to be able to properly shutdown the PARI instance and reinstantiating it, but that looks non-trivial. |
comment:5
So, Jean-Pierre, you suggest that the fact that Sage does not crash when exiting is good enough for a test? Shall I add a docstring to the dealloc method saying exactly this? |
comment:6
I think so. The only other "proper" solution I see is to gather all allocation made at the top level of gen.pyx into a global function or a member function of PariInstance, and call this function from the top level after the PariInstance is initialized. All that said, deallocation of gen's does not involve the Pari instance they were created with, and the memory they use does not belong to PARI (i.e. PARI will not try to deallocate this memory when quitting, what FLINT would do following my above remarks), but the fact that at the python level they have a reference to this instance would make calling "del" on the unique Pari instance useless unless we proceed as above and first delete all these global gen's automatically created when importing gen.pyx. |
Attachment: trac13741_pari_dealloc.patch.gz Pari deallocation in a more Cythonic way |
comment:7
I did not add a test, for the reasons we discussed, but I added a comment in the docstring of |
comment:8
Could you just remove the ending newline and use a ..NOTE:: contruction? I'm not really sure the shared C-data is really what should be said. What do you think? |
comment:9
Is this ticket actually up for review? Are we just bikeshedding the hypothetical layout of the docstring if underscore methods would actually appear in the reference manual? |
comment:10
Replying to @vbraun:
Exactly... although this docstring will be useful for future development and let people know what really happens under the rug. But feel free to pick either Simon docstring or mine, or mix'em up as you prefer and we can get this in. |
Reviewer: Volker Braun |
Merged: sage-5.5.rc1 |
comment:13
Follow-up: #18385 (Since the PARI instance is a [module-]global variable, its |
Currently, the unique instance of Pari is deallocated manually when Sage executes sage.all.quit_sage.
I think that's unsafe. In fact, it led to problems at #12215. My suggestion is to deallocate the unique Pari instance in the default Cython way: With a
__dealloc__
method.Hence, I am moving a part of the second patch of #12215 to here. I believe this is cleaner than packing a bunch of unrelated changes into one ticket.
CC: @jpflori @zimmermann6 @vbraun @robertwb @nbruin @malb @orlitzky
Component: memleak
Keywords: pari deallocation
Author: Simon King
Reviewer: Volker Braun
Merged: sage-5.5.rc1
Issue created by migration from https://trac.sagemath.org/ticket/13741
The text was updated successfully, but these errors were encountered: