[Python-checkins] commit of r41584 - in python/branches/ast-objects: Include/Python-ast.h Parser/asdl_c.py Python/Python-ast.c Python/ast.c

martin.v.loewis python-checkins at python.org
Sun Dec 4 10:29:28 CET 2005


Author: martin.v.loewis
Date: Sun Dec  4 10:29:19 2005
New Revision: 41584

Modified:
   python/branches/ast-objects/Include/Python-ast.h
   python/branches/ast-objects/Parser/asdl_c.py
   python/branches/ast-objects/Python/Python-ast.c
   python/branches/ast-objects/Python/ast.c
Log:
Change constructor functions to expect PyObject*
again, remove typedefs.


Modified: python/branches/ast-objects/Include/Python-ast.h
==============================================================================
--- python/branches/ast-objects/Include/Python-ast.h	(original)
+++ python/branches/ast-objects/Include/Python-ast.h	Sun Dec  4 10:29:19 2005
@@ -4,6 +4,8 @@
    macro, type and constant names which are not Py_-prefixed.
    Therefore, the file should not be included in Python.h;
    all symbols relevant to linkage are Py_-prefixed. */
+
+
 PyAPI_DATA(PyTypeObject) Py_mod_Type;
 #define mod_Check(op) PyObject_TypeCheck(op, &Py_mod_Type)
 

Modified: python/branches/ast-objects/Parser/asdl_c.py
==============================================================================
--- python/branches/ast-objects/Parser/asdl_c.py	(original)
+++ python/branches/ast-objects/Parser/asdl_c.py	Sun Dec  4 10:29:19 2005
@@ -162,7 +162,6 @@
             assert type in asdl.builtin_types, type
             emit("%s %s;" % (type, field.name), depth + 1)
         emit("};")
-        emit("typedef PyObject * %s;" % name)
         emit("#define %s_kind(o) (((struct _%s*)o)->_kind)" % (name, name))
         emit("")
         for t in sum.types:
@@ -234,7 +233,7 @@
     def emit_ctor(self, name, args, attrs):
         def emit(s, depth=0, reflow=1):
             self.emit(s, depth, reflow)
-        argstr = ["%s %s" % (f.type, f.name) for f in args]
+        argstr = ["%s %s" % (get_c_type(f.type), f.name) for f in args]
         argstr += ["%s %s" % (argtype, argname)
                    for argtype, argname, opt in attrs]
         argstr = ", ".join(argstr)
@@ -255,7 +254,7 @@
                     emit("}", 1)
                 elif f.seq:
                     emit("if (%s == NULL)" % f.name, 1)
-                    emit("%s = Py_List_New(0);" % f.name, 2)
+                    emit("%s = PyList_New(0);" % f.name, 2)
                 emit("Py_INCREF(%s);" % f.name, 1)
             emit("result->%s = %s;" % (f.name, f.name), 1)
         for argtype, argname, opt in attrs:
@@ -521,12 +520,6 @@
     print >> f, "   Therefore, the file should not be included in Python.h;"
     print >> f, "   all symbols relevant to linkage are Py_-prefixed. */"
     print >> f, "\n"
-    print >> f, "/* typedefs of ASDL's builtin types */"
-    print >> f, "typedef PyObject * identifier;"
-    print >> f, "typedef PyObject * string;"
-    print >> f, "typedef PyObject * bool;"
-    print >> f, "typedef PyObject * object;"
-    print >> f, "\n"
     c = HeaderVisitor(f)
     c.visit(mod)
     f.close()

Modified: python/branches/ast-objects/Python/Python-ast.c
==============================================================================
--- python/branches/ast-objects/Python/Python-ast.c	(original)
+++ python/branches/ast-objects/Python/Python-ast.c	Sun Dec  4 10:29:19 2005
@@ -174,13 +174,13 @@
         return -1;
 }
 PyObject*
-Py_Module_New(stmt body)
+Py_Module_New(PyObject* body)
 {
         struct _Module *result = PyObject_New(struct _Module, &Py_Module_Type);
         if (result == NULL)
                 return NULL;
         if (body == NULL)
-                body = Py_List_New(0);
+                body = PyList_New(0);
         Py_INCREF(body);
         result->body = body;
         return (PyObject*)result;
@@ -259,13 +259,13 @@
 }
 
 PyObject*
-Py_Interactive_New(stmt body)
+Py_Interactive_New(PyObject* body)
 {
         struct _Interactive *result = PyObject_New(struct _Interactive, &Py_Interactive_Type);
         if (result == NULL)
                 return NULL;
         if (body == NULL)
-                body = Py_List_New(0);
+                body = PyList_New(0);
         Py_INCREF(body);
         result->body = body;
         return (PyObject*)result;
@@ -344,7 +344,7 @@
 }
 
 PyObject*
-Py_Expression_New(expr body)
+Py_Expression_New(PyObject* body)
 {
         struct _Expression *result = PyObject_New(struct _Expression, &Py_Expression_Type);
         if (result == NULL)
@@ -418,13 +418,13 @@
 }
 
 PyObject*
-Py_Suite_New(stmt body)
+Py_Suite_New(PyObject* body)
 {
         struct _Suite *result = PyObject_New(struct _Suite, &Py_Suite_Type);
         if (result == NULL)
                 return NULL;
         if (body == NULL)
-                body = Py_List_New(0);
+                body = PyList_New(0);
         Py_INCREF(body);
         result->body = body;
         return (PyObject*)result;
@@ -602,8 +602,8 @@
         return -1;
 }
 PyObject*
