summaryrefslogtreecommitdiffstats
path: root/Parser/asdl_c.py
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2005-12-17 20:54:49 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2005-12-17 20:54:49 (GMT)
commitadb69fcdffdc50ee3e1d33b00cd874020197b445 (patch)
tree9ea2ddcf5d0625a43739da1d5db7915ef597c8b1 /Parser/asdl_c.py
parent23a695891069f619b5b992d877820558bb8dc70f (diff)
downloadcpython-adb69fcdffdc50ee3e1d33b00cd874020197b445.zip
cpython-adb69fcdffdc50ee3e1d33b00cd874020197b445.tar.gz
cpython-adb69fcdffdc50ee3e1d33b00cd874020197b445.tar.bz2
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
simplifies a lot of error handling code, and fixes many memory leaks.
Diffstat (limited to 'Parser/asdl_c.py')
-rwxr-xr-xParser/asdl_c.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index f45bee4..b1fc77d 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -249,8 +249,9 @@ class PrototypeVisitor(EmitVisitor):
if args:
argstr = ", ".join(["%s %s" % (atype, aname)
for atype, aname, opt in args])
+ argstr += ", PyArena *arena"
else:
- argstr = "void"
+ argstr = "PyArena *arena"
self.emit("%s %s(%s);" % (ctype, name, argstr), 0)
def visitProduct(self, prod, name):
@@ -265,6 +266,10 @@ class FunctionVisitor(PrototypeVisitor):
self.emit(s, depth, reflow)
argstr = ", ".join(["%s %s" % (atype, aname)
for atype, aname, opt in args + attrs])
+ if argstr:
+ argstr += ", PyArena *arena"
+ else:
+ argstr = "PyArena *arena"
self.emit("%s" % ctype, 0)
emit("%s(%s)" % (name, argstr))
emit("{")
@@ -280,7 +285,7 @@ class FunctionVisitor(PrototypeVisitor):
emit('return NULL;', 2)
emit('}', 1)
- emit("p = (%s)malloc(sizeof(*p));" % ctype, 1)
+ emit("p = (%s)PyArena_Malloc(arena, sizeof(*p));" % ctype, 1);
emit("if (!p) {", 1)
emit("PyErr_NoMemory();", 2)
emit("return NULL;", 2)
@@ -655,7 +660,7 @@ def main(srcfile):
c = ChainOfVisitors(TypeDefVisitor(f),
StructVisitor(f),
PrototypeVisitor(f),
- FreePrototypeVisitor(f),
+## FreePrototypeVisitor(f),
)
c.visit(mod)
f.close()
@@ -671,8 +676,8 @@ def main(srcfile):
print >> f
v = ChainOfVisitors(MarshalPrototypeVisitor(f),
FunctionVisitor(f),
- FreeUtilVisitor(f),
- FreeVisitor(f),
+## FreeUtilVisitor(f),
+## FreeVisitor(f),
MarshalUtilVisitor(f),
MarshalFunctionVisitor(f),
)