summaryrefslogtreecommitdiffstats
path: root/pyarg-parsetuple.cocci
diff options
context:
space:
mode:
Diffstat (limited to 'pyarg-parsetuple.cocci')
-rw-r--r--pyarg-parsetuple.cocci87
1 files changed, 67 insertions, 20 deletions
diff --git a/pyarg-parsetuple.cocci b/pyarg-parsetuple.cocci
index 706a489..a33e678 100644
--- a/pyarg-parsetuple.cocci
+++ b/pyarg-parsetuple.cocci
@@ -1,38 +1,85 @@
+@initialize:python@
+"""
+Analyze format strings, compare to vararg types actually passed
+
+FIXME: generalize this to varargs
+"""
+import sys
+sys.path.append('.')
+from validate import validate_types
+num_errors = 0
+
@ParseTuple_1@
-position p1;
+position pos;
expression args;
expression fmt;
type t1;
t1 e1;
@@
-PyArg_ParseTuple(args, fmt@p1, e1)
-
-@initialize:python@
-import sys
-sys.path.append('.')
-from validate import validate_types
+PyArg_ParseTuple@pos(args, fmt, e1)
@script:python@
+pos << ParseTuple_1.pos;
args << ParseTuple_1.args;
fmt << ParseTuple_1.fmt;
t1 << ParseTuple_1.t1;
-p1 << ParseTuple_1.p1;
@@
-"""
-Analyze format strings, compare to vararg types actually passed
-
-FIXME: generalize this to varargs
-"""
-
-#print "args: %s" % args
-#print "fmt: %s" % fmt
-#print "var1: %s" % t1
-#print get_types(fmt.expr)
-
# For some reason, locations are coming as a 1-tuple containing a Location (from
# coccilibs.elems), rather than the location itself
# Hence we use p1[0], not p1
-validate_types(p1[0], fmt.expr, [t1])
+num_errors += validate_types(pos[0], fmt.expr, [t1])
+
+
+
+@ParseTuple_2@
+position pos;
+expression args;
+expression fmt;
+type t1;
+t1 e1;
+type t2;
+t2 e2;
+@@
+
+PyArg_ParseTuple(args@pos, fmt, e1, e2)
+
+@script:python@
+args << ParseTuple_2.args;
+fmt << ParseTuple_2.fmt;
+pos << ParseTuple_2.pos;
+t1 << ParseTuple_2.t1;
+t2 << ParseTuple_2.t2;
+@@
+num_errors += validate_types(pos[0], fmt.expr, [t1, t2])
+
+
+
+@ParseTuple_3@
+position pos;
+expression args;
+expression fmt;
+type t1; t1 e1;
+type t2; t2 e2;
+type t3; t3 e3;
+@@
+
+PyArg_ParseTuple(args@pos, fmt, e1, e2, e3)
+
+@script:python@
+pos << ParseTuple_3.pos;
+args << ParseTuple_3.args;
+fmt << ParseTuple_3.fmt;
+pos << ParseTuple_3.pos;
+t1 << ParseTuple_3.t1;
+t2 << ParseTuple_3.t2;
+t3 << ParseTuple_3.t3;
+@@
+num_errors += validate_types(pos[0], fmt.expr, [t1, t2, t3])
+
+
+@script:python @
+@@
+sys.exit(num_errors)