commit d1a082fd6b825386460b43380fe1bc401d81fdb9
Author: David Malcolm <dmalcolm(a)redhat.com>
Date: Fri Mar 30 17:24:56 2012 -0400
cpychecker: cope with C++ destructors
libcpychecker/absinterp.py | 4 +-
.../refcounts/cplusplus/destructor/input.cc | 42 ++++++++++++++++++++
.../refcounts/cplusplus/destructor/script.py | 22 ++++++++++
.../refcounts/cplusplus/destructor/stdout.txt | 11 +++++
4 files changed, 78 insertions(+), 1 deletions(-)
---
diff --git a/libcpychecker/absinterp.py b/libcpychecker/absinterp.py
index 97e5d7f..0c71e76 100644
--- a/libcpychecker/absinterp.py
+++ b/libcpychecker/absinterp.py
@@ -1818,7 +1818,9 @@ class State(object):
def make_field_region(self, target, field):
check_isinstance(target, Region)
- check_isinstance(field, str)
+ if field:
+ # (field can be None for C++ destructors)
+ check_isinstance(field, str)
log('make_field_region(%r, %r)', target, field)
if field in target.fields:
log('reusing')
diff --git a/tests/cpychecker/refcounts/cplusplus/destructor/input.cc
b/tests/cpychecker/refcounts/cplusplus/destructor/input.cc
new file mode 100644
index 0000000..b9a6fca
--- /dev/null
+++ b/tests/cpychecker/refcounts/cplusplus/destructor/input.cc
@@ -0,0 +1,42 @@
+/*
+ Copyright 2012 David Malcolm <dmalcolm(a)redhat.com>
+ Copyright 2012 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/>.
+*/
+
+
+/* Verify that the checker can cope with a C++ destructor */
+#include <Python.h>
+
+class Foo
+{
+public:
+ virtual ~Foo();
+};
+
+class Bar : public Foo
+{
+public:
+ ~Bar() {}
+};
+
+/*
+ PEP-7
+Local variables:
+c-basic-offset: 4
+indent-tabs-mode: nil
+End:
+*/
diff --git a/tests/cpychecker/refcounts/cplusplus/destructor/script.py
b/tests/cpychecker/refcounts/cplusplus/destructor/script.py
new file mode 100644
index 0000000..fdd5ba3
--- /dev/null
+++ b/tests/cpychecker/refcounts/cplusplus/destructor/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/cplusplus/destructor/stdout.txt
b/tests/cpychecker/refcounts/cplusplus/destructor/stdout.txt
new file mode 100644
index 0000000..40cdaa9
--- /dev/null
+++ b/tests/cpychecker/refcounts/cplusplus/destructor/stdout.txt
@@ -0,0 +1,11 @@
+Trace 0:
+ Transitions:
+ 'taking False path'
+ 'returning'
+ Exception:
+ (struct PyObject *)0
+Trace 0:
+ Transitions:
+ 'returning'
+ Exception:
+ (struct PyObject *)0