Message155978
| Author |
gregory.p.smith |
| Recipients |
belopolsky, benjamin.peterson, georg.brandl, gregory.p.smith, meador.inge |
| Date |
2012年03月16日.00:33:03 |
| SpamBayes Score |
2.2848392e-08 |
| Marked as misclassified |
No |
| Message-id |
<1331857984.55.0.759612679406.issue11105@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|