[Python-Dev] PyAST_FromNode returning PyTypeObject* ?

"Martin v. Löwis" martin at v.loewis.de
Thu Dec 1 09:22:50 CET 2005


Neal,

Why did you suggest that PyAST_FromNode returns PyTypeObject*?
I can't see why type objects are much used in the AST, unless
I'm missing something essential.

Anyway, I started converting ast.c (two functions only), and
noticed that there is a convention to have nested variables
referring to fresh memory (e.g. inside switch statements). I
started changing these to have all variables at the toplevel.

Then, in either success or failure, you have to release all
of them. Unfortunately, sometimes in failure, an additional
function is called, which isn't called in success. So I
added a success: label.

Also, it is somewhat inconvenient that PyList_SET_ITEM
steals references. Currently, I INCREF the objects added
to the list (as the success: label will DECREF them);
alternatively, clearing the pointer to NULL might also
be appropriate. Perhaps we could have a STEAL_ITEM
macro inside ast.c:

#define STEAL_ITEM(list,index,variable) \
do{PyList_SET_ITEM(list,index,variable);variable=NULL;}while(0)

Regards,
Martin


More information about the Python-Dev mailing list