]> granicus.if.org Git - python/commitdiff
SF #1685563, MSVCCompiler creates redundant and long PATH strings
authorNeal Norwitz <nnorwitz@gmail.com>
Sun, 1 Apr 2007 18:24:22 +0000 (18:24 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sun, 1 Apr 2007 18:24:22 +0000 (18:24 +0000)
If MSVCCompiler.initialize() was called multiple times, the path
would get duplicated.  On Windows, this is a problem because the
path is limited to 4k.  There's no benefit in adding a path multiple
times, so prevent that from occuring.  We also normalize the path
before checking for duplicates so things like /a and /a/ won't both
be stored.

Will backport.

Lib/distutils/msvccompiler.py
Misc/NEWS

index 0d72837ed3011035647dd97cb348129bc7596325..29a9020956987a198a0d84e4c21050dd1df26bb9 100644 (file)
@@ -187,6 +187,19 @@ def get_build_architecture():
     j = string.find(sys.version, ")", i)
     return sys.version[i+len(prefix):j]
 
+def normalize_and_reduce_paths(paths):
+    """Return a list of normalized paths with duplicates removed.
+
+    The current order of paths is maintained.
+    """
+    # Paths are normalized so things like:  /a and /a/ aren't both preserved.
+    reduced_paths = []
+    for p in paths:
+        np = os.path.normpath(p)
+        # XXX(nnorwitz): O(n**2), if reduced_paths gets long perhaps use a set.
+        if np not in reduced_paths:
+            reduced_paths.append(np)
+    return reduced_paths
 
 
 class MSVCCompiler (CCompiler) :
@@ -270,6 +283,7 @@ class MSVCCompiler (CCompiler) :
                 self.__paths.append(p)
         except KeyError:
             pass
+        self.__paths = normalize_and_reduce_paths(self.__paths)
         os.environ['path'] = string.join(self.__paths, ';')
 
         self.preprocess_options = None
index 9cbdc3a6bb7ad74137b4a89c40ed0dae09e9ce7a..408de56c2a4120fa54e4380e0793f955f359e016 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -1,4 +1,4 @@
-__init+++++++++++
++++++++++++
 Python News
 +++++++++++
 
@@ -200,6 +200,8 @@ Core and builtins
 Library
 -------
 
+- Patch #1685563: remove (don't add) duplicate paths in distutils.MSVCCompiler.
+
 - Added a timeout parameter to the constructor of other protocols
   (telnetlib, ftplib, smtplib and poplib). This is second part of the
   work started with create_connection() and timeout in httplib, and