-Py_FunctionDef_New(identifier name, arguments args, stmt body, expr decorators,
-                   int lineno)
+Py_FunctionDef_New(PyObject* name, PyObject* args, PyObject* body, PyObject*
+                   decorators, int lineno)
 {
         struct _FunctionDef *result = PyObject_New(struct _FunctionDef, &Py_FunctionDef_Type);
         if (result == NULL)
@@ -613,11 +613,11 @@
         Py_INCREF(args);
         result->args = args;
         if (body == NULL)
-                body = Py_List_New(0);
+                body = PyList_New(0);
         Py_INCREF(body);
         result->body = body;
         if (decorators == NULL)
-                decorators = Py_List_New(0);
+                decorators = PyList_New(0);
         Py_INCREF(decorators);
         result->decorators = decorators;
         result->_base.lineno = lineno;
@@ -721,7 +721,7 @@
 }
 
 PyObject*
-Py_ClassDef_New(identifier name, expr bases, stmt body, int lineno)
+Py_ClassDef_New(PyObject* name, PyObject* bases, PyObject* body, int lineno)
 {
         struct _ClassDef *result = PyObject_New(struct _ClassDef, &Py_ClassDef_Type);
         if (result == NULL)
@@ -729,11 +729,11 @@
         Py_INCREF(name);
         result->name = name;
         if (bases == NULL)
-                bases = Py_List_New(0);
+                bases = PyList_New(0);
         Py_INCREF(bases);
         result->bases = bases;
         if (body == NULL)
-                body = Py_List_New(0);
+                body = PyList_New(0);
         Py_INCREF(body);
         result->body = body;
         result->_base.lineno = lineno;
@@ -832,7 +832,7 @@
 }
 
 PyObject*
-Py_Return_New(expr value, int lineno)
+Py_Return_New(PyObject* value, int lineno)
 {
         struct _Return *result = PyObject_New(struct _Return, &Py_Return_Type);
         if (result == NULL)
@@ -914,13 +914,13 @@
 }
 
 PyObject*
-Py_Delete_New(expr targets, int lineno)
+Py_Delete_New(PyObject* targets, int lineno)
 {
         struct _Delete *result = PyObject_New(struct _Delete, &Py_Delete_Type);
         if (result == NULL)
                 return NULL;
         if (targets == NULL)
-                targets = Py_List_New(0);
+                targets = PyList_New(0);
         Py_INCREF(targets);
         result->targets = targets;
         result->_base.lineno = lineno;
@@ -1001,13 +1001,13 @@
 }
 
 PyObject*
-Py_Assign_New(expr targets, expr value, int lineno)
+Py_Assign_New(PyObject* targets, PyObject* value, int lineno)
 {
         struct _Assign *result = PyObject_New(struct _Assign, &Py_Assign_Type);
         if (result == NULL)
                 return NULL;
         if (targets == NULL)
-                targets = Py_List_New(0);
+                targets = PyList_New(0);
         Py_INCREF(targets);
         result->targets = targets;
         Py_INCREF(value);
@@ -1095,7 +1095,7 @@
 }
 
 PyObject*
-Py_AugAssign_New(expr target, operator op, expr value, int lineno)
+Py_AugAssign_New(PyObject* target, PyObject* op, PyObject* value, int lineno)
 {
         struct _AugAssign *result = PyObject_New(struct _AugAssign, &Py_AugAssign_Type);
         if (result == NULL)
@@ -1184,7 +1184,7 @@
 }
 
 PyObject*
-Py_Print_New(expr dest, expr values, bool nl, int lineno)
+Py_Print_New(PyObject* dest, PyObject* values, PyObject* nl, int lineno)
 {
         struct _Print *result = PyObject_New(struct _Print, &Py_Print_Type);
         if (result == NULL)
@@ -1196,7 +1196,7 @@
         Py_INCREF(dest);
         result->dest = dest;
         if (values == NULL)
-                values = Py_List_New(0);
+                values = PyList_New(0);
         Py_INCREF(values);
         result->values = values;
         Py_INCREF(nl);
@@ -1292,7 +1292,8 @@
 }
 
 PyObject*
-Py_For_New(expr target, expr iter, stmt body, stmt orelse, int lineno)
+Py_For_New(PyObject* target, PyObject* iter, PyObject* body, PyObject* orelse,
+           int lineno)
 {
         struct _For *result = PyObject_New(struct _For, &Py_For_Type);
         if (result == NULL)
@@ -1302,11 +1303,11 @@
         Py_INCREF(iter);
         result->iter = iter;
         if (body == NULL)
-                body = Py_List_New(0);
+                body = PyList_New(0);
         Py_INCREF(body);
         result->body = body;
         if (orelse == NULL)
-                orelse = Py_List_New(0);
+                orelse = PyList_New(0);
         Py_INCREF(orelse);
         result->orelse = orelse;
         result->_base.lineno = lineno;
@@ -1410,7 +1411,7 @@
 }
 
 PyObject*
-Py_While_New(expr test, stmt body, stmt orelse, int lineno)
+Py_While_New(PyObject* test, PyObject* body, PyObject* orelse, int lineno)
 {
         struct _While *result = PyObject_New(struct _While, &Py_While_Type);
         if (result == NULL)
@@ -1418,11 +1419,11 @@
         Py_INCREF(test);
         result->test = test;
         if (body == NULL)
-                body = Py_List_New(0);
+                body = PyList_New(0);
         Py_INCREF(body);
         result->body = body;
         if (orelse == NULL)
-                orelse = Py_List_New(0);
+                orelse = PyList_New(0);
         Py_INCREF(orelse);
         result->orelse = orelse;
         result->_base.lineno = lineno;
@@ -1521,7 +1522,7 @@
 }
 
 PyObject*
