Skip to content

Commit

Permalink
BUG: fix weave issue with too long file names with MSVC. Closes scipy…
Browse files Browse the repository at this point in the history
…gh-3216.

This issue was introduced in 021e0ee.  It's MSVC specific; MSVC
has a 260 char file name (including full path).  So truncation the
has to 50 chars, plus filename prefix (``sc_`` or ``compiler_``), leaves
200 chars for the path which should be enough.
  • Loading branch information
rgommers committed Jan 22, 2014
1 parent 6b6b41a commit d4f7987
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions scipy/weave/accelerate_tools.py
Expand Up @@ -364,15 +364,15 @@ def singleton(self,signature):
return fast

def identifier(self,signature):
# Build a SHA-256 checksum
# Build a (truncated, see gh-3216) SHA-256 checksum
f = self.function
co = f.func_code
identifier = str(signature) + \
str(co.co_argcount) + \
str(co.co_consts) + \
str(co.co_varnames) + \
co.co_code
return 'F' + sha256(identifier).hexdigest()
return 'F' + sha256(identifier).hexdigest()[:96]

def accelerate(self,signature,identifier):
P = Python2CXX(self.function,signature,name=identifier)
Expand Down
4 changes: 2 additions & 2 deletions scipy/weave/build_tools.py
Expand Up @@ -236,8 +236,8 @@ def build_extension(module_path,compiler_name='',build_dir=None,
# object files separated from each other. gcc2.x and gcc3.x C++
# object files are not compatible, so we'll stick them in a sub
# dir based on their version. This will add a SHA-256 check sum
# of the compiler binary to the directory name to keep objects
# from different compilers in different locations.
# (truncated to ~100 characters) of the compiler binary to the directory
# name to keep objects from different compilers in different locations.

compiler_dir = platform_info.get_compiler_dir(compiler_name)
temp_dir = os.path.join(temp_dir,compiler_dir)
Expand Down
4 changes: 3 additions & 1 deletion scipy/weave/catalog.py
Expand Up @@ -92,7 +92,9 @@ def expr_to_filename(expr):
"""
from hashlib import sha256
base = 'sc_'
return base + sha256(expr).hexdigest()
# 99 chars is enough for unique filenames; too long names don't work for
# MSVC (see gh-3216). Don't use md5, gives a FIPS warning.
return base + sha256(expr).hexdigest()[:96]


def unique_file(d,expr):
Expand Down
2 changes: 1 addition & 1 deletion scipy/weave/platform_info.py
Expand Up @@ -103,7 +103,7 @@ def check_sum(file):
except IOError:
bytes = ''
chk_sum = sha256(bytes)
return chk_sum.hexdigest()
return chk_sum.hexdigest()[:96] # truncation needed, see gh-3216


def get_compiler_dir(compiler_name):
Expand Down

0 comments on commit d4f7987

Please sign in to comment.