From 6b6788c12c0a20be6778dd2b7da4a809aca1bca6 Mon Sep 17 00:00:00 2001 From: Kai Huuhko Date: Mon, 15 Sep 2014 15:26:41 +0300 Subject: [PATCH] api_coverage.py: Add detection for changed func return value --- api_coverage.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/api_coverage.py b/api_coverage.py index e2de438..63dd6a9 100755 --- a/api_coverage.py +++ b/api_coverage.py @@ -114,12 +114,14 @@ def pkg_config(require, min_vers=None): def get_capis(inc_path, prefix): + capirets = [] capis = [] capilns = [] capi_pattern = re.compile( - "^ *EAPI [A-Za-z_ *\n]+ *\**\n?(?!" + - c_excludes + ")(" + prefix + - "_\w+) *\(", + "^ *EAPI " + + "([A-Za-z_ *\n]+)[ *]*\n?" + + "(?!" + c_excludes + ")" + + "(" + prefix + "_\w+)" + " *\(", flags=re.S | re.M ) @@ -143,24 +145,29 @@ def get_capis(inc_path, prefix): i += len(line) matches = re.finditer(capi_pattern, capi) for match in matches: - func = match.group(1) + funcret = match.group(1) + funcname = match.group(2) start = match.start() line_n = line_starts.index(start) + 1 capilns.append((f, line_n)) - capis.append(func) + capirets.append(funcret) + capis.append(funcname) - return capilns, capis + return capilns, capirets, capis def get_pyapis(pxd_path, header_name, prefix): pyapilns = [] + pyapirets = [] pyapis = [] pyapi_pattern1 = re.compile( 'cdef extern from "' + header_name + '\.h":\n(.+)', flags=re.S ) pyapi_pattern2 = re.compile( - "^ +[a-zA-Z _*]+?(?!" + py_excludes + ")(" + prefix + "_\w+)\(", + "^ +([a-zA-Z _*]+?)" + + "(?!" + py_excludes + ")" + + "(" + prefix + "_\w+)" + "\(", flags=re.M ) @@ -186,13 +193,15 @@ def get_pyapis(pxd_path, header_name, prefix): i += len(line) matches = re.finditer(pyapi_pattern2, cdef.group(1)) for match in matches: - func = match.group(1) + funcret = match.group(1) + func = match.group(2) start = match.start() + offset line_n = line_starts.index(start) + 1 pyapilns.append((f, line_n)) + pyapirets.append(funcret) pyapis.append(func) - return pyapilns, pyapis + return pyapilns, pyapirets, pyapis rows, columns = os.popen('stty size', 'r').read().split() @@ -218,8 +227,13 @@ for lib in args.libs: pxd_path, header_name, prefix = params[lib] - c_api_line_ns, c_apis = get_capis(inc_path, prefix) - py_api_line_ns, py_apis = get_pyapis(pxd_path, header_name, prefix) + c_api_line_ns, c_api_rets, c_apis = get_capis(inc_path, prefix) + py_api_line_ns, py_api_rets, py_apis = get_pyapis(pxd_path, header_name, prefix) + + rets = zip(c_api_line_ns, c_api_rets, py_api_line_ns, py_api_rets) + for cln, cret, pyln, pyret in rets: + if cret != pyret: + print("SIGNATURE DIFFERS BETWEEN %s: %s AND %s: %s !!!" % (cln, cret, pyln, pyret)) capis = set(c_apis) pyapis = set(py_apis)