-Py_If_New(expr test, stmt body, stmt orelse, int lineno)
+Py_If_New(PyObject* test, PyObject* body, PyObject* orelse, int lineno)
 {
         struct _If *result = PyObject_New(struct _If, &Py_If_Type);
         if (result == NULL)
@@ -1529,11 +1530,11 @@
         Py_INCREF(test);
         result->test = test;
         if (body == NULL)
-                body = Py_List_New(0);
+                body = PyList_New(0);
         Py_INCREF(body);
         result->body = body;
         if (orelse == NULL)
-                orelse = Py_List_New(0);
+                orelse = PyList_New(0);
         Py_INCREF(orelse);
         result->orelse = orelse;
         result->_base.lineno = lineno;
@@ -1632,7 +1633,7 @@
 }
 
 PyObject*
-Py_Raise_New(expr type, expr inst, expr tback, int lineno)
+Py_Raise_New(PyObject* type, PyObject* inst, PyObject* tback, int lineno)
 {
         struct _Raise *result = PyObject_New(struct _Raise, &Py_Raise_Type);
         if (result == NULL)
@@ -1742,21 +1743,22 @@
 }
 
 PyObject*
-Py_TryExcept_New(stmt body, excepthandler handlers, stmt orelse, int lineno)
+Py_TryExcept_New(PyObject* body, PyObject* handlers, PyObject* orelse, int
+                 lineno)
 {
         struct _TryExcept *result = PyObject_New(struct _TryExcept, &Py_TryExcept_Type);
         if (result == NULL)
                 return NULL;
         if (body == NULL)
-                body = Py_List_New(0);
+                body = PyList_New(0);
         Py_INCREF(body);
         result->body = body;
         if (handlers == NULL)
-                handlers = Py_List_New(0);
+                handlers = PyList_New(0);
         Py_INCREF(handlers);
         result->handlers = handlers;
         if (orelse == NULL)
-                orelse = Py_List_New(0);
+                orelse = PyList_New(0);
         Py_INCREF(orelse);
         result->orelse = orelse;
         result->_base.lineno = lineno;
@@ -1865,17 +1867,17 @@
 }
 
 PyObject*
-Py_TryFinally_New(stmt body, stmt finalbody, int lineno)
+Py_TryFinally_New(PyObject* body, PyObject* finalbody, int lineno)
 {
         struct _TryFinally *result = PyObject_New(struct _TryFinally, &Py_TryFinally_Type);
         if (result == NULL)
                 return NULL;
         if (body == NULL)
-                body = Py_List_New(0);
+                body = PyList_New(0);
         Py_INCREF(body);
         result->body = body;
         if (finalbody == NULL)
-                finalbody = Py_List_New(0);
+                finalbody = PyList_New(0);
         Py_INCREF(finalbody);
         result->finalbody = finalbody;
         result->_base.lineno = lineno;
@@ -1969,7 +1971,7 @@
 }
 
 PyObject*
-Py_Assert_New(expr test, expr msg, int lineno)
+Py_Assert_New(PyObject* test, PyObject* msg, int lineno)
 {
         struct _Assert *result = PyObject_New(struct _Assert, &Py_Assert_Type);
         if (result == NULL)
@@ -2058,13 +2060,13 @@
 }
 
 PyObject*
-Py_Import_New(alias names, int lineno)
+Py_Import_New(PyObject* names, int lineno)
 {
         struct _Import *result = PyObject_New(struct _Import, &Py_Import_Type);
         if (result == NULL)
                 return NULL;
         if (names == NULL)
-                names = Py_List_New(0);
+                names = PyList_New(0);
         Py_INCREF(names);
         result->names = names;
         result->_base.lineno = lineno;
@@ -2145,7 +2147,7 @@
 }
 
 PyObject*
-Py_ImportFrom_New(identifier module, alias names, int lineno)
+Py_ImportFrom_New(PyObject* module, PyObject* names, int lineno)
 {
         struct _ImportFrom *result = PyObject_New(struct _ImportFrom, &Py_ImportFrom_Type);
         if (result == NULL)
@@ -2153,7 +2155,7 @@
         Py_INCREF(module);
         result->module = module;
         if (names == NULL)
-                names = Py_List_New(0);
+                names = PyList_New(0);
         Py_INCREF(names);
         result->names = names;
         result->_base.lineno = lineno;
@@ -2239,7 +2241,7 @@
 }
 
 PyObject*
-Py_Exec_New(expr body, expr globals, expr locals, int lineno)
+Py_Exec_New(PyObject* body, PyObject* globals, PyObject* locals, int lineno)
 {
         struct _Exec *result = PyObject_New(struct _Exec, &Py_Exec_Type);
         if (result == NULL)
@@ -2342,13 +2344,13 @@
 }
 
 PyObject*
-Py_Global_New(identifier names, int lineno)
+Py_Global_New(PyObject* names, int lineno)
 {
         struct _Global *result = PyObject_New(struct _Global, &Py_Global_Type);
         if (result == NULL)
                 return NULL;
         if (names == NULL)
-                names = Py_List_New(0);
+                names = PyList_New(0);
         Py_INCREF(names);
         result->names = names;
         result->_base.lineno = lineno;
@@ -2427,7 +2429,7 @@
 }
 
 PyObject*
-Py_Expr_New(expr value, int lineno)
+Py_Expr_New(PyObject* value, int lineno)
 {
         struct _Expr *result = PyObject_New(struct _Expr, &Py_Expr_Type);
         if (result == NULL)
@@ -2794,7 +2796,7 @@
         return -1;
 }
 PyObject*
