Gregory P. Smith <g...@krypto.org> added the comment:

i haven't confirmed if it is this exact bug but I believe a coworker just ran 
into something similar.  he wrote code to use the ast to remove docstrings from 
code before passing it to compile() (as that saves a noticable amount of 
memory).  in the case the ast for code like:

def foo():
  """this is a docstring."""

Removing the docstring and passing such a thing to compile triggers a problem.  
A workaround was to add a pass in such cases:

if (node.body and isinstance(node.body[0], ast.Expr) and
    isinstance(node.body[0].value, ast.Str)):
  docstring = node.body.pop(0)
  if len(node.body) == 0:
    # An empty body will sometimes provoke a segfault when you call
    # compile on the code object.
    node.body.append(ast.Pass(lineno=docstring.lineno,
                              col_offset=docstring.col_offset))

regardless, it'd be better if compile() *never* crashed on strange input.

----------
nosy: +gregory.p.smith

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11105>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to