commit d7115d8472ed8ac8f8288fd997f6e70941ae4e31
Author: David Malcolm <dmalcolm(a)redhat.com>
Date: Thu Dec 22 16:07:36 2011 -0500
cpychecker: implement PyMapping_Size
libcpychecker/refcounts.py | 23 ++++++++++++
.../refcounts/PyMapping_Size/basic/input.c | 38 ++++++++++++++++++++
.../refcounts/PyMapping_Size/basic/script.py | 22 +++++++++++
.../refcounts/PyMapping_Size/basic/stdout.txt | 29 +++++++++++++++
4 files changed, 112 insertions(+), 0 deletions(-)
---
diff --git a/libcpychecker/refcounts.py b/libcpychecker/refcounts.py
index 9df2635..78e9660 100644
--- a/libcpychecker/refcounts.py
+++ b/libcpychecker/refcounts.py
@@ -1674,6 +1674,29 @@ class CPython(Facet):
return [t_success, t_failure]
########################################################################
+ # PyMapping_*
+ ########################################################################
+
+ def impl_PyMapping_Size(self, stmt, v_o):
+ fnmeta = FnMeta(name='PyMapping_Size',
+
docurl='http://docs.python.org/c-api/mapping.html#PyMapping_Size';,
+ prototype='Py_ssize_t PyMapping_Size(PyObject *o)',
+ defined_in='Objects/abstract.c',
+ notes='Can cope with NULL (sets exception)')
+ t_success = self.state.mktrans_assignment(stmt.lhs,
+ UnknownValue.make(stmt.lhs.type,
+ stmt.loc),
+ fnmeta.desc_when_call_succeeds())
+ t_failure = self.state.mktrans_assignment(stmt.lhs,
+ ConcreteValue(stmt.lhs.type,
+ stmt.loc,
+ -1),
+ fnmeta.desc_when_call_fails())
+ t_failure.dest.cpython.set_exception('PyExc_TypeError',
+ stmt.loc)
+ return [t_success, t_failure]
+
+ ########################################################################
# PyMem_*
########################################################################
def impl_PyMem_Free(self, stmt, v_ptr):
diff --git a/tests/cpychecker/refcounts/PyMapping_Size/basic/input.c
b/tests/cpychecker/refcounts/PyMapping_Size/basic/input.c
new file mode 100644
index 0000000..7de2e0c
--- /dev/null
+++ b/tests/cpychecker/refcounts/PyMapping_Size/basic/input.c
@@ -0,0 +1,38 @@
+/*
+ Copyright 2011 David Malcolm <dmalcolm(a)redhat.com>
+ Copyright 2011 Red Hat, Inc.
+
+ This is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <
http://www.gnu.org/licenses/>.
+*/
+
+#include <Python.h>
+
+/*
+ Basic test coverage for our handler for PyMapping_Size
+*/
+
+Py_ssize_t
+test(PyObject *obj)
+{
+ return PyMapping_Size(obj);
+}
+
+/*
+ PEP-7
+Local variables:
+c-basic-offset: 4
+indent-tabs-mode: nil
+End:
+*/
diff --git a/tests/cpychecker/refcounts/PyMapping_Size/basic/script.py
b/tests/cpychecker/refcounts/PyMapping_Size/basic/script.py
new file mode 100644
index 0000000..fdd5ba3
--- /dev/null
+++ b/tests/cpychecker/refcounts/PyMapping_Size/basic/script.py
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+# Copyright 2011 David Malcolm <dmalcolm(a)redhat.com>
+# Copyright 2011 Red Hat, Inc.
+#
+# This is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see
+# <
http://www.gnu.org/licenses/>.
+
+from libcpychecker import main
+main(verify_refcounting=True,
+ dump_traces=True,
+ show_traces=False)
diff --git a/tests/cpychecker/refcounts/PyMapping_Size/basic/stdout.txt
b/tests/cpychecker/refcounts/PyMapping_Size/basic/stdout.txt
new file mode 100644
index 0000000..871895f
--- /dev/null
+++ b/tests/cpychecker/refcounts/PyMapping_Size/basic/stdout.txt
@@ -0,0 +1,29 @@
+Trace 0:
+ Transitions:
+ 'when PyMapping_Size() succeeds'
+ 'returning'
+ Return value:
+ repr(): WithinRange(gcctype='Py_ssize_t',
loc=gcc.Location(file='tests/cpychecker/refcounts/PyMapping_Size/basic/input.c',
line=29), minvalue=-0x8000000000000000, maxvalue=0x7fffffffffffffff)
+ str(): (Py_ssize_t)val [-0x8000000000000000 <= val <= 0x7fffffffffffffff] from
tests/cpychecker/refcounts/PyMapping_Size/basic/input.c:29
+ Region("region-for-arg-gcc.ParmDecl('obj')"):
+ repr(): Region("region-for-arg-gcc.ParmDecl('obj')")
+ str(): Region("region-for-arg-gcc.ParmDecl('obj')")
+ r->ob_refcnt: refs: 0 + N where N >= 1
+ r->ob_type: PointerToRegion(gcctype='struct PyTypeObject *',
loc=gcc.Location(file='tests/cpychecker/refcounts/PyMapping_Size/basic/input.c',
line=27), region=Region("region-for-type-of-arg-gcc.ParmDecl('obj')"))
+ Exception:
+ (struct PyObject *)0 from tests/cpychecker/refcounts/PyMapping_Size/basic/input.c:28
+
+Trace 1:
+ Transitions:
+ 'when PyMapping_Size() fails'
+ 'returning'
+ Return value:
+ repr(): ConcreteValue(gcctype='Py_ssize_t',
loc=gcc.Location(file='tests/cpychecker/refcounts/PyMapping_Size/basic/input.c',
line=29), value=-1)
+ str(): (Py_ssize_t)-1 from
tests/cpychecker/refcounts/PyMapping_Size/basic/input.c:29
+ Region("region-for-arg-gcc.ParmDecl('obj')"):
+ repr(): Region("region-for-arg-gcc.ParmDecl('obj')")
+ str(): Region("region-for-arg-gcc.ParmDecl('obj')")
+ r->ob_refcnt: refs: 0 + N where N >= 1
+ r->ob_type: PointerToRegion(gcctype='struct PyTypeObject *',
loc=gcc.Location(file='tests/cpychecker/refcounts/PyMapping_Size/basic/input.c',
line=27), region=Region("region-for-type-of-arg-gcc.ParmDecl('obj')"))
+ Exception:
+ (struct PyObject *)&RegionForGlobal(gcc.VarDecl('PyExc_TypeError')) from
tests/cpychecker/refcounts/PyMapping_Size/basic/input.c:29