-Py_BoolOp_New(boolop op, expr values, int lineno)
+Py_BoolOp_New(PyObject* op, PyObject* values, int lineno)
 {
         struct _BoolOp *result = PyObject_New(struct _BoolOp, &Py_BoolOp_Type);
         if (result == NULL)
@@ -2802,7 +2804,7 @@
         Py_INCREF(op);
         result->op = op;
         if (values == NULL)
-                values = Py_List_New(0);
+                values = PyList_New(0);
         Py_INCREF(values);
         result->values = values;
         result->_base.lineno = lineno;
@@ -2888,7 +2890,7 @@
 }
 
 PyObject*
-Py_BinOp_New(expr left, operator op, expr right, int lineno)
+Py_BinOp_New(PyObject* left, PyObject* op, PyObject* right, int lineno)
 {
         struct _BinOp *result = PyObject_New(struct _BinOp, &Py_BinOp_Type);
         if (result == NULL)
@@ -2977,7 +2979,7 @@
 }
 
 PyObject*
-Py_UnaryOp_New(unaryop op, expr operand, int lineno)
+Py_UnaryOp_New(PyObject* op, PyObject* operand, int lineno)
 {
         struct _UnaryOp *result = PyObject_New(struct _UnaryOp, &Py_UnaryOp_Type);
         if (result == NULL)
@@ -3059,7 +3061,7 @@
 }
 
 PyObject*
-Py_Lambda_New(arguments args, expr body, int lineno)
+Py_Lambda_New(PyObject* args, PyObject* body, int lineno)
 {
         struct _Lambda *result = PyObject_New(struct _Lambda, &Py_Lambda_Type);
         if (result == NULL)
@@ -3141,17 +3143,17 @@
 }
 
 PyObject*
-Py_Dict_New(expr keys, expr values, int lineno)
+Py_Dict_New(PyObject* keys, PyObject* values, int lineno)
 {
         struct _Dict *result = PyObject_New(struct _Dict, &Py_Dict_Type);
         if (result == NULL)
                 return NULL;
         if (keys == NULL)
-                keys = Py_List_New(0);
+                keys = PyList_New(0);
         Py_INCREF(keys);
         result->keys = keys;
         if (values == NULL)
-                values = Py_List_New(0);
+                values = PyList_New(0);
         Py_INCREF(values);
         result->values = values;
         result->_base.lineno = lineno;
@@ -3245,7 +3247,7 @@
 }
 
 PyObject*
-Py_ListComp_New(expr elt, comprehension generators, int lineno)
+Py_ListComp_New(PyObject* elt, PyObject* generators, int lineno)
 {
         struct _ListComp *result = PyObject_New(struct _ListComp, &Py_ListComp_Type);
         if (result == NULL)
@@ -3253,7 +3255,7 @@
         Py_INCREF(elt);
         result->elt = elt;
         if (generators == NULL)
-                generators = Py_List_New(0);
+                generators = PyList_New(0);
         Py_INCREF(generators);
         result->generators = generators;
         result->_base.lineno = lineno;
@@ -3340,7 +3342,7 @@
 }
 
 PyObject*
-Py_GeneratorExp_New(expr elt, comprehension generators, int lineno)
+Py_GeneratorExp_New(PyObject* elt, PyObject* generators, int lineno)
 {
         struct _GeneratorExp *result = PyObject_New(struct _GeneratorExp, &Py_GeneratorExp_Type);
         if (result == NULL)
@@ -3348,7 +3350,7 @@
         Py_INCREF(elt);
         result->elt = elt;
         if (generators == NULL)
-                generators = Py_List_New(0);
+                generators = PyList_New(0);
         Py_INCREF(generators);
         result->generators = generators;
         result->_base.lineno = lineno;
@@ -3435,7 +3437,7 @@
 }
 
 PyObject*
-Py_Yield_New(expr value, int lineno)
+Py_Yield_New(PyObject* value, int lineno)
 {
         struct _Yield *result = PyObject_New(struct _Yield, &Py_Yield_Type);
         if (result == NULL)
@@ -3517,7 +3519,7 @@
 }
 
 PyObject*
-Py_Compare_New(expr left, cmpop ops, expr comparators, int lineno)
+Py_Compare_New(PyObject* left, PyObject* ops, PyObject* comparators, int lineno)
 {
         struct _Compare *result = PyObject_New(struct _Compare, &Py_Compare_Type);
         if (result == NULL)
@@ -3525,11 +3527,11 @@
         Py_INCREF(left);
         result->left = left;
         if (ops == NULL)
-                ops = Py_List_New(0);
+                ops = PyList_New(0);
         Py_INCREF(ops);
         result->ops = ops;
         if (comparators == NULL)
-                comparators = Py_List_New(0);
+                comparators = PyList_New(0);
         Py_INCREF(comparators);
         result->comparators = comparators;
         result->_base.lineno = lineno;
@@ -3628,8 +3630,8 @@
 }
 
 PyObject*
