[Python-Dev] Memory management in the AST parser & compiler
nnorwitz at gmail.com
Tue Nov 29 19:29:07 CET 2005
On 11/29/05, Nick Coghlan <ncoghlan at gmail.com> wrote:
> When working on the CST->AST parser, there were only a few things I found to
> be seriously painful about the memory management:
> 1. Remembering which free_* variant to call for AST nodes
> 2. Remembering which asdl_seq_*_free variant to call for ASDL sequences (it
> was worse when the variant I wanted didn't exist, since this was done with
> functions rather than preprocessor macros)
> 3. Remembering to transpose free_* and *_free between freeing a single node
> and freeing a sequence.
> 4. Remembering whether or not a given cleanup function could cope with
> NULL's or not
> 5. The fact that there wasn't a consistent "goto error" exception-alike
> mechanism in use
> (I had a Spanish Inquisition-esque experience writing that list ;)
:-) I agree all those are existing issues. #3 could be easily fixed.
#4 I think all cleanup functions can deal with NULLs now. #5
probably ought to be fixed in favor of using gotos.
> Simply switching to PyObjects would solve the first four problems: everything
> becomes a Py_XDECREF.
I'm mostly convinced that using PyObjects would be a good thing.
However, making the change isn't free as all the types need to be
created and this is likely quite a bit of code. I'd like to hear what
Jeremy thinks about this.
Is anyone interested in creating a patch along these lines (even a
partial patch) to see the benefits?
More information about the Python-Dev