Issue Details (XML | Word | Printable)

Key: MODPYTHON-48
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Graham Dumpleton
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
mod_python

psp.PSP doesn't work for a text string

Created: 27/Apr/05 10:31 AM   Updated: 05/Mar/06 01:53 PM
Return to search
Component/s: None
Affects Version/s: 3.1.4
Fix Version/s: 3.2.7

Time Tracking:
Not Specified

File Attachments:
  Size
File Licensed for inclusion in ASF works psp.diff 2005-04-27 10:35 AM Graham Dumpleton 2 kB
File Licensed for inclusion in ASF works psp2.diff 2005-04-27 06:11 PM dharana 2 kB

Resolution Date: 27/Apr/05 04:33 PM


 Description  « Hide
The following code doesn't work.

  from mod_python import apache
  from mod_python import psp

  def handler(req):
       content_file = psp.PSP(req, string='hello world')
       content_file.run()
       return apache.OK

The problems range from typos in the Python code, the Python code
not actually compiling the parsed string and core dumps in PSP parser
due to double deletes.

Issues have been discussed on mailing list. Some of the main posts are:

  http://www.modpython.org/pipermail/mod_python/2005-April/017932.html
  http://www.modpython.org/pipermail/mod_python/2005-April/017938.html
  http://www.modpython.org/pipermail/mod_python/2005-April/017946.html

Patches are required to lib/python/mod_python/psp.py and src/_pspmodule.c.
These are include below. An independent check of whether removing explicit
destruction of the buffer in _pspmodule.c is the correct thing to do should be
done. Whether "__psp__" is an appropriate second argument to compile() in
change should be considered.

*** ../mod_python-3.1.3/lib/python/mod_python/psp.py Tue Feb 17 06:47:27 2004
--- lib/python/mod_python/psp.py Wed Apr 27 11:00:19 2005
***************
*** 111,122 ****
              self.load_from_file()
          else:
  
! cached = strcache.get(string)
              if cached:
                  self.code = cached
              else:
! self.code = _psp.parsestring(string)
! strcache.store(string)
  
      def cache_get(self, filename, mtime):
  
--- 111,124 ----
              self.load_from_file()
          else:
  
! cached = mem_scache.get(string)
              if cached:
                  self.code = cached
              else:
! source = _psp.parsestring(string)
! code = compile(source, "__psp__", "exec")
! mem_scache.store(string,code)
! self.code = code
  
      def cache_get(self, filename, mtime):
  
***************
*** 358,365 ****
  
      def get(self, key):
          if self.cache.has_key(key):
! hist, val = self.cache[key]
! self.cache[key] = (hits+1, code)
              return val
          else:
              return None
--- 360,367 ----
  
      def get(self, key):
          if self.cache.has_key(key):
! hits, val = self.cache[key]
! self.cache[key] = (hits+1, val)
              return val
          else:
              return None


*** ../mod_python-3.1.3/src/_pspmodule.c Tue Feb 17 06:47:27 2004
--- src/_pspmodule.c Wed Apr 27 10:43:51 2005
***************
*** 146,152 ****
      bs = yy_scan_string(PyString_AsString(str), scanner);
      yylex(scanner);
  
! yy_delete_buffer(bs, scanner);
      yylex_destroy(scanner);
      
      psp_string_0(&parser->pycode);
--- 146,152 ----
      bs = yy_scan_string(PyString_AsString(str), scanner);
      yylex(scanner);
  
! /* yy_delete_buffer(bs, scanner); */
      yylex_destroy(scanner);
      
      psp_string_0(&parser->pycode);



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #164956 Wed Apr 27 07:32:02 UTC 2005 nlehuen Graham's fix for MODPYTHON-48.
Files Changed
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/psp.py
MODIFY /httpd/mod_python/trunk/src/_pspmodule.c