-Py_Call_New(expr func, expr args, keyword keywords, expr starargs, expr kwargs,
-            int lineno)
+Py_Call_New(PyObject* func, PyObject* args, PyObject* keywords, PyObject*
+            starargs, PyObject* kwargs, int lineno)
 {
         struct _Call *result = PyObject_New(struct _Call, &Py_Call_Type);
         if (result == NULL)
@@ -3637,11 +3639,11 @@
         Py_INCREF(func);
         result->func = func;
         if (args == NULL)
-                args = Py_List_New(0);
+                args = PyList_New(0);
         Py_INCREF(args);
         result->args = args;
         if (keywords == NULL)
-                keywords = Py_List_New(0);
+                keywords = PyList_New(0);
         Py_INCREF(keywords);
         result->keywords = keywords;
         if (starargs == NULL) {
@@ -3768,7 +3770,7 @@
 }
 
 PyObject*
-Py_Repr_New(expr value, int lineno)
+Py_Repr_New(PyObject* value, int lineno)
 {
         struct _Repr *result = PyObject_New(struct _Repr, &Py_Repr_Type);
         if (result == NULL)
@@ -3843,7 +3845,7 @@
 }
 
 PyObject*
-Py_Num_New(object n, int lineno)
+Py_Num_New(PyObject* n, int lineno)
 {
         struct _Num *result = PyObject_New(struct _Num, &Py_Num_Type);
         if (result == NULL)
@@ -3918,7 +3920,7 @@
 }
 
 PyObject*
-Py_Str_New(string s, int lineno)
+Py_Str_New(PyObject* s, int lineno)
 {
         struct _Str *result = PyObject_New(struct _Str, &Py_Str_Type);
         if (result == NULL)
@@ -3993,7 +3995,7 @@
 }
 
 PyObject*
-Py_Attribute_New(expr value, identifier attr, expr_context ctx, int lineno)
+Py_Attribute_New(PyObject* value, PyObject* attr, PyObject* ctx, int lineno)
 {
         struct _Attribute *result = PyObject_New(struct _Attribute, &Py_Attribute_Type);
         if (result == NULL)
@@ -4082,7 +4084,7 @@
 }
 
 PyObject*
-Py_Subscript_New(expr value, slice slice, expr_context ctx, int lineno)
+Py_Subscript_New(PyObject* value, PyObject* slice, PyObject* ctx, int lineno)
 {
         struct _Subscript *result = PyObject_New(struct _Subscript, &Py_Subscript_Type);
         if (result == NULL)
@@ -4171,7 +4173,7 @@
 }
 
 PyObject*
-Py_Name_New(identifier id, expr_context ctx, int lineno)
+Py_Name_New(PyObject* id, PyObject* ctx, int lineno)
 {
         struct _Name *result = PyObject_New(struct _Name, &Py_Name_Type);
         if (result == NULL)
@@ -4253,13 +4255,13 @@
 }
 
 PyObject*
-Py_List_New(expr elts, expr_context ctx, int lineno)
+Py_List_New(PyObject* elts, PyObject* ctx, int lineno)
 {
         struct _List *result = PyObject_New(struct _List, &Py_List_Type);
         if (result == NULL)
                 return NULL;
         if (elts == NULL)
-                elts = Py_List_New(0);
+                elts = PyList_New(0);
         Py_INCREF(elts);
         result->elts = elts;
         Py_INCREF(ctx);
@@ -4346,13 +4348,13 @@
 }
 
 PyObject*
-Py_Tuple_New(expr elts, expr_context ctx, int lineno)
+Py_Tuple_New(PyObject* elts, PyObject* ctx, int lineno)
 {
         struct _Tuple *result = PyObject_New(struct _Tuple, &Py_Tuple_Type);
         if (result == NULL)
                 return NULL;
         if (elts == NULL)
-                elts = Py_List_New(0);
+                elts = PyList_New(0);
         Py_INCREF(elts);
         result->elts = elts;
         Py_INCREF(ctx);
@@ -5031,7 +5033,7 @@
 }
 
 PyObject*
-Py_Slice_New(expr lower, expr upper, expr step)
+Py_Slice_New(PyObject* lower, PyObject* upper, PyObject* step)
 {
         struct _Slice *result = PyObject_New(struct _Slice, &Py_Slice_Type);
         if (result == NULL)
@@ -5140,13 +5142,13 @@
 }
 
 PyObject*
-Py_ExtSlice_New(slice dims)
+Py_ExtSlice_New(PyObject* dims)
 {
         struct _ExtSlice *result = PyObject_New(struct _ExtSlice, &Py_ExtSlice_Type);
         if (result == NULL)
                 return NULL;
         if (dims == NULL)
-                dims = Py_List_New(0);
+                dims = PyList_New(0);
         Py_INCREF(dims);
         result->dims = dims;
         return (PyObject*)result;
@@ -5226,7 +5228,7 @@
 }
 
 PyObject*
-Py_Index_New(expr value)
+Py_Index_New(PyObject* value)
 {
         struct _Index *result = PyObject_New(struct _Index, &Py_Index_Type);
         if (result == NULL)
@@ -7424,7 +7426,7 @@
 }
 
 PyObject*
-Py_comprehension_New(expr target, expr iter, expr ifs)
+Py_comprehension_New(PyObject* target, PyObject* iter, PyObject* ifs)
 {
         struct _comprehension *result = PyObject_New(struct _comprehension, &Py_comprehension_Type);
         if (result == NULL)
@@ -7434,7 +7436,7 @@
         Py_INCREF(iter);
         result->iter = iter;
         if (ifs == NULL)
-                ifs = Py_List_New(0);
+                ifs = PyList_New(0);
         Py_INCREF(ifs);
         result->ifs = ifs;
         return (PyObject*)result;
@@ -7523,7 +7525,7 @@
 }
 
 PyObject*
-Py_excepthandler_New(expr type, expr name, stmt body)
+Py_excepthandler_New(PyObject* type, PyObject* name, PyObject* body)
 {
         struct _excepthandler *result = PyObject_New(struct _excepthandler, &Py_excepthandler_Type);
         if (result == NULL)
@@ -7541,7 +7543,7 @@
         Py_INCREF(name);
         result->name = name;
         if (body == NULL)
-                body = Py_List_New(0);
+                body = PyList_New(0);
         Py_INCREF(body);
         result->body = body;
         return (PyObject*)result;
@@ -7636,13 +7638,14 @@
 }
 
 PyObject*
-Py_arguments_New(expr args, identifier vararg, identifier kwarg, expr defaults)
+Py_arguments_New(PyObject* args, PyObject* vararg, PyObject* kwarg, PyObject*
+                 defaults)
 {
         struct _arguments *result = PyObject_New(struct _arguments, &Py_arguments_Type);
         if (result == NULL)
                 return NULL;
         if (args == NULL)
-                args = Py_List_New(0);
+                args = PyList_New(0);
         Py_INCREF(args);
         result->args = args;
         if (vararg == NULL) {
@@ -7658,7 +7661,7 @@
         Py_INCREF(kwarg);
         result->kwarg = kwarg;
         if (defaults == NULL)
-                defaults = Py_List_New(0);
+                defaults = PyList_New(0);
         Py_INCREF(defaults);
         result->defaults = defaults;
         return (PyObject*)result;
@@ -7763,7 +7766,7 @@
 }
 
 PyObject*
-Py_keyword_New(identifier arg, expr value)
+Py_keyword_New(PyObject* arg, PyObject* value)
 {
         struct _keyword *result = PyObject_New(struct _keyword, &Py_keyword_Type);
         if (result == NULL)
@@ -7844,7 +7847,7 @@
 }
 
 PyObject*
-Py_alias_New(identifier name, identifier asname)
+Py_alias_New(PyObject* name, PyObject* asname)
 {
         struct _alias *result = PyObject_New(struct _alias, &Py_alias_Type);
         if (result == NULL)

Modified: python/branches/ast-objects/Python/ast.c
==============================================================================
--- python/branches/ast-objects/Python/ast.c	(original)
+++ python/branches/ast-objects/Python/ast.c	Sun Dec  4 10:29:19 2005
@@ -90,6 +90,9 @@
 
 #define NEW_IDENTIFIER(n) PyString_InternFromString(STR(n))
 
+#define Py_RELEASE(var)   do{Py_DECREF(var);var=NULL;}while(0);
+#define STEAL_ITEM(l,i,o) do{PyList_SET_ITEM(l,i,o);o=NULL;}while(0);
+
 /* This routine provides an invalid object for the syntax error.
    The outermost routine must unpack this error and create the
    proper object.  We do this so that we don't have to pass
@@ -278,8 +281,7 @@
 		s = Pass(n->n_lineno);
 		if (!s)
 		    goto error;
-		Py_INCREF(s); /* set_item will steal the ref */
-                PyList_SET_ITEM(stmts, 0, s);
+		STEAL_ITEM(stmts, 0, s);
 		result = Interactive(stmts);
 		goto success;
             }
@@ -293,8 +295,7 @@
 		    s = ast_for_stmt(&c, n);
 		    if (!s)
 			goto error;
-		    Py_INCREF(s);
-                    PyList_SET_ITEM(stmts, 0, s);
+                    STEAL_ITEM(stmts, 0, s);
                 }
                 else {
                     /* Only a simple_stmt can contain multiple statements. */
@@ -305,8 +306,7 @@
                         s = ast_for_stmt(&c, CHILD(n, i));
                         if (!s)
                             goto error;
-			Py_INCREF(s);
-                        PyList_SET_ITEM(stmts, i / 2, s);
+                        STEAL_ITEM(stmts, i / 2, s);
                     }
                 }
 
