summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2009-11-16 14:19:02 -0500
committerDavid Malcolm <dmalcolm@redhat.com>2009-11-16 14:19:02 -0500
commit254f88a995334acfe04b5774a6be048a365cdb86 (patch)
tree1219c6c4220b90078ec323a62782ddcb46dd21d3
parent41a0e658a2db1c95bb9ca9ad7dc55a3d7d57e8a4 (diff)
downloadcheck-cpython-254f88a995334acfe04b5774a6be048a365cdb86.tar.gz
check-cpython-254f88a995334acfe04b5774a6be048a365cdb86.tar.xz
check-cpython-254f88a995334acfe04b5774a6be048a365cdb86.zip
Add LGPLv2.1 license to .cocci and .py file; introduce PyArg_ParseTupleAndKeywords, reworking cocci file somewhat
-rw-r--r--pyarg-parsetuple.cocci94
-rw-r--r--validate.py16
2 files changed, 91 insertions, 19 deletions
diff --git a/pyarg-parsetuple.cocci b/pyarg-parsetuple.cocci
index 4195b5e..c0d9595 100644
--- a/pyarg-parsetuple.cocci
+++ b/pyarg-parsetuple.cocci
@@ -1,3 +1,18 @@
+// Copyright © 2009 Red Hat, Inc.
+//
+// This software is licensed to you under the GNU Lesser General Public
+// License, version 2.1 (LGPLv2.1). There is NO WARRANTY for this software,
+// express or implied, including the implied warranties of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. You should have received a copy of
+// LGPLv2.1 along with this software; if not, see
+// http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
+//
+// Red Hat trademarks are not licensed under LGPLv2.1. No permission is
+// granted to use or replicate Red Hat trademarks that are incorporated in
+// this software or its documentation.
+//
+// Red Hat Author(s): David Hugh Malcolm <dmalcolm@redhat.com>
+
@initialize:python@
"""
Analyze format strings passed to variadic function, compare to vararg types actually passed
@@ -8,7 +23,8 @@ import sys
sys.path.append('.')
from validate import validate_types
num_errors = 0
-@ParseTuple_1@
+
+@ check_PyArg_ParseTuple_1 @
position pos;
expression args;
expression fmt;
@@ -19,10 +35,9 @@ t1 e1;
PyArg_ParseTuple@pos(args, fmt, e1)
@script:python@
-pos << ParseTuple_1.pos;
-args << ParseTuple_1.args;
-fmt << ParseTuple_1.fmt;
-t1 << ParseTuple_1.t1;
+pos << check_PyArg_ParseTuple_1.pos;
+fmt << check_PyArg_ParseTuple_1.fmt;
+t1 << check_PyArg_ParseTuple_1.t1;
@@
# For some reason, locations are coming as a 1-tuple containing a Location (from
@@ -32,7 +47,7 @@ num_errors += validate_types(pos[0], fmt.expr, [t1])
-@ParseTuple_2@
+@ check_PyArg_ParseTuple_2 @
position pos;
expression args;
expression fmt;
@@ -45,17 +60,16 @@ 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;
+fmt << check_PyArg_ParseTuple_2.fmt;
+pos << check_PyArg_ParseTuple_2.pos;
+t1 << check_PyArg_ParseTuple_2.t1;
+t2 << check_PyArg_ParseTuple_2.t2;
@@
num_errors += validate_types(pos[0], fmt.expr, [t1, t2])
-@ParseTuple_3@
+@ check_PyArg_ParseTuple_3 @
position pos;
expression args;
expression fmt;
@@ -67,18 +81,60 @@ 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;
+pos << check_PyArg_ParseTuple_3.pos;
+fmt << check_PyArg_ParseTuple_3.fmt;
+pos << check_PyArg_ParseTuple_3.pos;
+t1 << check_PyArg_ParseTuple_3.t1;
+t2 << check_PyArg_ParseTuple_3.t2;
+t3 << check_PyArg_ParseTuple_3.t3;
@@
num_errors += validate_types(pos[0], fmt.expr, [t1, t2, t3])
# and so on... need to find a general way of doing this, rather than repeating for 4, 5, 6...
+# likewise for PyArg_Parse:
+
+
+@ check_PyArg_Parse_1 @
+position pos;
+expression args;
+expression fmt;
+type t1;
+t1 e1;
+@@
+
+PyArg_Parse@pos(args, fmt, e1)
+@script:python@
+pos << check_PyArg_Parse_1.pos;
+args << check_PyArg_Parse_1.args;
+fmt << check_PyArg_Parse_1.fmt;
+pos << check_PyArg_Parse_1.pos;
+t1 << check_PyArg_Parse_1.t1;
+@@
+num_errors += validate_types(pos[0], fmt.expr, [t1])
+
+# again, for all N
+# similarly for PyArg_ParseTupleAndKeywords:
+
+@ check_PyArg_ParseTupleAndKeywords_1 @
+position pos;
+expression args, kw, fmt, keywords;
+type t1;
+t1 e1;
+@@
+
+PyArg_ParseTupleAndKeywords@pos(args, kw, fmt, keywords, e1)
+@script:python@
+pos << check_PyArg_Parse_1.pos;
+args << check_PyArg_Parse_1.args;
+fmt << check_PyArg_Parse_1.fmt;
+pos << check_PyArg_Parse_1.pos;
+t1 << check_PyArg_Parse_1.t1;
+@@
+num_errors += validate_types(pos[0], fmt.expr, [t1])
+
+# etc
@script:python @
@@
+# Shutdown hook: report the number of errors for use in Makefiles etc:
sys.exit(num_errors)
diff --git a/validate.py b/validate.py
index ced4611..786d7c0 100644
--- a/validate.py
+++ b/validate.py
@@ -1,3 +1,19 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright © 2009 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU Lesser General Public
+# License, version 2.1 (LGPLv2.1). There is NO WARRANTY for this software,
+# express or implied, including the implied warranties of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. You should have received a copy of
+# LGPLv2.1 along with this software; if not, see
+# http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
+#
+# Red Hat trademarks are not licensed under LGPLv2.1. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated in
+# this software or its documentation.
+#
+# Red Hat Author(s): David Hugh Malcolm <dmalcolm@redhat.com>
"""
Hooks for validating CPython extension source code
"""