[Python-Dev] Memory management in the AST parser & compiler

Brett Cannon bcannon at gmail.com
Tue Nov 29 23:05:21 CET 2005

On 11/29/05, Neal Norwitz <nnorwitz at gmail.com> wrote:
> 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?

Or should perhaps a branch be made since Subversion makes it so cheap
and this allows multiple people to work on it?


More information about the Python-Dev mailing list