This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: AST compile() patch
Type: Stage:
Components: Interpreter Core Versions: Python 2.6
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: aronacher, christian.heimes, georg.brandl, thomaslee
Priority: normal Keywords: patch

Created on 2008-01-11 23:58 by thomaslee, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
ast-r01.patch thomaslee, 2008-01-11 23:58 A(n almost complete) patch implementing this feature thomaslee, 2008-01-12 00:00 A demonstration of the crash occuring when ast-r01.patch is applied
ast-r02.patch thomaslee, 2008-01-13 01:20 Complete patch?
ast-r03.patch thomaslee, 2008-03-15 11:01 Updated to apply cleanly against HEAD, still pending review.
Messages (9)
msg59764 - (view) Author: Thomas Lee (thomaslee) (Python committer) Date: 2008-01-11 23:58
This patch against HEAD provides the inverse operations to all the
ast2obj_* functions in Python/Python-ast.c: effectively, this allows
conversion to & from a PyObject representation of a Python AST.

Additionally, it updates the compile() builtin to allow it to compile
Python ASTs to bytecode.

The patch seems to work for most simple cases, but crashes out with a
segfault when trying to compile functions for some reason.
msg59765 - (view) Author: Thomas Lee (thomaslee) (Python committer) Date: 2008-01-12 00:00
Attaching a sample program to demonstrate the crash.
msg59766 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-12 00:03
Georg is working on the AST front.
msg59813 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-01-12 11:15
This is great work!

The problem is that ast2obj_object translates NULL values to Py_None,
but obj2ast_object doesn't translate that back. This definition fixes
your testcase:

static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
    if (obj == Py_None)
        obj = NULL;
    *out = obj;
    return 0;
msg59847 - (view) Author: Thomas Lee (thomaslee) (Python committer) Date: 2008-01-13 01:20
I knew it would be a simple one for somebody who knew what to look for
:) Thanks Georg! r02 is the updated patch. Changing the title of the
tracker issue to reflect that this *should* be a complete patch now.

Any further recommendations?
msg63545 - (view) Author: Thomas Lee (thomaslee) (Python committer) Date: 2008-03-15 10:49
Georg, just a ping: still waiting on a review for this.
msg63546 - (view) Author: Thomas Lee (thomaslee) (Python committer) Date: 2008-03-15 11:00
Updating the patch to apply cleanly against HEAD.
msg63562 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-03-15 19:56
I'll try to handle it this weekend.
msg64630 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-03-28 12:12
So I finally got to this one :)
I had to fix a few things, mainly error handling, and a refleak.
And I found a refleak in the compiler :)
Reviewed and committed in r62004.
Date User Action Args
2022-04-11 14:56:29adminsetgithub: 46135
2008-03-28 12:12:15georg.brandlsetstatus: open -> closed
resolution: accepted
messages: + msg64630
2008-03-22 23:03:55aronachersetnosy: + aronacher
2008-03-15 19:56:48georg.brandlsetmessages: + msg63562
2008-03-15 11:01:04thomasleesetfiles: + ast-r03.patch
messages: + msg63546
2008-03-15 10:49:55thomasleesetmessages: + msg63545
2008-01-13 01:20:44thomasleesetfiles: + ast-r02.patch
messages: + msg59847
title: Partial AST compile() patch -> AST compile() patch
2008-01-12 11:15:17georg.brandlsetmessages: + msg59813
2008-01-12 00:03:24christian.heimessetpriority: normal
assignee: georg.brandl
messages: + msg59766
keywords: + patch
nosy: + georg.brandl, christian.heimes
2008-01-12 00:00:36thomasleesetfiles: +
messages: + msg59765
2008-01-11 23:58:41thomasleecreate