[issue9263] Try to print repr() when an C-level assert fails (in the garbage collector, beyond?)

Dave Malcolm report at bugs.python.org
Thu Jul 15 01:50:50 CEST 2010


New submission from Dave Malcolm <dmalcolm at redhat.com>:

Modules/gcmodule.c contains various assertions which can fail due to reference counting errors elsewhere in either python, or an extension module.  These can be difficult to track down.

In the hope of maximizing the information from crash reports, the attached patch (against py3k) introduces a new assertion macro to Objects/object.h and Objects.c, which provides a richer debug message.  In particular, it identifies which object has the issue, and can more clearly spell out the problem.

The patch replaces all uses of assert() in Modules/gcmodule.c for which a specific object has an issue (e.g. bogus reference count).

The implementation may play somewhat fast-and-loose with rules about object invariants: you might have an only partially valid object, but the process is about to abort, so it seems acceptable to try to glean extra information on stderr.  (This may turn an abort into a segfault, of course)

Caveats:
- exact name of the API probably could be better
- I don't yet have a specific use for the "callback" idea; I was thinking of trying to display all objects that reference that object.  Might need a void* closure to be useful.  Might be a useless complication.
- Only tested on gcc-4.4.3 so far; the __STRING(expr) and __PRETTY_FUNCTION__ look non-portable.
- no test case; I thought about using ctypes to extract PyObject_IncRef from the implementation, but this is likely to lead to brittle test cases.  Alternatively, is xxmodule to be used for this kind of thing?

Thoughts?

----------
components: Interpreter Core
files: py3k-repr-on-gcmodule-assertions.patch
keywords: patch
messages: 110341
nosy: dmalcolm
priority: normal
severity: normal
stage: patch review
status: open
title: Try to print repr() when an C-level assert fails (in the garbage collector, beyond?)
type: feature request
versions: Python 3.2
Added file: http://bugs.python.org/file18007/py3k-repr-on-gcmodule-assertions.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9263>
_______________________________________


More information about the Python-bugs-list mailing list