commit 63ea6c0548da9869b15b87f41abf47bb4ec6f791
Author: David Malcolm <dmalcolm(a)redhat.com>
Date: Fri Jun 24 20:01:29 2011 -0400
Use newlines and indentation to try to make the PyArg_ error messages more readable
libcpychecker/PyArg_ParseTuple.py | 29 ++++++---
testcpychecker.py | 27 ++++++--
.../incorrect_code_z_hash/stderr.txt | 7 ++-
.../incorrect_codes_S_and_U/stderr.txt | 14 +++-
.../incorrect_converters/stderr.txt | 71 +++++++++++++++-----
5 files changed, 109 insertions(+), 39 deletions(-)
---
diff --git a/libcpychecker/PyArg_ParseTuple.py b/libcpychecker/PyArg_ParseTuple.py
index f0b0687..bf99e35 100644
--- a/libcpychecker/PyArg_ParseTuple.py
+++ b/libcpychecker/PyArg_ParseTuple.py
@@ -416,13 +416,21 @@ class WrongNumberOfVars(ParsedFormatStringError):
self.varargs = varargs
def __str__(self):
- return '%s in call to %s with format string "%s" : expected %i extra arguments (%s), but got %i' % (
- self._get_desc_prefix(),
- self.funcname,
- self.fmt.fmt_string,
- self.fmt.num_expected(),
- ', '.join([describe_type(exp_type) for (arg, exp_type) in self.fmt.iter_exp_types()]),
- len(self.varargs))
+ result = ('%s in call to %s with format string "%s"\n'
+ ' expected %i extra arguments:\n'
+ % (self._get_desc_prefix(),
+ self.funcname,
+ self.fmt.fmt_string,
+ self.fmt.num_expected()))
+ for (arg, exp_type) in self.fmt.iter_exp_types():
+ result += ' %s\n' % describe_type(exp_type)
+ if len(self.varargs) == 0:
+ result += ' but got none\n'
+ else:
+ result += ' but got %i:\n' % len(self.varargs)
+ for arg in self.varargs:
+ result += ' %s\n' % describe_type(arg.type)
+ return result
def _get_desc_prefix(self):
raise NotImplementedError
@@ -450,8 +458,11 @@ class MismatchingType(ParsedFormatStringError):
result += describe_precision(va.operand.type)
return result
- return (' argument %i ("%s") had type %s\n'
- ' but was expecting %s for format code "%s"\n'
+ return (' argument %i ("%s") had type\n'
+ ' %s\n'
+ ' but was expecting\n'
+ ' %s\n'
+ ' for format code "%s"\n'
% (self.arg_num, self.vararg, describe_type(self.vararg.type),
describe_type(self.exp_type), self.arg_fmt_string))
diff --git a/testcpychecker.py b/testcpychecker.py
index a7cb255..3a00576 100644
--- a/testcpychecker.py
+++ b/testcpychecker.py
@@ -126,8 +126,11 @@ socket_htons(PyObject *self, PyObject *args)
self.assertFindsError(src,
'$(SRCFILE): In function ‘socket_htons’:\n'
'$(SRCFILE):17:26: error: Mismatching type in call to PyArg_ParseTuple with format code "i:htons" [-fpermissive]\n'
- ' argument 3 ("&x1") had type "long unsigned int *" (pointing to 64 bits)\n'
- ' but was expecting "int *" (pointing to 32 bits) for format code "i"\n')
+ ' argument 3 ("&x1") had type\n'
+ ' "long unsigned int *" (pointing to 64 bits)\n'
+ ' but was expecting\n'
+ ' "int *" (pointing to 32 bits)\n'
+ ' for format code "i"\n')
def test_not_enough_varargs(self):
src = """
@@ -142,7 +145,11 @@ not_enough_varargs(PyObject *self, PyObject *args)
"""
self.assertFindsError(src,
'$(SRCFILE): In function ‘not_enough_varargs’:\n'
- '$(SRCFILE):13:25: error: Not enough arguments in call to PyArg_ParseTuple with format string "i" : expected 1 extra arguments ("int *" (pointing to 32 bits)), but got 0 [-fpermissive]\n')
+ '$(SRCFILE):13:25: error: Not enough arguments in call to PyArg_ParseTuple with format string "i"\n'
+ ' expected 1 extra arguments:\n'
+ ' "int *" (pointing to 32 bits)\n'
+ ' but got none\n'
+ ' [-fpermissive]\n')
def test_too_many_varargs(self):
src = """
@@ -158,7 +165,13 @@ too_many_varargs(PyObject *self, PyObject *args)
"""
self.assertFindsError(src,
'$(SRCFILE): In function ‘too_many_varargs’:\n'
- '$(SRCFILE):14:26: error: Too many arguments in call to PyArg_ParseTuple with format string "i" : expected 1 extra arguments ("int *" (pointing to 32 bits)), but got 2 [-fpermissive]\n')
+ '$(SRCFILE):14:26: error: Too many arguments in call to PyArg_ParseTuple with format string "i"\n'
+ ' expected 1 extra arguments:\n'
+ ' "int *" (pointing to 32 bits)\n'
+ ' but got 2:\n'
+ ' "int *" (pointing to 32 bits)\n'
+ ' "int *" (pointing to 32 bits)\n'
+ ' [-fpermissive]\n')
def test_correct_usage(self):
src = """
@@ -229,8 +242,10 @@ correct_usage(PyObject *self, PyObject *args)
def get_expected_error(self):
return ('$(SRCFILE): In function ‘%(function_name)s’:\n'
'$(SRCFILE):%(linenum)i:%(colnum)i: error: Mismatching type in call to %(funcname)s with format code "%(code)s" [-fpermissive]\n'
- ' argument %(argindex)i ("&val") had type "void * *"\n'
- ' but was expecting "%(exptypename)s *"')
+ ' argument %(argindex)i ("&val") had type\n'
+ ' "void * *"\n'
+ ' but was expecting\n'
+ ' "%(exptypename)s *"')
# we stop there, to avoid spelling out the various possible
# (pointing to N bits)
# variants of the message
diff --git a/tests/cpychecker/PyArg_ParseTuple/incorrect_code_z_hash/stderr.txt b/tests/cpychecker/PyArg_ParseTuple/incorrect_code_z_hash/stderr.txt
index 278daf8..88340a2 100644
--- a/tests/cpychecker/PyArg_ParseTuple/incorrect_code_z_hash/stderr.txt
+++ b/tests/cpychecker/PyArg_ParseTuple/incorrect_code_z_hash/stderr.txt
@@ -1,4 +1,7 @@
tests/cpychecker/PyArg_ParseTuple/incorrect_code_z_hash/input.c: In function ‘incorrect_code_z_hash’:
tests/cpychecker/PyArg_ParseTuple/incorrect_code_z_hash/input.c:34:26: error: Mismatching type in call to PyArg_ParseTuple with format code "z#" [-fpermissive]
- argument 4 ("&len") had type "float *" (pointing to 32 bits)
- but was expecting "Py_ssize_t *" for format code "z#"
+ argument 4 ("&len") had type
+ "float *" (pointing to 32 bits)
+ but was expecting
+ "Py_ssize_t *"
+ for format code "z#"
diff --git a/tests/cpychecker/PyArg_ParseTuple/incorrect_codes_S_and_U/stderr.txt b/tests/cpychecker/PyArg_ParseTuple/incorrect_codes_S_and_U/stderr.txt
index aa46e20..9558f79 100644
--- a/tests/cpychecker/PyArg_ParseTuple/incorrect_codes_S_and_U/stderr.txt
+++ b/tests/cpychecker/PyArg_ParseTuple/incorrect_codes_S_and_U/stderr.txt
@@ -1,7 +1,13 @@
tests/cpychecker/PyArg_ParseTuple/incorrect_codes_S_and_U/input.c: In function ‘incorrect_usage_of_S_and_U’:
tests/cpychecker/PyArg_ParseTuple/incorrect_codes_S_and_U/input.c:29:26: error: Mismatching type in call to PyArg_ParseTuple with format code "SU" [-fpermissive]
- argument 3 ("&val1") had type "int *" (pointing to 32 bits)
- but was expecting one of "PyStringObject * *" or "PyObject * *" for format code "S"
+ argument 3 ("&val1") had type
+ "int *" (pointing to 32 bits)
+ but was expecting
+ one of "PyStringObject * *" or "PyObject * *"
+ for format code "S"
tests/cpychecker/PyArg_ParseTuple/incorrect_codes_S_and_U/input.c:29:26: error: Mismatching type in call to PyArg_ParseTuple with format code "SU" [-fpermissive]
- argument 4 ("&val2") had type "int *" (pointing to 32 bits)
- but was expecting one of "PyUnicodeObject * *" or "PyObject * *" for format code "U"
+ argument 4 ("&val2") had type
+ "int *" (pointing to 32 bits)
+ but was expecting
+ one of "PyUnicodeObject * *" or "PyObject * *"
+ for format code "U"
diff --git a/tests/cpychecker/PyArg_ParseTuple/incorrect_converters/stderr.txt b/tests/cpychecker/PyArg_ParseTuple/incorrect_converters/stderr.txt
index 454911b..f668a2b 100644
--- a/tests/cpychecker/PyArg_ParseTuple/incorrect_converters/stderr.txt
+++ b/tests/cpychecker/PyArg_ParseTuple/incorrect_converters/stderr.txt
@@ -1,27 +1,62 @@
tests/cpychecker/PyArg_ParseTuple/incorrect_converters/input.c: In function ‘incorrect_usages_of_converter’:
-tests/cpychecker/PyArg_ParseTuple/incorrect_converters/input.c:36:26: error: Not enough arguments in call to PyArg_ParseTuple with format string "O&" : expected 2 extra arguments ("int (converter)(PyObject *, T*)" for some type T, "T*" for some type T), but got 0 [-fpermissive]
-tests/cpychecker/PyArg_ParseTuple/incorrect_converters/input.c:39:26: error: Not enough arguments in call to PyArg_ParseTuple with format string "O&" : expected 2 extra arguments ("int (converter)(PyObject *, T*)" for some type T, "T*" for some type T), but got 1 [-fpermissive]
+tests/cpychecker/PyArg_ParseTuple/incorrect_converters/input.c:36:26: error: Not enough arguments in call to PyArg_ParseTuple with format string "O&"
+ expected 2 extra arguments:
+ "int (converter)(PyObject *, T*)" for some type T
+ "T*" for some type T
+ but got none
+ [-fpermissive]
+tests/cpychecker/PyArg_ParseTuple/incorrect_converters/input.c:39:26: error: Not enough arguments in call to PyArg_ParseTuple with format string "O&"
+ expected 2 extra arguments:
+ "int (converter)(PyObject *, T*)" for some type T
+ "T*" for some type T
+ but got 1:
+ "int"
+ [-fpermissive]
tests/cpychecker/PyArg_ParseTuple/incorrect_converters/input.c:44:26: error: Mismatching type in call to PyArg_ParseTuple with format code "O&" [-fpermissive]
- argument 3 ("42") had type "int"
- but was expecting "int (converter)(PyObject *, T*)" for some type T for format code "O&"
+ argument 3 ("42") had type
+ "int"
+ but was expecting
+ "int (converter)(PyObject *, T*)" for some type T
+ for format code "O&"
tests/cpychecker/PyArg_ParseTuple/incorrect_converters/input.c:49:26: error: Mismatching type in call to PyArg_ParseTuple with format code "O&" [-fpermissive]
- argument 3 ("&i0") had type "int *" (pointing to 32 bits)
- but was expecting "int (converter)(PyObject *, T*)" for some type T for format code "O&"
+ argument 3 ("&i0") had type
+ "int *" (pointing to 32 bits)
+ but was expecting
+ "int (converter)(PyObject *, T*)" for some type T
+ for format code "O&"
tests/cpychecker/PyArg_ParseTuple/incorrect_converters/input.c:54:26: error: Mismatching type in call to PyArg_ParseTuple with format code "O&" [-fpermissive]
- argument 3 ("not_returning_int") had type "void (*fn) ()"
- but was expecting "int (converter)(PyObject *, T*)" for some type T for format code "O&"
+ argument 3 ("not_returning_int") had type
+ "void (*fn) ()"
+ but was expecting
+ "int (converter)(PyObject *, T*)" for some type T
+ for format code "O&"
tests/cpychecker/PyArg_ParseTuple/incorrect_converters/input.c:57:26: error: Mismatching type in call to PyArg_ParseTuple with format code "O&" [-fpermissive]
- argument 3 ("not_enough_args") had type "int (*fn) (struct PyObject *)"
- but was expecting "int (converter)(PyObject *, T*)" for some type T for format code "O&"
+ argument 3 ("not_enough_args") had type
+ "int (*fn) (struct PyObject *)"
+ but was expecting
+ "int (converter)(PyObject *, T*)" for some type T
+ for format code "O&"
tests/cpychecker/PyArg_ParseTuple/incorrect_converters/input.c:60:26: error: Mismatching type in call to PyArg_ParseTuple with format code "O&" [-fpermissive]
- argument 3 ("too_many_args") had type "int (*fn) (struct PyObject *, int *, int)"
- but was expecting "int (converter)(PyObject *, T*)" for some type T for format code "O&"
+ argument 3 ("too_many_args") had type
+ "int (*fn) (struct PyObject *, int *, int)"
+ but was expecting
+ "int (converter)(PyObject *, T*)" for some type T
+ for format code "O&"
tests/cpychecker/PyArg_ParseTuple/incorrect_converters/input.c:63:26: error: Mismatching type in call to PyArg_ParseTuple with format code "O&" [-fpermissive]
- argument 3 ("not_taking_PyObjectPtr") had type "int (*fn) (int, int)"
- but was expecting "int (converter)(PyObject *, T*)" for some type T for format code "O&"
+ argument 3 ("not_taking_PyObjectPtr") had type
+ "int (*fn) (int, int)"
+ but was expecting
+ "int (converter)(PyObject *, T*)" for some type T
+ for format code "O&"
tests/cpychecker/PyArg_ParseTuple/incorrect_converters/input.c:68:26: error: Mismatching type in call to PyArg_ParseTuple with format code "O&" [-fpermissive]
- argument 4 ("42") had type "int"
- but was expecting "Py_ssize_t *" (pointing to 64 bits) (from second argument of "int (*fn) (struct PyObject *, Py_ssize_t *)") for format code "O&"
+ argument 4 ("42") had type
+ "int"
+ but was expecting
+ "Py_ssize_t *" (pointing to 64 bits) (from second argument of "int (*fn) (struct PyObject *, Py_ssize_t *)")
+ for format code "O&"
tests/cpychecker/PyArg_ParseTuple/incorrect_converters/input.c:73:26: error: Mismatching type in call to PyArg_ParseTuple with format code "O&" [-fpermissive]
- argument 4 ("&i0") had type "int *" (pointing to 32 bits)
- but was expecting "Py_ssize_t *" (pointing to 64 bits) (from second argument of "int (*fn) (struct PyObject *, Py_ssize_t *)") for format code "O&"
+ argument 4 ("&i0") had type
+ "int *" (pointing to 32 bits)
+ but was expecting
+ "Py_ssize_t *" (pointing to 64 bits) (from second argument of "int (*fn) (struct PyObject *, Py_ssize_t *)")
+ for format code "O&"