提交 0899f5e4 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #2447 from carriepl/bug_cop_sections

COp conflict between old section markers and new section markers
...@@ -1062,11 +1062,28 @@ class COp(Op): ...@@ -1062,11 +1062,28 @@ class COp(Op):
with open(func_file, 'r') as f: with open(func_file, 'r') as f:
self.func_codes.append(f.read()) self.func_codes.append(f.read())
# If both the old section markers and the new section markers are
# present, raise an error because we don't know which ones to follow.
old_markers_present = False
new_markers_present = False
for code in self.func_codes:
if self.backward_re.search(code):
old_markers_present = True
if self.section_re.search(code):
new_markers_present = True
if old_markers_present and new_markers_present:
raise ValueError('Both the new and the old syntax for '
'identifying code sections are present in the '
'provided C code. These two syntaxes should not '
'be used at the same time.')
self.code_sections = dict() self.code_sections = dict()
for i, code in enumerate(self.func_codes): for i, code in enumerate(self.func_codes):
if ('THEANO_APPLY_CODE_SECTION' in code or if self.backward_re.search(code):
'THEANO_SUPPORT_CODE_SECTION' in code):
# This is backward compat code that will go away in a while # This is backward compat code that will go away in a while
# Separate the code into the proper sections
split = self.backward_re.split(code) split = self.backward_re.split(code)
n = 1 n = 1
while n < len(split): while n < len(split):
...@@ -1076,11 +1093,17 @@ class COp(Op): ...@@ -1076,11 +1093,17 @@ class COp(Op):
self.code_sections['support_code'] = split[n+1] self.code_sections['support_code'] = split[n+1]
n += 2 n += 2
continue continue
elif self.section_re.search(code):
# Check for code outside of the supported sections
split = self.section_re.split(code) split = self.section_re.split(code)
if split[0].strip() != '': if split[0].strip() != '':
raise ValueError('Stray code before first #section ' raise ValueError('Stray code before first #section '
'statement (in file %s): %s' % 'statement (in file %s): %s' %
(self.func_files[i], split[0])) (self.func_files[i], split[0]))
# Separate the code into the proper sections
n = 1 n = 1
while n < len(split): while n < len(split):
if split[n] not in self.SECTIONS: if split[n] not in self.SECTIONS:
...@@ -1091,6 +1114,10 @@ class COp(Op): ...@@ -1091,6 +1114,10 @@ class COp(Op):
self.code_sections[split[n]] += split[n+1] self.code_sections[split[n]] += split[n+1]
n += 2 n += 2
else:
raise ValueError("No valid section marker was found in file "
"%s" % self.func_files[i])
def c_code_cache_version(self): def c_code_cache_version(self):
return hash(tuple(self.func_codes)) return hash(tuple(self.func_codes))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论