<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
<channel>
<title>Fun with ones and zeros - mod_python</title>
<description><![CDATA[Barry's notes on computer software and hardware]]></description>
<link>/blog/tags/mod_python</link>
<lastBuildDate>Wed, 20 May 2026 01:51:15 -0700</lastBuildDate>
<item>
<title>mod_python segfault fixed
</title>
<link>/blog/entries/mod_python_segfault_3</link>
<pubDate>Sun, 12 Feb 2006 19:40:49 -0800</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[
<p>
Just as a followup, it seems the segfault in mod_python on FreeBSD I <a href="/blog/bugs/mod_python_segfault.html">mentioned before</a>
was <a href="http://www.mail-archive.com/python-dev@httpd.apache.org/msg01062.html">found</a> and fixed.
Turns out to not be any kind of pointer/memory corruption like I thought, but rather a mishandled
return code from an APR (Apache Portable Runtime) function.  Oh well, I got to play with gdb, ddd, and valgrind a bit, which 
is good stuff to be familiar with.
</p>



]]></description>
</item>
<item>
<title>Debugging mod_python with Valgrind
</title>
<link>/blog/entries/mod_python_segfault_2</link>
<pubDate>Sun, 29 Jan 2006 20:17:35 -0800</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[
<p>
Other people have <a href="http://www.mail-archive.com/python-dev@httpd.apache.org/msg01042.html">reported</a> 
the same problem with mod_python on FreeBSD I had seen <a href="/blog/bugs/mod_python_segfault.html">before</a>,
so I'm happy that I'm not losing my mind.
</p>
<p>
I took a stab at using <a href="http://valgrind.org">Valgrind</a> to find the problem.  Didn't
actually find anything, but I thought I'd jot down notes on how I went about this.
</p>
<p>
First, the Valgrind port didn't seem to work on FreeBSD 6.0.  When I tried running it against the sample
code in the <a href="http://valgrind.org/docs/manual/quick-start.html">Valgrind Quick Start guide</a>, it
didn't find anything wrong with it.  Ended up finding a FreeBSD 5.4 machine, which did see the expected problem.
</p>
<p>
Next, I built the Apache 2.0.x port with: <code>make WITH_THREADS=1 WITH_DEBUG=1</code>, and then built mod_python
which uses <a href="http://httpd.apache.org/docs/2.0/programs/apxs.html">APXS</a> and picks up the debug compile option from that.
</p>
<p>
Then, in the mod_python distribution, went into the <code>test</code> directory, and downloaded a Valgrind suppression
file for Python, <a href="http://svn.python.org/projects/python/trunk/Misc/valgrind-python.supp"><code>valgrind-python.supp</code></a>, 
and in it uncommented the suppressions for <code>PyObject_Free</code> and <code>PyObject_Realloc</code> (<i>otherwise the Valgrind output is full
of stuff that is <a href="http://svn.python.org/projects/python/trunk/Misc/README.valgrind">really OK</a></i>). 
Then tweaked <code>test/test.py</code> around line 307 where it starts Apache, to insert
</p>
<blockquote><code>
valgrind --tool=memcheck --logfile=/tmp/valgrind_httpd --suppressions=valgrind-python.supp
</code></blockquote>
<p>
At the front of the <code>cmd</code> variable that's being composed to execute httpd.
</p>
<p>
Finally, ran <code>python test.py</code>, and then looked at <code>/tmp/valgrind_httpd.pid####</code> to 
see the results.
</p>



]]></description>
</item>
<item>
<title>mod_python segfault on FreeBSD
</title>
<link>/blog/entries/mod_python_segfault</link>
<pubDate>Mon, 16 Jan 2006 11:56:26 -0800</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[
<p>
I've been testing <a href="http://www.modpython.org">mod_python</a> 3.2.x betas as 
<a href="http://www.mail-archive.com/python-dev@httpd.apache.org/msg00984.html">requested</a>
 by the developers on their mailing list.  Unfortunately there 
seems to be some subtle memory-related but that only occurs on FreeBSD 
(or at least FreeBSD the way I normally install it along with Apache and Python).
</p>
<p>
Made some mention of it <a href="http://www.mail-archive.com/python-dev@httpd.apache.org/msg00750.html">here</a>
and an <a href="http://issues.apache.org/jira/browse/MODPYTHON-102">almost identical problem is reported for MacOSX</a>, 
even down to the value <code>0x58</code> being at the top of the backtrace.
</p>
<p>
Did a lot of poking around the core with gdb and browsing of the mod_python 
and Apache sourcecode, but never quite saw where the problem could be.  Took another
approach and started stripping down the big mod_python testsuite, and found that the test
that was failing ran fine by itself, but when it ran after another test for handling 
large file uploads - then it would crash.  
</p>
<p>
So I suspect there's a problem in a whole different area of mod_python, that's screwing
something up in memory that doesn't trigger a segfault til later during the connectionhandler
test.  My <a href="http://www.mail-archive.com/python-dev@httpd.apache.org/msg00989.html">latest post</a>
to the list covers some of that.
</p>



]]></description>
</item>
</channel>
</rss>