[Python-checkins] python/dist/src/Parser asdl_c.py,1.1.2.4,1.1.2.5

bcannon at users.sourceforge.net bcannon at users.sourceforge.net
Mon Mar 21 00:41:01 CET 2005


Update of /cvsroot/python/python/dist/src/Parser
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15588/Parser

Modified Files:
      Tag: ast-branch
	asdl_c.py 
Log Message:
Fix Python/asdl_c.py so that generated files Include/Python-ast.h and
Python/Python-ast.c do proper casting so that the files now compile.

Also removed warning about ambiguous 'if' and 'else' blocks by putting in curly
braces.

Closes bug #1102710.  Thanks logistix.


Index: asdl_c.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Parser/Attic/asdl_c.py,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -d -r1.1.2.4 -r1.1.2.5
--- asdl_c.py	16 Jan 2005 17:09:11 -0000	1.1.2.4
+++ asdl_c.py	20 Mar 2005 23:40:58 -0000	1.1.2.5
@@ -9,7 +9,7 @@
 import asdl
 
 TABSIZE = 8
-MAX_COL = 76
+MAX_COL = 80
 
 def get_c_type(name):
     """Return a string for the C name of the type.
@@ -416,19 +416,22 @@
         # don't call free_TYPE() for them.
 
         elif field.opt:
-            emit("if (%s)" % value, 0)
+            emit("if (%s) {" % value, 0)
             self.free(field, value, depth + 1)
+            emit("}", 0)
         else:
             self.free(field, value, depth)
 
     def free(self, field, value, depth):
-        if str(field.type) in ("identifier", "string"):
-            self.emit("Py_DECREF(%s);" % value, depth)
+        if str(field.type) in ("identifier", "string", "object"):
+            ctype = get_c_type(field.type)
+            self.emit("Py_DECREF((%s)%s);" % (ctype, value), depth)
         elif str(field.type) == "bool":
             return
         else:
             print >> sys.stderr, field.type
-            self.emit("free_%s(%s);" % (field.type, value), depth)
+            ctype = get_c_type(field.type)
+            self.emit("free_%s((%s)%s);" % (field.type, ctype, value), depth)
         
 
 class MarshalFunctionVisitor(PickleVisitor):
@@ -490,15 +493,18 @@
             emit("marshal_write_int(buf, off, asdl_seq_LEN(%s));" % value, 0)
             emit("for (i = 0; i < asdl_seq_LEN(%s); i++) {" % value, 0)
             emit("void *elt = asdl_seq_GET(%s, i);" % value, 1);
-            emit("marshal_write_%s(buf, off, elt);" % field.type, 1)
+            ctype = get_c_type(field.type);
+            emit("marshal_write_%s(buf, off, (%s)elt);" % (field.type,
+                    ctype), 1)
             emit("}", 0)
         elif field.opt:
             emit("if (%s) {" % value, 0)
             emit("marshal_write_int(buf, off, 1);", 1)
             emit("marshal_write_%s(buf, off, %s);" % (field.type, value), 1)
             emit("}", 0)
-            emit("else", 0)
+            emit("else {", 0)
             emit("marshal_write_int(buf, off, 0);", 1)
+            emit("}", 0)
         else:
             emit("marshal_write_%s(buf, off, %s);" % (field.type, value), 0)
 



More information about the Python-checkins mailing list