[mod_python] psp.PSP(req, string='hello world') causes segfault

dharana dharana at dharana.net
Tue Apr 26 18:49:08 EDT 2005


There where 3 typos in psp.py. I could only fix them by temporarily 
commenting out the _psp.parsestring call. I leave to you the C side :)

I've included the patch file with the typos fixed. Hope it helps. I'm 
also forwarding to python-dev because I believe I've crossed the line again.

-----------------------------------------------------------------------
--- /usr/src/mod_python-3.1.4/lib/python/mod_python/psp.py      Sat Jan 
29 22:25:29 2005
+++ /usr/local/hosting/lib/python2.4/site-packages/mod_python/psp.py 
Wed Apr 27 00:43:06 2005
@@ -111,12 +111,12 @@
              self.load_from_file()
          else:

-            cached = strcache.get(string)
+            cached = mem_scache.get(string)
              if cached:
                  self.code = cached
              else:
                  self.code = _psp.parsestring(string)
-                strcache.store(string)
+                mem_scache.store(string, self.code)

      def cache_get(self, filename, mtime):

@@ -358,8 +358,8 @@

      def get(self, key):
          if self.cache.has_key(key):
-            hist, val = self.cache[key]
-            self.cache[key] = (hits+1, code)
+            hits, val = self.cache[key]
+            self.cache[key] = (hits+1, val)
              return val
          else:
              return None
-----------------------------------------------------------------------

dharana wrote:
> modified handler
> -- -------------------------------------------------
> from mod_python import apache
> #from mod_python import psp
> 
> import sys
> import os
> import marshal
> import new
> from cgi import escape
> import anydbm, whichdb
> import tempfile
> 
> def handler(req):
> #    content_file = psp.PSP(req, string='hello world')
> #    content_file.run()
>     return apache.OK
> -----------------------------------------------------
> 
> It doesn't segfault like this.
> 
> 
> 
> 
> 
> 
> I tried to hunt it a little bit deeper right into the mod_python's 
> psp.py file:
> 
> -- site-packages/mod_python/psp.py snippet ---------------------
>         if filename:
> 
>             # if filename is not absolute, default to our guess
>             # of current directory
>             if not os.path.isabs(filename):
>                 base = os.path.split(req.filename)[0]
>                 self.filename = os.path.join(base, filename)
> 
>             self.load_from_file()
>         else:
> 
>             cached = mem_scache.get(string)
>             if cached:
>                 self.code = cached
>             else:
> (line 118)      self.code = _psp.parsestring(string)
>                 mem_scache.store(string)
> -----------------------------------------------------------------
> 
> Commenting out line 118 and trying to run the script in the previous 
> email (the one that is causing the segfault) gives me this error:
> 
> --- traceback -------------------------------------------------------
> Mod_python error: "PythonHandler webapps.admin.controller"
> 
> Traceback (most recent call last):
> 
>   File 
> "/usr/local/hosting/lib/python2.4/site-packages/mod_python/apache.py", 
> line 299, in HandlerDispatch
>     result = object(req)
> 
>   File "/home/dharana/websites/ozone2/webapps/admin/controller.py", line 
> 13, in handler
>     content_file = psp.PSP(req, string='hello world')
> 
>   File 
> "/usr/local/hosting/lib/python2.4/site-packages/mod_python/psp.py", line 
> 119, in __init__
>     mem_scache.store(string)
> 
> TypeError: store() takes exactly 3 arguments (2 given)
> -------------------------------------------------------------------
> 
> I don't know why this is failling, maybe it has something to do with the 
> problem. _psp.parsestring(string) shouldn't modify "string" in any way 
> nor should it be able to pass hidden args to the mem_scache.store() 
> function, right?
> 
> 
> 
> Anyways, I tried to investigate it further but I couldn't go deeper than 
> the mod_python source file src/_pspmodule.c (lines 129 to 160). My C 
> skills are non-existent.
> 
> 
> 
> 
> 
> 
> Grisha, if you read this, this is one of the previous references I found 
> about the problem:
> 
>   http://www.modpython.org/pipermail/mod_python/2004-May/015552.html
> 
> Maybe the typo/bugfix didn't completely solve the problem at hand.
> 
> 
> 
> Graham Dumpleton wrote:
> 
>> The segmentation fault problems are generally caused by a mismatch in 
>> versions
>> of shared libraries that various packages have been compiled against. 
>> The main
>> culprits are libexpat, MySQL client libraries and sometimes Sleepycat 
>> DBM. The
>> clash is between the version expected by PHP or Apache, and that which 
>> may be
>> expected by a Python module being used. Because it is an environment 
>> issue, it
>> may well only affect you.
> 
> 
> Thank you for the explanation!
> 

-- 
dharana



More information about the Mod_python mailing list