SF.net SVN: jython:[7192] trunk/jython

[email protected] Wed, 02 Feb 2011 10:36:56 +0000
Newsgroups gmane.comp.lang.jython.cvs
Message-ID <[email protected]>
Revision: 7192
          http://jython.svn.sourceforge.net/jython/?rev=7192&view=rev
Author:   otmarhumbel
Date:     2011-02-02 10:36:55 +0000 (Wed, 02 Feb 2011)

Log Message:
-----------
prevent internal variables from being reused in subrocess calls
fixes issue #1700

thanks agronholm for the analysis

Modified Paths:
--------------
    trunk/jython/Lib/test/test_bat_jy.py
    trunk/jython/NEWS
    trunk/jython/src/shell/jython.bat

Modified: trunk/jython/Lib/test/test_bat_jy.py
===================================================================
--- trunk/jython/Lib/test/test_bat_jy.py	2011-01-25 23:46:27 UTC (rev 7191)
+++ trunk/jython/Lib/test/test_bat_jy.py	2011-02-02 10:36:55 UTC (rev 7192)
@@ -48,7 +48,7 @@
         return self.process.getErrorStream()
 
 class StarterProcess:
-    def writeStarter(self, args, javaHome, jythonHome, jythonOpts):
+    def writeStarter(self, args, javaHome, jythonHome, jythonOpts, internals=False):
         (starter, starterPath) = tempfile.mkstemp(suffix='.bat', prefix='starter', text=True)
         starter.close()
         outfilePath = starterPath[:-4] + '.out'
@@ -60,6 +60,9 @@
                 starter.write('set JYTHON_HOME=%s\n' % jythonHome)
             if jythonOpts:
                 starter.write('set JYTHON_OPTS=%s\n' % jythonOpts)
+            if internals:
+                starter.write('set _JYTHON_OPTS=leaking_internals\n')
+                starter.write('set _JYTHON_HOME=c:/leaking/internals\n')
             starter.write(self.buildCommand(args, outfilePath))
             return (starterPath, outfilePath)
         finally:
@@ -92,9 +95,9 @@
         except IllegalThreadStateException:
             return True
 
-    def run(self, args, javaHome, jythonHome, jythonOpts):
+    def run(self, args, javaHome, jythonHome, jythonOpts, internals=False):
         ''' creates a start script, executes it and captures the output '''
-        (starterPath, outfilePath) = self.writeStarter(args, javaHome, jythonHome, jythonOpts)
+        (starterPath, outfilePath) = self.writeStarter(args, javaHome, jythonHome, jythonOpts, internals)
         try:
             process = Runtime.getRuntime().exec(starterPath)
             stdoutMonitor = StdoutMonitor(process)
@@ -130,7 +133,7 @@
             home = ex[:-11] # \jython.bat
         return home
 
-    def assertOutput(self, flags=None, javaHome=None, jythonHome=None, jythonOpts=None):
+    def assertOutput(self, flags=None, javaHome=None, jythonHome=None, jythonOpts=None, internals=False):
         args = [self.quote(sys.executable), '--print']
         memory = None
         stack = None
@@ -161,7 +164,7 @@
                     jythonArgs = jythonArgs.replace('%%', '%') # workaround two .bat files
                 args.append(flag)
         process = StarterProcess()
-        out = process.run(args, javaHome, jythonHome, jythonOpts)
+        out = process.run(args, javaHome, jythonHome, jythonOpts, internals)
         self.assertNotEquals('', out)
         homeIdx = out.find('-Dpython.home=')
         java = 'java'
@@ -256,7 +259,11 @@
         
     def test_multiple(self):
         self.assertOutput(jythonOpts='some arbitrary options')
-     
+
+class InternalsTest(BaseTest):
+    def test_no_leaks(self):
+        self.assertOutput(internals=True)
+
 class JavaOptsTest(BaseTest):
     def test_memory(self):
         self.assertOutput(['-J-Xmx321m'])
@@ -387,6 +394,7 @@
                                   JavaHomeTest,
                                   JythonHomeTest,
                                   JythonOptsTest,
+                                  InternalsTest,
                                   JavaOptsTest,
                                   ArgsTest,
                                   DoubleDashTest,

Modified: trunk/jython/NEWS
===================================================================
--- trunk/jython/NEWS	2011-01-25 23:46:27 UTC (rev 7191)
+++ trunk/jython/NEWS	2011-02-02 10:36:55 UTC (rev 7192)
@@ -5,6 +5,7 @@
     - [ 1667 ] thread.local subclasses with constructor params fail
     - [ 1698 ] warnings module fails under JSR-223
     - [ 1697 ] Wrong error message when http connection can not be established
+    - [ 1700 ] "virtualenv is not compatible" to 2.5.2rc3
 
 Jython 2.5.2rc3
   Bugs Fixed

Modified: trunk/jython/src/shell/jython.bat
===================================================================
--- trunk/jython/src/shell/jython.bat	2011-01-25 23:46:27 UTC (rev 7191)
+++ trunk/jython/src/shell/jython.bat	2011-02-02 10:36:55 UTC (rev 7192)
@@ -24,9 +24,12 @@
 
 rem ----- Verify and set required environment variables -----------------------
 
+rem make sure to clear the internal variables, to prevent leaking into subprocess calls
 set _JAVA_CMD=java
 if defined JAVA_HOME set _JAVA_CMD="%JAVA_HOME:"=%\bin\java"
-if defined JYTHON_OPTS set _JYTHON_OPTS="%JYTHON_OPTS:"=%" 
+set _JYTHON_OPTS=
+if defined JYTHON_OPTS set _JYTHON_OPTS="%JYTHON_OPTS:"=%"
+set _JYTHON_HOME=
 if defined JYTHON_HOME set _JYTHON_HOME="%JYTHON_HOME:"=%"
 if defined _JYTHON_HOME goto gotHome
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d