[PATCH] also check for WithinRange when changing a refcount
by Tom Tromey
This changes CPython.change_refcount to also look for a WithinRange
object. This is needed because UnknownValue.make may return a
WithinRange object in some cases.
This fixes issue #46.
---
libcpychecker/refcounts.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcpychecker/refcounts.py b/libcpychecker/refcounts.py
index abe034a..8d2228b 100644
--- a/libcpychecker/refcounts.py
+++ b/libcpychecker/refcounts.py
@@ -549,7 +549,7 @@ class CPython(Facet):
check_isinstance(oldvalue, AbstractValue)
log('oldvalue: %r', oldvalue)
# If we never had a ob_refcnt, treat it as a borrowed reference:
- if isinstance(oldvalue, UnknownValue):
+ if isinstance(oldvalue, UnknownValue) or isinstance(oldvalue, WithinRange):
oldvalue = RefcountValue.borrowed_ref(loc, pyobjectptr.region)
check_isinstance(oldvalue, RefcountValue)
newvalue = fn(oldvalue)
--
1.8.1.4
11 years
[PATCH] handle PySequence_DelItem
by Tom Tromey
This adds support for PySequence_DelItem.
---
docs/cpychecker.rst | 1 +
libcpychecker/refcounts.py | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/docs/cpychecker.rst b/docs/cpychecker.rst
index 200536a..8cd699e 100644
--- a/docs/cpychecker.rst
+++ b/docs/cpychecker.rst
@@ -717,6 +717,7 @@ known to the checker are:
`PyRun_SimpleFileExFlags <http://docs.python.org/c-api/veryhigh.html#PyRun_SimpleFileExFlags>`_,
`PyRun_SimpleStringFlags <http://docs.python.org/c-api/veryhigh.html#PyRun_SimpleStringFlags>`_,
`PySequence_Concat <http://docs.python.org/c-api/sequence.html#PySequence_Concat>`_,
+`PySequence_DelItem <http://docs.python.org/c-api/sequence.html#PySequence_DelItem>`_,
`PySequence_GetItem <http://docs.python.org/c-api/sequence.html#PySequence_GetItem>`_,
`PySequence_GetSlice <http://docs.python.org/c-api/sequence.html#PySequence_GetSlice>`_,
`PySequence_SetItem <http://docs.python.org/c-api/sequence.html#PySequence_SetItem>`_,
diff --git a/libcpychecker/refcounts.py b/libcpychecker/refcounts.py
index c331822..d6f4c55 100644
--- a/libcpychecker/refcounts.py
+++ b/libcpychecker/refcounts.py
@@ -3088,6 +3088,27 @@ class CPython(Facet):
fnmeta,
'new ref from %s' % fnmeta.name)
+ def impl_PySequence_DelItem(self, stmt, v_o, v_i):
+ fnmeta = FnMeta(name='PySequence_DelItem',
+ docurl='http://docs.python.org/c-api/sequence.html#PySequence_DelItem',
+ declared_in='abstract.h',
+ prototype='int PySequence_DelItem(PyObject *o, Py_ssize_t i);',
+ defined_in='Objects/abstract.c')
+ # safely handles NULL via null_error():
+ t_err = self.handle_null_error(stmt, 0, v_o, rawreturnvalue=-1)
+ if t_err:
+ return [t_err]
+
+ # can fail with -1, setting an exception
+ s_failure = self.state.mkstate_concrete_return_of(stmt, -1)
+ s_failure.cpython.set_exception('PyExc_TypeError', stmt.loc)
+
+ # otherwise, expect zero
+ s_success = self.state.mkstate_concrete_return_of(stmt, 0)
+
+ return self.state.make_transitions_for_fncall(stmt, fnmeta,
+ s_success, s_failure)
+
def impl_PySequence_GetItem(self, stmt, v_o, v_i):
fnmeta = FnMeta(name='PySequence_GetItem',
docurl='http://docs.python.org/c-api/sequence.html#PySequence_GetItem',
--
1.8.1.4
11 years
[PATCH] fix buglet in impl_PyRun_SimpleStringFlags
by Tom Tromey
This fixes a bug in impl_PyRun_SimpleStringFlags:
[...]
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/refcounts.py", line 3066, in impl_PyRun_SimpleStringFlags
oc_failure.returns(-1)
NameError: global name 'oc_failure' is not defined
---
libcpychecker/refcounts.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcpychecker/refcounts.py b/libcpychecker/refcounts.py
index d6f4c55..abe034a 100644
--- a/libcpychecker/refcounts.py
+++ b/libcpychecker/refcounts.py
@@ -3063,7 +3063,7 @@ class CPython(Facet):
on_success.returns(0)
on_failure = fncall.can_fail()
- oc_failure.returns(-1)
+ on_failure.returns(-1)
# (no way to get the exception on failure)
return fncall.get_transitions()
--
1.8.1.4
11 years
[PATCH] add info and texinfo documentation targets
by Tom Tromey
This patch adds support for "info" and "texinfo" targets to
doc/Makefile. This lets me build info pages for use in Emacs. This
works at least with python-sphinx 1.1.3, which is in Fedora 18.
---
docs/Makefile | 12 ++++++++++++
docs/conf.py | 10 +++++++++-
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/docs/Makefile b/docs/Makefile
index 2fe488c..991f4fd 100644
--- a/docs/Makefile
+++ b/docs/Makefile
@@ -29,6 +29,8 @@ help:
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " text to make text files"
@echo " man to make manual pages"
+ @echo " texinfo to make a Texinfo document"
+ @echo " info to make an info page"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
@@ -113,6 +115,16 @@ man:
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+texinfo:
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+ @echo
+ @echo "Build finished. The Texinfo pages are in $(BUILDDIR)/texinfo."
+
+info: texinfo
+ cd $(BUILDDIR)/texinfo && $(MAKE) info
+ @echo
+ @echo "Build finished. The info pages are in $(BUILDDIR)/texinfo."
+
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
diff --git a/docs/conf.py b/docs/conf.py
index 052455c..a181d76 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -1,4 +1,4 @@
-# Copyright 2011, 2012 David Malcolm <dmalcolm(a)redhat.com>
+# Copyright 2011, 2012, 2013 David Malcolm <dmalcolm(a)redhat.com>
# Copyright 2011, 2012 Red Hat, Inc.
#
# This is free software: you can redistribute it and/or modify it
@@ -233,3 +233,11 @@ man_pages = [
('gcc-with-python', 'gcc-with-python', u'Run GCC whilst invoking a Python script',
[u'David Malcolm'], 1)
]
+
+# -- Options for Texinfo output ------------------------------------------------
+
+texinfo_documents = [
+ (master_doc, 'gcc-python-plugin', 'gcc-python-plugin Documentation',
+ 'David Malcolm', 'gcc-python-plugin', 'gcc-python-plugin Documentation',
+ 'Software development', False)
+]
--
1.8.1.4
11 years
ANN: gcc-python-plugin 0.12
by David Malcolm
gcc-python-plugin is a plugin for GCC 4.6 onwards which embeds the
CPython interpreter within GCC, allowing you to write new compiler
warnings in Python, generate code visualizations, etc.
It ships with "gcc-with-cpychecker", which implements static analysis
passes for GCC aimed at finding bugs in CPython extensions. In
particular, it can automatically detect reference-counting errors:
http://gcc-python-plugin.readthedocs.org/en/latest/cpychecker.html
Major new features in 0.12
==========================
* support added for GCC 4.8 (along with 4.6 and 4.7)
* addition of a new "gcc-c-api" component to isolate much of GCC's
internals (and the differences between 4.6-4.8). I plan for this to
eventually be its own project, aiming at providing a stable API and ABI
for working with GCC, once it has proven itself in the context of the
python plugin.
* link-time-optimization support, for e.g. whole-program visualizations
across multiple source files.
See
http://gcc-python-plugin.readthedocs.org/en/latest/0.12.html
for more information, and for details of the numerous other changes.
Tarball releases are available at:
https://fedorahosted.org/releases/g/c/gcc-python-plugin/
Prebuilt-documentation can be seen at:
http://gcc-python-plugin.readthedocs.org/en/latest/index.html
The project's homepage is:
https://fedorahosted.org/gcc-python-plugin/
The plugin and checker are Free Software, licensed under the GPLv3 or
later.
Enjoy!
Dave Malcolm
11 years, 1 month