Here is try #2.
Tom
From 2de0ba029f3b5d7ec2353a13385e648b3ace54ec Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey(a)redhat.com>
Date: Thu, 18 Apr 2013 09:25:59 -0600
Subject: [PATCH] fix issue #46
This fixes issue #46.
The bug is that State.var_region checks for PyObject globals, but it
should also check for derived types like PyTypeObject. The fix is to
use the existing type_is_pyobjptr_subclass function to do the check.
This still gives an error for the test case in the issue -- but that
test case leaks a reference in the situation where PyModule_AddObject
fails.
---
libcpychecker/absinterp.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libcpychecker/absinterp.py b/libcpychecker/absinterp.py
index c66e9ed..d11de19 100644
--- a/libcpychecker/absinterp.py
+++ b/libcpychecker/absinterp.py
@@ -1634,7 +1634,8 @@ class State(object):
# Initialize the refcount of global PyObject instances
# e.g. _Py_NoneStruct to 0 i.e. we don't own any references to them
- if str(var.type) == 'struct PyObject':
+ from libcpychecker.refcounts import type_is_pyobjptr_subclass
+ if type_is_pyobjptr_subclass(var.type.pointer):
from libcpychecker.refcounts import RefcountValue
ob_refcnt = self.make_field_region(region, 'ob_refcnt') # FIXME:
this should be a memref and fieldref
self.value_for_region[ob_refcnt] = RefcountValue.borrowed_ref(None,
region)
--
1.8.1.4