@@ -332,34 +332,35 @@
 /* Return the AST repr. of the operator represented as syntax (|, ^, etc.)
 */
 
-static operator_ty
+static PyObject*
 get_operator(const node *n)
 {
     switch (TYPE(n)) {
         case VBAR:
-            return BitOr;
+            return BitOr();
         case CIRCUMFLEX:
-            return BitXor;
+            return BitXor();
         case AMPER:
-            return BitAnd;
+            return BitAnd();
         case LEFTSHIFT:
-            return LShift;
+            return LShift();
         case RIGHTSHIFT:
-            return RShift;
+            return RShift();
         case PLUS:
-            return Add;
+            return Add();
         case MINUS:
-            return Sub;
+            return Sub();
         case STAR:
-            return Mult;
+            return Mult();
         case SLASH:
-            return Div;
+            return Div();
         case DOUBLESLASH:
-            return FloorDiv;
+            return FloorDiv();
         case PERCENT:
-            return Mod;
+            return Mod();
         default:
-            return 0;
+	    PyErr_BadInternalCall();
+            return NULL;
     }
 }
 
@@ -375,42 +376,44 @@
 */
 
 static int
-set_context(expr_ty e, expr_context_ty ctx, const node *n)
+set_context(PyObject* _e, PyObject* ctx, const node *n)
 {
-    asdl_seq *s = NULL;
+    struct _expr *e = (struct _expr*)_e;
+    PyObject *s = NULL;
 
-    switch (e->kind) {
+#define SET_CTX(x) Py_DECREF(x); Py_INCREF(ctx); x = ctx
+    switch (e->_kind) {
         case Attribute_kind:
-	    if (ctx == Store &&
-		!strcmp(PyString_AS_STRING(e->v.Attribute.attr), "None")) {
+	    if (Store_Check(ctx) &&
+		!strcmp(PyString_AS_STRING(Attribute_attr(e)), "None")) {
 		    return ast_error(n, "assignment to None");
 	    }
-	    e->v.Attribute.ctx = ctx;
+	    SET_CTX(Attribute_ctx(e));
 	    break;
         case Subscript_kind:
-	    e->v.Subscript.ctx = ctx;
+	    SET_CTX(Subscript_ctx(e));
 	    break;
         case Name_kind:
-	    if (ctx == Store &&
-		!strcmp(PyString_AS_STRING(e->v.Name.id), "None")) {
+	    if (Store_Check(ctx) &&
+		!strcmp(PyString_AS_STRING(Name_id(e)), "None")) {
 		    return ast_error(n, "assignment to None");
 	    }
-	    e->v.Name.ctx = ctx;
+	    SET_CTX(Name_ctx(e));
 	    break;
         case List_kind:
-	    e->v.List.ctx = ctx;
-	    s = e->v.List.elts;
+	    SET_CTX(List_ctx(e));
+	    s = List_elts(e);
 	    break;
         case Tuple_kind:
-            if (asdl_seq_LEN(e->v.Tuple.elts) == 0) 
+            if (PyList_GET_SIZE(Tuple_elts(e)) == 0) 
                 return ast_error(n, "can't assign to ()");
-	    e->v.Tuple.ctx = ctx;
-	    s = e->v.Tuple.elts;
+	    SET_CTX(Tuple_ctx(e));
+	    s = Tuple_elts(e);
 	    break;
         case Call_kind:
-	    if (ctx == Store)
+	    if (Store_Check(ctx))
 		return ast_error(n, "can't assign to function call");
-	    else if (ctx == Del)
+	    else if (Del_Check(ctx))
 		return ast_error(n, "can't delete function call");
 	    else
 		return ast_error(n, "unexpected operation on function call");
@@ -427,7 +430,7 @@
 	   char buf[300];
 	   PyOS_snprintf(buf, sizeof(buf), 
 			 "unexpected expression in assignment %d (line %d)", 
-			 e->kind, e->lineno);
+			 e->_kind, e->lineno);
 	   return ast_error(n, buf);
        }
     }
@@ -437,53 +440,54 @@
     if (s) {
 	int i;
 
-	for (i = 0; i < asdl_seq_LEN(s); i++) {
-	    if (!set_context(asdl_seq_GET(s, i), ctx, n))
+	for (i = 0; i < PyList_GET_SIZE(s); i++) {
+	    if (!set_context(PyList_GET_ITEM(s, i), ctx, n))
 		return 0;
 	}
     }
     return 1;
+#undef SET_CTX
 }
 
-static operator_ty
+static PyObject*
 ast_for_augassign(const node *n)
 {
     REQ(n, augassign);
     n = CHILD(n, 0);
     switch (STR(n)[0]) {
         case '+':
-            return Add;
+            return Add();
         case '-':
-            return Sub;
+            return Sub();
         case '/':
             if (STR(n)[1] == '/')
-                return FloorDiv;
+                return FloorDiv();
             else
-                return Div;
+                return Div();
         case '%':
-            return Mod;
+            return Mod();
         case '<':
-            return LShift;
+            return LShift();
         case '>':
-            return RShift;
+            return RShift();
         case '&':
-            return BitAnd;
+            return BitAnd();
         case '^':
-            return BitXor;
+            return BitXor();
         case '|':
-            return BitOr;
+            return BitOr();
         case '*':
             if (STR(n)[1] == '*')
-                return Pow;
+                return Pow();
             else
-                return Mult;
+                return Mult();
         default:
             PyErr_Format(PyExc_SystemError, "invalid augassign: %s", STR(n));
             return 0;
     }
 }
 
-static cmpop_ty
+static PyObject*
 ast_for_comp_op(const node *n)
 {
     /* comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'
@@ -494,22 +498,22 @@
 	n = CHILD(n, 0);
 	switch (TYPE(n)) {
             case LESS:
-                return Lt;
+                return Lt();
             case GREATER:
-                return Gt;
+                return Gt();
             case EQEQUAL:			/* == */
-                return Eq;
+                return Eq();
             case LESSEQUAL:
-                return LtE;
+                return LtE();
             case GREATEREQUAL:
-                return GtE;
+                return GtE();
             case NOTEQUAL:
-                return NotEq;
+                return NotEq();
             case NAME:
                 if (strcmp(STR(n), "in") == 0)
-                    return In;
+                    return In();
                 if (strcmp(STR(n), "is") == 0)
-                    return Is;
+                    return Is();
             default:
                 PyErr_Format(PyExc_SystemError, "invalid comp_op: %s",
                              STR(n));
@@ -521,9 +525,9 @@
 	switch (TYPE(CHILD(n, 0))) {
             case NAME:
                 if (strcmp(STR(CHILD(n, 1)), "in") == 0)
-                    return NotIn;
+                    return NotIn();
                 if (strcmp(STR(CHILD(n, 0)), "is") == 0)
-                    return IsNot;
+                    return IsNot();
             default:
                 PyErr_Format(PyExc_SystemError, "invalid comp_op: %s %s",
                              STR(CHILD(n, 0)), STR(CHILD(n, 1)));
@@ -572,35 +576,44 @@
     return result;
 }
 
-static expr_ty
+static PyObject*
 compiler_complex_args(const node *n)
 {
     int i, len = (NCH(n) + 1) / 2;
-    expr_ty result;
-    asdl_seq *args = asdl_seq_new(len);
+    PyObject *result = NULL;
+    PyObject *args = PyList_New(len);
+    PyObject *store = NULL;
+    PyObject *arg = NULL;
     if (!args)
-        return NULL;
+	goto error;
+    store = Store();
+    if (!store)
+	goto error;
 
     REQ(n, fplist);
 
     for (i = 0; i < len; i++) {
         const node *child = CHILD(CHILD(n, 2*i), 0);
-        expr_ty arg;
         if (TYPE(child) == NAME) {
-		if (!strcmp(STR(child), "None")) {
-			ast_error(child, "assignment to None");
-			return NULL;
-		}
-            arg = Name(NEW_IDENTIFIER(child), Store, LINENO(child));
+	    if (!strcmp(STR(child), "None")) {
+		ast_error(child, "assignment to None");
+		goto error;
+	    }
+            arg = Name(NEW_IDENTIFIER(child), store, LINENO(child));
 	}
         else
             arg = compiler_complex_args(CHILD(CHILD(n, 2*i), 1));
-	set_context(arg, Store, n);
-        asdl_seq_SET(args, i, arg);
+	if (!set_context(arg, store, n))
+	    goto error;
+        PyList_SET_ITEM(args, i, arg);
     }
 
-    result = Tuple(args, Store, LINENO(n));
-    set_context(result, Store, n);
+    result = Tuple(args, store, LINENO(n));
+    set_context(result, store, n);
+ error:
+    Py_XDECREF(args);
+    Py_XDECREF(arg);
+    Py_XDECREF(store);
     return result;
 }
 
@@ -610,7 +623,7 @@
        - check for invalid argument lists like normal after default
 */
 
-static arguments_ty
+static PyObject*
 ast_for_arguments(struct compiling *c, const node *n)
 {
     /* parameters: '(' [varargslist] ')'
@@ -618,8 +631,15 @@
             | '**' NAME) | fpdef ['=' test] (',' fpdef ['=' test])* [',']
     */
     int i, n_args = 0, n_defaults = 0, found_default = 0;
-    asdl_seq *args, *defaults;
-    identifier vararg = NULL, kwarg = NULL;
+    int defno = 0, argno = 0;
+    PyObject *result = NULL;
+    PyObject *args = NULL;
+    PyObject *defaults = NULL;
+    PyObject *vararg = NULL;
+    PyObject *kwarg = NULL;
+    PyObject *e = NULL;
+    PyObject *id = NULL;
+    PyObject *param = NULL;
     node *ch;
 
     if (TYPE(n) == parameters) {
@@ -638,10 +658,10 @@
 	if (TYPE(ch) == EQUAL)
 	    n_defaults++;
     }
-    args = (n_args ? asdl_seq_new(n_args) : NULL);
+    args = (n_args ? PyList_New(n_args) : NULL);
     if (!args && n_args)
-    	return NULL; /* Don't need to go to NULL; nothing allocated */
-    defaults = (n_defaults ? asdl_seq_new(n_defaults) : NULL);
+    	goto error;
+    defaults = (n_defaults ? PyList_New(n_defaults) : NULL);
     if (!defaults && n_defaults)
         goto error;
 
@@ -657,8 +677,10 @@
                    anything other than EQUAL or a comma? */
                 /* XXX Should NCH(n) check be made a separate check? */
                 if (i + 1 < NCH(n) && TYPE(CHILD(n, i + 1)) == EQUAL) {
-                    asdl_seq_APPEND(defaults, 
-				    ast_for_expr(c, CHILD(n, i + 2)));
+		    e = ast_for_expr(c, CHILD(n, i + 2));
+		    if (!e)
+			goto error;
+                    STEAL_ITEM(defaults, defno++, e);
                     i += 2;
 		    found_default = 1;
                 }
@@ -669,20 +691,24 @@
 		}
 
                 if (NCH(ch) == 3) {
-                    asdl_seq_APPEND(args, 
-                                    compiler_complex_args(CHILD(ch, 1))); 
+		    e = compiler_complex_args(CHILD(ch, 1));
+		    if (!e)
+			goto error;
+                    STEAL_ITEM(args, argno++, e);
 		}
                 else if (TYPE(CHILD(ch, 0)) == NAME) {
-		    expr_ty name;
 		    if (!strcmp(STR(CHILD(ch, 0)), "None")) {
 			    ast_error(CHILD(ch, 0), "assignment to None");
 			    goto error;
 		    }
-                    name = Name(NEW_IDENTIFIER(CHILD(ch, 0)),
-                                Param, LINENO(ch));
-                    if (!name)
+		    id = NEW_IDENTIFIER(CHILD(ch, 0));
+		    if (!id) goto error;
+		    if (!param) param = Param();
+		    if (!param) goto error;
+                    e = Name(id, param, LINENO(ch));
+                    if (!e)
                         goto error;
-                    asdl_seq_APPEND(args, name);
+                    STEAL_ITEM(args, argno++, e);
 					 
 		}
                 i += 2; /* the name and the comma */
@@ -693,6 +719,8 @@
 			goto error;
 		}
                 vararg = NEW_IDENTIFIER(CHILD(n, i+1));
+		if (!vararg)
+		    goto error;
                 i += 3;
                 break;
             case DOUBLESTAR:
@@ -701,6 +729,8 @@
 			goto error;
 		}
                 kwarg = NEW_IDENTIFIER(CHILD(n, i+1));
+		if (!kwarg)
+		    goto error;
                 i += 3;
                 break;
             default:
@@ -711,16 +741,16 @@
 	}
     }
 
-    return arguments(args, vararg, kwarg, defaults);
-
+    result = arguments(args, vararg, kwarg, defaults);
  error:
     Py_XDECREF(vararg);
     Py_XDECREF(kwarg);
-    if (args)
-        asdl_expr_seq_free(args);
-    if (defaults)
-        asdl_expr_seq_free(defaults);
-    return NULL;
+    Py_XDECREF(args);
+    Py_XDECREF(defaults);
+    Py_XDECREF(e);
+    Py_XDECREF(id);
+    Py_XDECREF(param);
+    return result;
 }
 
 static expr_ty
@@ -1846,7 +1876,7 @@
                   ast_error(CHILD(ch, 0), "keyword can't be an expression");
                   goto error;
                 }
-		key = e->v.Name.id;
+		key = Name_id(e);
 		free(e); /* XXX: is free correct here? */
 		e = ast_for_expr(c, CHILD(ch, 2));
                 if (!e)


More information about the Python-checkins mailing list